Fix debris

master
Louis Pearson 2022-08-04 02:22:34 -06:00
parent 21f8ae7087
commit 41b0846713
3 changed files with 31 additions and 24 deletions

View File

@ -35,19 +35,19 @@ pub fn extractLevel(opt: Options) !void {
map.map_size = .{ level.width, height };
circuit.map_size = .{ level.width, height };
var solid_map = try alloc.alloc(bool, size);
defer alloc.free(solid_map);
var auto_map = try alloc.alloc(bool, size);
defer alloc.free(auto_map);
var circuit_map = try alloc.alloc(CircuitType, size);
defer alloc.free(circuit_map);
for (level.tiles) |tile, i| {
if (tile.is_tile) {
// solid_map[i] = is_solid(tile.data.tile);
auto_map[i] = false;
map.tiles[i] = tile.data.tile;
circuit_map[i] = .None;
} else {
solid_map[i] = tile.data.flags.solid;
auto_map[i] = tile.data.flags.solid;
circuit_map[i] = @intToEnum(CircuitType, tile.data.flags.circuit);
}
}
@ -62,7 +62,7 @@ pub fn extractLevel(opt: Options) !void {
const y = @divTrunc(i, width);
const stride = width;
if (!solid_map[i]) {
if (!auto_map[i]) {
autotiles[i] = null;
continue;
}
@ -76,25 +76,25 @@ pub fn extractLevel(opt: Options) !void {
// Check horizontal neighbors
if (x == 0) {
west = out_of_bounds;
east = solid_map[i + 1];
east = auto_map[i + 1];
} else if (x == width - 1) {
west = solid_map[i - 1];
west = auto_map[i - 1];
east = out_of_bounds;
} else {
west = solid_map[i - 1];
east = solid_map[i + 1];
west = auto_map[i - 1];
east = auto_map[i + 1];
}
// Check vertical neighbours
if (y == 0) {
north = out_of_bounds;
south = solid_map[i + stride];
south = auto_map[i + stride];
} else if (y == height - 1) {
north = solid_map[i - stride];
north = auto_map[i - stride];
south = out_of_bounds;
} else {
north = solid_map[i - stride];
south = solid_map[i + stride];
north = auto_map[i - stride];
south = auto_map[i + stride];
}
autotiles[i] = AutoTile{
@ -111,6 +111,10 @@ pub fn extractLevel(opt: Options) !void {
const li = autotile.to_u4();
const tile = tileset.lookup[li];
map.tiles[i] = tile;
} else {
const x = @mod(i, width);
const y = @divTrunc(i, width);
w4.trace("{}, {}: {}", .{ x, y, map.tiles[i] });
}
}
}

View File

@ -32,7 +32,7 @@ pub const TileStore = struct {
if (store.is_tile) {
return 1 | (store.data.tile << 1);
} else {
return 0 | (@intCast(u2, @boolToInt(store.data.flags.solid)) << 1) | (store.data.flags.circuit << 2);
return (@intCast(u7, @boolToInt(store.data.flags.solid)) << 1) | (@intCast(u7, store.data.flags.circuit) << 2);
}
}
@ -41,14 +41,14 @@ pub const TileStore = struct {
if (is_tile) {
const tile = @intCast(u7, (~@as(u7, 1) & byte) >> 1);
return TileStore{
.is_tile = is_tile,
.is_tile = true,
.data = .{ .tile = tile },
};
} else {
const is_solid = (0b0000_0010 & byte) > 0;
const circuit = @intCast(u4, (0b0011_1100 & byte) >> 2);
return TileStore{
.is_tile = is_tile,
.is_tile = false,
.data = .{ .flags = .{
.solid = is_solid,
.circuit = circuit,

View File

@ -112,22 +112,25 @@ fn make(step: *std.build.Step) !void {
const i = @intCast(usize, x + y * width);
tiles[i] = world.TileStore{
.is_tile = true,
.data = .{ .tile = @intCast(u7, autotile.t) },
.data = .{ .tile = @intCast(u7, autotile.t + 1) },
};
}
for (circuit.intGridCsv) |cir64, i| {
const cir = @intCast(u4, cir64);
const col = collision.intGridCsv[i];
if (col != 2) {
tiles[i] = world.TileStore{
.is_tile = false,
.data = .{
.flags = .{
.data = .{ .flags = .{
.solid = col == 1,
.circuit = cir,
},
},
} },
};
}
if (col == 2) {
tiles[i].is_tile = true;
}
try writer.writeByte(tiles[i].toByte());
}
}