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")
|
client:send("SINFO\t" .. data[i+1] .. "\t" .. sim.nwires .. "\t" .. sim.ngates .. "\t" .. sim.ninports .. "\t" .. sim.noutports .. "\n")
|
||||||
i = i + 1
|
i = i + 1
|
||||||
elseif data[i] == "TICK" then
|
elseif data[i] == "TICK" then
|
||||||
Simulation.tick(sim)
|
Simulation.tickinit(sim)
|
||||||
|
Simulation.tickinput(sim)
|
||||||
|
Simulation.ticklogic(sim)
|
||||||
ticks = ticks + 1
|
ticks = ticks + 1
|
||||||
elseif data[i] == "IN" then
|
elseif data[i] == "IN" then
|
||||||
local gate = Simulation.getgatebyref(sim, tonumber(data[i+1]))
|
local gate = Simulation.getgatebyref(sim, tonumber(data[i+1]))
|
||||||
@ -323,20 +325,18 @@ while 1 do
|
|||||||
if time-lastticktime >= OPT_TICK_TIME then
|
if time-lastticktime >= OPT_TICK_TIME then
|
||||||
lastticktime = time
|
lastticktime = time
|
||||||
|
|
||||||
if OPT_TICK_TIME==0 then
|
Simulation.tickinit(sim)
|
||||||
for i = 1, OPT_TICK_INF do
|
Simulation.tickinput(sim)
|
||||||
Simulation.tick(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
|
end
|
||||||
ticks = ticks+OPT_TICK_INF
|
ticks = ticks+ticksthis
|
||||||
else
|
|
||||||
for i = 1, OPT_TICK_MULT do
|
if os.clock()-time>0.1 then
|
||||||
Simulation.tick(sim)
|
break
|
||||||
ticks = ticks+1
|
|
||||||
|
|
||||||
local elapsed = os.clock()-time
|
|
||||||
if elapsed>0.1 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -294,27 +294,13 @@ function Simulation.queuecallback(sim, gate, ...)
|
|||||||
sim.callbacks[gate.objref] = {...}
|
sim.callbacks[gate.objref] = {...}
|
||||||
end
|
end
|
||||||
|
|
||||||
function Simulation.tick(sim)
|
function Simulation.ticklogic(sim)
|
||||||
for k, group in ipairs(sim.groupqueue) do
|
for k, group in ipairs(sim.groupqueue) do
|
||||||
Group.update(group)
|
Group.update(group)
|
||||||
group.in_queue = false
|
group.in_queue = false
|
||||||
end
|
end
|
||||||
sim.groupqueue = {}
|
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
|
if sim.tickqueue[sim.current_tick] ~= nil then
|
||||||
for i, gate in pairs(sim.tickqueue[sim.current_tick]) do
|
for i, gate in pairs(sim.tickqueue[sim.current_tick]) do
|
||||||
Simulation.queuegate(sim, gate)
|
Simulation.queuegate(sim, gate)
|
||||||
@ -331,6 +317,24 @@ function Simulation.tick(sim)
|
|||||||
sim.current_tick = sim.current_tick + 1
|
sim.current_tick = sim.current_tick + 1
|
||||||
end
|
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)
|
function Simulation.sendfxupdate(sim)
|
||||||
for k, group in pairs(sim.groupfxqueue) do
|
for k, group in pairs(sim.groupfxqueue) do
|
||||||
if group.state ~= group.fxstate then
|
if group.state ~= group.fxstate then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user