mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-05 05:53:33 +00:00
Improve lovr.timer;
This commit is contained in:
parent
38c46106da
commit
1cdde81e35
|
@ -2,6 +2,8 @@
|
||||||
#include "../timer/timer.h"
|
#include "../timer/timer.h"
|
||||||
|
|
||||||
const luaL_Reg lovrTimer[] = {
|
const luaL_Reg lovrTimer[] = {
|
||||||
|
{ "getDelta", l_lovrTimerGetDelta },
|
||||||
|
{ "getTime", l_lovrTimerGetTime },
|
||||||
{ "step", l_lovrTimerStep },
|
{ "step", l_lovrTimerStep },
|
||||||
{ "sleep", l_lovrTimerSleep },
|
{ "sleep", l_lovrTimerSleep },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
|
@ -10,6 +12,17 @@ const luaL_Reg lovrTimer[] = {
|
||||||
int l_lovrTimerInit(lua_State* L) {
|
int l_lovrTimerInit(lua_State* L) {
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
luaL_register(L, NULL, lovrTimer);
|
luaL_register(L, NULL, lovrTimer);
|
||||||
|
lovrTimerInit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_lovrTimerGetDelta(lua_State* L) {
|
||||||
|
lua_pushnumber(L, lovrTimerGetDelta());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_lovrTimerGetTime(lua_State* L) {
|
||||||
|
lua_pushnumber(L, lovrTimerGetTime());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,5 +4,7 @@
|
||||||
|
|
||||||
extern const luaL_Reg lovrTimer[];
|
extern const luaL_Reg lovrTimer[];
|
||||||
int l_lovrTimerInit(lua_State* L);
|
int l_lovrTimerInit(lua_State* L);
|
||||||
|
int l_lovrTimerGetDelta(lua_State* L);
|
||||||
|
int l_lovrTimerGetTime(lua_State* L);
|
||||||
int l_lovrTimerStep(lua_State* L);
|
int l_lovrTimerStep(lua_State* L);
|
||||||
int l_lovrTimerSleep(lua_State* L);
|
int l_lovrTimerSleep(lua_State* L);
|
||||||
|
|
|
@ -6,10 +6,25 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static TimerState timerState;
|
||||||
|
|
||||||
|
void lovrTimerInit() {
|
||||||
|
lovrTimerStep();
|
||||||
|
}
|
||||||
|
|
||||||
|
double lovrTimerGetDelta() {
|
||||||
|
return timerState.dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
double lovrTimerGetTime() {
|
||||||
|
return glfwGetTime();
|
||||||
|
}
|
||||||
|
|
||||||
double lovrTimerStep() {
|
double lovrTimerStep() {
|
||||||
double time = glfwGetTime();
|
timerState.lastTime = timerState.time;
|
||||||
glfwSetTime(0);
|
timerState.time = glfwGetTime();
|
||||||
return time;
|
timerState.dt = timerState.time - timerState.lastTime;
|
||||||
|
return timerState.dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lovrTimerSleep(double seconds) {
|
void lovrTimerSleep(double seconds) {
|
||||||
|
|
|
@ -1,2 +1,13 @@
|
||||||
|
#ifndef LOVR_TIMER_TYPES
|
||||||
|
typedef struct {
|
||||||
|
double lastTime;
|
||||||
|
double time;
|
||||||
|
double dt;
|
||||||
|
} TimerState;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void lovrTimerInit();
|
||||||
|
double lovrTimerGetDelta();
|
||||||
|
double lovrTimerGetTime();
|
||||||
double lovrTimerStep();
|
double lovrTimerStep();
|
||||||
void lovrTimerSleep(double seconds);
|
void lovrTimerSleep(double seconds);
|
||||||
|
|
Loading…
Reference in a new issue