core: refactor glfw appUpdateThread
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
c32c1df00a
commit
69b749879d
1 changed files with 58 additions and 51 deletions
|
|
@ -51,6 +51,7 @@ max_refresh_rate: u32,
|
|||
|
||||
// Mutable fields only used by main thread
|
||||
app_update_thread_started: bool = false,
|
||||
app_update_thread_frequency_started: bool = false,
|
||||
linux_gamemode: ?bool = null,
|
||||
cursors: [@typeInfo(CursorShape).Enum.fields.len]?glfw.Cursor,
|
||||
cursors_tried: [@typeInfo(CursorShape).Enum.fields.len]bool,
|
||||
|
|
@ -540,10 +541,11 @@ pub fn deinit(self: *Core) void {
|
|||
self.instance.release();
|
||||
}
|
||||
|
||||
// Secondary app-update thread
|
||||
pub fn appUpdateThread(self: *Core, app: anytype) void {
|
||||
pub fn appUpdateThreadTick(self: *Core, app: anytype) bool {
|
||||
if (!self.app_update_thread_frequency_started) {
|
||||
self.app_update_thread_frequency_started = true;
|
||||
self.frame.start() catch unreachable;
|
||||
while (true) {
|
||||
}
|
||||
if (self.swap_chain_update.isSet()) blk: {
|
||||
self.swap_chain_update.reset();
|
||||
|
||||
|
|
@ -585,14 +587,19 @@ pub fn appUpdateThread(self: *Core, app: anytype) void {
|
|||
// Wake the main thread from any event handling, so there is not e.g. a one second delay
|
||||
// in exiting the application.
|
||||
glfw.postEmptyEvent();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
self.gpu_device.tick();
|
||||
self.gpu_device.machWaitForCommandsToBeScheduled();
|
||||
|
||||
self.frame.tick();
|
||||
if (self.frame.delay_ns != 0) std.time.sleep(self.frame.delay_ns);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Secondary app-update thread
|
||||
pub fn appUpdateThread(self: *Core, app: anytype) void {
|
||||
while (self.appUpdateThreadTick(app)) {}
|
||||
}
|
||||
|
||||
// Called on the main thread
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue