separate logic and init/input ticks; make inputs stack
This commit is contained in:
parent
8bb4ff4421
commit
7157957d71
28
sim/main.lua
28
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)
|
||||
end
|
||||
ticks = ticks+OPT_TICK_INF
|
||||
else
|
||||
for i = 1, OPT_TICK_MULT do
|
||||
Simulation.tick(sim)
|
||||
ticks = ticks+1
|
||||
Simulation.tickinit(sim)
|
||||
Simulation.tickinput(sim)
|
||||
|
||||
local elapsed = os.clock()-time
|
||||
if elapsed>0.1 then
|
||||
break
|
||||
end
|
||||
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+ticksthis
|
||||
|
||||
if os.clock()-time>0.1 then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user