From aa8d27959cfbd0a683d44d373ffd3d2e43967f8d Mon Sep 17 00:00:00 2001 From: empathicqubit Date: Sat, 1 May 2021 21:25:38 -0400 Subject: [PATCH] Change how the timer is dispatched based on the threadedness of the application. --- pool.lua | 21 +++++++++++++++------ runner-process.lua | 4 +--- runner.lua | 5 +++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pool.lua b/pool.lua index 50b2ba3..3753b44 100644 --- a/pool.lua +++ b/pool.lua @@ -3,12 +3,6 @@ local callback, set_timer_timeout = callback, set_timer_timeout local base = string.gsub(@@LUA_SCRIPT_FILENAME@@, "(.*[/\\])(.*)", "%1") local Promise = dofile(base.."/promise.lua") --- Only the parent should manage ticks! -callback.register('timer', function() - Promise.update() - set_timer_timeout(1) -end) -set_timer_timeout(1) local config = dofile(base.."/config.lua") local util = dofile(base.."/util.lua")(Promise) @@ -18,6 +12,21 @@ local libDeflate = dofile(base.."/LibDeflate.lua") local hasThreads = not util.isWin and config.NeatConfig.Threads > 1 + +-- Only the parent should manage ticks! +-- I'm not terribly thrilled with this logic +if hasThreads then + callback.register('timer', function() + Promise.update() + set_timer_timeout(1) + end) + set_timer_timeout(1) +else + callback.register('input', function() + Promise.update() + end) +end + local Runner = nil if hasThreads then local warn = '========== When using threads, the ROM file to use comes from config.lua. Also, you do not need to start any ROM in the parent process.' diff --git a/runner-process.lua b/runner-process.lua index 474d6d0..4a63647 100644 --- a/runner-process.lua +++ b/runner-process.lua @@ -4,11 +4,9 @@ local base = string.gsub(@@LUA_SCRIPT_FILENAME@@, "(.*[/\\])(.*)", "%1") local Promise = dofile(base.."/promise.lua") -- Only the parent should manage ticks! -callback.register('timer', function() +callback.register('input', function() Promise.update() - set_timer_timeout(1) end) -set_timer_timeout(1) local Runner = dofile(base.."/runner.lua") local serpent = dofile(base.."/serpent.lua") diff --git a/runner.lua b/runner.lua index d6e97c5..d2b3efa 100644 --- a/runner.lua +++ b/runner.lua @@ -2,9 +2,12 @@ local gui, input, movie, settings, exec, callback, set_timer_timeout = gui, inpu local base = string.gsub(@@LUA_SCRIPT_FILENAME@@, "(.*[/\\])(.*)", "%1") +local Promise = nil + local config = dofile(base.."/config.lua") local game = dofile(base.."/game.lua") local mathFunctions = dofile(base.."/mathFunctions.lua") +local util = dofile(base.."/util.lua")() local Inputs = config.InputSize+1 local Outputs = #config.ButtonNames @@ -12,8 +15,6 @@ local Outputs = #config.ButtonNames local guiWidth = 0 local guiHeight = 0 -local Promise = nil - local function message(_M, msg, color) if color == nil then color = 0x00009900