diff --git a/sim/main.lua b/sim/main.lua index c0f817a..c933328 100644 --- a/sim/main.lua +++ b/sim/main.lua @@ -289,7 +289,9 @@ while 1 do client:send("SINFO\t" .. data[i+1] .. "\t" .. sim.nwires .. "\t" .. sim.ngates .. "\t" .. sim.ninports .. "\t" .. sim.noutports .. "\n") i = i + 1 elseif data[i] == "TICK" then - Simulation.tick(sim) + Simulation.tickinit(sim) + Simulation.tickinput(sim) + Simulation.ticklogic(sim) ticks = ticks + 1 elseif data[i] == "IN" then local gate = Simulation.getgatebyref(sim, tonumber(data[i+1])) @@ -323,20 +325,18 @@ while 1 do if time-lastticktime >= OPT_TICK_TIME then lastticktime = time - if OPT_TICK_TIME==0 then - for i = 1, OPT_TICK_INF do - Simulation.tick(sim) + Simulation.tickinit(sim) + Simulation.tickinput(sim) + + for i = 1, OPT_TICK_MULT, 100 do + local ticksthis = math.min(OPT_TICK_MULT-i+1, 100) + for j = 1, ticksthis do + Simulation.ticklogic(sim) end - ticks = ticks+OPT_TICK_INF - else - for i = 1, OPT_TICK_MULT do - Simulation.tick(sim) - ticks = ticks+1 - - local elapsed = os.clock()-time - if elapsed>0.1 then - break - end + ticks = ticks+ticksthis + + if os.clock()-time>0.1 then + break end end diff --git a/sim/simulation.lua b/sim/simulation.lua index 6375c3c..58a7826 100644 --- a/sim/simulation.lua +++ b/sim/simulation.lua @@ -294,27 +294,13 @@ function Simulation.queuecallback(sim, gate, ...) sim.callbacks[gate.objref] = {...} end -function Simulation.tick(sim) +function Simulation.ticklogic(sim) for k, group in ipairs(sim.groupqueue) do Group.update(group) group.in_queue = false end sim.groupqueue = {} - if sim.initqueue ~= nil then - for k, gate in pairs(sim.initqueue) do - Gate.init(gate) - end - sim.initqueue = nil - end - - if sim.inputqueue ~= nil then - for gate, argv in pairs(sim.inputqueue) do - Gate.input(gate, argv) - end - sim.inputqueue = nil - end - if sim.tickqueue[sim.current_tick] ~= nil then for i, gate in pairs(sim.tickqueue[sim.current_tick]) do Simulation.queuegate(sim, gate) @@ -331,6 +317,24 @@ function Simulation.tick(sim) sim.current_tick = sim.current_tick + 1 end +function Simulation.tickinit(sim) + if sim.initqueue ~= nil then + for k, gate in pairs(sim.initqueue) do + Gate.init(gate) + end + sim.initqueue = nil + end +end + +function Simulation.tickinput(sim) + if sim.inputqueue ~= nil then + for gate, argv in pairs(sim.inputqueue) do + Gate.input(gate, argv) + end + sim.inputqueue = nil + end +end + function Simulation.sendfxupdate(sim) for k, group in pairs(sim.groupfxqueue) do if group.state ~= group.fxstate then