diff options
Diffstat (limited to 'src/player.zig')
| -rw-r--r-- | src/player.zig | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/player.zig b/src/player.zig index 74a1f10..491fc27 100644 --- a/src/player.zig +++ b/src/player.zig @@ -92,19 +92,16 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { acc_x: f32 = 0, acc_y: f32 = 0, height: f32 = 2.0 * (1.8 / 2.5), // TODO - z_buffer: std.BoundedArray(f32, PlanePixels), - + z_buffer: [PlanePixels]f32, anim_step: f32 = 0, // standing still at the given location, looking in direction ang - pub fn new(pos_x: f32, pos_y: f32, ang: f32) !@This() { - const infs = [_]f32{std.math.inf(f32)} ** PlanePixels; + pub fn new(pos_x: f32, pos_y: f32, ang: f32) @This() { return Player(PlaneWidth, PlaneHeight){ .pos_x = pos_x, .pos_y = pos_y, .ang = ang, - // TODO: is there some clever way to avoid this long name? - .z_buffer = try std.BoundedArray(f32, PlanePixels).fromSlice(&infs), + .z_buffer = [_]f32{std.math.inf(f32)} ** PlanePixels, }; } @@ -172,7 +169,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { // Fist reset the z_buffer var i: usize = 0; while (i < self.z_buffer.len) : (i += 1) { - self.z_buffer.set(i, std.math.inf(f32)); + self.z_buffer[i] = std.math.inf(f32); } var pixels = [_]Colour{Colour.Transparent} ** (PlaneWidth * PlaneHeight); @@ -262,7 +259,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { texel_y += inv_height; }) { const index = col * @floatToInt(usize, PlaneHeight) + @floatToInt(usize, bottom); - if (self.z_buffer.get(index) < scaled_perp_distance) { + if (self.z_buffer[index] < scaled_perp_distance) { break; } else { const tx = @floatToInt(c_uint, tex_frac * constants.TextureDim); @@ -409,7 +406,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { pixels[pix_index] = texel; const index = @intCast(usize, col * @floatToInt(i32, PlaneHeight) + zb_y); - self.z_buffer.set(index, distance); + self.z_buffer[index] = distance; } highest_point = top; } @@ -451,7 +448,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { // record in the z_buffer only if we're above the floor! if (cell.height > 0) { const index = col * @floatToInt(usize, PlaneHeight) + ptop; - self.z_buffer.set(index, row_dist); + self.z_buffer[index] = row_dist; } } highest_point = next_top; @@ -501,7 +498,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { const iy = @floatToInt(i32, sy.ipart); const index = col * @floatToInt(usize, PlaneHeight) + @floatToInt(usize, PlaneHeight - 1) - row; - if (map.inBounds(ix, iy) and row_dist < self.z_buffer.get(index)) { + if (map.inBounds(ix, iy) and row_dist < self.z_buffer[index]) { const cell = map.lookup(ix, iy); const toff = cell.ceiling_texture * @floatToInt(c_uint, constants.TextureDim); const px = @floatToInt(c_uint, constants.TextureDim * std.math.fabs(sx.fpart)); |
