Fix debris
parent
21f8ae7087
commit
41b0846713
|
@ -35,19 +35,19 @@ pub fn extractLevel(opt: Options) !void {
|
||||||
map.map_size = .{ level.width, height };
|
map.map_size = .{ level.width, height };
|
||||||
circuit.map_size = .{ level.width, height };
|
circuit.map_size = .{ level.width, height };
|
||||||
|
|
||||||
var solid_map = try alloc.alloc(bool, size);
|
var auto_map = try alloc.alloc(bool, size);
|
||||||
defer alloc.free(solid_map);
|
defer alloc.free(auto_map);
|
||||||
|
|
||||||
var circuit_map = try alloc.alloc(CircuitType, size);
|
var circuit_map = try alloc.alloc(CircuitType, size);
|
||||||
defer alloc.free(circuit_map);
|
defer alloc.free(circuit_map);
|
||||||
|
|
||||||
for (level.tiles) |tile, i| {
|
for (level.tiles) |tile, i| {
|
||||||
if (tile.is_tile) {
|
if (tile.is_tile) {
|
||||||
// solid_map[i] = is_solid(tile.data.tile);
|
auto_map[i] = false;
|
||||||
map.tiles[i] = tile.data.tile;
|
map.tiles[i] = tile.data.tile;
|
||||||
circuit_map[i] = .None;
|
circuit_map[i] = .None;
|
||||||
} else {
|
} else {
|
||||||
solid_map[i] = tile.data.flags.solid;
|
auto_map[i] = tile.data.flags.solid;
|
||||||
circuit_map[i] = @intToEnum(CircuitType, tile.data.flags.circuit);
|
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 y = @divTrunc(i, width);
|
||||||
const stride = width;
|
const stride = width;
|
||||||
|
|
||||||
if (!solid_map[i]) {
|
if (!auto_map[i]) {
|
||||||
autotiles[i] = null;
|
autotiles[i] = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -76,25 +76,25 @@ pub fn extractLevel(opt: Options) !void {
|
||||||
// Check horizontal neighbors
|
// Check horizontal neighbors
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
west = out_of_bounds;
|
west = out_of_bounds;
|
||||||
east = solid_map[i + 1];
|
east = auto_map[i + 1];
|
||||||
} else if (x == width - 1) {
|
} else if (x == width - 1) {
|
||||||
west = solid_map[i - 1];
|
west = auto_map[i - 1];
|
||||||
east = out_of_bounds;
|
east = out_of_bounds;
|
||||||
} else {
|
} else {
|
||||||
west = solid_map[i - 1];
|
west = auto_map[i - 1];
|
||||||
east = solid_map[i + 1];
|
east = auto_map[i + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check vertical neighbours
|
// Check vertical neighbours
|
||||||
if (y == 0) {
|
if (y == 0) {
|
||||||
north = out_of_bounds;
|
north = out_of_bounds;
|
||||||
south = solid_map[i + stride];
|
south = auto_map[i + stride];
|
||||||
} else if (y == height - 1) {
|
} else if (y == height - 1) {
|
||||||
north = solid_map[i - stride];
|
north = auto_map[i - stride];
|
||||||
south = out_of_bounds;
|
south = out_of_bounds;
|
||||||
} else {
|
} else {
|
||||||
north = solid_map[i - stride];
|
north = auto_map[i - stride];
|
||||||
south = solid_map[i + stride];
|
south = auto_map[i + stride];
|
||||||
}
|
}
|
||||||
|
|
||||||
autotiles[i] = AutoTile{
|
autotiles[i] = AutoTile{
|
||||||
|
@ -111,6 +111,10 @@ pub fn extractLevel(opt: Options) !void {
|
||||||
const li = autotile.to_u4();
|
const li = autotile.to_u4();
|
||||||
const tile = tileset.lookup[li];
|
const tile = tileset.lookup[li];
|
||||||
map.tiles[i] = tile;
|
map.tiles[i] = tile;
|
||||||
|
} else {
|
||||||
|
const x = @mod(i, width);
|
||||||
|
const y = @divTrunc(i, width);
|
||||||
|
w4.trace("{}, {}: {}", .{ x, y, map.tiles[i] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub const TileStore = struct {
|
||||||
if (store.is_tile) {
|
if (store.is_tile) {
|
||||||
return 1 | (store.data.tile << 1);
|
return 1 | (store.data.tile << 1);
|
||||||
} else {
|
} 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) {
|
if (is_tile) {
|
||||||
const tile = @intCast(u7, (~@as(u7, 1) & byte) >> 1);
|
const tile = @intCast(u7, (~@as(u7, 1) & byte) >> 1);
|
||||||
return TileStore{
|
return TileStore{
|
||||||
.is_tile = is_tile,
|
.is_tile = true,
|
||||||
.data = .{ .tile = tile },
|
.data = .{ .tile = tile },
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const is_solid = (0b0000_0010 & byte) > 0;
|
const is_solid = (0b0000_0010 & byte) > 0;
|
||||||
const circuit = @intCast(u4, (0b0011_1100 & byte) >> 2);
|
const circuit = @intCast(u4, (0b0011_1100 & byte) >> 2);
|
||||||
return TileStore{
|
return TileStore{
|
||||||
.is_tile = is_tile,
|
.is_tile = false,
|
||||||
.data = .{ .flags = .{
|
.data = .{ .flags = .{
|
||||||
.solid = is_solid,
|
.solid = is_solid,
|
||||||
.circuit = circuit,
|
.circuit = circuit,
|
||||||
|
|
|
@ -112,22 +112,25 @@ fn make(step: *std.build.Step) !void {
|
||||||
const i = @intCast(usize, x + y * width);
|
const i = @intCast(usize, x + y * width);
|
||||||
tiles[i] = world.TileStore{
|
tiles[i] = world.TileStore{
|
||||||
.is_tile = true,
|
.is_tile = true,
|
||||||
.data = .{ .tile = @intCast(u7, autotile.t) },
|
.data = .{ .tile = @intCast(u7, autotile.t + 1) },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (circuit.intGridCsv) |cir64, i| {
|
for (circuit.intGridCsv) |cir64, i| {
|
||||||
const cir = @intCast(u4, cir64);
|
const cir = @intCast(u4, cir64);
|
||||||
const col = collision.intGridCsv[i];
|
const col = collision.intGridCsv[i];
|
||||||
|
if (col != 2) {
|
||||||
tiles[i] = world.TileStore{
|
tiles[i] = world.TileStore{
|
||||||
.is_tile = false,
|
.is_tile = false,
|
||||||
.data = .{
|
.data = .{ .flags = .{
|
||||||
.flags = .{
|
|
||||||
.solid = col == 1,
|
.solid = col == 1,
|
||||||
.circuit = cir,
|
.circuit = cir,
|
||||||
},
|
} },
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
if (col == 2) {
|
||||||
|
tiles[i].is_tile = true;
|
||||||
|
}
|
||||||
try writer.writeByte(tiles[i].toByte());
|
try writer.writeByte(tiles[i].toByte());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue