1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-02 12:33:52 +00:00

lovr.timer.getAverageDelta;

This commit is contained in:
bjorn 2017-05-16 20:25:29 -06:00
parent 29f4878dbc
commit 9d6e5252a5
3 changed files with 13 additions and 0 deletions

View file

@ -13,6 +13,11 @@ int l_lovrTimerGetDelta(lua_State* L) {
return 1; return 1;
} }
int l_lovrTimerGetAverageDelta(lua_State* L) {
lua_pushnumber(L, lovrTimerGetAverageDelta());
return 1;
}
int l_lovrTimerGetFPS(lua_State* L) { int l_lovrTimerGetFPS(lua_State* L) {
lua_pushnumber(L, lovrTimerGetFPS()); lua_pushnumber(L, lovrTimerGetFPS());
return 1; return 1;
@ -36,6 +41,7 @@ int l_lovrTimerSleep(lua_State* L) {
const luaL_Reg lovrTimer[] = { const luaL_Reg lovrTimer[] = {
{ "getDelta", l_lovrTimerGetDelta }, { "getDelta", l_lovrTimerGetDelta },
{ "getAverageDelta", l_lovrTimerGetAverageDelta },
{ "getFPS", l_lovrTimerGetFPS }, { "getFPS", l_lovrTimerGetFPS },
{ "getTime", l_lovrTimerGetTime }, { "getTime", l_lovrTimerGetTime },
{ "step", l_lovrTimerStep }, { "step", l_lovrTimerStep },

View file

@ -28,6 +28,7 @@ double lovrTimerStep() {
timerState.tickSum -= timerState.tickBuffer[timerState.tickIndex]; timerState.tickSum -= timerState.tickBuffer[timerState.tickIndex];
timerState.tickSum += timerState.dt; timerState.tickSum += timerState.dt;
timerState.tickBuffer[timerState.tickIndex] = timerState.dt; timerState.tickBuffer[timerState.tickIndex] = timerState.dt;
timerState.averageDelta = timerState.tickSum / TICK_SAMPLES;
timerState.fps = (int) (1 / (timerState.tickSum / TICK_SAMPLES) + .5); timerState.fps = (int) (1 / (timerState.tickSum / TICK_SAMPLES) + .5);
if (++timerState.tickIndex == TICK_SAMPLES) { if (++timerState.tickIndex == TICK_SAMPLES) {
timerState.tickIndex = 0; timerState.tickIndex = 0;
@ -35,6 +36,10 @@ double lovrTimerStep() {
return timerState.dt; return timerState.dt;
} }
double lovrTimerGetAverageDelta() {
return timerState.averageDelta;
}
int lovrTimerGetFPS() { int lovrTimerGetFPS() {
return timerState.fps; return timerState.fps;
} }

View file

@ -9,6 +9,7 @@ typedef struct {
int tickIndex; int tickIndex;
double tickSum; double tickSum;
double tickBuffer[TICK_SAMPLES]; double tickBuffer[TICK_SAMPLES];
double averageDelta;
int fps; int fps;
} TimerState; } TimerState;
@ -16,5 +17,6 @@ void lovrTimerInit();
double lovrTimerGetDelta(); double lovrTimerGetDelta();
double lovrTimerGetTime(); double lovrTimerGetTime();
double lovrTimerStep(); double lovrTimerStep();
double lovrTimerGetAverageDelta();
int lovrTimerGetFPS(); int lovrTimerGetFPS();
void lovrTimerSleep(double seconds); void lovrTimerSleep(double seconds);