make net updates c
This commit is contained in:
parent
17edf2a782
commit
c73fea8cca
@ -1 +0,0 @@
|
|||||||
|
|
@ -1 +1,78 @@
|
|||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
struct Net;
|
||||||
|
struct Gate;
|
||||||
|
|
||||||
|
struct Gate {
|
||||||
|
int* in_queue;
|
||||||
|
int* port_states;
|
||||||
|
int** port_net_state;
|
||||||
|
int** port_net_state_num;
|
||||||
|
int** port_net_in_queue;
|
||||||
|
struct Net** port_nets_c;
|
||||||
|
int objref;
|
||||||
|
};
|
||||||
|
struct Net {
|
||||||
|
int* state;
|
||||||
|
int* state_num;
|
||||||
|
int* in_queue;
|
||||||
|
int* update_tick;
|
||||||
|
int* num_gates_update;
|
||||||
|
struct Gate** gates_update_c;
|
||||||
|
int id;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void sim_set_data(struct Net** net_queue, int* num_net_queue, struct Gate** gate_queue, int* num_gate_queue, int* current_tick, int queue_max);
|
||||||
|
void sim_update_nets();
|
||||||
|
|
||||||
|
struct Net** net_queue;
|
||||||
|
int* num_net_queue;
|
||||||
|
struct Gate** gate_queue;
|
||||||
|
int* num_gate_queue;
|
||||||
|
int* current_tick;
|
||||||
|
int queue_max;
|
||||||
|
|
||||||
|
void sim_set_data(struct Net** net_queue_in, int* num_net_queue_in, struct Gate** gate_queue_in, int* num_gate_queue_in, int* current_tick_in, int queue_max_in) {
|
||||||
|
net_queue = net_queue_in;
|
||||||
|
num_net_queue = num_net_queue_in;
|
||||||
|
gate_queue = gate_queue_in;
|
||||||
|
num_gate_queue = num_gate_queue_in;
|
||||||
|
current_tick = current_tick_in;
|
||||||
|
queue_max = queue_max_in;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sim_update_net(struct Net* net);
|
||||||
|
void sim_update_nets() {
|
||||||
|
for(int i=0; i<*num_net_queue; i++) {
|
||||||
|
struct Net* net = net_queue[i];
|
||||||
|
sim_update_net(net);
|
||||||
|
*(net->in_queue) = 0;
|
||||||
|
net_queue[i] = 0;
|
||||||
|
}
|
||||||
|
*num_net_queue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
////
|
||||||
|
|
||||||
|
void sim_queue_gate(struct Gate* gate) {
|
||||||
|
assert(*num_gate_queue < queue_max);
|
||||||
|
gate_queue[*num_gate_queue++] = gate;
|
||||||
|
*(gate->in_queue) = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sim_update_net(struct Net* net) {
|
||||||
|
int state = *(net->state_num) > 0;
|
||||||
|
if(state != *(net->state)) {
|
||||||
|
*(net->state) = state;
|
||||||
|
*(net->update_tick) = *current_tick;
|
||||||
|
|
||||||
|
for(int i=0; i<*(net->num_gates_update); i++) {
|
||||||
|
struct Gate* gate = net->gates_update_c[i];
|
||||||
|
if(!*(gate->in_queue)) {
|
||||||
|
sim_queue_gate(gate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Binary file not shown.
@ -212,23 +212,23 @@ function Group.mergeinto(group, group2)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Logic Critical
|
-- Logic Critical
|
||||||
function Group.update_c(cnet, tick)
|
--function Group.update_c(cnet, tick)
|
||||||
local state = cnet.state_num[0]>0 and 1 or 0
|
-- local state = cnet.state_num[0]>0 and 1 or 0
|
||||||
if state ~= cnet.state[0] then
|
-- if state ~= cnet.state[0] then
|
||||||
cnet.state[0] = state
|
-- cnet.state[0] = state
|
||||||
cnet.update_tick[0] = tick
|
-- cnet.update_tick[0] = tick
|
||||||
|
--
|
||||||
local len = cnet.num_gates_update[0]-1
|
-- local len = cnet.num_gates_update[0]-1
|
||||||
for i = 0, len do
|
-- for i = 0, len do
|
||||||
local cgate = cnet.gates_update_c[i]
|
-- local cgate = cnet.gates_update_c[i]
|
||||||
if cgate.in_queue[0]==0 then
|
-- if cgate.in_queue[0]==0 then
|
||||||
Simulation.queuegate_c(GSim, cgate)
|
-- Simulation.queuegate_c(GSim, cgate)
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
|
--
|
||||||
--Simulation.queuegroupfx(GSim, net)
|
-- --Simulation.queuegroupfx(GSim, net)
|
||||||
end
|
-- end
|
||||||
end
|
--end
|
||||||
|
|
||||||
function Group.rebuild_ports(net)
|
function Group.rebuild_ports(net)
|
||||||
net.gates_update = {}
|
net.gates_update = {}
|
||||||
|
@ -26,7 +26,6 @@ dofile("gatedef.lua")
|
|||||||
dofile("port.lua")
|
dofile("port.lua")
|
||||||
dofile("gate.lua")
|
dofile("gate.lua")
|
||||||
dofile("save.lua")
|
dofile("save.lua")
|
||||||
dofile("compile.lua")
|
|
||||||
dofile("network.lua")
|
dofile("network.lua")
|
||||||
FFI = nil
|
FFI = nil
|
||||||
|
|
||||||
|
@ -4,7 +4,10 @@ local ffi = FFI or require("ffi")
|
|||||||
ffi.cdef [[
|
ffi.cdef [[
|
||||||
struct Gate;
|
struct Gate;
|
||||||
struct Net;
|
struct Net;
|
||||||
|
void sim_set_data(struct Net** net_queue, int* num_net_queue, struct Gate** gate_queue, int* num_gate_queue, int* current_tick, int queue_max);
|
||||||
|
void sim_update_nets();
|
||||||
]]
|
]]
|
||||||
|
local csim = ffi.load("compiled_sim.dll")
|
||||||
|
|
||||||
Simulation = {}
|
Simulation = {}
|
||||||
|
|
||||||
@ -39,6 +42,7 @@ function Simulation.new(sim)
|
|||||||
o.num_groupqueue[0] = 0
|
o.num_groupqueue[0] = 0
|
||||||
o.num_gatequeue[0] = 0
|
o.num_gatequeue[0] = 0
|
||||||
o.current_tick[0] = 0
|
o.current_tick[0] = 0
|
||||||
|
sim_set_data(o.groupqueue, o.num_groupqueue, o.gatequeue, o.num_gatequeue, o.current_tick, queue_max)
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -346,13 +350,14 @@ end
|
|||||||
|
|
||||||
-- Logic Critical
|
-- Logic Critical
|
||||||
function Simulation.ticklogic(sim)
|
function Simulation.ticklogic(sim)
|
||||||
for i = 0, sim.num_groupqueue[0]-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[0])
|
-- Group.update_c(cnet, sim.current_tick[0])
|
||||||
cnet.in_queue[0] = 0
|
-- cnet.in_queue[0] = 0
|
||||||
sim.groupqueue[i] = nil
|
-- sim.groupqueue[i] = nil
|
||||||
end
|
--end
|
||||||
sim.num_groupqueue[0] = 0
|
--sim.num_groupqueue[0] = 0
|
||||||
|
csim.sim_update_nets()
|
||||||
|
|
||||||
if sim.tickqueue[sim.current_tick[0]] ~= nil then
|
if sim.tickqueue[sim.current_tick[0]] ~= nil then
|
||||||
for i, gate in pairs(sim.tickqueue[sim.current_tick[0]]) do
|
for i, gate in pairs(sim.tickqueue[sim.current_tick[0]]) do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user