Skip to content

Commit

Permalink
sdl: copy/present only after rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Daft-Freak authored Oct 2, 2024
1 parent 06b84c4 commit 1963776
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions 32blit-sdl/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,19 @@ int System::update_thread() {
while (true) {
SDL_SemWait(s_loop_update);
if(!running) break;
loop();
bool rendered = loop();
if(!running) break;
SDL_PushEvent(&event);
SDL_SemWait(s_loop_redraw);
if(rendered) {
// present on main thread if we need to
SDL_PushEvent(&event);
SDL_SemWait(s_loop_redraw);
}
}
SDL_SemPost(s_loop_ended);
return 0;
}

void System::loop() {
bool System::loop() {
SDL_LockMutex(m_input);
blit::buttons = shadow_buttons;
blit::tilt.x = shadow_tilt[0];
Expand All @@ -314,6 +317,8 @@ void System::loop() {
blit::joystick.y = shadow_joystick[1];
SDL_UnlockMutex(m_input);

bool rendered = false;

// only render at 50Hz (main loop runs at 100Hz)
// however, the emscripten loop (usually) runs at the display refresh rate
auto time_now = ::now();
Expand All @@ -328,12 +333,16 @@ void System::loop() {
_mode = requested_mode;
cur_format = requested_format;
}

rendered = true;
}

blit::tick(::now());
blit_input->rumble_controllers(blit::vibration);

blit_multiplayer->update();

return rendered;
}

Uint32 System::mode() {
Expand Down
2 changes: 1 addition & 1 deletion 32blit-sdl/System.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class System {
int update_thread();
int timer_thread();

void loop();
bool loop();

Uint32 mode();
Uint32 format();
Expand Down

0 comments on commit 1963776

Please sign in to comment.