lovr.timer.sleep;

This commit is contained in:
bjorn 2016-10-01 15:11:33 -07:00
parent d14bcfeea0
commit 8c047729df
5 changed files with 23 additions and 0 deletions

View File

@ -59,6 +59,7 @@ void lovrInit(lua_State* L) {
" else lovr.draw() end "
" end "
" lovr.graphics.present() "
" lovr.timer.sleep(.001) "
" end "
"end"
);

View File

@ -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;
}

View File

@ -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);

View File

@ -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
}

View File

@ -1 +1,2 @@
double lovrTimerStep();
void lovrTimerSleep(double seconds);