mirror of
https://github.com/love2d/love.git
synced 2026-08-19 04:06:17 +02:00
Finally abstracted constants properly. Changed how the event module works; wasn't really abstract before. Removed libs we're not going to use: native, signal.
This commit is contained in:
@@ -202,15 +202,19 @@ namespace sdl
|
||||
return (SDL_JoystickGetButton(joysticks[index], button) == 1);
|
||||
}
|
||||
|
||||
int Joystick::getHat(int index, int hat)
|
||||
Joystick::Hat Joystick::getHat(int index, int hat)
|
||||
{
|
||||
Hat h = HAT_INVALID;
|
||||
|
||||
if(!verifyJoystick(index))
|
||||
return 0;
|
||||
return h;
|
||||
|
||||
if(hat >= getNumHats(index))
|
||||
return 0;
|
||||
return h;
|
||||
|
||||
return SDL_JoystickGetHat(joysticks[index], hat);
|
||||
hats.find(SDL_JoystickGetHat(joysticks[index], hat), h);
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
void Joystick::close(int index)
|
||||
@@ -225,6 +229,21 @@ namespace sdl
|
||||
}
|
||||
}
|
||||
|
||||
EnumMap<Joystick::Hat, Uint8, Joystick::HAT_MAX_ENUM>::Entry Joystick::hatEntries[] =
|
||||
{
|
||||
{Joystick::HAT_CENTERED, SDL_HAT_CENTERED},
|
||||
{Joystick::HAT_UP, SDL_HAT_UP},
|
||||
{Joystick::HAT_RIGHT, SDL_HAT_RIGHT},
|
||||
{Joystick::HAT_DOWN, SDL_HAT_DOWN},
|
||||
{Joystick::HAT_LEFT, SDL_HAT_LEFT},
|
||||
{Joystick::HAT_RIGHTUP, SDL_HAT_RIGHTUP},
|
||||
{Joystick::HAT_RIGHTDOWN, SDL_HAT_RIGHTDOWN},
|
||||
{Joystick::HAT_LEFTUP, SDL_HAT_LEFTUP},
|
||||
{Joystick::HAT_LEFTDOWN, SDL_HAT_LEFTDOWN},
|
||||
};
|
||||
|
||||
EnumMap<Joystick::Hat, Uint8, Joystick::HAT_MAX_ENUM> Joystick::hats(Joystick::hatEntries, sizeof(Joystick::hatEntries));
|
||||
|
||||
} // sdl
|
||||
} // joystick
|
||||
} // love
|
||||
|
||||
@@ -21,11 +21,12 @@
|
||||
#ifndef LOVE_JOYSTICK_SDL_JOYSTICK_H
|
||||
#define LOVE_JOYSTICK_SDL_JOYSTICK_H
|
||||
|
||||
// SDL
|
||||
#include <SDL.h>
|
||||
|
||||
// LOVE
|
||||
#include <joystick/Joystick.h>
|
||||
#include <common/EnumMap.h>
|
||||
|
||||
// SDL
|
||||
#include <SDL.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -59,9 +60,14 @@ namespace sdl
|
||||
int getAxes(lua_State * L);
|
||||
int getBall(lua_State * L);
|
||||
bool isDown(int index, int button);
|
||||
int getHat(int index, int hat);
|
||||
Hat getHat(int index, int hat);
|
||||
void close(int index);
|
||||
|
||||
private:
|
||||
|
||||
static EnumMap<Hat, Uint8, Joystick::HAT_MAX_ENUM>::Entry hatEntries[];
|
||||
static EnumMap<Hat, Uint8, Joystick::HAT_MAX_ENUM> hats;
|
||||
|
||||
}; // Joystick
|
||||
|
||||
} // sdl
|
||||
|
||||
@@ -113,7 +113,13 @@ namespace sdl
|
||||
{
|
||||
int index = luaL_checkint(L, 1);
|
||||
int hat = luaL_checkint(L, 2);
|
||||
lua_pushinteger(L, instance->getHat(index, hat));
|
||||
|
||||
Joystick::Hat h = instance->getHat(index, hat);
|
||||
|
||||
const char * direction = "";
|
||||
Joystick::getConstant(h, direction);
|
||||
lua_pushstring(L, direction);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -145,23 +151,6 @@ namespace sdl
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
// List of constants.
|
||||
static const Constant constants[] = {
|
||||
{ "joystick_axis_horizontal", Joystick::JOYSTICK_AXIS_HORIZONTAL },
|
||||
{ "joystick_axis_vertical", Joystick::JOYSTICK_AXIS_VERITCAL },
|
||||
|
||||
{ "joystick_hat_centered", Joystick::JOYSTICK_HAT_CENTERED },
|
||||
{ "joystick_hat_up", Joystick::JOYSTICK_HAT_UP },
|
||||
{ "joystick_hat_right", Joystick::JOYSTICK_HAT_RIGHT },
|
||||
{ "joystick_hat_down", Joystick::JOYSTICK_HAT_DOWN },
|
||||
{ "joystick_hat_left", Joystick::JOYSTICK_HAT_LEFT },
|
||||
{ "joystick_hat_rightup", Joystick::JOYSTICK_HAT_RIGHTUP },
|
||||
{ "joystick_hat_rightdown", Joystick::JOYSTICK_HAT_RIGHTDOWN },
|
||||
{ "joystick_hat_leftup", Joystick::JOYSTICK_HAT_LEFTUP },
|
||||
{ "joystick_hat_leftdown", Joystick::JOYSTICK_HAT_LEFTDOWN },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_love_joystick(lua_State * L)
|
||||
{
|
||||
if(instance == 0)
|
||||
@@ -183,7 +172,6 @@ namespace sdl
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = 0;
|
||||
w.constants = constants;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user