From 327682d07f70a28af6d23e0eca715191ea5cfb03 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 19 Sep 2016 22:43:47 -0300 Subject: [PATCH 1/2] Add support for passing a table to love.mouse.isDown, love.keyboard.isDown, love.keyboard.isScancodeDown, Joystick:isDown, and Joystick:isGamepadDown. --- src/modules/joystick/wrap_Joystick.cpp | 67 +++++++++++++++++++++----- src/modules/keyboard/wrap_Keyboard.cpp | 48 +++++++++++++++--- src/modules/mouse/wrap_Mouse.cpp | 20 ++++++-- 3 files changed, 111 insertions(+), 24 deletions(-) diff --git a/src/modules/joystick/wrap_Joystick.cpp b/src/modules/joystick/wrap_Joystick.cpp index f02df8257..32791d1cc 100644 --- a/src/modules/joystick/wrap_Joystick.cpp +++ b/src/modules/joystick/wrap_Joystick.cpp @@ -105,8 +105,8 @@ int w_Joystick_getAxes(lua_State *L) Joystick *j = luax_checkjoystick(L, 1); std::vector axes = j->getAxes(); - for (size_t i = 0; i < axes.size(); i++) - lua_pushnumber(L, axes[i]); + for (float value : axes) + lua_pushnumber(L, value); return (int) axes.size(); } @@ -129,11 +129,29 @@ int w_Joystick_isDown(lua_State *L) { Joystick *j = luax_checkjoystick(L, 1); - luaL_checkinteger(L, 2); + bool istable = lua_istable(L, 2); + int num = istable ? (int) luax_objlen(L, 2) : (lua_gettop(L) - 1); + + if (num == 0) + luaL_checkinteger(L, 2); std::vector buttons; - for (int i = 2; i <= lua_gettop(L); i++) - buttons.push_back((int) luaL_checknumber(L, i) - 1); + buttons.reserve(num); + + if (istable) + { + for (int i = 0; i < num; i++) + { + lua_rawgeti(L, 2, i + 1); + buttons.push_back((int) luaL_checknumber(L, -1) - 1); + lua_pop(L, 1); + } + } + else + { + for (int i = 0; i < num; i++) + buttons.push_back((int) luaL_checknumber(L, i + 2) - 1); + } luax_pushboolean(L, j->isDown(buttons)); return 1; @@ -164,20 +182,43 @@ int w_Joystick_isGamepadDown(lua_State *L) { Joystick *j = luax_checkjoystick(L, 1); + bool istable = lua_istable(L, 2); + int num = istable ? (int) luax_objlen(L, 2) : (lua_gettop(L) - 1); + + if (num == 0) + luaL_checkstring(L, 2); + std::vector buttons; - buttons.reserve(lua_gettop(L) - 1); + buttons.reserve(num); - luaL_checkstring(L, 2); + Joystick::GamepadButton button; - for (int i = 2; i <= lua_gettop(L); i++) + if (istable) { - const char *str = luaL_checkstring(L, i); - Joystick::GamepadButton button; + for (int i = 0; i < num; i++) + { + lua_rawgeti(L, 2, i + 1); + const char *str = luaL_checkstring(L, -1); - if (!joystick::Joystick::getConstant(str, button)) - return luaL_error(L, "Invalid gamepad button: %s", str); + if (!joystick::Joystick::getConstant(str, button)) + return luaL_error(L, "Invalid gamepad button: %s", str); - buttons.push_back(button); + buttons.push_back(button); + + lua_pop(L, 1); + } + } + else + { + for (int i = 0; i < num; i++) + { + const char *str = luaL_checkstring(L, i + 2); + + if (!joystick::Joystick::getConstant(str, button)) + return luaL_error(L, "Invalid gamepad button: %s", str); + + buttons.push_back(button); + } } luax_pushboolean(L, j->isGamepadDown(buttons)); diff --git a/src/modules/keyboard/wrap_Keyboard.cpp b/src/modules/keyboard/wrap_Keyboard.cpp index 3b5b9ed1f..647905b19 100644 --- a/src/modules/keyboard/wrap_Keyboard.cpp +++ b/src/modules/keyboard/wrap_Keyboard.cpp @@ -46,14 +46,30 @@ int w_hasKeyRepeat(lua_State *L) int w_isDown(lua_State *L) { Keyboard::Key k; - int num = lua_gettop(L); + + bool istable = lua_istable(L, 1); + int num = istable ? (int) luax_objlen(L, 1) : lua_gettop(L); + std::vector keylist; keylist.reserve(num); - for (int i = 0; i < num; i++) + if (istable) { - if (Keyboard::getConstant(luaL_checkstring(L, i+1), k)) - keylist.push_back(k); + for (int i = 0; i < num; i++) + { + lua_rawgeti(L, 1, i + 1); + if (Keyboard::getConstant(luaL_checkstring(L, -1), k)) + keylist.push_back(k); + lua_pop(L, 1); + } + } + else + { + for (int i = 0; i < num; i++) + { + if (Keyboard::getConstant(luaL_checkstring(L, i+1), k)) + keylist.push_back(k); + } } luax_pushboolean(L, instance()->isDown(keylist)); @@ -63,14 +79,30 @@ int w_isDown(lua_State *L) int w_isScancodeDown(lua_State *L) { Keyboard::Scancode scancode; - int num = lua_gettop(L); + + bool istable = lua_istable(L, 1); + int num = istable ? (int) luax_objlen(L, 1) : lua_gettop(L); + std::vector scancodelist; scancodelist.reserve(num); - for (int i = 0; i < num; i++) + if (istable) { - if (Keyboard::getConstant(luaL_checkstring(L, i+1), scancode)) - scancodelist.push_back(scancode); + for (int i = 0; i < num; i++) + { + lua_rawgeti(L, 1, i + 1); + if (Keyboard::getConstant(luaL_checkstring(L, -1), scancode)) + scancodelist.push_back(scancode); + lua_pop(L, 1); + } + } + else + { + for (int i = 0; i < num; i++) + { + if (Keyboard::getConstant(luaL_checkstring(L, i+1), scancode)) + scancodelist.push_back(scancode); + } } luax_pushboolean(L, instance()->isScancodeDown(scancodelist)); diff --git a/src/modules/mouse/wrap_Mouse.cpp b/src/modules/mouse/wrap_Mouse.cpp index 2d7f7dc21..90b8892a6 100644 --- a/src/modules/mouse/wrap_Mouse.cpp +++ b/src/modules/mouse/wrap_Mouse.cpp @@ -142,12 +142,26 @@ int w_setPosition(lua_State *L) int w_isDown(lua_State *L) { - int num = lua_gettop(L); + bool istable = lua_istable(L, 1); + int num = istable ? (int) luax_objlen(L, 1) : lua_gettop(L); + std::vector buttons; buttons.reserve(num); - for (int i = 0; i < num; i++) - buttons.push_back((int) luaL_checknumber(L, i + 1)); + if (istable) + { + for (int i = 0; i < num; i++) + { + lua_rawgeti(L, 1, i + 1); + buttons.push_back((int) luaL_checknumber(L, -1)); + lua_pop(L, 1); + } + } + else + { + for (int i = 0; i < num; i++) + buttons.push_back((int) luaL_checknumber(L, i + 1)); + } luax_pushboolean(L, instance()->isDown(buttons)); return 1; From 304ccec71c86446707383fb9a490ff1d504bb85c Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 27 Sep 2016 23:12:33 -0300 Subject: [PATCH 2/2] Updated the changelog --- changes.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/changes.txt b/changes.txt index d63a92966..3a82e87ab 100644 --- a/changes.txt +++ b/changes.txt @@ -4,32 +4,45 @@ LOVE 0.10.2 [Super Toast] Released: N/A * Added lovec.exe in Windows. It is the same as love.exe but built with the Console subsystem, so it always uses or provides a console. + * Added the ability to restart the game via love.event.quit("restart"). + * Added support for passing a table to love.mouse.isDown, love.keyboard.isDown, love.keyboard.isScancodeDown, Joystick:isDown, and Joystick:isGamepadDown. * Added 'shaderswitches' field to the table returned by love.graphics.getStats. * Added Quad:getTextureDimensions. * Added PrismaticJoint:getAxis and WheelJoint:getAxis. * Added 2-point version of love.physics.newRevoluteJoint. * Added table variants of Fixture:setCategory and Fixture:setMask. * Added getNextVertex and getPreviousVertex to ChainShape and EdgeShape. + * Added optional reference angle arguments to RevoluteJoint, PrismaticJoint, and WeldJoint constructors. + * Added RevoluteJoint:getReferenceAngle, PrismaticJoint:getReferenceAngle, and WeldJoint:getReferenceAngle. + + * Deprecated Shader:sendTexture, Shader:sendMatrix, Shader:sendInt, and Shader:sendFloat. * Fixed love on iOS 6. * Fixed os.execute always returning -1 on Linux. + * Fixed the love.lowmemory callback to call collectgarbage() after the callback has fired, instead of before. * Fixed a hang at the end of video playback with some video files. * Fixed the video decoding thread to not do any work when there are no videos to decode. + * Fixed love.graphics.newVideo(file) to no longer error if love.audio is disabled. * Fixed a rare bug in Source:play for streaming Sources if the associated OpenAL source object was previously used for a static Source. * Fixed corrupted Font glyphs in rare cases. * Fixed stencils inside Canvases on some OpenGL ES 2 devices. + * Fixed an OpenGL error in OpenGL ES 3 when multiple render targets are used. * Fixed love.window.setMode crashing when called with a Canvas active. * Fixed gamma correction of ImageFonts and BMFonts with colored images. * Fixed the default shader improperly applying gamma correction to per-vertex colors when gamma correction is requested but not supported on OpenGL ES. * Fixed text coloring breaking because of an empty string. * Fixed large burst of particles when dramatically increasing the emission rate of a ParticleSystem. + * Fixed SpriteBatch:setBufferSize to keep old sprite data if it can fit. * Fixed MouseJoint:getBodies unconditionally erroring. * Fixed memory leak in Text:set. * Fixed incorrect kerning caused by using kerning information for the wrong character in some fonts. * 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. LOVE 0.10.1 [Super Toast]