make simulation non-global

This commit is contained in:
Redo0
2021-05-23 15:36:40 -05:00
parent 6c997a36fa
commit 569e79ab96
8 changed files with 52 additions and 54 deletions

View File

@@ -1,11 +1,12 @@
Gate = {}
function Gate.new(self, objref, definition)
function Gate.new(self, objref, definition, sim)
local o = {
objref = objref,
definition = definition,
ports = {}
ports = {},
sim = sim,
}
setmetatable(o, self)
self.__index = self
@@ -41,34 +42,14 @@ function Gate:getportisfalling(index)
return Port.isfalling(self.ports[index])
end
-- function Gate:cb(...)
-- local args = {...}
-- local str = tostring(#args)
-- for i, v in ipairs(args) do
-- v = bool_to_int[v] or tostring(v)
-- str = str .. "\t" .. tostring(v)
-- end
-- sim:queuecallback(self, str)
-- end
function Gate.cb(self, ...)
Simulation.queuecallback(sim, self, ...)
function Gate.cb(gate, ...)
Simulation.queuecallback(gate.sim, gate, ...)
end
function Gate.queue(self, delay)
Simulation.queuegatelater(sim, self, delay)
Simulation.queuegatelater(self.sim, self, delay)
end
function Gate.testlogic(self, n)
--local time = os.clock()
--for i = 1, n do
-- self.definition.logic(self)
--end
--client:send("TEST\t" .. (os.clock()-time) .. "\n")
end
function Gate.gettick(self)
return sim.currenttick
function Gate.gettick(gate)
return gate.sim.currenttick
end