Get wires connecting
Unforunately this has exposed my circuit analysis is incompletemaster
parent
ae51861c6e
commit
8c26b29ca6
|
@ -3528,10 +3528,10 @@
|
||||||
"optionalRules": [],
|
"optionalRules": [],
|
||||||
"intGridCsv": [
|
"intGridCsv": [
|
||||||
0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,5,1,0,0,0,0,0,0,0,0,0,0,1,0,0,
|
0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,5,1,0,0,0,0,0,0,0,0,0,0,1,0,0,
|
||||||
0,0,0,2,1,0,0,1,1,1,1,2,0,0,0,2,0,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,
|
0,0,0,2,1,0,0,1,2,0,0,0,0,0,0,2,0,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,
|
||||||
1,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,
|
1,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,
|
||||||
0,0,8,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,
|
0,0,8,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,
|
||||||
1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,2,0,0,0,0,0,0,0,
|
1,0,0,0,0,0,0,1,1,1,1,1,6,1,1,1,1,1,1,0,1,0,0,0,0,0,0,2,0,0,0,0,0,0,0,
|
||||||
0,0,0,2,0,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,
|
0,0,0,2,0,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,
|
||||||
0,0,1,1,1,1,1,1,1,9,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,
|
0,0,1,1,1,1,1,1,1,9,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,
|
||||||
|
@ -3563,7 +3563,6 @@
|
||||||
{ "px": [0,136], "src": [40,48], "f": 0, "t": 101, "d": [38,340] },
|
{ "px": [0,136], "src": [40,48], "f": 0, "t": 101, "d": [38,340] },
|
||||||
{ "px": [40,152], "src": [40,48], "f": 0, "t": 101, "d": [38,385] },
|
{ "px": [40,152], "src": [40,48], "f": 0, "t": 101, "d": [38,385] },
|
||||||
{ "px": [80,24], "src": [56,48], "f": 0, "t": 103, "d": [42,70] },
|
{ "px": [80,24], "src": [56,48], "f": 0, "t": 103, "d": [42,70] },
|
||||||
{ "px": [96,56], "src": [56,48], "f": 0, "t": 103, "d": [42,152] },
|
|
||||||
{ "px": [96,24], "src": [88,48], "f": 0, "t": 107, "d": [43,72] },
|
{ "px": [96,24], "src": [88,48], "f": 0, "t": 107, "d": [43,72] },
|
||||||
{ "px": [16,0], "src": [48,48], "f": 0, "t": 102, "d": [44,2] },
|
{ "px": [16,0], "src": [48,48], "f": 0, "t": 102, "d": [44,2] },
|
||||||
{ "px": [24,0], "src": [48,48], "f": 0, "t": 102, "d": [44,3] },
|
{ "px": [24,0], "src": [48,48], "f": 0, "t": 102, "d": [44,3] },
|
||||||
|
@ -3575,9 +3574,6 @@
|
||||||
{ "px": [72,0], "src": [48,48], "f": 0, "t": 102, "d": [44,9] },
|
{ "px": [72,0], "src": [48,48], "f": 0, "t": 102, "d": [44,9] },
|
||||||
{ "px": [80,0], "src": [48,48], "f": 0, "t": 102, "d": [44,10] },
|
{ "px": [80,0], "src": [48,48], "f": 0, "t": 102, "d": [44,10] },
|
||||||
{ "px": [88,0], "src": [48,48], "f": 0, "t": 102, "d": [44,11] },
|
{ "px": [88,0], "src": [48,48], "f": 0, "t": 102, "d": [44,11] },
|
||||||
{ "px": [24,16], "src": [48,48], "f": 0, "t": 102, "d": [44,43] },
|
|
||||||
{ "px": [32,16], "src": [48,48], "f": 0, "t": 102, "d": [44,44] },
|
|
||||||
{ "px": [40,16], "src": [48,48], "f": 0, "t": 102, "d": [44,45] },
|
|
||||||
{ "px": [64,24], "src": [48,48], "f": 0, "t": 102, "d": [44,68] },
|
{ "px": [64,24], "src": [48,48], "f": 0, "t": 102, "d": [44,68] },
|
||||||
{ "px": [72,24], "src": [48,48], "f": 0, "t": 102, "d": [44,69] },
|
{ "px": [72,24], "src": [48,48], "f": 0, "t": 102, "d": [44,69] },
|
||||||
{ "px": [88,24], "src": [48,48], "f": 0, "t": 102, "d": [44,71] },
|
{ "px": [88,24], "src": [48,48], "f": 0, "t": 102, "d": [44,71] },
|
||||||
|
@ -3633,12 +3629,13 @@
|
||||||
{ "px": [80,16], "src": [24,8], "f": 0, "t": 19, "d": [56,50] },
|
{ "px": [80,16], "src": [24,8], "f": 0, "t": 19, "d": [56,50] },
|
||||||
{ "px": [96,72], "src": [24,8], "f": 0, "t": 19, "d": [56,192] },
|
{ "px": [96,72], "src": [24,8], "f": 0, "t": 19, "d": [56,192] },
|
||||||
{ "px": [144,8], "src": [16,8], "f": 0, "t": 18, "d": [59,38] },
|
{ "px": [144,8], "src": [16,8], "f": 0, "t": 18, "d": [59,38] },
|
||||||
{ "px": [48,16], "src": [8,8], "f": 0, "t": 17, "d": [58,46] },
|
{ "px": [24,16], "src": [8,8], "f": 0, "t": 17, "d": [58,43] },
|
||||||
{ "px": [56,64], "src": [0,8], "f": 0, "t": 16, "d": [57,167] },
|
{ "px": [56,64], "src": [0,8], "f": 0, "t": 16, "d": [57,167] },
|
||||||
{ "px": [144,64], "src": [0,8], "f": 0, "t": 16, "d": [57,178] },
|
{ "px": [144,64], "src": [0,8], "f": 0, "t": 16, "d": [57,178] },
|
||||||
{ "px": [40,128], "src": [96,8], "f": 0, "t": 28, "d": [78,325] },
|
{ "px": [40,128], "src": [96,8], "f": 0, "t": 28, "d": [78,325] },
|
||||||
{ "px": [72,128], "src": [96,8], "f": 0, "t": 28, "d": [78,329] },
|
{ "px": [72,128], "src": [96,8], "f": 0, "t": 28, "d": [78,329] },
|
||||||
{ "px": [0,8], "src": [48,48], "f": 0, "t": 102, "d": [68,20] },
|
{ "px": [0,8], "src": [48,48], "f": 0, "t": 102, "d": [68,20] },
|
||||||
|
{ "px": [96,56], "src": [32,8], "f": 0, "t": 20, "d": [82,152] },
|
||||||
{ "px": [56,120], "src": [32,8], "f": 0, "t": 20, "d": [82,307] }
|
{ "px": [56,120], "src": [32,8], "f": 0, "t": 20, "d": [82,307] }
|
||||||
],
|
],
|
||||||
"seed": 1371187,
|
"seed": 1371187,
|
||||||
|
@ -3666,7 +3663,7 @@
|
||||||
"optionalRules": [],
|
"optionalRules": [],
|
||||||
"intGridCsv": [
|
"intGridCsv": [
|
||||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,3,3,1,1,1,
|
0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,3,3,3,3,1,1,1,
|
||||||
1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,
|
1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,
|
||||||
0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||||
1,1,1,0,0,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,
|
1,1,1,0,0,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
@ -3796,11 +3793,13 @@
|
||||||
{ "px": [8,136], "src": [16,56], "f": 0, "t": 114, "d": [20,341] },
|
{ "px": [8,136], "src": [16,56], "f": 0, "t": 114, "d": [20,341] },
|
||||||
{ "px": [56,32], "src": [8,56], "f": 0, "t": 113, "d": [23,87] },
|
{ "px": [56,32], "src": [8,56], "f": 0, "t": 113, "d": [23,87] },
|
||||||
{ "px": [88,120], "src": [8,56], "f": 0, "t": 113, "d": [23,311] },
|
{ "px": [88,120], "src": [8,56], "f": 0, "t": 113, "d": [23,311] },
|
||||||
{ "px": [40,24], "src": [8,16], "f": 0, "t": 33, "d": [125,65] },
|
|
||||||
{ "px": [40,56], "src": [8,16], "f": 0, "t": 33, "d": [125,145] },
|
{ "px": [40,56], "src": [8,16], "f": 0, "t": 33, "d": [125,145] },
|
||||||
{ "px": [40,88], "src": [8,16], "f": 0, "t": 33, "d": [125,225] },
|
{ "px": [40,88], "src": [8,16], "f": 0, "t": 33, "d": [125,225] },
|
||||||
{ "px": [32,40], "src": [24,16], "f": 0, "t": 35, "d": [126,104] },
|
{ "px": [32,40], "src": [24,16], "f": 0, "t": 35, "d": [126,104] },
|
||||||
{ "px": [32,72], "src": [24,16], "f": 0, "t": 35, "d": [126,184] },
|
{ "px": [32,72], "src": [24,16], "f": 0, "t": 35, "d": [126,184] },
|
||||||
|
{ "px": [24,24], "src": [16,16], "f": 0, "t": 34, "d": [127,63] },
|
||||||
|
{ "px": [32,24], "src": [16,16], "f": 0, "t": 34, "d": [127,64] },
|
||||||
|
{ "px": [40,24], "src": [16,16], "f": 0, "t": 34, "d": [127,65] },
|
||||||
{ "px": [48,24], "src": [16,16], "f": 0, "t": 34, "d": [127,66] },
|
{ "px": [48,24], "src": [16,16], "f": 0, "t": 34, "d": [127,66] },
|
||||||
{ "px": [24,40], "src": [16,16], "f": 0, "t": 34, "d": [127,103] },
|
{ "px": [24,40], "src": [16,16], "f": 0, "t": 34, "d": [127,103] },
|
||||||
{ "px": [48,56], "src": [16,16], "f": 0, "t": 34, "d": [127,146] },
|
{ "px": [48,56], "src": [16,16], "f": 0, "t": 34, "d": [127,146] },
|
||||||
|
|
23
src/game.zig
23
src/game.zig
|
@ -677,7 +677,11 @@ fn updateCircuit() !void {
|
||||||
@intCast(i16, cellEnd[1]),
|
@intCast(i16, cellEnd[1]),
|
||||||
}).addC(topleft);
|
}).addC(topleft);
|
||||||
|
|
||||||
db.connectPlugs(p1, p2);
|
w4.tracef("p1 %d, %d \t p2 %d, %d", p1.val[0], p1.val[1], p2.val[0], p2.val[1]);
|
||||||
|
|
||||||
|
db.connectPlugs(p1, p2) catch {
|
||||||
|
w4.tracef("connect plugs error");
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simulate circuit
|
// Simulate circuit
|
||||||
|
@ -708,6 +712,23 @@ fn updateCircuit() !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
db.updateCircuit();
|
db.updateCircuit();
|
||||||
|
|
||||||
|
for (db.circuit_info) |node, n| {
|
||||||
|
switch (node.kind) {
|
||||||
|
.Conduit => |Conduit| w4.tracef("[%d]: Conduit [%d, %d]", n, Conduit[0], Conduit[1]),
|
||||||
|
.And => |And| w4.tracef("[%d]: And [%d, %d]", n, And[0], And[1]),
|
||||||
|
.Xor => |Xor| w4.tracef("[%d]: Xor [%d, %d]", n, Xor[0], Xor[1]),
|
||||||
|
.Source => w4.tracef("[%d]: Source", n),
|
||||||
|
.Plug => |Plug| {
|
||||||
|
const plug = Plug orelse std.math.maxInt(world.NodeID);
|
||||||
|
w4.tracef("[%d]: Plug [%d]", n, plug);
|
||||||
|
},
|
||||||
|
.Jack => |Jack| w4.tracef("[%d]: Jack [%d]", n, Jack),
|
||||||
|
.Switch => |Switch| w4.tracef("[%d]: Switch [%s]", n, &@tagName(Switch)),
|
||||||
|
.Join => |Join| w4.tracef("[%d]: Join [%d]", n, Join),
|
||||||
|
.Outlet => |Outlet| w4.tracef("[%d]: Outlet [%d]", n, Outlet),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wirePhysicsProcess(dt: f32, wire: *Wire) !void {
|
fn wirePhysicsProcess(dt: f32, wire: *Wire) !void {
|
||||||
|
|
|
@ -635,22 +635,24 @@ pub const Database = struct {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn connectPlugs(db: *Database, p1: Coord, p2: Coord) void {
|
fn getNodeID(db: *Database, coord: Coord) ?NodeID {
|
||||||
var opt1: ?usize = null;
|
|
||||||
var opt2: ?usize = null;
|
|
||||||
for (db.circuit_info) |node, i| {
|
for (db.circuit_info) |node, i| {
|
||||||
if (!p1.eq(node.coord) or !p2.eq(node.coord)) continue;
|
if (!coord.eq(node.coord)) continue;
|
||||||
if (p1.eq(node.coord)) opt1 = i else opt2 = i;
|
return @intCast(NodeID, i);
|
||||||
}
|
}
|
||||||
var plug1 = db.circuit_info[opt1 orelse return];
|
return null;
|
||||||
var plug2 = db.circuit_info[opt2 orelse return];
|
}
|
||||||
|
|
||||||
if (plug1.energized and !plug2.energized) {
|
pub fn connectPlugs(db: *Database, p1: Coord, p2: Coord) !void {
|
||||||
plug2.energized = true;
|
const p1id = db.getNodeID(p1) orelse return;
|
||||||
plug2.kind.Plug = @intCast(NodeID, opt1.?);
|
const p2id = db.getNodeID(p2) orelse return;
|
||||||
} else if (plug2.energized and !plug1.energized) {
|
|
||||||
plug1.energized = true;
|
if (db.circuit_info[p1id].kind == .Jack and db.circuit_info[p2id].kind == .Plug) {
|
||||||
plug1.kind.Plug = @intCast(NodeID, opt2.?);
|
db.circuit_info[p2id].kind.Plug = p1id;
|
||||||
|
} else if (db.circuit_info[p2id].kind == .Jack and db.circuit_info[p1id].kind == .Plug) {
|
||||||
|
db.circuit_info[p1id].kind.Plug = p2id;
|
||||||
|
} else if (db.circuit_info[p2id].kind == .Jack and db.circuit_info[p1id].kind == .Plug) {
|
||||||
|
return error.Unimplemented;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,6 +697,9 @@ pub const Database = struct {
|
||||||
db.circuit_info[i].energized = false;
|
db.circuit_info[i].energized = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
.Jack => |Jack| {
|
||||||
|
db.circuit_info[i].energized = db.circuit_info[Jack].energized;
|
||||||
|
},
|
||||||
.Switch => |state| {
|
.Switch => |state| {
|
||||||
// TODO Rework switch to make sense
|
// TODO Rework switch to make sense
|
||||||
db.circuit_info[i].energized = false;
|
db.circuit_info[i].energized = false;
|
||||||
|
@ -763,6 +768,7 @@ const NodeEnum = enum(u4) {
|
||||||
Source,
|
Source,
|
||||||
Conduit,
|
Conduit,
|
||||||
Plug,
|
Plug,
|
||||||
|
Jack,
|
||||||
Switch,
|
Switch,
|
||||||
Join,
|
Join,
|
||||||
Outlet,
|
Outlet,
|
||||||
|
@ -780,6 +786,8 @@ pub const NodeKind = union(NodeEnum) {
|
||||||
/// This node represents a physical plug in the game world. The
|
/// This node represents a physical plug in the game world. The
|
||||||
/// NodeID points to another plug, if connected
|
/// NodeID points to another plug, if connected
|
||||||
Plug: ?NodeID,
|
Plug: ?NodeID,
|
||||||
|
/// If a plug is connected to a circuit fragment with a source, it is a jack.
|
||||||
|
Jack: NodeID,
|
||||||
/// A switch can be in one of five states, though only
|
/// A switch can be in one of five states, though only
|
||||||
/// two apply to any one switch.
|
/// two apply to any one switch.
|
||||||
/// Vertical = Off or Top/Bottom, depending on flow
|
/// Vertical = Off or Top/Bottom, depending on flow
|
||||||
|
@ -822,6 +830,9 @@ pub const NodeKind = union(NodeEnum) {
|
||||||
kind = .{ .Plug = plug };
|
kind = .{ .Plug = plug };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
.Jack => {
|
||||||
|
kind = .{ .Jack = try reader.readInt(NodeID, .Little) };
|
||||||
|
},
|
||||||
.Switch => {
|
.Switch => {
|
||||||
kind = .{
|
kind = .{
|
||||||
.Switch = @intToEnum(SwitchEnum, try reader.readInt(NodeID, .Little)),
|
.Switch = @intToEnum(SwitchEnum, try reader.readInt(NodeID, .Little)),
|
||||||
|
@ -857,6 +868,9 @@ pub const NodeKind = union(NodeEnum) {
|
||||||
const plug = Plug orelse std.math.maxInt(NodeID);
|
const plug = Plug orelse std.math.maxInt(NodeID);
|
||||||
try writer.writeInt(NodeID, plug, .Little);
|
try writer.writeInt(NodeID, plug, .Little);
|
||||||
},
|
},
|
||||||
|
.Jack => |Jack| {
|
||||||
|
try writer.writeInt(NodeID, Jack, .Little);
|
||||||
|
},
|
||||||
.Switch => |Switch| {
|
.Switch => |Switch| {
|
||||||
try writer.writeInt(NodeID, @enumToInt(Switch), .Little);
|
try writer.writeInt(NodeID, @enumToInt(Switch), .Little);
|
||||||
},
|
},
|
||||||
|
@ -879,6 +893,7 @@ pub const NodeKind = union(NodeEnum) {
|
||||||
.Xor => |Xor| std.fmt.format(writer, "{s} [{}, {}]", .{ name, Xor[0], Xor[1] }),
|
.Xor => |Xor| std.fmt.format(writer, "{s} [{}, {}]", .{ name, Xor[0], Xor[1] }),
|
||||||
.Source => std.fmt.format(writer, "{s}", .{name}),
|
.Source => std.fmt.format(writer, "{s}", .{name}),
|
||||||
.Plug => |Plug| std.fmt.format(writer, "{s} [{?}]", .{ name, Plug }),
|
.Plug => |Plug| std.fmt.format(writer, "{s} [{?}]", .{ name, Plug }),
|
||||||
|
.Jack => |Jack| std.fmt.format(writer, "{s} [{}]", .{ name, Jack }),
|
||||||
.Switch => |Switch| std.fmt.format(writer, "{s} [{s}]", .{ name, @tagName(Switch) }),
|
.Switch => |Switch| std.fmt.format(writer, "{s} [{s}]", .{ name, @tagName(Switch) }),
|
||||||
.Join => |Join| std.fmt.format(writer, "{s} [{}]", .{ name, Join }),
|
.Join => |Join| std.fmt.format(writer, "{s} [{}]", .{ name, Join }),
|
||||||
.Outlet => |Outlet| std.fmt.format(writer, "{s} [{}]", .{ name, Outlet }),
|
.Outlet => |Outlet| std.fmt.format(writer, "{s} [{}]", .{ name, Outlet }),
|
||||||
|
|
|
@ -371,13 +371,23 @@ pub fn buildCircuit(alloc: std.mem.Allocator, levels: []world.Level) !std.ArrayL
|
||||||
// TODO
|
// TODO
|
||||||
},
|
},
|
||||||
.Plug => {
|
.Plug => {
|
||||||
// These have already been added, so just continue the
|
if (last_node == std.math.maxInt(world.NodeID)) {
|
||||||
// search
|
next_node = @intCast(world.NodeID, nodes.items.len);
|
||||||
next_node = @intCast(world.NodeID, nodes.items.len);
|
try nodes.append(.{
|
||||||
try nodes.append(.{
|
.kind = .{ .Plug = null },
|
||||||
.kind = .{ .Plug = null },
|
.coord = coord,
|
||||||
.coord = coord,
|
});
|
||||||
});
|
} else {
|
||||||
|
// This plug is connected directly to a circuit fragment
|
||||||
|
// with a source, so we are at the end of the search along
|
||||||
|
// this conduit path. Make the plug a jack instead, so it
|
||||||
|
// looks at the last node instead of being null
|
||||||
|
try nodes.append(.{
|
||||||
|
.kind = .{ .Jack = last_node },
|
||||||
|
.coord = coord,
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
.Outlet => {
|
.Outlet => {
|
||||||
next_node = @intCast(world.NodeID, nodes.items.len);
|
next_node = @intCast(world.NodeID, nodes.items.len);
|
||||||
|
|
Loading…
Reference in New Issue