Uncomment door code
Still doesn't work because I decided to do doors differently. My next step is to make the door entities add and remove tilesmaster
parent
3c0f4580b5
commit
cce79b4d90
|
@ -1,2 +1 @@
|
||||||
pub usingnamespace @import("tiles.zig");
|
pub usingnamespace @import("tiles.zig");
|
||||||
pub usingnamespace @import("maps/map.zig");
|
|
||||||
|
|
|
@ -235,9 +235,12 @@ pub fn enabledBridges(this: @This(), alloc: std.mem.Allocator) !util.Buffer(usiz
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enabledDoors(this: @This(), alloc: std.mem.Allocator) !util.Buffer(Cell) {
|
pub fn enabledDoors(this: @This(), alloc: std.mem.Allocator) !util.Buffer(Cell) {
|
||||||
var items = try alloc.alloc(Cell, this.doors.len);
|
var items = try alloc.alloc(Cell, this.doors.items.len);
|
||||||
var buffer = util.Buffer(Cell).init(items);
|
var buffer = util.Buffer(Cell).init(items);
|
||||||
for (this.doors.items) |d| {
|
for (this.doors.items) |d| {
|
||||||
|
const x = d.cell[0];
|
||||||
|
const y = d.cell[1];
|
||||||
|
w4.tracef("%d, %d", x, y);
|
||||||
if (d.enabled) buffer.append(d.cell);
|
if (d.enabled) buffer.append(d.cell);
|
||||||
}
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
|
@ -617,10 +617,11 @@ fn updateCircuit() !void {
|
||||||
(circuit.isEnabled(cellEnd) and end.pinned)) wire.enabled = true;
|
(circuit.isEnabled(cellEnd) and end.pinned)) wire.enabled = true;
|
||||||
}
|
}
|
||||||
// map.reset(&assets.solid);
|
// map.reset(&assets.solid);
|
||||||
// const enabledDoors = try circuit.enabledDoors(frame_alloc);
|
const enabledDoors = try circuit.enabledDoors(frame_alloc);
|
||||||
// for (enabledDoors.items) |door| {
|
defer frame_alloc.free(enabledDoors.items);
|
||||||
// try map.set_cell(door, 0);
|
for (enabledDoors.items) |door| {
|
||||||
// }
|
try map.set_cell(door, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wirePhysicsProcess(dt: f32, wire: *Wire) !void {
|
fn wirePhysicsProcess(dt: f32, wire: *Wire) !void {
|
||||||
|
|
|
@ -29,7 +29,7 @@ export fn update() void {
|
||||||
.Menu => menu.update(),
|
.Menu => menu.update(),
|
||||||
.Game => game.update(time) catch |e| switch (e) {
|
.Game => game.update(time) catch |e| switch (e) {
|
||||||
error.Overflow => showErr(@errorName(e)),
|
error.Overflow => showErr(@errorName(e)),
|
||||||
// error.OutOfBounds => showErr(@errorName(e)),
|
error.OutOfBounds => showErr(@errorName(e)),
|
||||||
// error.EndOfStream => showErr(@errorName(e)),
|
// error.EndOfStream => showErr(@errorName(e)),
|
||||||
error.OutOfMemory => showErr(@errorName(e)),
|
error.OutOfMemory => showErr(@errorName(e)),
|
||||||
},
|
},
|
||||||
|
@ -40,7 +40,7 @@ export fn update() void {
|
||||||
.Menu => menu.start(),
|
.Menu => menu.start(),
|
||||||
.Game => game.start() catch |e| switch (e) {
|
.Game => game.start() catch |e| switch (e) {
|
||||||
error.Overflow => showErr(@errorName(e)),
|
error.Overflow => showErr(@errorName(e)),
|
||||||
// error.OutOfBounds => showErr(@errorName(e)),
|
error.OutOfBounds => showErr(@errorName(e)),
|
||||||
error.EndOfStream => showErr(@errorName(e)),
|
error.EndOfStream => showErr(@errorName(e)),
|
||||||
error.OutOfMemory => showErr(@errorName(e)),
|
error.OutOfMemory => showErr(@errorName(e)),
|
||||||
error.NullTiles => showErr(@errorName(e)),
|
error.NullTiles => showErr(@errorName(e)),
|
||||||
|
|
25
src/util.zig
25
src/util.zig
|
@ -107,24 +107,33 @@ test "Queue" {
|
||||||
|
|
||||||
pub fn Buffer(comptime T: type) type {
|
pub fn Buffer(comptime T: type) type {
|
||||||
return struct {
|
return struct {
|
||||||
len: usize,
|
len: usize = 0,
|
||||||
|
backing_buffer: []T,
|
||||||
items: []T,
|
items: []T,
|
||||||
|
|
||||||
pub fn init(slice: []T) @This() {
|
pub fn init(backing_buffer: []T) @This() {
|
||||||
return @This(){
|
var this = @This(){
|
||||||
.len = 0,
|
.items = backing_buffer,
|
||||||
.items = slice,
|
.backing_buffer = backing_buffer,
|
||||||
};
|
};
|
||||||
|
this.set_len(0);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_len(this: *@This(), len: usize) void {
|
||||||
|
this.len = len;
|
||||||
|
this.items.len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(buf: *@This()) void {
|
pub fn reset(buf: *@This()) void {
|
||||||
buf.len = 0;
|
buf.len = 0;
|
||||||
|
buf.items.len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append(buf: *@This(), item: T) void {
|
pub fn append(buf: *@This(), item: T) void {
|
||||||
std.debug.assert(buf.len < buf.items.len);
|
std.debug.assert(buf.len < buf.backing_buffer.len);
|
||||||
buf.items[buf.len] = item;
|
buf.backing_buffer[buf.len] = item;
|
||||||
buf.len += 1;
|
buf.set_len(buf.len + 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue