mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +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:
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Joystick.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace joystick
|
||||
{
|
||||
|
||||
Joystick::~Joystick()
|
||||
{
|
||||
}
|
||||
|
||||
bool Joystick::getConstant(const char * in, Joystick::Hat & out)
|
||||
{
|
||||
return hats.find(in, out);
|
||||
}
|
||||
|
||||
bool Joystick::getConstant(Joystick::Hat in, const char *& out)
|
||||
{
|
||||
return hats.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Joystick::Hat, Joystick::HAT_MAX_ENUM>::Entry Joystick::hatEntries[] =
|
||||
{
|
||||
{"c", Joystick::HAT_CENTERED},
|
||||
{"u", Joystick::HAT_UP},
|
||||
{"r", Joystick::HAT_RIGHT},
|
||||
{"d", Joystick::HAT_DOWN},
|
||||
{"l", Joystick::HAT_LEFT},
|
||||
{"ru", Joystick::HAT_RIGHTUP},
|
||||
{"rd", Joystick::HAT_RIGHTDOWN},
|
||||
{"lu", Joystick::HAT_LEFTUP},
|
||||
{"ld", Joystick::HAT_LEFTDOWN},
|
||||
};
|
||||
|
||||
StringMap<Joystick::Hat, Joystick::HAT_MAX_ENUM> Joystick::hats(Joystick::hatEntries, sizeof(Joystick::hatEntries));
|
||||
|
||||
} // joystick
|
||||
} // love
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
// LOVE
|
||||
#include <common/Module.h>
|
||||
#include <common/StringMap.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -32,26 +33,30 @@ namespace joystick
|
||||
{
|
||||
public:
|
||||
|
||||
enum JoystickAxis
|
||||
enum Hat
|
||||
{
|
||||
JOYSTICK_AXIS_HORIZONTAL = 0,
|
||||
JOYSTICK_AXIS_VERITCAL = 1,
|
||||
HAT_INVALID,
|
||||
HAT_CENTERED,
|
||||
HAT_UP,
|
||||
HAT_RIGHT,
|
||||
HAT_DOWN,
|
||||
HAT_LEFT,
|
||||
HAT_RIGHTUP,
|
||||
HAT_RIGHTDOWN,
|
||||
HAT_LEFTUP,
|
||||
HAT_LEFTDOWN,
|
||||
HAT_MAX_ENUM = 16
|
||||
};
|
||||
|
||||
enum JoystickHat
|
||||
{
|
||||
JOYSTICK_HAT_CENTERED = 0,
|
||||
JOYSTICK_HAT_UP = 1,
|
||||
JOYSTICK_HAT_RIGHT = 2,
|
||||
JOYSTICK_HAT_DOWN = 4,
|
||||
JOYSTICK_HAT_LEFT = 8,
|
||||
JOYSTICK_HAT_RIGHTUP = (2|1),
|
||||
JOYSTICK_HAT_RIGHTDOWN = (2|4),
|
||||
JOYSTICK_HAT_LEFTUP = (8|1),
|
||||
JOYSTICK_HAT_LEFTDOWN = (8|4)
|
||||
};
|
||||
virtual ~Joystick();
|
||||
|
||||
virtual ~Joystick(){};
|
||||
static bool getConstant(const char * in, Hat & out);
|
||||
static bool getConstant(Hat in, const char *& out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<Hat, HAT_MAX_ENUM>::Entry hatEntries[];
|
||||
static StringMap<Hat, HAT_MAX_ENUM> hats;
|
||||
|
||||
}; // Joystick
|
||||
|
||||
|
||||
@@ -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