diff --git a/src/lovr.c b/src/lovr.c index 82dd21fa..5d1bed5e 100644 --- a/src/lovr.c +++ b/src/lovr.c @@ -59,6 +59,7 @@ void lovrInit(lua_State* L) { " else lovr.draw() end " " end " " lovr.graphics.present() " + " lovr.timer.sleep(.001) " " end " "end" ); diff --git a/src/lovr/timer.c b/src/lovr/timer.c index a902885f..a5345172 100644 --- a/src/lovr/timer.c +++ b/src/lovr/timer.c @@ -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; +} diff --git a/src/lovr/timer.h b/src/lovr/timer.h index ea3db1fc..a97cc9cf 100644 --- a/src/lovr/timer.h +++ b/src/lovr/timer.h @@ -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); diff --git a/src/timer/timer.c b/src/timer/timer.c index f4974af3..1a8c40c5 100644 --- a/src/timer/timer.c +++ b/src/timer/timer.c @@ -1,8 +1,21 @@ #include "timer.h" #include "../glfw.h" +#ifdef WIN32 +#include +#else +#include +#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 +} diff --git a/src/timer/timer.h b/src/timer/timer.h index 89acf01d..16c76729 100644 --- a/src/timer/timer.h +++ b/src/timer/timer.h @@ -1 +1,2 @@ double lovrTimerStep(); +void lovrTimerSleep(double seconds);