From 0b4b1db9fe9ddafb1c93d5f7338cc78243736a4e Mon Sep 17 00:00:00 2001 From: Er2 Date: Sat, 20 Aug 2022 10:44:34 +0300 Subject: [PATCH 1/9] SDL 2.24.0 support --- src/modules/joystick/Joystick.h | 4 ++++ src/modules/joystick/sdl/Joystick.cpp | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/modules/joystick/Joystick.h b/src/modules/joystick/Joystick.h index 4ca9d26e2..40002b460 100644 --- a/src/modules/joystick/Joystick.h +++ b/src/modules/joystick/Joystick.h @@ -68,6 +68,10 @@ public: GAMEPAD_TYPE_AMAZON_LUNA, GAMEPAD_TYPE_STADIA, GAMEPAD_TYPE_VIRTUAL, + GAMEPAD_TYPE_NVIDIA_SHIELD, + GAMEPAD_TYPE_JOYCON_LEFT, + GAMEPAD_TYPE_JOYCON_RIGHT, + GAMEPAD_TYPE_JOYCON_PAIR, GAMEPAD_TYPE_MAX_ENUM }; diff --git a/src/modules/joystick/sdl/Joystick.cpp b/src/modules/joystick/sdl/Joystick.cpp index 3a43f7190..db8b47e2c 100644 --- a/src/modules/joystick/sdl/Joystick.cpp +++ b/src/modules/joystick/sdl/Joystick.cpp @@ -260,6 +260,12 @@ Joystick::GamepadType Joystick::getGamepadType() const #if SDL_VERSION_ATLEAST(2, 0, 16) case SDL_CONTROLLER_TYPE_AMAZON_LUNA: return GAMEPAD_TYPE_AMAZON_LUNA; case SDL_CONTROLLER_TYPE_GOOGLE_STADIA: return GAMEPAD_TYPE_STADIA; +#endif +#if SDL_VERSION_ATLEAST(2, 24, 0) + case SDL_CONTROLLER_TYPE_NVIDIA_SHIELD: return GAMEPAD_TYPE_NVIDIA_SHIELD; + case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT: return GAMEPAD_TYPE_JOYCON_LEFT; + case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT: return GAMEPAD_TYPE_JOYCON_RIGHT; + case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR: return GAMEPAD_TYPE_JOYCON_PAIR; #endif } #endif @@ -509,7 +515,7 @@ bool Joystick::setVibration(float left, float right, float duration) Uint32 length = SDL_HAPTIC_INFINITY; if (duration >= 0.0f) { - float maxduration = std::numeric_limits::max() / 1000.0f; + float maxduration = std::numeric_limits::max() / 1000; length = Uint32(std::min(duration, maxduration) * 1000); } From 7c9d6d569464a321e536295c1775deba022f19ba Mon Sep 17 00:00:00 2001 From: Er2 Date: Sat, 20 Aug 2022 10:51:39 +0300 Subject: [PATCH 2/9] add Lua string for new controllers --- src/modules/joystick/Joystick.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/modules/joystick/Joystick.cpp b/src/modules/joystick/Joystick.cpp index 1a3172dd4..7bb9bf060 100644 --- a/src/modules/joystick/Joystick.cpp +++ b/src/modules/joystick/Joystick.cpp @@ -58,16 +58,20 @@ STRINGMAP_CLASS_END(Joystick, Joystick::Hat, Joystick::HAT_MAX_ENUM, hat) STRINGMAP_CLASS_BEGIN(Joystick, Joystick::GamepadType, Joystick::GAMEPAD_TYPE_MAX_ENUM, gamepadType) { - { "unknown", Joystick::GAMEPAD_TYPE_UNKNOWN }, - { "xbox360", Joystick::GAMEPAD_TYPE_XBOX360 }, - { "xboxone", Joystick::GAMEPAD_TYPE_XBOXONE }, - { "ps3", Joystick::GAMEPAD_TYPE_PS3 }, - { "ps4", Joystick::GAMEPAD_TYPE_PS4 }, - { "ps5", Joystick::GAMEPAD_TYPE_PS5 }, - { "switchpro", Joystick::GAMEPAD_TYPE_NINTENDO_SWITCH_PRO }, - { "amazonluna", Joystick::GAMEPAD_TYPE_AMAZON_LUNA }, - { "stadia", Joystick::GAMEPAD_TYPE_STADIA }, - { "virtual", Joystick::GAMEPAD_TYPE_VIRTUAL }, + { "unknown", Joystick::GAMEPAD_TYPE_UNKNOWN }, + { "xbox360", Joystick::GAMEPAD_TYPE_XBOX360 }, + { "xboxone", Joystick::GAMEPAD_TYPE_XBOXONE }, + { "ps3", Joystick::GAMEPAD_TYPE_PS3 }, + { "ps4", Joystick::GAMEPAD_TYPE_PS4 }, + { "ps5", Joystick::GAMEPAD_TYPE_PS5 }, + { "switchpro", Joystick::GAMEPAD_TYPE_NINTENDO_SWITCH_PRO }, + { "amazonluna", Joystick::GAMEPAD_TYPE_AMAZON_LUNA }, + { "stadia", Joystick::GAMEPAD_TYPE_STADIA }, + { "virtual", Joystick::GAMEPAD_TYPE_VIRTUAL }, + { "shield", Joystick::GAMEPAD_TYPE_NVIDIA_SHIELD }, + { "joycon_left", Joystick::GAMEPAD_TYPE_JOYCON_LEFT }, + { "joycon_right", Joystick::GAMEPAD_TYPE_JOYCON_RIGHT }, + { "joycon_pair", Joystick::GAMEPAD_TYPE_JOYCON_PAIR }, } STRINGMAP_CLASS_END(Joystick, Joystick::GamepadType, Joystick::GAMEPAD_TYPE_MAX_ENUM, gamepadType) From 53b20b134196eb4cc3c56092b4bd3390a85f2c8b Mon Sep 17 00:00:00 2001 From: Er2 Date: Sat, 20 Aug 2022 18:30:32 +0300 Subject: [PATCH 3/9] some fixes Fixed duration and love naming conventions. --- src/modules/joystick/Joystick.cpp | 6 +++--- src/modules/joystick/sdl/Joystick.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/joystick/Joystick.cpp b/src/modules/joystick/Joystick.cpp index 7bb9bf060..7fec99840 100644 --- a/src/modules/joystick/Joystick.cpp +++ b/src/modules/joystick/Joystick.cpp @@ -69,9 +69,9 @@ STRINGMAP_CLASS_BEGIN(Joystick, Joystick::GamepadType, Joystick::GAMEPAD_TYPE_MA { "stadia", Joystick::GAMEPAD_TYPE_STADIA }, { "virtual", Joystick::GAMEPAD_TYPE_VIRTUAL }, { "shield", Joystick::GAMEPAD_TYPE_NVIDIA_SHIELD }, - { "joycon_left", Joystick::GAMEPAD_TYPE_JOYCON_LEFT }, - { "joycon_right", Joystick::GAMEPAD_TYPE_JOYCON_RIGHT }, - { "joycon_pair", Joystick::GAMEPAD_TYPE_JOYCON_PAIR }, + { "joyconleft", Joystick::GAMEPAD_TYPE_JOYCON_LEFT }, + { "joyconright", Joystick::GAMEPAD_TYPE_JOYCON_RIGHT }, + { "joyconpair", Joystick::GAMEPAD_TYPE_JOYCON_PAIR }, } STRINGMAP_CLASS_END(Joystick, Joystick::GamepadType, Joystick::GAMEPAD_TYPE_MAX_ENUM, gamepadType) diff --git a/src/modules/joystick/sdl/Joystick.cpp b/src/modules/joystick/sdl/Joystick.cpp index db8b47e2c..482a4b48a 100644 --- a/src/modules/joystick/sdl/Joystick.cpp +++ b/src/modules/joystick/sdl/Joystick.cpp @@ -515,7 +515,7 @@ bool Joystick::setVibration(float left, float right, float duration) Uint32 length = SDL_HAPTIC_INFINITY; if (duration >= 0.0f) { - float maxduration = std::numeric_limits::max() / 1000; + float maxduration = (float) (std::numeric_limits::max() / 1000.0); length = Uint32(std::min(duration, maxduration) * 1000); } From 96820749adec1c9af4c4b7f85a16851ef9f3c021 Mon Sep 17 00:00:00 2001 From: slime Date: Thu, 25 Aug 2022 18:17:31 -0300 Subject: [PATCH 4/9] Potential optimization for built-in uniform access in shader code. Assigning to and accessing extra shader variables can increase VGPR / wave-variant register usage in shaders, which is often a limiting factor for performance in non-trivial shaders. Accessing the uniforms directly should bypass that. --- src/modules/graphics/Shader.cpp | 57 ++++++--------------------------- 1 file changed, 10 insertions(+), 47 deletions(-) diff --git a/src/modules/graphics/Shader.cpp b/src/modules/graphics/Shader.cpp index 17a7bb463..96c095b42 100644 --- a/src/modules/graphics/Shader.cpp +++ b/src/modules/graphics/Shader.cpp @@ -91,53 +91,23 @@ static const char render_uniforms[] = R"( // We *really* don't want to use mediump for these in vertex shaders though. uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw[13]; -// These are initialized in love_initializeBuiltinUniforms below. GLSL ES can't -// do it as an initializer. -LOVE_HIGHP_OR_MEDIUMP mat4 TransformMatrix; -LOVE_HIGHP_OR_MEDIUMP mat4 ProjectionMatrix; -LOVE_HIGHP_OR_MEDIUMP mat3 NormalMatrix; - -LOVE_HIGHP_OR_MEDIUMP vec4 love_ScreenSize; -LOVE_HIGHP_OR_MEDIUMP vec4 ConstantColor; - -LOVE_HIGHP_OR_MEDIUMP float CurrentDPIScale; - -LOVE_HIGHP_OR_MEDIUMP float ConstantPointSize; - +// Older GLSL doesn't support preprocessor line continuations... +#define TransformMatrix mat4(love_UniformsPerDraw[0], love_UniformsPerDraw[1], love_UniformsPerDraw[2], love_UniformsPerDraw[3]) +#define ProjectionMatrix mat4(love_UniformsPerDraw[4], love_UniformsPerDraw[5], love_UniformsPerDraw[6], love_UniformsPerDraw[7]) #define TransformProjectionMatrix (ProjectionMatrix * TransformMatrix) +#define NormalMatrix mat3(love_UniformsPerDraw[8].xyz, love_UniformsPerDraw[9].xyz, love_UniformsPerDraw[10].xyz) + +#define CurrentDPIScale (love_UniformsPerDraw[8].w) +#define ConstantPointSize (love_UniformsPerDraw[9].w) +#define ConstantColor (love_UniformsPerDraw[12]) +#define love_ScreenSize (love_UniformsPerDraw[11]) + // Alternate names #define ViewSpaceFromLocal TransformMatrix #define ClipSpaceFromView ProjectionMatrix #define ClipSpaceFromLocal TransformProjectionMatrix #define ViewNormalFromLocal NormalMatrix - -void love_initializeBuiltinUniforms() { - TransformMatrix = mat4( - love_UniformsPerDraw[0], - love_UniformsPerDraw[1], - love_UniformsPerDraw[2], - love_UniformsPerDraw[3] - ); - - ProjectionMatrix = mat4( - love_UniformsPerDraw[4], - love_UniformsPerDraw[5], - love_UniformsPerDraw[6], - love_UniformsPerDraw[7] - ); - - NormalMatrix = mat3( - love_UniformsPerDraw[8].xyz, - love_UniformsPerDraw[9].xyz, - love_UniformsPerDraw[10].xyz - ); - - CurrentDPIScale = love_UniformsPerDraw[8].w; - ConstantPointSize = love_UniformsPerDraw[9].w; - love_ScreenSize = love_UniformsPerDraw[11]; - ConstantColor = love_UniformsPerDraw[12]; -} )"; static const char global_functions[] = R"( @@ -274,7 +244,6 @@ varying vec4 VaryingColor; vec4 position(mat4 clipSpaceFromLocal, vec4 localPosition); void main() { - love_initializeBuiltinUniforms(); VaryingTexCoord = VertexTexCoord; VaryingColor = gammaCorrectColor(VertexColor) * ConstantColor; love_Position = position(ClipSpaceFromLocal, VertexPosition); @@ -285,7 +254,6 @@ static const char vertex_main_raw[] = R"( void vertexmain(); void main() { - love_initializeBuiltinUniforms(); vertexmain(); } )"; @@ -344,7 +312,6 @@ varying mediump vec4 VaryingColor; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord); void main() { - love_initializeBuiltinUniforms(); love_PixelColor = effect(VaryingColor, MainTex, VaryingTexCoord.st, love_PixelCoord); } )"; @@ -380,7 +347,6 @@ varying mediump vec4 VaryingColor; void effect(); void main() { - love_initializeBuiltinUniforms(); effect(); } )"; @@ -389,7 +355,6 @@ static const char pixel_main_raw[] = R"( void pixelmain(); void main() { - love_initializeBuiltinUniforms(); pixelmain(); } )"; @@ -404,7 +369,6 @@ static const char compute_header[] = R"( )"; static const char compute_uniforms[] = R"( -void love_initializeBuiltinUniforms() {} )"; static const char compute_functions[] = R"()"; @@ -413,7 +377,6 @@ static const char compute_main[] = R"( void computemain(); void main() { - love_initializeBuiltinUniforms(); computemain(); } )"; From db1bf4707cb6a9c803c6c69bb92db469df541237 Mon Sep 17 00:00:00 2001 From: slime Date: Thu, 25 Aug 2022 19:25:01 -0300 Subject: [PATCH 5/9] Workaround for built-in shaders on some ES2 devices which don't support highp in pixel shaders. --- src/modules/graphics/Shader.cpp | 30 ++++++++++++++++++++------ src/modules/graphics/Shader.h | 5 ++++- src/modules/graphics/opengl/Shader.cpp | 30 +++++++++++++++++++++++--- src/modules/graphics/opengl/Shader.h | 2 ++ 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/modules/graphics/Shader.cpp b/src/modules/graphics/Shader.cpp index 96c095b42..ee580cd53 100644 --- a/src/modules/graphics/Shader.cpp +++ b/src/modules/graphics/Shader.cpp @@ -89,7 +89,12 @@ static const char render_uniforms[] = R"( // According to the GLSL ES 1.0 spec, uniform precision must match between stages, // but we can't guarantee that highp is always supported in fragment shaders... // We *really* don't want to use mediump for these in vertex shaders though. +#ifdef LOVE_SPLIT_UNIFORMS_PER_DRAW +uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw[12]; +uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw2[1]; +#else uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw[13]; +#endif // Older GLSL doesn't support preprocessor line continuations... #define TransformMatrix mat4(love_UniformsPerDraw[0], love_UniformsPerDraw[1], love_UniformsPerDraw[2], love_UniformsPerDraw[3]) @@ -100,8 +105,13 @@ uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw[13]; #define CurrentDPIScale (love_UniformsPerDraw[8].w) #define ConstantPointSize (love_UniformsPerDraw[9].w) -#define ConstantColor (love_UniformsPerDraw[12]) -#define love_ScreenSize (love_UniformsPerDraw[11]) +#define ConstantColor (love_UniformsPerDraw[11]) + +#ifdef LOVE_SPLIT_UNIFORMS_PER_DRAW +#define love_ScreenSize (love_UniformsPerDraw2[0]) +#else +#define love_ScreenSize (love_UniformsPerDraw[12]) +#endif // Alternate names #define ViewSpaceFromLocal TransformMatrix @@ -538,6 +548,11 @@ std::string Shader::createShaderStageCode(Graphics *gfx, ShaderStageType stage, if (info.usesMRT) ss << "#define LOVE_MULTI_RENDER_TARGETS 1\n"; + // Note: backends are expected to handle this situation if highp is ever + // conditional in that backend. + if (!gfx->getCapabilities().features[Graphics::FEATURE_PIXEL_SHADER_HIGHP]) + ss << "#define LOVE_SPLIT_UNIFORMS_PER_DRAW 1"; + for (const auto &def : options.defines) ss << "#define " + def.first + " " + def.second + "\n"; @@ -1164,11 +1179,12 @@ static StringMap languages(language static StringMap::Entry builtinNameEntries[] = { - { "MainTex", Shader::BUILTIN_TEXTURE_MAIN }, - { "love_VideoYChannel", Shader::BUILTIN_TEXTURE_VIDEO_Y }, - { "love_VideoCbChannel", Shader::BUILTIN_TEXTURE_VIDEO_CB }, - { "love_VideoCrChannel", Shader::BUILTIN_TEXTURE_VIDEO_CR }, - { "love_UniformsPerDraw", Shader::BUILTIN_UNIFORMS_PER_DRAW }, + { "MainTex", Shader::BUILTIN_TEXTURE_MAIN }, + { "love_VideoYChannel", Shader::BUILTIN_TEXTURE_VIDEO_Y }, + { "love_VideoCbChannel", Shader::BUILTIN_TEXTURE_VIDEO_CB }, + { "love_VideoCrChannel", Shader::BUILTIN_TEXTURE_VIDEO_CR }, + { "love_UniformsPerDraw", Shader::BUILTIN_UNIFORMS_PER_DRAW }, + { "love_UniformsPerDraw2", Shader::BUILTIN_UNIFORMS_PER_DRAW_2 }, }; static StringMap builtinNames(builtinNameEntries, sizeof(builtinNameEntries)); diff --git a/src/modules/graphics/Shader.h b/src/modules/graphics/Shader.h index 862e9f268..579ca3a10 100644 --- a/src/modules/graphics/Shader.h +++ b/src/modules/graphics/Shader.h @@ -64,6 +64,7 @@ public: BUILTIN_TEXTURE_VIDEO_CB, BUILTIN_TEXTURE_VIDEO_CR, BUILTIN_UNIFORMS_PER_DRAW, + BUILTIN_UNIFORMS_PER_DRAW_2, BUILTIN_MAX_ENUM }; @@ -176,8 +177,10 @@ public: Matrix4 transformMatrix; Matrix4 projectionMatrix; Vector4 normalMatrix[3]; // 3x3 matrix padded to an array of 3 vector4s. - Vector4 screenSizeParams; Colorf constantColor; + + // Pixel shader-centric variables past this point. + Vector4 screenSizeParams; }; // Pointer to currently active Shader. diff --git a/src/modules/graphics/opengl/Shader.cpp b/src/modules/graphics/opengl/Shader.cpp index bdcc4d8ab..ee75d0c8c 100644 --- a/src/modules/graphics/opengl/Shader.cpp +++ b/src/modules/graphics/opengl/Shader.cpp @@ -46,6 +46,7 @@ static bool isBuffer(Shader::UniformType utype) Shader::Shader(StrongRef stages[SHADERSTAGE_MAX_ENUM]) : love::graphics::Shader(stages) , program(0) + , splitUniformsPerDraw(false) , builtinUniforms() , builtinUniformInfo() { @@ -486,6 +487,11 @@ bool Shader::loadVolatile() { OpenGL::TempDebugGroup debuggroup("Shader load"); + // love::graphics::Shader sets up the shader code-side of this. + auto gfx = Module::getInstance(Module::M_GRAPHICS); + if (gfx != nullptr) + splitUniformsPerDraw = gfx->getCapabilities().features[Graphics::FEATURE_PIXEL_SHADER_HIGHP]; + // zero out active texture list textureUnits.clear(); textureUnits.push_back(TextureUnit()); @@ -1014,9 +1020,27 @@ void Shader::updateBuiltinUniforms(love::graphics::Graphics *gfx, int viewportW, data.constantColor = gfx->getColor(); gammaCorrectColor(data.constantColor); - GLint location = builtinUniforms[BUILTIN_UNIFORMS_PER_DRAW]; - if (location >= 0) - glUniform4fv(location, 13, (const GLfloat *) &data); + // This branch is to avoid always declaring the whole array as highp in the + // vertex shader and mediump in the pixel shader for love's default shaders, + // on systems that don't support highp in pixel shaders. The default shaders + // use the transform matrices in vertex shaders and screen size params in + // pixel shaders. If there's a single array containing both and each shader + // stage declares a different precision, that's a compile error. + if (splitUniformsPerDraw) + { + GLint location = builtinUniforms[BUILTIN_UNIFORMS_PER_DRAW]; + if (location >= 0) + glUniform4fv(location, 12, (const GLfloat *) &data); + GLint location2 = builtinUniforms[BUILTIN_UNIFORMS_PER_DRAW_2]; + if (location2 >= 0) + glUniform4fv(location2, 1, (const GLfloat *) &data.screenSizeParams); + } + else + { + GLint location = builtinUniforms[BUILTIN_UNIFORMS_PER_DRAW]; + if (location >= 0) + glUniform4fv(location, 13, (const GLfloat *) &data); + } } int Shader::getUniformTypeComponents(GLenum type) const diff --git a/src/modules/graphics/opengl/Shader.h b/src/modules/graphics/opengl/Shader.h index 40545a2a2..12ae79ae6 100644 --- a/src/modules/graphics/opengl/Shader.h +++ b/src/modules/graphics/opengl/Shader.h @@ -112,6 +112,8 @@ private: // volatile GLuint program; + bool splitUniformsPerDraw; + // Location values for any built-in uniform variables. GLint builtinUniforms[BUILTIN_MAX_ENUM]; UniformInfo *builtinUniformInfo[BUILTIN_MAX_ENUM]; From bded15ff2a67cda2cbf01669d0264d028a6d563a Mon Sep 17 00:00:00 2001 From: slime Date: Thu, 25 Aug 2022 19:44:10 -0300 Subject: [PATCH 6/9] Decoders failing to allocate their buffer will cause a Lua error instead of crashing. --- src/modules/sound/Decoder.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/sound/Decoder.cpp b/src/modules/sound/Decoder.cpp index 355b783c9..9b8923db6 100644 --- a/src/modules/sound/Decoder.cpp +++ b/src/modules/sound/Decoder.cpp @@ -39,7 +39,14 @@ Decoder::Decoder(Stream *stream, int bufferSize) if (!stream->isReadable() || !stream->isSeekable()) throw love::Exception("Decoder input stream must be readable and seekable."); - buffer = new char[bufferSize]; + try + { + buffer = new char[bufferSize]; + } + catch (std::exception &) + { + throw love::Exception("Out of memory."); + } } Decoder::~Decoder() From 03939299dbf4de6d6a48230a8dc17932e0d3d2d1 Mon Sep 17 00:00:00 2001 From: Klonan <11986037+Klonan@users.noreply.github.com> Date: Sat, 27 Aug 2022 17:12:19 +0200 Subject: [PATCH 7/9] Added World:getFixturesInArea() --- changes.txt | 5 ++-- src/modules/physics/box2d/World.cpp | 36 ++++++++++++++++++++++++ src/modules/physics/box2d/World.h | 20 ++++++++++++- src/modules/physics/box2d/wrap_World.cpp | 10 +++++++ 4 files changed, 68 insertions(+), 3 deletions(-) diff --git a/changes.txt b/changes.txt index 2b98cbc6e..d5a383905 100644 --- a/changes.txt +++ b/changes.txt @@ -45,6 +45,7 @@ Released: N/A * Added love.keyboard.isModifierActive. * Added love.system.getPreferredLocales. * Added love.localechanged callback. +* Added World:getFixturesInArea(). * Changed the default font from Vera size 12 to Noto Sans size 13. * Changed the Texture class and implementation to no longer have separate Canvas and Image subclasses. @@ -165,7 +166,7 @@ Released: 2019-10-27 * Fixed audio clicks immediately after playing a Source on iOS. * Fixed Source:play + Source:stop + Source:play looping the first few ms of sound for streaming Sources on iOS. * Fixed Source:play + Source:seek looping the first few ms of sound for streaming Sources on iOS. -* Fixed occasional pops in streaming sources on iOS. +* Fixed occasional pops in streaming sources on iOS. * Fixed love.audio.play(sources) to use previously set playback positions on stopped Sources. * Fixed Source:setEffect(name, true) and Source:getEffect(name) when the effect has no associated Filter. * Fixed love.audio.newSource(filename, "queue") to cause a Lua error. @@ -437,7 +438,7 @@ Released: 2016-10-31 * Improved performance of Channel methods by roughly 2x in many cases. * Improved performance of Shader:send when small numbers of arguments are given. - + * Updated love.filesystem.mount to accept a DroppedFile as the first parameter. * Updated Shader:send to do type and argument checking based on the specified uniform variable's information instead of the arguments to the function. * Updated Shader:send to accept a flat table for matrix uniforms. diff --git a/src/modules/physics/box2d/World.cpp b/src/modules/physics/box2d/World.cpp index d7ba8d11d..a5bc8c8cf 100644 --- a/src/modules/physics/box2d/World.cpp +++ b/src/modules/physics/box2d/World.cpp @@ -171,6 +171,28 @@ bool World::QueryCallback::ReportFixture(b2Fixture *fixture) return true; } +World::CollectCallback::CollectCallback(World *world, lua_State *L) + : world(world) + , L(L) +{ + lua_newtable(L); +} + +World::CollectCallback::~CollectCallback() +{ +} + +bool World::CollectCallback::ReportFixture(b2Fixture *f) +{ + Fixture* fixture = (Fixture*)world->findObject(f); + if (!fixture) + throw love::Exception("A fixture has escaped Memoizer!"); + luax_pushtype(L, fixture); + lua_rawseti(L, -2, i); + i++; + return true; +} + World::RayCastCallback::RayCastCallback(World *world, lua_State *L, int idx) : world(world) , L(L) @@ -556,6 +578,20 @@ int World::queryBoundingBox(lua_State *L) return 0; } +int World::getFixturesInArea(lua_State *L) +{ + float lx = (float)luaL_checknumber(L, 1); + float ly = (float)luaL_checknumber(L, 2); + float ux = (float)luaL_checknumber(L, 3); + float uy = (float)luaL_checknumber(L, 4); + b2AABB box; + box.lowerBound = Physics::scaleDown(b2Vec2(lx, ly)); + box.upperBound = Physics::scaleDown(b2Vec2(ux, uy)); + CollectCallback query(this, L); + world->QueryAABB(&query, box); + return 1; +} + int World::rayCast(lua_State *L) { float x1 = (float)luaL_checknumber(L, 1); diff --git a/src/modules/physics/box2d/World.h b/src/modules/physics/box2d/World.h index 39bfe0333..247bea463 100644 --- a/src/modules/physics/box2d/World.h +++ b/src/modules/physics/box2d/World.h @@ -102,6 +102,18 @@ public: int funcidx; }; + class CollectCallback : public b2QueryCallback + { + public: + CollectCallback(World *world, lua_State *L); + ~CollectCallback(); + virtual bool ReportFixture(b2Fixture *fixture); + private: + World *world; + lua_State *L; + int i = 1; + }; + class RayCastCallback : public b2RayCastCallback { public: @@ -270,10 +282,16 @@ public: b2Body *getGroundBody() const; /** - * Gets all fixtures that overlap a given bounding box. + * Calls a callback on all fixtures that overlap a given bounding box. **/ int queryBoundingBox(lua_State *L); + /** + * Gets all fixtures that overlap a given bounding box. + **/ + int getFixturesInArea(lua_State *L); + + /** * Raycasts the World for all Fixtures in the path of the ray. **/ diff --git a/src/modules/physics/box2d/wrap_World.cpp b/src/modules/physics/box2d/wrap_World.cpp index 6b3e13a48..676e6bfda 100644 --- a/src/modules/physics/box2d/wrap_World.cpp +++ b/src/modules/physics/box2d/wrap_World.cpp @@ -185,6 +185,15 @@ int w_World_queryBoundingBox(lua_State *L) return t->queryBoundingBox(L); } +int w_World_getFixturesInArea(lua_State *L) +{ + World *t = luax_checkworld(L, 1); + lua_remove(L, 1); + int ret = 0; + luax_catchexcept(L, [&](){ ret = t->getFixturesInArea(L); }); + return ret; +} + int w_World_rayCast(lua_State *L) { World *t = luax_checkworld(L, 1); @@ -228,6 +237,7 @@ static const luaL_Reg w_World_functions[] = { "getJoints", w_World_getJoints }, { "getContacts", w_World_getContacts }, { "queryBoundingBox", w_World_queryBoundingBox }, + { "getFixturesInArea", w_World_getFixturesInArea }, { "rayCast", w_World_rayCast }, { "destroy", w_World_destroy }, { "isDestroyed", w_World_isDestroyed }, From 4e81a31cd1dd820daeac009a34fad19d3f07daf2 Mon Sep 17 00:00:00 2001 From: Klonan <11986037+Klonan@users.noreply.github.com> Date: Sat, 27 Aug 2022 17:35:41 +0200 Subject: [PATCH 8/9] Code style (tabs) --- src/modules/physics/box2d/World.cpp | 38 ++++++++++++------------ src/modules/physics/box2d/World.h | 20 ++++++------- src/modules/physics/box2d/wrap_World.cpp | 6 ++-- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/modules/physics/box2d/World.cpp b/src/modules/physics/box2d/World.cpp index a5bc8c8cf..598918d86 100644 --- a/src/modules/physics/box2d/World.cpp +++ b/src/modules/physics/box2d/World.cpp @@ -172,10 +172,10 @@ bool World::QueryCallback::ReportFixture(b2Fixture *fixture) } World::CollectCallback::CollectCallback(World *world, lua_State *L) - : world(world) - , L(L) + : world(world) + , L(L) { - lua_newtable(L); + lua_newtable(L); } World::CollectCallback::~CollectCallback() @@ -184,13 +184,13 @@ World::CollectCallback::~CollectCallback() bool World::CollectCallback::ReportFixture(b2Fixture *f) { - Fixture* fixture = (Fixture*)world->findObject(f); - if (!fixture) - throw love::Exception("A fixture has escaped Memoizer!"); - luax_pushtype(L, fixture); - lua_rawseti(L, -2, i); - i++; - return true; + Fixture *fixture = (Fixture *)world->findObject(f); + if (!fixture) + throw love::Exception("A fixture has escaped Memoizer!"); + luax_pushtype(L, fixture); + lua_rawseti(L, -2, i); + i++; + return true; } World::RayCastCallback::RayCastCallback(World *world, lua_State *L, int idx) @@ -580,16 +580,16 @@ int World::queryBoundingBox(lua_State *L) int World::getFixturesInArea(lua_State *L) { - float lx = (float)luaL_checknumber(L, 1); - float ly = (float)luaL_checknumber(L, 2); - float ux = (float)luaL_checknumber(L, 3); - float uy = (float)luaL_checknumber(L, 4); + float lx = (float)luaL_checknumber(L, 1); + float ly = (float)luaL_checknumber(L, 2); + float ux = (float)luaL_checknumber(L, 3); + float uy = (float)luaL_checknumber(L, 4); b2AABB box; - box.lowerBound = Physics::scaleDown(b2Vec2(lx, ly)); - box.upperBound = Physics::scaleDown(b2Vec2(ux, uy)); - CollectCallback query(this, L); - world->QueryAABB(&query, box); - return 1; + box.lowerBound = Physics::scaleDown(b2Vec2(lx, ly)); + box.upperBound = Physics::scaleDown(b2Vec2(ux, uy)); + CollectCallback query(this, L); + world->QueryAABB(&query, box); + return 1; } int World::rayCast(lua_State *L) diff --git a/src/modules/physics/box2d/World.h b/src/modules/physics/box2d/World.h index 247bea463..22ec4fe84 100644 --- a/src/modules/physics/box2d/World.h +++ b/src/modules/physics/box2d/World.h @@ -102,17 +102,17 @@ public: int funcidx; }; - class CollectCallback : public b2QueryCallback - { - public: - CollectCallback(World *world, lua_State *L); - ~CollectCallback(); - virtual bool ReportFixture(b2Fixture *fixture); - private: - World *world; + class CollectCallback : public b2QueryCallback + { + public: + CollectCallback(World *world, lua_State *L); + ~CollectCallback(); + virtual bool ReportFixture(b2Fixture *fixture); + private: + World *world; lua_State *L; - int i = 1; - }; + int i = 1; + }; class RayCastCallback : public b2RayCastCallback { diff --git a/src/modules/physics/box2d/wrap_World.cpp b/src/modules/physics/box2d/wrap_World.cpp index 676e6bfda..e5dbae297 100644 --- a/src/modules/physics/box2d/wrap_World.cpp +++ b/src/modules/physics/box2d/wrap_World.cpp @@ -188,9 +188,9 @@ int w_World_queryBoundingBox(lua_State *L) int w_World_getFixturesInArea(lua_State *L) { World *t = luax_checkworld(L, 1); - lua_remove(L, 1); - int ret = 0; - luax_catchexcept(L, [&](){ ret = t->getFixturesInArea(L); }); + lua_remove(L, 1); + int ret = 0; + luax_catchexcept(L, [&](){ ret = t->getFixturesInArea(L); }); return ret; } From 7595bc7edb2a51631ecd289b982b476839a71859 Mon Sep 17 00:00:00 2001 From: Klonan <11986037+Klonan@users.noreply.github.com> Date: Sat, 27 Aug 2022 17:37:30 +0200 Subject: [PATCH 9/9] whitespace micro --- src/modules/physics/box2d/World.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/physics/box2d/World.h b/src/modules/physics/box2d/World.h index 22ec4fe84..a2d48f8ce 100644 --- a/src/modules/physics/box2d/World.h +++ b/src/modules/physics/box2d/World.h @@ -291,7 +291,6 @@ public: **/ int getFixturesInArea(lua_State *L); - /** * Raycasts the World for all Fixtures in the path of the ray. **/