aboutsummaryrefslogtreecommitdiff
path: root/src/player.zig
diff options
context:
space:
mode:
authortslil clingman <>2021-09-22 23:12:19 -0400
committertslil clingman <>2021-09-22 23:13:34 -0400
commit48f51653ae90bdabb5bb738a5c78cd9a53f498a9 (patch)
treee52938ae5f9d61cfe4be6d993d319d277ad7202b /src/player.zig
parentd932cb0a1fd0235c8f298dd7f3acbf2864338903 (diff)
There was really no reason to use a BoundedArray instead of an array
Diffstat (limited to 'src/player.zig')
-rw-r--r--src/player.zig19
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));