Added new flag t.accelerometerjoystick to love.conf (true by default.) When set to false on mobile, the device's accelerometer will not show up as a joystick even if the joystick module is loaded.

This can reduce CPU usage if you don't use the accelerometer but you don't want to disable the joystick module entirely.
This commit is contained in:
Alex Szpakowski
2015-03-07 15:36:53 -04:00
parent 7e99ea6839
commit afcad4defc
4 changed files with 48 additions and 0 deletions
+4
View File
@@ -79,6 +79,10 @@
# define LOVE_LEGENDARY_APP_ARGV_HACK
#endif
#if defined(LOVE_ANDROID) || defined(LOVE_IOS)
# define LOVE_LEGENDARY_ACCELEROMETER_AS_JOYSTICK_HACK
#endif
// Autotools config.h
#ifdef HAVE_CONFIG_H
# include <../config.h>
+22
View File
@@ -36,6 +36,10 @@
#include <fstream>
#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK
#ifdef LOVE_LEGENDARY_ACCELEROMETER_AS_JOYSTICK_HACK
#include <SDL_hints.h>
#endif // LOVE_LEGENDARY_ACCELEROMETER_AS_JOYSTICK_HACK
// Libraries.
#ifdef LOVE_ENABLE_LUASOCKET
# include "libraries/luasocket/luasocket.h"
@@ -169,6 +173,10 @@ static const luaL_Reg modules[] = {
int w__openConsole(lua_State *L);
#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK
#ifdef LOVE_LEGENDARY_ACCELEROMETER_AS_JOYSTICK_HACK
int w__setAccelerometerAsJoystick(lua_State *L);
#endif
const char *love_version()
{
// Do not refer to love::VERSION here, the linker
@@ -213,6 +221,11 @@ int luaopen_love(lua_State * L)
lua_setfield(L, -2, "_openConsole");
#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK
#ifdef LOVE_LEGENDARY_ACCELEROMETER_AS_JOYSTICK_HACK
lua_pushcfunction(L, w__setAccelerometerAsJoystick);
lua_setfield(L, -2, "_setAccelerometerAsJoystick");
#endif
lua_newtable(L);
for (int i = 0; love::VERSION_COMPATIBILITY[i] != 0; ++i)
@@ -333,6 +346,15 @@ int w__openConsole(lua_State *L)
#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK
#ifdef LOVE_LEGENDARY_ACCELEROMETER_AS_JOYSTICK_HACK
int w__setAccelerometerAsJoystick(lua_State *L)
{
bool enable = (bool) lua_toboolean(L, 1);
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, enable ? "1" : "0");
return 0;
}
#endif // LOVE_LEGENDARY_ACCELEROMETER_AS_JOYSTICK_HACK
int luaopen_love_boot(lua_State *L)
{
if (luaL_loadbuffer(L, (const char *)love::boot_lua, sizeof(love::boot_lua), "boot.lua") == 0)
+6
View File
@@ -361,6 +361,7 @@ function love.init()
console = false, -- Only relevant for windows.
identity = false,
appendidentity = false,
accelerometerjoystick = true, -- Only relevant for Android / iOS.
}
-- Console hack, part 1.
@@ -389,6 +390,11 @@ function love.init()
love._openConsole()
end
-- Hack for disabling accelerometer-as-joystick on Android / iOS.
if love._setAccelerometerAsJoystick then
love._setAccelerometerAsJoystick(c.accelerometerjoystick)
end
-- Gets desired modules.
for k,v in ipairs{
"thread",
+16
View File
@@ -657,6 +657,10 @@ const unsigned char boot_lua[] =
0x2c, 0x0a,
0x09, 0x09, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x20, 0x3d,
0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x0a,
0x09, 0x09, 0x61, 0x63, 0x63, 0x65, 0x6c, 0x65, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x6a, 0x6f, 0x79,
0x73, 0x74, 0x69, 0x63, 0x6b, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x20, 0x2d, 0x2d, 0x20, 0x4f,
0x6e, 0x6c, 0x79, 0x20, 0x72, 0x65, 0x6c, 0x65, 0x76, 0x61, 0x6e, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x41,
0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x20, 0x2f, 0x20, 0x69, 0x4f, 0x53, 0x2e, 0x0a,
0x09, 0x7d, 0x0a,
0x09, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x20, 0x68, 0x61, 0x63, 0x6b, 0x2c, 0x20,
0x70, 0x61, 0x72, 0x74, 0x20, 0x31, 0x2e, 0x0a,
@@ -714,6 +718,18 @@ const unsigned char boot_lua[] =
0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x5f, 0x6f, 0x70, 0x65, 0x6e, 0x43, 0x6f, 0x6e, 0x73, 0x6f, 0x6c,
0x65, 0x28, 0x29, 0x0a,
0x09, 0x65, 0x6e, 0x64, 0x0a,
0x09, 0x2d, 0x2d, 0x20, 0x48, 0x61, 0x63, 0x6b, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x64, 0x69, 0x73, 0x61, 0x62,
0x6c, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x63, 0x63, 0x65, 0x6c, 0x65, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x65, 0x72,
0x2d, 0x61, 0x73, 0x2d, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x20, 0x6f, 0x6e, 0x20, 0x41, 0x6e,
0x64, 0x72, 0x6f, 0x69, 0x64, 0x20, 0x2f, 0x20, 0x69, 0x4f, 0x53, 0x2e, 0x0a,
0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x5f, 0x73, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x6c,
0x65, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x41, 0x73, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b,
0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x5f, 0x73, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x6c, 0x65, 0x72,
0x6f, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x41, 0x73, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x28, 0x63,
0x2e, 0x61, 0x63, 0x63, 0x65, 0x6c, 0x65, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x6a, 0x6f, 0x79, 0x73,
0x74, 0x69, 0x63, 0x6b, 0x29, 0x0a,
0x09, 0x65, 0x6e, 0x64, 0x0a,
0x09, 0x2d, 0x2d, 0x20, 0x47, 0x65, 0x74, 0x73, 0x20, 0x64, 0x65, 0x73, 0x69, 0x72, 0x65, 0x64, 0x20, 0x6d,
0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x2e, 0x0a,
0x09, 0x66, 0x6f, 0x72, 0x20, 0x6b, 0x2c, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x69, 0x70, 0x61, 0x69, 0x72, 0x73,