mirror of https://github.com/bjornbytes/lovr.git
lovr.timer.sleep;
This commit is contained in:
parent
d14bcfeea0
commit
8c047729df
|
@ -59,6 +59,7 @@ void lovrInit(lua_State* L) {
|
|||
" else lovr.draw() end "
|
||||
" end "
|
||||
" lovr.graphics.present() "
|
||||
" lovr.timer.sleep(.001) "
|
||||
" end "
|
||||
"end"
|
||||
);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
const luaL_Reg lovrTimer[] = {
|
||||
{ "step", l_lovrTimerStep },
|
||||
{ "sleep", l_lovrTimerSleep },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
@ -16,3 +17,9 @@ int l_lovrTimerStep(lua_State* L) {
|
|||
lua_pushnumber(L, lovrTimerStep());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrTimerSleep(lua_State* L) {
|
||||
double duration = luaL_checknumber(L, 1);
|
||||
lovrTimerSleep(duration);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -5,3 +5,4 @@
|
|||
extern const luaL_Reg lovrTimer[];
|
||||
int l_lovrTimerInit(lua_State* L);
|
||||
int l_lovrTimerStep(lua_State* L);
|
||||
int l_lovrTimerSleep(lua_State* L);
|
||||
|
|
|
@ -1,8 +1,21 @@
|
|||
#include "timer.h"
|
||||
#include "../glfw.h"
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
double lovrTimerStep() {
|
||||
double time = glfwGetTime();
|
||||
glfwSetTime(0);
|
||||
return time;
|
||||
}
|
||||
|
||||
void lovrTimerSleep(double seconds) {
|
||||
#ifdef WIN32
|
||||
Sleep((unsigned int)(seconds * 1000));
|
||||
#else
|
||||
usleep((unsigned int)(seconds * 1000000));
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
double lovrTimerStep();
|
||||
void lovrTimerSleep(double seconds);
|
||||
|
|
Loading…
Reference in New Issue