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,4 +1,9 @@
assert(getmetatable(_G)==nil, "_G already has a metatable")
setmetatable(_G, {
__index = function(t, i) error("attempt to access nil variable "..i, 2) end
})
OPT_SAVE_DIR = arg[1] or error("must specify save location")
OPT_SAVE_DIR = OPT_SAVE_DIR:gsub("\\", "/")
OPT_SAVE_DIR = OPT_SAVE_DIR:gsub("/$", "")
@@ -16,6 +21,7 @@ dofile("gatedef.lua")
dofile("gate.lua")
dofile("port.lua")
dofile("save.lua")
dofile("compile.lua")
OPT_TICK_ENABLED = true
OPT_TICK_TIME = 0.032
@@ -39,7 +45,7 @@ local lastfxtime = 0
local avgticks = {}
local totalticks = 0
sim = Simulation:new()
local sim = Simulation:new()
local units = {
"uHz",
@@ -151,7 +157,7 @@ while 1 do
local position = vectotable(data[i+3])
local rotation = tonumber(data[i+4])
local gate = GateDefinition.constructgate(definition, objref, position, rotation)
local gate = GateDefinition.constructgate(definition, objref, position, rotation, sim)
Simulation.addgate(sim, gate)
--print(gate.objref)
@@ -279,10 +285,6 @@ while 1 do
elseif data[i] == "TICK" then
Simulation.tick(sim)
ticks = ticks + 1
elseif data[i] == "TEST" then
local gate = Simulation.getgatebyref(sim, tonumber(data[i+1]))
Gate.testlogic(gate, tonumber(data[i+2]))
i = i + 2
elseif data[i] == "IN" then
local gate = Simulation.getgatebyref(sim, tonumber(data[i+1]))
local argc = tonumber(data[i+2])