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
+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
-108
View File
@@ -1,108 +0,0 @@
/**
* 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.
**/
// LOVE
#include "wrap_Timer.h"
namespace love
{
namespace timer
{
namespace sdl
{
static Timer * instance = 0;
int w_step(lua_State *)
{
instance->step();
return 0;
}
int w_getDelta(lua_State * L)
{
lua_pushnumber(L, instance->getDelta());
return 1;
}
int w_getFPS(lua_State * L)
{
lua_pushnumber(L, instance->getFPS());
return 1;
}
int w_sleep(lua_State * L)
{
instance->sleep((float) luaL_checknumber(L, 1));
return 0;
}
int w_getTime(lua_State * L)
{
lua_pushnumber(L, instance->getTime());
return 1;
}
int w_getMicroTime(lua_State * L)
{
lua_pushnumber(L, instance->getMicroTime());
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] = {
{ "step", w_step },
{ "getDelta", w_getDelta },
{ "getFPS", w_getFPS },
{ "sleep", w_sleep },
{ "getTime", w_getTime },
{ "getMicroTime", w_getMicroTime },
{ 0, 0 }
};
int luaopen_love_timer(lua_State * L)
{
if(instance == 0)
{
try
{
instance = new Timer();
}
catch(Exception & e)
{
return luaL_error(L, e.what());
}
}
else
instance->retain();
WrappedModule w;
w.module = instance;
w.name = "timer";
w.flags = MODULE_T;
w.functions = functions;
w.types = 0;
return luax_register_module(L, w);
}
} // sdl
} // timer
} // love
-46
View File
@@ -1,46 +0,0 @@
/**
* 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_SDL_WRAP_TIMER_H
#define LOVE_TIMER_SDL_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);
int w_getFPS(lua_State * L);
int w_sleep(lua_State * L);
int w_getTime(lua_State * L);
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