mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user