From 3c0f4580b55e7a97e4ffad4285ea7c028231f832 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Fri, 5 Aug 2022 15:23:22 -0600 Subject: [PATCH] Fix bug where some tiles were not showing up Turns out I was shifting a u7 thinking it was u8, and this caused the high bit to be chopped off of some values. I also made the high bit indicate the type instead of the low bit. --- src/world.zig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/world.zig b/src/world.zig index 573f6b4..7a915d4 100644 --- a/src/world.zig +++ b/src/world.zig @@ -26,19 +26,19 @@ pub const TileData = union(enum) { pub fn toByte(data: TileData) u8 { switch (data) { - .tile => |int| return 0b0000_0001 | (int << 1), - .flags => |flags| return (@intCast(u7, @boolToInt(flags.solid)) << 1) | (@intCast(u7, flags.circuit) << 2), + .tile => |int| return 0b1000_0000 | @intCast(u8, int), + .flags => |flags| return (@intCast(u7, @boolToInt(flags.solid))) | (@intCast(u7, flags.circuit) << 1), } } pub fn fromByte(byte: u8) TileData { - const is_tile = (0b0000_0001 & byte) > 0; + const is_tile = (0b1000_0000 & byte) > 0; if (is_tile) { - const tile = @intCast(u7, (0b1111_1110 & byte) >> 1); + const tile = @intCast(u7, (0b0111_1111 & byte)); return TileData{ .tile = tile }; } else { - const is_solid = (0b0000_0010 & byte) > 0; - const circuit = @intCast(u4, (0b0011_1100 & byte) >> 2); + const is_solid = (0b0000_0001 & byte) > 0; + const circuit = @intCast(u4, (0b0001_1110 & byte) >> 1); return TileData{ .flags = .{ .solid = is_solid, .circuit = circuit,