From 61856ed5407a227aab35d7b800daad883c265dd9 Mon Sep 17 00:00:00 2001 From: tslil clingman <> Date: Fri, 15 Oct 2021 17:11:06 -0400 Subject: Well, there's no reason not to do this ... Multiple polygon layers! --- src/level.zig | 57 +++++++----- src/main.zig | 109 ++++++++++++++-------- src/player.zig | 8 +- src/render.zig | 283 +++++++++++++++++++++++++++++---------------------------- 4 files changed, 255 insertions(+), 202 deletions(-) diff --git a/src/level.zig b/src/level.zig index 87c3e80..81a0e67 100644 --- a/src/level.zig +++ b/src/level.zig @@ -17,37 +17,48 @@ const std = @import("std"); -pub const Object = struct { - height: f32, - width: f32, - texture: u8, - pos_x: f32, - pos_y: f32, - pos_z: f32 = 0, +pub const Layer = struct { + pub const MAX_VERTS = 16; + + height : f32 = 0, + vertical_texture : u8 = 0, + horizontal_texture : u8 = 0, + // What happened to this error? Is it comptime? + vertices: std.BoundedArray([2]f32, MAX_VERTS), }; pub const Cell = struct { - floor_height: f32 = 0, - ceiling_height: f32 = DEFAULT_HEIGHT, - draw_down: bool = false, - lower_texture: u8 = 0, - upper_texture: u8 = 0, - floor_texture: u8 = 0, - ceiling_texture: u8 = 2, + pub const MAX_LAYERS = 16; + // floor_height: f32 = 0, + // ceiling_height: f32 = DEFAULT_HEIGHT, + // draw_down: bool = false, + // lower_texture: u8 = 0, + // upper_texture: u8 = 0, + // floor_texture: u8 = 0, + // ceiling_texture: u8 = 2, - vertices: []const [2]f32 = &[_][2]f32{ - .{ 0.25, 0.25 }, - .{ 0.75, 0.25 }, - .{ 0.75, 0.75 }, - .{ 0.25, 0.75 }, - .{ 0.25, 0.25 }, - }, + lower_layers : std.BoundedArray(Layer, MAX_LAYERS), - pub const floor = Cell{}; + // I'm not sure how i feel about reaching into the implementation of + // BoundedArray like this. Surely there should be an ``.empty'' or something + // default? + fn empty() !Cell { + const lower_layers = try std.BoundedArray(Layer, MAX_LAYERS).init(0); + return Cell{ . lower_layers = lower_layers }; + } pub const DEFAULT_HEIGHT: f32 = 4; }; +pub const Object = struct { + height: f32, + width: f32, + texture: u8, + pos_x: f32, + pos_y: f32, + pos_z: f32 = 0, +}; + pub const Map = struct { width: u32, height: u32, @@ -63,7 +74,7 @@ pub const Map = struct { pub fn new(width: u32, height: u32, alloc: *std.mem.Allocator) !Map { var cells = std.ArrayList(Cell).init(alloc); try cells.ensureTotalCapacity(width * height); - try cells.appendNTimes(Cell.floor, width * height); + try cells.appendNTimes(try Cell.empty(), width * height); var objects = std.ArrayList(Object).init(alloc); diff --git a/src/main.zig b/src/main.zig index 3d74daa..6e535b9 100644 --- a/src/main.zig +++ b/src/main.zig @@ -49,46 +49,79 @@ pub fn main() !void { var map = try level.Map.new(16, 16, &gpa.allocator); defer map.deinit(); - var y: u32 = 0; - while (y < 16) : (y += 1) { - map.cells.items[y * 16 + 00] = level.Cell{ .floor_height = level.Cell.DEFAULT_HEIGHT }; - map.cells.items[y * 16 + 15] = level.Cell{ .floor_height = level.Cell.DEFAULT_HEIGHT, .lower_texture = 2 }; - map.cells.items[15 * 16 + y] = level.Cell{ .floor_height = level.Cell.DEFAULT_HEIGHT }; - map.cells.items[00 * 16 + y] = level.Cell{ .floor_height = level.Cell.DEFAULT_HEIGHT }; - - if (y < 15) { - map.cells.items[y * 16 + 01] = level.Cell{ - .ceiling_height = 3, - .upper_texture = 3, - .draw_down = true, - }; - } + var y: u32 = 5; + while (y < 10) : (y += 1) { + // HACK + const vert_coords0 = [_][2]f32{ + .{ 0.25, 0.25 }, + .{ 0.75, 0.25 }, + .{ 0.75, 0.75 }, + .{ 0.25, 0.75 }, + .{ 0.25, 0.25 }, + }; + var verts = try std.BoundedArray([2]f32, level.Layer.MAX_VERTS).fromSlice(vert_coords0[0..]); + var layer = level.Layer{ .height = 1, .vertices = verts }; + try map.cells.items[07 * 16 + y].lower_layers.append(layer); + + const vert_coords1 = [_][2]f32{ + .{ 0.75, 0.5 }, + .{ 0.72838634, 0.60168415 }, + .{ 0.66728264, 0.68578625 }, + .{ 0.57725424, 0.7377641 }, + .{ 0.47386786, 0.74863046 }, + .{ 0.375, 0.71650636 }, + .{ 0.29774573, 0.6469463 }, + .{ 0.2554631, 0.5519779 }, + .{ 0.25546312, 0.44802207 }, + .{ 0.29774576, 0.35305366 }, + .{ 0.37500003, 0.28349364 }, + .{ 0.47386792, 0.25136954 }, + .{ 0.5772543, 0.26223588 }, + .{ 0.6672827, 0.3142138 }, + .{ 0.7283864, 0.39831588 }, + .{ 0.75, 0.50 }, + }; + verts = try std.BoundedArray([2]f32, level.Layer.MAX_VERTS).fromSlice(vert_coords1[0..]); + + layer = level.Layer{ .height = 2, .vertices = verts, .vertical_texture = 3 }; + try map.cells.items[07 * 16 + y].lower_layers.append(layer); + // map.cells.items[y * 16 + 15] = level.Cell{ .floor_height = level.Cell.DEFAULT_HEIGHT, .lower_texture = 2 }; + // map.cells.items[15 * 16 + y] = level.Cell{ .floor_height = level.Cell.DEFAULT_HEIGHT }; + // map.cells.items[00 * 16 + y] = level.Cell{ .floor_height = level.Cell.DEFAULT_HEIGHT }; + + // if (y < 15) { + // map.cells.items[y * 16 + 01] = level.Cell{ + // .ceiling_height = 3, + // .upper_texture = 3, + // .draw_down = true, + // }; + // } } - map.cells.items[16 * 7 + 7] = level.Cell{ - .floor_height = 0.2, - .ceiling_height = 2, - .lower_texture = 1, - .upper_texture = 1, - .floor_texture = 1, - .ceiling_texture = 2, - .draw_down = true, - .vertices = &[_][2]f32{ - .{ 0.00, 0.50 }, - .{ 0.25, 0.66 }, - .{ 0.25, 1.00 }, - .{ 0.50, 0.66 }, - .{ 0.75, 1.00 }, - .{ 0.75, 0.66 }, - .{ 1.00, 0.50 }, - .{ 0.75, 0.33 }, - .{ 0.75, 0.00 }, - .{ 0.50, 0.33 }, - .{ 0.25, 0.00 }, - .{ 0.25, 0.33 }, - .{ 0.00, 0.50 }, - }, - }; + // map.cells.items[16 * 7 + 7] = level.Cell{ + // .floor_height = 0.2, + // .ceiling_height = 2, + // .lower_texture = 1, + // .upper_texture = 1, + // .floor_texture = 1, + // .ceiling_texture = 2, + // .draw_down = true, + // .vertices = &[_][2]f32{ + // .{ 0.00, 0.50 }, + // .{ 0.25, 0.66 }, + // .{ 0.25, 1.00 }, + // .{ 0.50, 0.66 }, + // .{ 0.75, 1.00 }, + // .{ 0.75, 0.66 }, + // .{ 1.00, 0.50 }, + // .{ 0.75, 0.33 }, + // .{ 0.75, 0.00 }, + // .{ 0.50, 0.33 }, + // .{ 0.25, 0.00 }, + // .{ 0.25, 0.33 }, + // .{ 0.00, 0.50 }, + // }, + // }; try map.objects.append(level.Object{ .pos_x = 1.5, .pos_y = 7.5, .pos_z = 2, .texture = 2, .height = 1, .width = 1 }); try map.objects.append(level.Object{ .pos_x = 4, .pos_y = 8.5, .texture = 0, .height = 1, .width = 1 }); diff --git a/src/player.zig b/src/player.zig index 258b924..eef41a7 100644 --- a/src/player.zig +++ b/src/player.zig @@ -65,9 +65,9 @@ pub const Player = struct { if (!map.inBounds(nix, iy) or blk: { - const cell = map.lookup(nix, iy); - if (cell.floor_height > 0) break :blk true; - if (cell.ceiling_height < self.height) break :blk true; + // const cell = map.lookup(nix, iy); + // if (cell.floor_height > 0) break :blk true; + // if (cell.ceiling_height < self.height) break :blk true; break :blk false; }) { next_x = fx + if (self.vel_x > 0) 1 - min_dist else min_dist; @@ -75,7 +75,7 @@ pub const Player = struct { self.acc_x = 0; } - if (!map.inBounds(ix, niy) or map.lookup(ix, niy).floor_height > 0) { + if (!map.inBounds(ix, niy)) { // or map.lookup(ix, niy).floor_height > 0 next_y = fy + if (self.vel_y > 0) 1 - min_dist else min_dist; self.vel_y = 0; self.acc_y = 0; diff --git a/src/render.zig b/src/render.zig index e2aa401..27bd0cc 100644 --- a/src/render.zig +++ b/src/render.zig @@ -290,6 +290,9 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { map: level.Map, pixels: []Colour, ) void { + // TODO REMOVE ME + std.debug.assert(surfaces_image.getSize().x > 0); + // This is a TERRIBLE hack: for whatever reason *linearly* // interpolating on the direction vectors gives // perspective-correct-seeming walls! @@ -347,8 +350,8 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { dist_x = (ppos_y - @intToFloat(f32, ipos_y)) * dx_for_y_step; } - var top_of_floor: f32 = undefined; - var bottom_of_ceiling: f32 = undefined; + var top_of_floor: f32 = 0; + var bottom_of_ceiling: f32 = PlaneHeight; var distance: f32 = 0; var next_distance: f32 = 0; @@ -404,7 +407,9 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { const cell = map.lookup(ipos_x, ipos_y); // Are we drawing vertical surfaces? - if (cell.floor_height > 0 or cell.draw_down) { + + // TODO: not quite right, ``anything vertical'' not just ``anything'' + if (cell.lower_layers.len > 0) { var ray0_x: f32 = undefined; var ray0_y: f32 = undefined; var ray1_x: f32 = undefined; @@ -429,153 +434,157 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { ray1_y = std.math.modf(next_distance * sinra + ppos_y).fpart; } - if (hitDistLocalCoords(ray0_x, ray0_y, ray1_x, ray1_y, cell.vertices)) |dist_frac| { - // TODO: Correct for fisheye? - const adj_distance = distance + dist_frac.local_dist; - - // project the top of the bottom and the bottom of the top - top_of_floor = PlaneHeight / 2 + PlaneDist * (cell.floor_height - pheight) / adj_distance; - bottom_of_ceiling = PlaneHeight / 2 + PlaneDist * (cell.ceiling_height - pheight) / adj_distance; + for (cell.lower_layers.constSlice()) |layer| { + if (hitDistLocalCoords(ray0_x, ray0_y, ray1_x, ray1_y, layer.vertices.constSlice())) |dist_frac| { + // TODO: Correct for fisheye? + const adj_distance = distance + dist_frac.local_dist; - const draw_lower = cell.floor_height > 0 and top_of_floor > highest_drawn; - const draw_upper = cell.draw_down and bottom_of_ceiling < lowest_drawn; + // project the top of the bottom and the bottom of the top + top_of_floor = PlaneHeight / 2 + PlaneDist * (layer.height - pheight) / adj_distance; + // bottom_of_ceiling = PlaneHeight / 2 + PlaneDist * (cell.ceiling_height - pheight) / adj_distance; - // Are we able to see any vertical faces? - if (draw_upper or draw_lower) { - const texstrip = @floatToInt(c_uint, constants.TextureDim * dist_frac.frac); + const draw_lower = layer.height > 0 and top_of_floor > highest_drawn; + // const draw_upper = cell.draw_down and bottom_of_ceiling < lowest_drawn; - // height of a unit-height wall at this distance - const nominal_length = PlaneDist / adj_distance; - // used for texel indexing - const inv_nom_len = adj_distance / PlaneDist; - - const td = @floatToInt(c_uint, constants.TextureDim); + // Are we able to see any vertical faces? if (draw_lower) { - // which texture index? - const t_lower_off = cell.lower_texture * td; - // Note the bizarre rounding we have to do to avoid artifacts - const constrained_top = std.math.floor(std.math.min(top_of_floor, lowest_drawn)); - const proj_height = cell.floor_height * nominal_length; - const constrained_bottom = std.math.max(highest_drawn, top_of_floor - proj_height); - const stop = @floatToInt(usize, PlaneWidth * (PlaneHeight - constrained_bottom)) + col; - const pix_y = @floatToInt(usize, std.math.ceil(std.math.max(PlaneHeight - constrained_top - 1, 0))); - var pix_index = pix_y * @floatToInt(usize, PlaneWidth) + col; - var texel_y: f32 = std.math.max((top_of_floor - constrained_top) / nominal_length, 0); - - // now we have what we need to draw the face, - // and update the z-buffer. - while (pix_index < stop) : ({ - pix_index += @floatToInt(usize, PlaneWidth); - texel_y += inv_nom_len; - }) { - const ty = @floatToInt(c_uint, std.math.modf(texel_y).fpart * constants.TextureDim); - const texel = walls_image.getPixel(.{ .x = t_lower_off + texstrip, .y = ty }); - - pixels[pix_index] = texel; - self.z_buffer[pix_index] = adj_distance; + const texstrip = @floatToInt(c_uint, constants.TextureDim * dist_frac.frac); + + // height of a unit-height wall at this distance + const nominal_length = PlaneDist / adj_distance; + // used for texel indexing + const inv_nom_len = adj_distance / PlaneDist; + + const td = @floatToInt(c_uint, constants.TextureDim); + if (draw_lower) { + // which texture index? + const t_lower_off = layer.vertical_texture * td; + // Note the bizarre rounding we have to do to avoid artifacts + const constrained_top = std.math.floor(std.math.min(top_of_floor, lowest_drawn)); + const proj_height = layer.height * nominal_length; + const constrained_bottom = std.math.max(highest_drawn, top_of_floor - proj_height); + const stop = @floatToInt(usize, PlaneWidth * (PlaneHeight - constrained_bottom)) + col; + const pix_y = @floatToInt(usize, std.math.ceil(std.math.max(PlaneHeight - constrained_top - 1, 0))); + var pix_index = pix_y * @floatToInt(usize, PlaneWidth) + col; + var texel_y: f32 = std.math.max((top_of_floor - constrained_top) / nominal_length, 0); + + // now we have what we need to draw the face, + // and update the z-buffer. + while (pix_index < stop) : ({ + pix_index += @floatToInt(usize, PlaneWidth); + texel_y += inv_nom_len; + }) { + const ty = @floatToInt(c_uint, std.math.modf(texel_y).fpart * constants.TextureDim); + const texel = walls_image.getPixel(.{ .x = t_lower_off + texstrip, .y = ty }); + + pixels[pix_index] = texel; + self.z_buffer[pix_index] = adj_distance; + } + highest_drawn = constrained_top; } - highest_drawn = constrained_top; } - if (draw_upper) { - const proj_default_end = PlaneHeight / 2 + PlaneDist * (level.Cell.DEFAULT_HEIGHT - pheight) / adj_distance; - const constrained_top = std.math.min(lowest_drawn, proj_default_end); - const constrained_bottom = std.math.ceil(std.math.max(bottom_of_ceiling, highest_drawn)); - const stop = @floatToInt(usize, PlaneWidth * (PlaneHeight - constrained_bottom)) + col; - const t_upper_off = cell.upper_texture * td; - const pix_y = @floatToInt(usize, std.math.ceil(std.math.max(PlaneHeight - constrained_top - 1, 0))); - var pix_index = pix_y * @floatToInt(usize, PlaneWidth) + col; - var texel_y: f32 = constants.TextureDim - (constrained_top - constrained_bottom) / nominal_length; - while (pix_index < stop) : ({ - pix_index += @floatToInt(usize, PlaneWidth); - texel_y += inv_nom_len; - }) { - const ty = @floatToInt(c_uint, std.math.modf(texel_y).fpart * constants.TextureDim); - const texel = walls_image.getPixel(.{ .x = t_upper_off + texstrip, .y = ty }); - - pixels[pix_index] = texel; - self.z_buffer[pix_index] = adj_distance; - } - lowest_drawn = constrained_bottom; - } + // if (draw_upper) { + // const proj_default_end = PlaneHeight / 2 + PlaneDist * (level.Cell.DEFAULT_HEIGHT - pheight) / adj_distance; + // const constrained_top = std.math.min(lowest_drawn, proj_default_end); + // const constrained_bottom = std.math.ceil(std.math.max(bottom_of_ceiling, highest_drawn)); + // const stop = @floatToInt(usize, PlaneWidth * (PlaneHeight - constrained_bottom)) + col; + // const t_upper_off = cell.upper_texture * td; + // const pix_y = @floatToInt(usize, std.math.ceil(std.math.max(PlaneHeight - constrained_top - 1, 0))); + // var pix_index = pix_y * @floatToInt(usize, PlaneWidth) + col; + // var texel_y: f32 = constants.TextureDim - (constrained_top - constrained_bottom) / nominal_length; + // while (pix_index < stop) : ({ + // pix_index += @floatToInt(usize, PlaneWidth); + // texel_y += inv_nom_len; + // }) { + // const ty = @floatToInt(c_uint, std.math.modf(texel_y).fpart * constants.TextureDim); + // const texel = walls_image.getPixel(.{ .x = t_upper_off + texstrip, .y = ty }); + + // pixels[pix_index] = texel; + // self.z_buffer[pix_index] = adj_distance; + // } + // lowest_drawn = constrained_bottom; + // } } } } - // do we potentially draw floor and or ceiling for this cell? - if (highest_drawn < PlaneHeight / 2 or (cell.draw_down and lowest_drawn > PlaneHeight / 2)) { - // Note: next_top can never exceed PlaneHeight / 2 in - // the body of the next block. If the wall is taller - // than us the back edge is lower than the front one so - // this check will fail as we just drew it (or higher - // than it). If the wall is shorter then the back edge - // is at most the horizon. Similarly so for next_bottom - const next_top = PlaneHeight / 2 + PlaneDist * (cell.floor_height - pheight) / next_distance; - const next_bottom = PlaneHeight / 2 + PlaneDist * (cell.ceiling_height - pheight) / next_distance; - - // draw floor? - if (false and next_top > highest_drawn) { - const toff = cell.floor_texture * @floatToInt(c_uint, constants.TextureDim); - - top_of_floor = std.math.ceil(std.math.min(std.math.min(next_top, lowest_drawn), PlaneHeight / 2 - 1)); - const thresh = std.math.ceil(highest_drawn); - - const itop = @floatToInt(usize, std.math.max(top_of_floor, 0)); - const ptop = @floatToInt(usize, PlaneHeight) - itop - 1; - var pix_index = ptop * @floatToInt(usize, PlaneWidth) + col; - while (top_of_floor > thresh) : ({ - top_of_floor -= 1; - pix_index += @floatToInt(usize, PlaneWidth); - }) { - const row_dist = (pheight - cell.floor_height) * PlaneDist / (PlaneHeight / 2 - top_of_floor); - // draw the correct pixel - const sx = std.math.modf(ppos_x + row_dist * cosra); - const sy = std.math.modf(ppos_y + row_dist * sinra); - const px = @floatToInt(c_uint, constants.TextureDim * std.math.fabs(sx.fpart)); - const py = @floatToInt(c_uint, constants.TextureDim * std.math.fabs(sy.fpart)); - const val = surfaces_image.getPixel(.{ .x = toff + px, .y = py }); - pixels[pix_index] = val; - - // record in the z_buffer only if we're above the floor! - if (cell.floor_height > 0) self.z_buffer[pix_index] = row_dist; - } - highest_drawn = next_top; - } - - // draw ceiling? - if (false and cell.draw_down and next_bottom < lowest_drawn) { - const toff = cell.ceiling_texture * @floatToInt(c_uint, constants.TextureDim); - - bottom_of_ceiling = std.math.ceil(lowest_drawn); - const thresh = std.math.max(std.math.max(next_bottom, highest_drawn), PlaneHeight / 2 - 1); - - const itop = @floatToInt(usize, bottom_of_ceiling); - const ptop = @floatToInt(usize, PlaneHeight) - itop - 1; - var pix_index = ptop * @floatToInt(usize, PlaneWidth) + col; - - while (bottom_of_ceiling > thresh) : ({ - bottom_of_ceiling -= 1; - pix_index += @floatToInt(usize, PlaneWidth); - }) { - const row_dist = (cell.ceiling_height - pheight) * PlaneDist / (bottom_of_ceiling - PlaneHeight / 2); - - const sx = std.math.modf(ppos_x + row_dist * cosra); - const sy = std.math.modf(ppos_y + row_dist * sinra); - const px = @floatToInt(c_uint, constants.TextureDim * std.math.fabs(sx.fpart)); - const py = @floatToInt(c_uint, constants.TextureDim * std.math.fabs(sy.fpart)); - const val = surfaces_image.getPixel(.{ .x = toff + px, .y = py }); - pixels[pix_index] = val; - - if (cell.draw_down) self.z_buffer[pix_index] = row_dist; - } - lowest_drawn = next_bottom; - } + // // do we potentially draw floor and or ceiling for this cell? + // if (highest_drawn < PlaneHeight / 2 or (cell.draw_down and lowest_drawn > PlaneHeight / 2)) { + // // Note: next_top can never exceed PlaneHeight / 2 in + // // the body of the next block. If the wall is taller + // // than us the back edge is lower than the front one so + // // this check will fail as we just drew it (or higher + // // than it). If the wall is shorter then the back edge + // // is at most the horizon. Similarly so for next_bottom + // const next_top = PlaneHeight / 2 + PlaneDist * (cell.floor_height - pheight) / next_distance; + // const next_bottom = PlaneHeight / 2 + PlaneDist * (cell.ceiling_height - pheight) / next_distance; + + // // draw floor? + // if (false and next_top > highest_drawn) { + // const toff = cell.floor_texture * @floatToInt(c_uint, constants.TextureDim); + + // top_of_floor = std.math.ceil(std.math.min(std.math.min(next_top, lowest_drawn), PlaneHeight / 2 - 1)); + // const thresh = std.math.ceil(highest_drawn); + + // const itop = @floatToInt(usize, std.math.max(top_of_floor, 0)); + // const ptop = @floatToInt(usize, PlaneHeight) - itop - 1; + // var pix_index = ptop * @floatToInt(usize, PlaneWidth) + col; + // while (top_of_floor > thresh) : ({ + // top_of_floor -= 1; + // pix_index += @floatToInt(usize, PlaneWidth); + // }) { + // const row_dist = (pheight - cell.floor_height) * PlaneDist / (PlaneHeight / 2 - top_of_floor); + // // draw the correct pixel + // const sx = std.math.modf(ppos_x + row_dist * cosra); + // const sy = std.math.modf(ppos_y + row_dist * sinra); + // const px = @floatToInt(c_uint, constants.TextureDim * std.math.fabs(sx.fpart)); + // const py = @floatToInt(c_uint, constants.TextureDim * std.math.fabs(sy.fpart)); + // const val = surfaces_image.getPixel(.{ .x = toff + px, .y = py }); + // pixels[pix_index] = val; + + // // record in the z_buffer only if we're above the floor! + // if (cell.floor_height > 0) self.z_buffer[pix_index] = row_dist; + // } + // highest_drawn = next_top; + // } + + // // draw ceiling? + // if (false and cell.draw_down and next_bottom < lowest_drawn) { + // const toff = cell.ceiling_texture * @floatToInt(c_uint, constants.TextureDim); + + // bottom_of_ceiling = std.math.ceil(lowest_drawn); + // const thresh = std.math.max(std.math.max(next_bottom, highest_drawn), PlaneHeight / 2 - 1); + + // const itop = @floatToInt(usize, bottom_of_ceiling); + // const ptop = @floatToInt(usize, PlaneHeight) - itop - 1; + // var pix_index = ptop * @floatToInt(usize, PlaneWidth) + col; + + // while (bottom_of_ceiling > thresh) : ({ + // bottom_of_ceiling -= 1; + // pix_index += @floatToInt(usize, PlaneWidth); + // }) { + // const row_dist = (cell.ceiling_height - pheight) * PlaneDist / (bottom_of_ceiling - PlaneHeight / 2); + + // const sx = std.math.modf(ppos_x + row_dist * cosra); + // const sy = std.math.modf(ppos_y + row_dist * sinra); + // const px = @floatToInt(c_uint, constants.TextureDim * std.math.fabs(sx.fpart)); + // const py = @floatToInt(c_uint, constants.TextureDim * std.math.fabs(sy.fpart)); + // const val = surfaces_image.getPixel(.{ .x = toff + px, .y = py }); + // pixels[pix_index] = val; + + // if (cell.draw_down) self.z_buffer[pix_index] = row_dist; + // } + // lowest_drawn = next_bottom; + // } + // } + // } + + // Have we filled this column? + if (top_of_floor > lowest_drawn or bottom_of_ceiling < highest_drawn) { + still_drawing = false; } } - // Have we filled this column? - if (top_of_floor > lowest_drawn or bottom_of_ceiling < highest_drawn) { - still_drawing = false; - } } } }; -- cgit v1.3.1