dimention

This commit is contained in:
Radonchnk 2025-04-19 17:46:27 +01:00
parent 1cc01e7cf9
commit 6bf75f87ab

View file

@ -82,12 +82,12 @@ pub const Chunk = struct {
}
// This cyclically permutes the x, y, z coordinates at compile time. Useful when iterating over x, y, and z axis.
inline fn getTileRawShifted(self: Chunk, x: u5, y: u5, z: u5, comptime dimention: comptime_int) u32 {
if (dimention % 3 == 0) {
inline fn getTileRawShifted(self: Chunk, x: u5, y: u5, z: u5, comptime dimension: comptime_int) u32 {
if (dimension % 3 == 0) {
return self.getTileRaw(x, y, z);
} else if (dimention % 3 == 1) {
} else if (dimension % 3 == 1) {
return self.getTileRaw(y, z, x);
} else if (dimention % 3 == 2) {
} else if (dimension % 3 == 2) {
return self.getTileRaw(z, x, y);
}
}
@ -98,7 +98,7 @@ pub const Chunk = struct {
y_start: usize, y_end: usize,
z_start: usize, z_end: usize,
sign: comptime_int,
dimention: comptime_int,
dimension: comptime_int,
surface: u32,
y_minus_obscuring_pattern: u32,
y_plus_obscuring_pattern: u32,
@ -114,7 +114,7 @@ pub const Chunk = struct {
const zleft: f32 = if (sign == 1) zmin else zmax;
const zright: f32 = if (sign == 1) zmax else zmin;
var raw_quad: RawQuad = undefined;
switch (dimention) {
switch (dimension) {
X_DIRECTION => {
raw_quad = .{
.tile = surface,
@ -189,7 +189,7 @@ pub const Chunk = struct {
defer raw_quads.deinit();
// Begin scanning the chunk for tile surfaces to make raw quads.
inline for (0..3) |dimention| { // Iterate over the 3 dimensions, X, Y and Z.
inline for (0..3) |dimension| { // Iterate over the 3 dimensions, X, Y and Z.
for (0..32) |raw_x| {
const x: u5 = @intCast(raw_x);
// Create surface arrays for the +x side of the layer and the -x side.
@ -198,11 +198,11 @@ pub const Chunk = struct {
for (0..32) |raw_y| for (0..32) |raw_z| {
const y: u5 = @intCast(raw_y);
const z: u5 = @intCast(raw_z);
const tile: u32 = chunk.getTileRawShifted(x, y, z, dimention);
const tile: u32 = chunk.getTileRawShifted(x, y, z, dimension);
if (tile == 0) continue; // If air, there is no surface.
// If either at the edge of the chunk or the tile is exposed, create a tile surface.
if (x == 31 or chunk.getTileRawShifted(x + 1, y, z, dimention) == 0) positive_tile_surfaces[y][z] = tile;
if (x == 0 or chunk.getTileRawShifted(x - 1, y, z, dimention) == 0) negative_tile_surfaces[y][z] = tile;
if (x == 31 or chunk.getTileRawShifted(x + 1, y, z, dimension) == 0) positive_tile_surfaces[y][z] = tile;
if (x == 0 or chunk.getTileRawShifted(x - 1, y, z, dimension) == 0) negative_tile_surfaces[y][z] = tile;
};
inline for (.{ -1, 1 }) |sign| {
var tile_surfaces = if (sign == 1) positive_tile_surfaces else negative_tile_surfaces;
@ -229,7 +229,7 @@ pub const Chunk = struct {
for (y_start..y_end) |raw_y| {
const y: u5 = @intCast(raw_y);
z_minus_obscuring_pattern <<= 1;
if (chunk.getTileRawShifted(if (sign == 1) x+1 else x-1, y, @intCast(z_start - 1), dimention) != 0) z_minus_obscuring_pattern |= 1;
if (chunk.getTileRawShifted(if (sign == 1) x+1 else x-1, y, @intCast(z_start - 1), dimension) != 0) z_minus_obscuring_pattern |= 1;
}
}
var z_plus_obscuring_pattern: u32 = 0;
@ -237,7 +237,7 @@ pub const Chunk = struct {
for (y_start..y_end) |raw_y| {
const y: u5 = @intCast(raw_y);
z_plus_obscuring_pattern <<= 1;
if (chunk.getTileRawShifted(if (sign == 1) x+1 else x-1, y, @intCast(z_end), dimention) != 0) z_plus_obscuring_pattern |= 1;
if (chunk.getTileRawShifted(if (sign == 1) x+1 else x-1, y, @intCast(z_end), dimension) != 0) z_plus_obscuring_pattern |= 1;
}
}
var y_minus_obscuring_pattern: u32 = 0;
@ -245,7 +245,7 @@ pub const Chunk = struct {
for (z_start..z_end) |raw_z| {
const z: u5 = @intCast(raw_z);
y_minus_obscuring_pattern <<= 1;
if (chunk.getTileRawShifted(if (sign == 1) x+1 else x-1, @intCast(y_start - 1), z, dimention) != 0) y_minus_obscuring_pattern |= 1;
if (chunk.getTileRawShifted(if (sign == 1) x+1 else x-1, @intCast(y_start - 1), z, dimension) != 0) y_minus_obscuring_pattern |= 1;
}
}
var y_plus_obscuring_pattern: u32 = 0;
@ -253,11 +253,11 @@ pub const Chunk = struct {
for (z_start..z_end) |raw_z| {
const z: u5 = @intCast(raw_z);
y_plus_obscuring_pattern <<= 1;
if (chunk.getTileRawShifted(if (sign == 1) x+1 else x-1, @intCast(y_end), z, dimention) != 0) y_plus_obscuring_pattern |= 1;
if (chunk.getTileRawShifted(if (sign == 1) x+1 else x-1, @intCast(y_end), z, dimension) != 0) y_plus_obscuring_pattern |= 1;
}
}
// std.debug.print("{}\n", .{z_minus_obscuring_pattern});
const raw_quad = pack_raw_quad(@floatFromInt(raw_x), y_start, y_end, z_start, z_end, sign, dimention, surface, y_minus_obscuring_pattern, y_plus_obscuring_pattern, z_minus_obscuring_pattern, z_plus_obscuring_pattern);
const raw_quad = pack_raw_quad(@floatFromInt(raw_x), y_start, y_end, z_start, z_end, sign, dimension, surface, y_minus_obscuring_pattern, y_plus_obscuring_pattern, z_minus_obscuring_pattern, z_plus_obscuring_pattern);
try raw_quads.append(raw_quad);
};
}