Abstractify some modules completely: timer, keyboard and mouse.

If this commit breaks some project file(s), well ...
I AM RUDE AND I WILL BREAK EVERYTHING, AHAHAHAHAHAHAHHAHAHAHAHA!
This commit is contained in:
rude
2011-10-28 10:47:16 +02:00
parent cd66b01da3
commit 2753c62985
18 changed files with 239 additions and 201 deletions
+2 -1
View File
@@ -18,13 +18,14 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#include <common/config.h>
#include "Keyboard.h"
namespace love
{
namespace keyboard
{
bool Keyboard::getConstant(const char * in, Keyboard::Key & out)
{
return keys.find(in, out);
+26
View File
@@ -184,6 +184,32 @@ namespace keyboard
virtual ~Keyboard(){}
/**
* Checks whether a certain key is down or not.
* @param key A key identifier.
* @return boolean
**/
virtual bool isDown(Key * keylist) const = 0;
/**
* Enables key repeating.
* @param delay The amount of delay before repeating the key (in milliseconds)
* @param interval Specifies the amount of time between repeats (in milliseconds)
**/
virtual void setKeyRepeat(int delay, int interval) const = 0;
/**
* Gets the specified delay for the key repeat.
* @return int
**/
virtual int getKeyRepeatDelay() const = 0;
/**
* Gets the specified interval for the key repeat.
* @return int
**/
virtual int getKeyRepeatInterval() const = 0;
static bool getConstant(const char * in, Key & out);
static bool getConstant(Key in, const char *& out);
+2
View File
@@ -18,6 +18,8 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#include <common/config.h>
#include "Keyboard.h"
namespace love
-22
View File
@@ -40,31 +40,9 @@ namespace sdl
// Implements Module.
const char * getName() const;
/**
* Checks whether a certain key is down or not.
* @param key A key identifier.
* @return boolean
**/
bool isDown(Key * keylist) const;
/**
* Enables key repeating.
* @param delay The amount of delay before repeating the key (in milliseconds)
* @param interval Specifies the amount of time between repeats (in milliseconds)
**/
void setKeyRepeat(int delay, int interval) const;
/**
* Gets the specified delay for the key repeat.
* @return int
**/
int getKeyRepeatDelay() const;
/**
* Gets the specified interval for the key repeat.
* @return int
**/
int getKeyRepeatInterval() const;
private:
@@ -18,13 +18,15 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#include <common/config.h>
#include "wrap_Keyboard.h"
#include "sdl/Keyboard.h"
namespace love
{
namespace keyboard
{
namespace sdl
{
static Keyboard * instance;
@@ -81,7 +83,7 @@ namespace sdl
{
try
{
instance = new Keyboard();
instance = new love::keyboard::sdl::Keyboard();
}
catch(Exception & e)
{
@@ -100,7 +102,5 @@ namespace sdl
return luax_register_module(L, w);
}
} // sdl
} // keyboard
} // love
@@ -18,29 +18,21 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_KEYBOARD_SDL_WRAP_KEYBOARD_H
#define LOVE_KEYBOARD_SDL_WRAP_KEYBOARD_H
#ifndef LOVE_KEYBOARD_WRAP_KEYBOARD_H
#define LOVE_KEYBOARD_WRAP_KEYBOARD_H
// LOVE
#include <common/config.h>
#include "Keyboard.h"
// SDL
#include <SDL.h>
namespace love
{
namespace keyboard
{
namespace sdl
{
int w_isDown(lua_State * L);
int w_setKeyRepeat(lua_State * L);
int w_getKeyRepeat(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_keyboard(lua_State * L);
} // sdl
} // keyboard
} // love
#endif // LOVE_KEYBOARD_SDL_WRAP_KEYBOARD_H
#endif // LOVE_KEYBOARD_WRAP_KEYBOARD_H
+10
View File
@@ -48,6 +48,16 @@ namespace mouse
virtual ~Mouse(){};
virtual int getX() const = 0;
virtual int getY() const = 0;
virtual void getPosition(int & x, int & y) const = 0;
virtual void setPosition(int x, int y) = 0;
virtual void setVisible(bool visible) = 0;
virtual bool isDown(Button * buttonlist) const = 0;
virtual bool isVisible() const = 0;
virtual void setGrab(bool grab) = 0;
virtual bool isGrabbed() const = 0;
static bool getConstant(const char * in, Button & out);
static bool getConstant(Button in, const char *& out);
-13
View File
@@ -91,19 +91,6 @@ namespace sdl
return (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON ? true : false);
}
EnumMap<Mouse::Button, unsigned, Mouse::BUTTON_MAX_ENUM>::Entry Mouse::buttonEntries[] =
{
{ Mouse::BUTTON_LEFT, SDL_BUTTON_LEFT},
{ Mouse::BUTTON_MIDDLE, SDL_BUTTON_MIDDLE},
{ Mouse::BUTTON_RIGHT, SDL_BUTTON_RIGHT},
{ Mouse::BUTTON_WHEELUP, SDL_BUTTON_WHEELUP},
{ Mouse::BUTTON_WHEELDOWN, SDL_BUTTON_WHEELDOWN},
{ Mouse::BUTTON_X1, SDL_BUTTON_X1},
{ Mouse::BUTTON_X2, SDL_BUTTON_X2},
};
EnumMap<Mouse::Button, unsigned, Mouse::BUTTON_MAX_ENUM> Mouse::buttons(Mouse::buttonEntries, sizeof(Mouse::buttonEntries));
} // sdl
} // mouse
} // love
-7
View File
@@ -23,7 +23,6 @@
// LOVE
#include <mouse/Mouse.h>
#include <common/EnumMap.h>
namespace love
{
@@ -47,12 +46,6 @@ namespace sdl
bool isVisible() const;
void setGrab(bool grab);
bool isGrabbed() const;
public:
static EnumMap<Button, unsigned, BUTTON_MAX_ENUM>::Entry buttonEntries[];
static EnumMap<Button, unsigned, BUTTON_MAX_ENUM> buttons;
}; // Mouse
} // sdl
@@ -18,13 +18,15 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#include <common/config.h>
#include "sdl/Mouse.h"
#include "wrap_Mouse.h"
namespace love
{
namespace mouse
{
namespace sdl
{
static Mouse * instance = 0;
@@ -122,7 +124,7 @@ namespace sdl
{
try
{
instance = new Mouse();
instance = new love::mouse::sdl::Mouse();
}
catch(Exception & e)
{
@@ -142,6 +144,5 @@ namespace sdl
return luax_register_module(L, w);
}
} // sdl
} // mouse
} // love
@@ -18,18 +18,15 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_MOUSE_SDL_WRAP_MOUSE_H
#define LOVE_MOUSE_SDL_WRAP_MOUSE_H
#ifndef LOVE_MOUSE_WRAP_MOUSE_H
#define LOVE_MOUSE_WRAP_MOUSE_H
// LOVE
#include <common/config.h>
#include "Mouse.h"
namespace love
{
namespace mouse
{
namespace sdl
{
int w_getX(lua_State * L);
int w_getY(lua_State * L);
@@ -42,9 +39,8 @@ namespace sdl
int w_isGrabbed(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_mouse(lua_State * L);
} // sdl
} // mouse
} // love
#endif // LOVE_MOUSE_SDL_WRAP_MOUSE_H
#endif // LOVE_MOUSE_WRAP_MOUSE_H
+85
View File
@@ -0,0 +1,85 @@
/**
* Copyright (c) 2006-2011 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.
**/
#ifndef LOVE_TIMER_TIMER_H
#define LOVE_TIMER_TIMER_H
// LOVE
#include <common/Module.h>
namespace love
{
namespace timer
{
class Timer : public Module
{
public:
/**
* Destructor.
**/
virtual ~Timer(){}
/**
* Measures the time between this call and the previous call,
* and updates internal values accordinly.
**/
virtual void step() = 0;
/**
* Tries to sleep for the specified amount of time. The precision is
* usually 1ms.
* @param seconds The number of seconds to sleep for.
**/
virtual void sleep(double seconds) = 0;
/**
* Gets the time between the last two frames, assuming step is called
* each frame.
**/
virtual double getDelta() const = 0;
/**
* Gets the average FPS over the last second. Beucase the value is only updated
* once per second, it does not look erratic when displayed on screen.
* @return The "current" FPS.
**/
virtual double getFPS() const = 0;
/**
* Gets the amount of time since the program started. Only useful for timing
* code or measuring intervals.
* @return The time (in seconds) since the program started.
**/
virtual double getTime() const = 0;
/**
* Gets the amount of time passed since an unspecified time. The time is accurate
* to the microsecond, and is limited to 24 hours.
* @return The time (in seconds)
**/
virtual double getMicroTime() const = 0;
}; // Timer
} // timer
} // love
#endif // LOVE_TIMER_TIMER_H
+25 -60
View File
@@ -25,7 +25,7 @@
#include <SDL.h>
// LOVE
#include <common/Module.h>
#include <timer/Timer.h>
namespace love
{
@@ -37,10 +37,33 @@ namespace sdl
* An SDL timer module. Can keep track of time between certain function
* calls, and provides access to a FPS metric which updates once each second.
**/
class Timer : public Module
class Timer : public love::timer::Timer
{
public:
/**
* Constructor. Initializes the SDL/timer subsystem.
**/
Timer();
/**
* Destructor.
**/
virtual ~Timer();
const char * getName() const;
void step();
void sleep(double seconds);
double getDelta() const;
double getFPS() const;
double getTime() const;
double getMicroTime() const;
private:
// Timing vars for benchmarking.
Uint32 time_init;
// Frame delta vars.
Uint32 currTime;
Uint32 prevTime;
@@ -58,64 +81,6 @@ namespace sdl
// The current timestep.
double dt;
public:
/**
* Constructor. Initializes the SDL/timer subsystem.
**/
Timer();
/**
* Destructor.
**/
~Timer();
/**
* Gets the name of the module.
* @return Always returns "love.timer.sdl".
**/
const char * getName() const;
/**
* Measures the time between this call and the previous call,
* and updates internal values accordinly.
**/
void step();
/**
* Tries to sleep for the specified amount of time. The precision is
* usually 1ms.
* @param seconds The number of seconds to sleep for.
**/
void sleep(double seconds);
/**
* Gets the time between the last two frames, assuming step is called
* each frame.
**/
double getDelta() const;
/**
* Gets the average FPS over the last second. Beucase the value is only updated
* once per second, it does not look erratic when displayed on screen.
* @return The "current" FPS.
**/
double getFPS() const;
/**
* Gets the amount of time since the program started. Only useful for timing
* code or measuring intervals.
* @return The time (in seconds) since the program started.
**/
double getTime() const;
/**
* Gets the amount of time passed since an unspecified time. The time is accurate
* to the microsecond, and is limited to 24 hours.
* @return The time (in seconds)
**/
double getMicroTime() const;
}; // Timer
} // sdl
@@ -18,14 +18,16 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#include <common/config.h>
// LOVE
#include "wrap_Timer.h"
#include "sdl/Timer.h"
namespace love
{
namespace timer
{
namespace sdl
{
static Timer * instance = 0;
@@ -83,7 +85,8 @@ namespace sdl
{
try
{
instance = new Timer();
instance = new love::timer::sdl::Timer();
}
catch(Exception & e)
{
@@ -103,6 +106,5 @@ namespace sdl
return luax_register_module(L, w);
}
} // sdl
} // timer
} // love
@@ -18,18 +18,15 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_TIMER_SDL_WRAP_TIMER_H
#define LOVE_TIMER_SDL_WRAP_TIMER_H
#ifndef LOVE_TIMER_WRAP_TIMER_H
#define LOVE_TIMER_WRAP_TIMER_H
// LOVE
#include <common/config.h>
#include "Timer.h"
namespace love
{
namespace timer
{
namespace sdl
{
int w_step(lua_State * L);
int w_getDelta(lua_State * L);
@@ -39,8 +36,7 @@ namespace sdl
int w_getMicroTime(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_timer(lua_State * L);
} // sdl
} // timer
} // love
#endif // LOVE_TIMER_SDL_WRAP_TIMER_H
#endif // LOVE_TIMER_WRAP_TIMER_H