Fix placement of switch outlets

master
Louis Pearson 2022-08-09 23:02:02 -06:00
parent cc5867424a
commit 9ef283d3ac
2 changed files with 37 additions and 2 deletions

View File

@ -341,6 +341,23 @@ pub fn fill(this: *@This(), alloc: std.mem.Allocator, db: world.Database, level:
try q.insert(.{ .node_id = new_id, .coord = node.coord.add(.{ 0, -1 }) }); try q.insert(.{ .node_id = new_id, .coord = node.coord.add(.{ 0, -1 }) });
continue; continue;
} }
if (T.is_switch(tile)) {
const n = node.coord.add(.{0,-1}) ;
const w = node.coord.add(.{-1,0}) ;
const e = node.coord.add(.{1,0}) ;
const s = node.coord.add(.{0,1}) ;
const nid = db.getLevelNodeID(level, n) ;
const wid = db.getLevelNodeID(level, w) ;
const eid = db.getLevelNodeID(level, e) ;
const sid = db.getLevelNodeID(level, s) ;
if(nid) |new_id| try q.insert(.{ .node_id = new_id, .coord = n });
if(wid) |new_id| try q.insert(.{ .node_id = new_id, .coord = w });
if(eid) |new_id| try q.insert(.{ .node_id = new_id, .coord = e });
if(sid) |new_id| try q.insert(.{ .node_id = new_id, .coord = s });
continue;
}
for (get_outputs(tile)) |conductor, i| { for (get_outputs(tile)) |conductor, i| {
// w4.tracef("[fill] outputs"); // w4.tracef("[fill] outputs");
if (!conductor) continue; if (!conductor) continue;

View File

@ -480,7 +480,7 @@ pub fn buildCircuit(alloc: std.mem.Allocator, levels: []world.Level) !std.ArrayL
// Add switch outlets // Add switch outlets
if (input_dir != .West and west) { if (input_dir != .West and west) {
const out_node = @intCast(world.NodeID, nodes.items.len); const out_node = @intCast(world.NodeID, nodes.items.len);
const new_coord = coord.add(.{1, 0}); const new_coord = coord.add(.{-1, 0});
try nodes.append(.{ try nodes.append(.{
.kind = .{ .SwitchOutlet = .{ .kind = .{ .SwitchOutlet = .{
.source = next_node, .source = next_node,
@ -499,7 +499,7 @@ pub fn buildCircuit(alloc: std.mem.Allocator, levels: []world.Level) !std.ArrayL
if (input_dir != .East and east) { if (input_dir != .East and east) {
const out_node = @intCast(world.NodeID, nodes.items.len); const out_node = @intCast(world.NodeID, nodes.items.len);
const new_coord = coord.add(.{-1, 0}); const new_coord = coord.add(.{1, 0});
try nodes.append(.{ try nodes.append(.{
.kind = .{ .SwitchOutlet = .{ .kind = .{ .SwitchOutlet = .{
.source = next_node, .source = next_node,
@ -614,9 +614,18 @@ pub fn buildCircuit(alloc: std.mem.Allocator, levels: []world.Level) !std.ArrayL
}); });
} }
try multi_input.put(coord, next_node); try multi_input.put(coord, next_node);
const up = try alloc.create(Node);
up.* = Node{ .data = .{
.last_node = next_node,
.coord = coord.add(.{ 0, -1 }),
.last_coord = coord,
} };
bfs_queue.append(up);
continue;
} }
}, },
.Xor => { .Xor => {
std.log.warn("XOR XOR XOR",.{});
// TODO: verify Xor gate is properly connected // TODO: verify Xor gate is properly connected
const last_coord = node.data.last_coord.?; const last_coord = node.data.last_coord.?;
const Side = enum { O, L, R }; const Side = enum { O, L, R };
@ -660,6 +669,14 @@ pub fn buildCircuit(alloc: std.mem.Allocator, levels: []world.Level) !std.ArrayL
}); });
} }
try multi_input.put(coord, next_node); try multi_input.put(coord, next_node);
const up = try alloc.create(Node);
up.* = Node{ .data = .{
.last_node = next_node,
.coord = coord.add(.{ 0, -1 }),
.last_coord = coord,
} };
bfs_queue.append(up);
continue;
} }
}, },
.None => continue, .None => continue,
@ -695,6 +712,7 @@ pub fn buildCircuit(alloc: std.mem.Allocator, levels: []world.Level) !std.ArrayL
bfs_queue.append(left); bfs_queue.append(left);
bfs_queue.append(down); bfs_queue.append(down);
bfs_queue.append(up); bfs_queue.append(up);
} }
} }
} }