Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdl: copy/present only after rendering #862

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions 32blit-sdl/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,25 +286,28 @@ int System::timer_thread() {
}

int System::update_thread() {
// Run the blit user code once every time we are signalled.
SDL_Event event = {};
event.type = loop_event;

::init(); // Run init here because the user can make it hang.

while (true) {
SDL_SemWait(s_loop_update);
if(!running) break;
loop();
if(!running) break;
SDL_PushEvent(&event);
SDL_SemWait(s_loop_redraw);
}
SDL_SemPost(s_loop_ended);
return 0;
// Run the blit user code once every time we are signalled.
SDL_Event event = {};
event.type = loop_event;

::init(); // Run init here because the user can make it hang.

while (true) {
SDL_SemWait(s_loop_update);
if(!running) break;
bool rendered = loop();
if(!running) break;
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
Loading