Get wires working again
parent
313c058ae3
commit
d73f8d16bb
|
@ -131,18 +131,19 @@ fn cell2index(c: Cell) ?usize {
|
||||||
|
|
||||||
const CellState = struct { enabled: bool = false, tile: u8 };
|
const CellState = struct { enabled: bool = false, tile: u8 };
|
||||||
const MAXCELLS = 400;
|
const MAXCELLS = 400;
|
||||||
|
const MAXBRIDGES = 10;
|
||||||
const CellMap = [MAXCELLS]CellState;
|
const CellMap = [MAXCELLS]CellState;
|
||||||
const BridgeState = struct { cells: [2]Cell, id: usize, enabled: bool };
|
const BridgeState = struct { cells: [2]Cell, id: usize, enabled: bool };
|
||||||
|
|
||||||
offset: Cell,
|
offset: Cell,
|
||||||
cells: CellMap,
|
cells: CellMap,
|
||||||
bridges: std.BoundedArray(BridgeState, 10),
|
bridges: std.BoundedArray(BridgeState, MAXBRIDGES),
|
||||||
|
|
||||||
pub fn init() @This() {
|
pub fn init() @This() {
|
||||||
var this = @This(){
|
var this = @This(){
|
||||||
.offset = Cell{ 0, 0 },
|
.offset = Cell{ 0, 0 },
|
||||||
.cells = undefined,
|
.cells = undefined,
|
||||||
.bridges = std.BoundedArray(BridgeState, 10).init(0) catch unreachable,
|
.bridges = std.BoundedArray(BridgeState, MAXBRIDGES).init(0) catch unreachable,
|
||||||
};
|
};
|
||||||
return this;
|
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) {
|
pub fn enabledBridges(this: @This()) std.BoundedArray(usize, MAXBRIDGES) {
|
||||||
var items = std.BoundedArray(usize, 10).init(0) catch unreachable;
|
var items = std.BoundedArray(usize, MAXBRIDGES).init(0) catch unreachable;
|
||||||
for (this.bridges.constSlice()) |b| {
|
for (this.bridges.constSlice()) |b| {
|
||||||
if (b.enabled) items.append(b.id) catch unreachable;
|
if (b.enabled) items.append(b.id) catch unreachable;
|
||||||
}
|
}
|
||||||
|
|
11
src/main.zig
11
src/main.zig
|
@ -115,7 +115,7 @@ const ParticleSystem = struct {
|
||||||
|
|
||||||
pub fn draw(this: @This()) void {
|
pub fn draw(this: @This()) void {
|
||||||
for (this.particles.constSlice()) |*part| {
|
for (this.particles.constSlice()) |*part| {
|
||||||
w4.DRAW_COLORS.* = 0x0001;
|
w4.DRAW_COLORS.* = 0x0002;
|
||||||
w4.oval(util.vec2fToVec2(part.pos.pos), Vec2{ 2, 2 });
|
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;
|
var time: usize = 0;
|
||||||
|
|
||||||
export fn update() void {
|
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();
|
circuit.clear();
|
||||||
const q = World.Query.require(&.{.wire});
|
const q = World.Query.require(&.{.wire});
|
||||||
var wireIter = world.iter(q);
|
var wireIter = world.iter(q);
|
||||||
|
@ -251,7 +250,7 @@ export fn update() void {
|
||||||
var wireComponents = world.components.items(.wire);
|
var wireComponents = world.components.items(.wire);
|
||||||
var enabledWires = circuit.enabledBridges();
|
var enabledWires = circuit.enabledBridges();
|
||||||
for (enabledWires.slice()) |wireID| {
|
for (enabledWires.slice()) |wireID| {
|
||||||
var wire = wireComponents[wireID].?;
|
var wire = &wireComponents[wireID].?;
|
||||||
wire.enabled = true;
|
wire.enabled = true;
|
||||||
if (time % 60 == 0) {
|
if (time % 60 == 0) {
|
||||||
if (!wire.begin().pinned) particles.createNRandom(wire.begin().pos, 8);
|
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}, velocityProcess);
|
||||||
world.process(1, &.{ .pos, .physics }, physicsProcess);
|
world.process(1, &.{ .pos, .physics }, physicsProcess);
|
||||||
|
|
Loading…
Reference in New Issue