make gates use net state pointers
This commit is contained in:
		
							
								
								
									
										11
									
								
								sim/gate.lua
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								sim/gate.lua
									
									
									
									
									
								
							| @@ -11,6 +11,9 @@ function Gate.new(objref, definition) | |||||||
| 		logic = definition.logic, | 		logic = definition.logic, | ||||||
| 		ports = {}, | 		ports = {}, | ||||||
| 		port_nets = {}, | 		port_nets = {}, | ||||||
|  | 		port_net_state     = ffi.new("int*["..(#definition.ports+1).."]"), | ||||||
|  | 		port_net_state_num = ffi.new("int*["..(#definition.ports+1).."]"), | ||||||
|  | 		port_net_in_queue  = ffi.new("int*["..(#definition.ports+1).."]"), | ||||||
| 		 | 		 | ||||||
| 		objref = objref, | 		objref = objref, | ||||||
| 		definition = definition, | 		definition = definition, | ||||||
| @@ -20,17 +23,17 @@ end | |||||||
|  |  | ||||||
| -- Logic Critical | -- Logic Critical | ||||||
| function Gate.getportstate(gate, index) | function Gate.getportstate(gate, index) | ||||||
| 	return gate.port_nets[index].state[0] | 	return gate.port_net_state[index][0] | ||||||
| end | end | ||||||
|  |  | ||||||
| -- Logic Critical | -- Logic Critical | ||||||
| function Gate.setportstate(gate, index, state) | function Gate.setportstate(gate, index, state) | ||||||
| 	if state ~= gate.port_states[index] then | 	if state ~= gate.port_states[index] then | ||||||
| 		local group = gate.port_nets[index] | 		gate.port_net_state_num[index][0] = gate.port_net_state_num[index][0] - gate.port_states[index] + state | ||||||
| 		group.state_num[0] = group.state_num[0] - gate.port_states[index] + state |  | ||||||
| 		gate.port_states[index] = state | 		gate.port_states[index] = state | ||||||
| 		 | 		 | ||||||
| 		if ((group.state_num[0]>0) ~= (group.state[0]==1)) and (group.in_queue[0]==0) then | 		if ((gate.port_net_state_num[index][0]>0) ~= (gate.port_net_state[index][0]==1)) and (gate.port_net_in_queue[index][0]==0) then | ||||||
|  | 			local group = gate.port_nets[index] | ||||||
| 			Simulation.queuegroup(GSim, group) | 			Simulation.queuegroup(GSim, group) | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
|   | |||||||
| @@ -104,6 +104,10 @@ function GateDefinition.constructgate(def, objref, position, rotation) | |||||||
| 		gate.ports[port.idx] = port | 		gate.ports[port.idx] = port | ||||||
| 		gate.port_nets[port.idx] = nil | 		gate.port_nets[port.idx] = nil | ||||||
| 		gate.port_states[port.idx] = 0 | 		gate.port_states[port.idx] = 0 | ||||||
|  | 		 | ||||||
|  | 		gate.port_net_state    [port.idx] = ffi.cast("int*", 0) | ||||||
|  | 		gate.port_net_state_num[port.idx] = ffi.cast("int*", 0) | ||||||
|  | 		gate.port_net_in_queue [port.idx] = ffi.cast("int*", 0) | ||||||
| 	end | 	end | ||||||
| 	 | 	 | ||||||
| 	return gate | 	return gate | ||||||
|   | |||||||
| @@ -50,6 +50,15 @@ end | |||||||
| function Port.setgroup(port, group) | function Port.setgroup(port, group) | ||||||
| 	port.group = group | 	port.group = group | ||||||
| 	Port.getgate(port).port_nets[port.idx] = group | 	Port.getgate(port).port_nets[port.idx] = group | ||||||
|  | 	if group then | ||||||
|  | 		Port.getgate(port).port_net_state    [port.idx] = group.state | ||||||
|  | 		Port.getgate(port).port_net_state_num[port.idx] = group.state_num | ||||||
|  | 		Port.getgate(port).port_net_in_queue [port.idx] = group.in_queue | ||||||
|  | 	else | ||||||
|  | 		Port.getgate(port).port_net_state    [port.idx] = ffi.cast("int*", 0) | ||||||
|  | 		Port.getgate(port).port_net_state_num[port.idx] = ffi.cast("int*", 0) | ||||||
|  | 		Port.getgate(port).port_net_in_queue [port.idx] = ffi.cast("int*", 0) | ||||||
|  | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| function Port.getgroup(port) | function Port.getgroup(port) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Redo
					Redo