diff --git a/src/circuit.zig b/src/circuit.zig index f4b0b62..a7d82bb 100644 --- a/src/circuit.zig +++ b/src/circuit.zig @@ -131,18 +131,19 @@ fn cell2index(c: Cell) ?usize { const CellState = struct { enabled: bool = false, tile: u8 }; const MAXCELLS = 400; +const MAXBRIDGES = 10; const CellMap = [MAXCELLS]CellState; const BridgeState = struct { cells: [2]Cell, id: usize, enabled: bool }; offset: Cell, cells: CellMap, -bridges: std.BoundedArray(BridgeState, 10), +bridges: std.BoundedArray(BridgeState, MAXBRIDGES), pub fn init() @This() { var this = @This(){ .offset = Cell{ 0, 0 }, .cells = undefined, - .bridges = std.BoundedArray(BridgeState, 10).init(0) catch unreachable, + .bridges = std.BoundedArray(BridgeState, MAXBRIDGES).init(0) catch unreachable, }; return this; } @@ -178,8 +179,8 @@ pub fn bridge(this: *@This(), cells: [2]Cell, bridgeID: usize) void { } } -pub fn enabledBridges(this: @This()) std.BoundedArray(usize, 10) { - var items = std.BoundedArray(usize, 10).init(0) catch unreachable; +pub fn enabledBridges(this: @This()) std.BoundedArray(usize, MAXBRIDGES) { + var items = std.BoundedArray(usize, MAXBRIDGES).init(0) catch unreachable; for (this.bridges.constSlice()) |b| { if (b.enabled) items.append(b.id) catch unreachable; } diff --git a/src/main.zig b/src/main.zig index 78141cc..f897122 100644 --- a/src/main.zig +++ b/src/main.zig @@ -115,7 +115,7 @@ const ParticleSystem = struct { pub fn draw(this: @This()) void { for (this.particles.constSlice()) |*part| { - w4.DRAW_COLORS.* = 0x0001; + w4.DRAW_COLORS.* = 0x0002; w4.oval(util.vec2fToVec2(part.pos.pos), Vec2{ 2, 2 }); } } @@ -230,10 +230,9 @@ var indicator: ?struct { pos: Vec2, t: enum { wire, plug, lever }, active: bool var time: usize = 0; export fn update() void { - w4.DRAW_COLORS.* = 0x0004; - w4.rect(.{ 0, 0 }, .{ 160, 160 }); - { + // Doing this before clearing the screen since the stack + // reaches the screen during this block circuit.clear(); const q = World.Query.require(&.{.wire}); var wireIter = world.iter(q); @@ -251,7 +250,7 @@ export fn update() void { var wireComponents = world.components.items(.wire); var enabledWires = circuit.enabledBridges(); for (enabledWires.slice()) |wireID| { - var wire = wireComponents[wireID].?; + var wire = &wireComponents[wireID].?; wire.enabled = true; if (time % 60 == 0) { if (!wire.begin().pinned) particles.createNRandom(wire.begin().pos, 8); @@ -259,6 +258,8 @@ export fn update() void { } } } + w4.DRAW_COLORS.* = 0x0004; + w4.rect(.{ 0, 0 }, .{ 160, 160 }); world.process(1, &.{.pos}, velocityProcess); world.process(1, &.{ .pos, .physics }, physicsProcess);