make queues c arrays
This commit is contained in:
		| @@ -1,12 +1,19 @@ | |||||||
|  |  | ||||||
|  | local ffi = FFI or require("ffi") | ||||||
|  |  | ||||||
|  | ffi.cdef [[ | ||||||
|  | 	struct Gate; | ||||||
|  | 	struct Net; | ||||||
|  | ]] | ||||||
|  |  | ||||||
| Simulation = {} | Simulation = {} | ||||||
|  |  | ||||||
| function Simulation.new(sim) | function Simulation.new(sim) | ||||||
| 	local o = { | 	local o = { | ||||||
| 		groupqueue = {}, | 		groupqueue = ffi.new("struct Gate*[131072]"), | ||||||
| 		num_groupqueue = 0, | 		num_groupqueue = ffi.new("int[1]"), | ||||||
| 		gatequeue = {}, | 		gatequeue = ffi.new("struct Net*[131072]"), | ||||||
| 		num_gatequeue = 0, | 		num_gatequeue = ffi.new("int[1]"), | ||||||
| 		--groupfxqueue = {}, | 		--groupfxqueue = {}, | ||||||
| 		current_tick = 0, | 		current_tick = 0, | ||||||
| 		 | 		 | ||||||
| @@ -27,6 +34,8 @@ function Simulation.new(sim) | |||||||
| 	} | 	} | ||||||
| 	setmetatable(o, sim) | 	setmetatable(o, sim) | ||||||
| 	sim.__index = sim | 	sim.__index = sim | ||||||
|  | 	o.num_groupqueue[0] = 0 | ||||||
|  | 	o.num_gatequeue[0] = 0 | ||||||
| 	return o | 	return o | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -247,8 +256,8 @@ end | |||||||
|  |  | ||||||
| -- Logic Critical | -- Logic Critical | ||||||
| function Simulation.queuegate_c(sim, cgate) | function Simulation.queuegate_c(sim, cgate) | ||||||
| 	sim.gatequeue[sim.num_gatequeue] = cgate | 	sim.gatequeue[sim.num_gatequeue[0]] = cgate | ||||||
| 	sim.num_gatequeue = sim.num_gatequeue + 1 | 	sim.num_gatequeue[0] = sim.num_gatequeue[0] + 1 | ||||||
| 	cgate.in_queue[0] = 1 | 	cgate.in_queue[0] = 1 | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -285,8 +294,8 @@ end | |||||||
|  |  | ||||||
| -- Logic Critical | -- Logic Critical | ||||||
| function Simulation.queuegroup_c(sim, cnet) | function Simulation.queuegroup_c(sim, cnet) | ||||||
| 	sim.groupqueue[sim.num_groupqueue] = cnet | 	sim.groupqueue[sim.num_groupqueue[0]] = cnet | ||||||
| 	sim.num_groupqueue = sim.num_groupqueue + 1 | 	sim.num_groupqueue[0] = sim.num_groupqueue[0] + 1 | ||||||
| 	cnet.in_queue[0] = 1 | 	cnet.in_queue[0] = 1 | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -303,7 +312,7 @@ end | |||||||
|  |  | ||||||
| function Simulation.dequeuegroup(sim, group) | function Simulation.dequeuegroup(sim, group) | ||||||
| 	if group.in_queue[0]~=0 then | 	if group.in_queue[0]~=0 then | ||||||
| 		sim.num_groupqueue = array_remove(sim.groupqueue, sim.num_groupqueue, group.c, true) | 		sim.num_groupqueue[0] = array_remove(sim.groupqueue, sim.num_groupqueue[0], group.c, true) | ||||||
| 		group.in_queue[0] = 0 | 		group.in_queue[0] = 0 | ||||||
| 	end | 	end | ||||||
| 	--sim.groupfxqueue[group] = nil | 	--sim.groupfxqueue[group] = nil | ||||||
| @@ -311,7 +320,7 @@ end | |||||||
|  |  | ||||||
| function Simulation.dequeuegate(sim, gate) | function Simulation.dequeuegate(sim, gate) | ||||||
| 	if gate.in_queue[0]~=0 then | 	if gate.in_queue[0]~=0 then | ||||||
| 		sim.num_gatequeue = array_remove(sim.gatequeue, sim.num_gatequeue, gate.c, true) | 		sim.num_gatequeue[0] = array_remove(sim.gatequeue, sim.num_gatequeue[0], gate.c, true) | ||||||
| 		gate.in_queue[0] = 0 | 		gate.in_queue[0] = 0 | ||||||
| 	end | 	end | ||||||
| 	if sim.inputqueue~=nil then sim.inputqueue[gate] = nil end | 	if sim.inputqueue~=nil then sim.inputqueue[gate] = nil end | ||||||
| @@ -332,13 +341,13 @@ end | |||||||
|  |  | ||||||
| -- Logic Critical | -- Logic Critical | ||||||
| function Simulation.ticklogic(sim) | function Simulation.ticklogic(sim) | ||||||
| 	for i = 0, sim.num_groupqueue-1 do | 	for i = 0, sim.num_groupqueue[0]-1 do | ||||||
| 		local cnet = sim.groupqueue[i] | 		local cnet = sim.groupqueue[i] | ||||||
| 		Group.update_c(cnet, sim.current_tick) | 		Group.update_c(cnet, sim.current_tick) | ||||||
| 		cnet.in_queue[0] = 0 | 		cnet.in_queue[0] = 0 | ||||||
| 		sim.groupqueue[i] = nil | 		sim.groupqueue[i] = nil | ||||||
| 	end | 	end | ||||||
| 	sim.num_groupqueue = 0 | 	sim.num_groupqueue[0] = 0 | ||||||
| 	 | 	 | ||||||
| 	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 | ||||||
| @@ -349,14 +358,14 @@ function Simulation.ticklogic(sim) | |||||||
| 		sim.tickqueue[sim.current_tick] = nil | 		sim.tickqueue[sim.current_tick] = nil | ||||||
| 	end | 	end | ||||||
| 	 | 	 | ||||||
| 	for i = 0, sim.num_gatequeue-1 do | 	for i = 0, sim.num_gatequeue[0]-1 do | ||||||
| 		local cgate = sim.gatequeue[i] | 		local cgate = sim.gatequeue[i] | ||||||
| 		local gate = Simulation.gate_from_cgate(sim, cgate) | 		local gate = Simulation.gate_from_cgate(sim, cgate) | ||||||
| 		gate.logic(gate) | 		gate.logic(gate) | ||||||
| 		cgate.in_queue[0] = 0 | 		cgate.in_queue[0] = 0 | ||||||
| 		sim.gatequeue[i] = nil | 		sim.gatequeue[i] = nil | ||||||
| 	end | 	end | ||||||
| 	sim.num_gatequeue = 0 | 	sim.num_gatequeue[0] = 0 | ||||||
| 	 | 	 | ||||||
| 	sim.current_tick = sim.current_tick + 1 | 	sim.current_tick = sim.current_tick + 1 | ||||||
| end | end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Redo
					Redo