aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp
index b2a48d9..24a3147 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -357,7 +357,7 @@ int main()
lua_setglobal(L, "HEIGHT");
SDL_Init(SDL_INIT_EVERYTHING);
- SDL_CreateWindowAndRenderer(WIDTH, HEIGHT, 0, &window, &renderer);
+ SDL_CreateWindowAndRenderer(WIDTH, HEIGHT, SDL_RENDERER_PRESENTVSYNC, &window, &renderer);
SDL_SetWindowTitle(window, "Showdown of the Sticks");
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_RenderSetLogicalSize(renderer, WIDTH, HEIGHT);
@@ -388,6 +388,9 @@ int main()
call_lua_function(L, "Setup");
+ Uint32 lastFrameTime = SDL_GetTicks();
+ float deltaTime = 0.0f;
+
while (running)
{
push_keys_to_lua(L, keys);
@@ -395,6 +398,13 @@ int main()
call_lua_function(L, "Update");
+ Uint32 currentFrameTime = SDL_GetTicks();
+ deltaTime = (currentFrameTime - lastFrameTime) / 1000.0f;
+ lastFrameTime = currentFrameTime;
+
+ lua_pushnumber(L, deltaTime);
+ lua_setglobal(L, "deltaTime");
+
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
@@ -538,7 +548,7 @@ int main()
textList.clear();
SDL_RenderPresent(renderer);
- SDL_Delay(10);
+ SDL_Delay(1);
}
lua_close(L);