From 7a574de4b609b748235b5abad1bda69634015c01 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 29 Dec 2022 21:12:04 +0100 Subject: [PATCH] -Sync even when not in focus --- mini.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/mini.cpp b/mini.cpp index 5f4bd46..cac48f9 100644 --- a/mini.cpp +++ b/mini.cpp @@ -196,7 +196,7 @@ int main(int argc,char*argv[]){ SDL_Init(SDL_INIT_EVERYTHING); mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width*screen_zoom, screen_height*screen_zoom, SDL_WINDOW_SHOWN); - mini_ren = SDL_CreateRenderer(mini_win, -1, SDL_RENDERER_PRESENTVSYNC); + mini_ren = SDL_CreateRenderer(mini_win, -1, 0); //SDL_CreateWindowAndRenderer(512,512,0,&mini_win,&mini_ren); SDL_RenderSetLogicalSize(mini_ren, screen_width, screen_height); SDL_ShowCursor(show_cursor); @@ -210,14 +210,15 @@ int main(int argc,char*argv[]){ lua_init(lua_files); lua_call_init(); + Uint32 dt=SDL_GetTicks(); + key_just_pressed = 0; while(!should_exit) { - key_just_pressed = 0; mouse_wheel = 0; while(SDL_PollEvent(&mini_eve)) { if (mini_eve.type == SDL_QUIT) { should_exit=true; should_quit=true; break; } if (mini_eve.type == SDL_KEYDOWN) { #ifdef DEBUG - if (mini_eve.key.keysym.scancode == SDL_SCANCODE_ESCAPE) { + if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F1) { chirp_stop(); if (lua_is_playing()) { lua_quit(); @@ -228,6 +229,7 @@ int main(int argc,char*argv[]){ } } else if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F5) { chirp_stop(); + should_exit=true; } else { key_just_pressed = mini_eve.key.keysym.scancode; } @@ -243,10 +245,14 @@ int main(int argc,char*argv[]){ mouse_buttons = SDL_GetMouseState(&mouse_x, &mouse_y); mouse_x /= screen_zoom; mouse_y /= screen_zoom; - if (lua_is_playing()) { - lua_call_update(); - } else { - loop(); + if (SDL_GetTicks()-dt>13) { + dt = SDL_GetTicks(); + if (lua_is_playing()) { + lua_call_update(); + } else { + loop(); + } + key_just_pressed = 0; } SDL_LockTexture(mini_bak, NULL, (void**)&pixels, &pitch); for (int i=0;isize;++i) pixels[i] = palette[screen_surface->p[i]];