Browse Source

Fix SDL time

Rob Loach 1 year ago
parent
commit
8ece4186aa

+ 5 - 5
demo/sdl_opengl2/nuklear_sdl_gl2.h

@@ -51,7 +51,7 @@ static struct nk_sdl {
     struct nk_sdl_device ogl;
     struct nk_context ctx;
     struct nk_font_atlas atlas;
-    float delta_time_seconds_last;
+    Uint64 time_of_last_frame;
 } sdl;
 
 NK_INTERN void
@@ -75,9 +75,9 @@ nk_sdl_render(enum nk_anti_aliasing AA)
     int display_width, display_height;
     struct nk_vec2 scale;
 
-    float now = ((float)SDL_GetTicks64()) / 1000;
-    sdl.ctx.delta_time_seconds = now - sdl.delta_time_seconds_last;
-    sdl.delta_time_seconds_last = now;
+    Uint64 now = SDL_GetTicks64();
+    sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000;
+    sdl.time_of_last_frame = now;
 
     SDL_GetWindowSize(sdl.win, &width, &height);
     SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height);
@@ -217,7 +217,7 @@ nk_sdl_init(SDL_Window *win)
     sdl.ctx.clip.paste = nk_sdl_clipboard_paste;
     sdl.ctx.clip.userdata = nk_handle_ptr(0);
     nk_buffer_init_default(&sdl.ogl.cmds);
-    sdl.time_of_last_frame = ((float)SDL_GetTicks64()) / 1000;
+    sdl.time_of_last_frame = SDL_GetTicks64();
     return &sdl.ctx;
 }
 

+ 5 - 5
demo/sdl_opengl3/nuklear_sdl_gl3.h

@@ -67,7 +67,7 @@ static struct nk_sdl {
     struct nk_sdl_device ogl;
     struct nk_context ctx;
     struct nk_font_atlas atlas;
-    float delta_time_seconds_last;
+    Uint64 time_of_last_frame;
 } sdl;
 
 #ifdef __APPLE__
@@ -199,9 +199,9 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
         { -1.0f,  1.0f,  0.0f, 1.0f },
     };
 
-    float now = ((float)SDL_GetTicks64()) / 1000;
-    sdl.ctx.delta_time_seconds = now - sdl.delta_time_seconds_last;
-    sdl.delta_time_seconds_last = now;
+    Uint64 now = SDL_GetTicks64();
+    sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000;
+    sdl.time_of_last_frame = now;
 
     SDL_GetWindowSize(sdl.win, &width, &height);
     SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height);
@@ -326,7 +326,7 @@ nk_sdl_init(SDL_Window *win)
     sdl.ctx.clip.paste = nk_sdl_clipboard_paste;
     sdl.ctx.clip.userdata = nk_handle_ptr(0);
     nk_sdl_device_create();
-    sdl.time_of_last_frame = ((float)SDL_GetTicks64()) / 1000;
+    sdl.time_of_last_frame = SDL_GetTicks64();
     return &sdl.ctx;
 }
 

+ 5 - 5
demo/sdl_opengles2/nuklear_sdl_gles2.h

@@ -71,7 +71,7 @@ static struct nk_sdl {
     struct nk_sdl_device ogl;
     struct nk_context ctx;
     struct nk_font_atlas atlas;
-    float delta_time_seconds_last;
+    Uint64 time_of_last_frame;
 } sdl;
 
 
@@ -187,9 +187,9 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
         { -1.0f,  1.0f,  0.0f, 1.0f },
     };
 
-    float now = ((float)SDL_GetTicks64()) / 1000;
-    sdl.ctx.delta_time_seconds = now - sdl.delta_time_seconds_last;
-    sdl.delta_time_seconds_last = now;
+    Uint64 now = SDL_GetTicks64();
+    sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000;
+    sdl.time_of_last_frame = now;
 
     SDL_GetWindowSize(sdl.win, &width, &height);
     SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height);
@@ -326,7 +326,7 @@ nk_sdl_init(SDL_Window *win)
     sdl.ctx.clip.paste = nk_sdl_clipboard_paste;
     sdl.ctx.clip.userdata = nk_handle_ptr(0);
     nk_sdl_device_create();
-    sdl.time_of_last_frame = ((float)SDL_GetTicks64()) / 1000;
+    sdl.time_of_last_frame = SDL_GetTicks64();
     return &sdl.ctx;
 }
 

+ 5 - 5
demo/sdl_renderer/nuklear_sdl_renderer.h

@@ -64,7 +64,7 @@ static struct nk_sdl {
     struct nk_sdl_device ogl;
     struct nk_context ctx;
     struct nk_font_atlas atlas;
-    float delta_time_seconds_last;
+    Uint64 time_of_last_frame;
 } sdl;
 
 NK_INTERN void
@@ -113,9 +113,9 @@ nk_sdl_render(enum nk_anti_aliasing AA)
             {NK_VERTEX_LAYOUT_END}
         };
 
-        float now = ((float)SDL_GetTicks64()) / 1000;
-        sdl.ctx.delta_time_seconds = now - sdl.delta_time_seconds_last;
-        sdl.delta_time_seconds_last = now;
+        Uint64 now = SDL_GetTicks64();
+        sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000;
+        sdl.time_of_last_frame = now;
 
         NK_MEMSET(&config, 0, sizeof(config));
         config.vertex_layout = vertex_layout;
@@ -245,7 +245,7 @@ nk_sdl_init(SDL_Window *win, SDL_Renderer *renderer)
 #endif
     sdl.win = win;
     sdl.renderer = renderer;
-    sdl.delta_time_seconds_last = ((float)SDL_GetTicks64()) / 1000;
+    sdl.time_of_last_frame = SDL_GetTicks64();
     nk_init_default(&sdl.ctx, 0);
     sdl.ctx.clip.copy = nk_sdl_clipboard_copy;
     sdl.ctx.clip.paste = nk_sdl_clipboard_paste;