diff options
| author | tslil clingman <> | 2021-10-17 21:03:38 -0400 |
|---|---|---|
| committer | tslil clingman <> | 2021-10-17 21:03:38 -0400 |
| commit | b55966e335d6de86309f6a7abafcdca8bc3adbb8 (patch) | |
| tree | fa6de1317265872f1b67576ba01814b12edff22f /src/render.zig | |
| parent | 260e1ae4b4d84cb28aebb4e7d1f1b54ed046e77b (diff) | |
A stray -1. Next issue: horizontal doesn't meet vertical on barrels?
Diffstat (limited to 'src/render.zig')
| -rw-r--r-- | src/render.zig | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/src/render.zig b/src/render.zig index aac8e6b..4753805 100644 --- a/src/render.zig +++ b/src/render.zig @@ -173,9 +173,6 @@ 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! @@ -348,15 +345,15 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { const constrained_top = std.math.floor(std.math.min(top_of_floor, lowest_drawn)); const proj_height = (layer.height - previous_layer_height) * nominal_length; - // if we're above the layer that set the highest_drawn - // values, we can draw down into it (for - // walls over floors) + // if we're above the layer that set the + // highest_drawn values, we can draw down + // into it (for walls over floors) const constrained_bottom = std.math.max(if (highest_drawn_same_square) 0 else highest_drawn, top_of_floor - proj_height); - const stop = @floatToInt(usize, PlaneWidth * (PlaneHeight - constrained_bottom)) + col; + const stop_top = std.math.max(0, PlaneHeight - constrained_bottom - 1); + const stop = @floatToInt(usize, PlaneWidth * stop_top) + 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) : ({ @@ -364,9 +361,7 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { 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 + texcol, .y = ty }); - - pixels[pix_index] = texel; + pixels[pix_index] = walls_image.getPixel(.{ .x = t_lower_off + texcol, .y = ty }); self.z_buffer[pix_index] = adj_distance; } highest_drawn = constrained_top; @@ -382,18 +377,17 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { // is at most the horizon. Similarly so for next_bottom const next_top = PlaneHeight / 2 + PlaneDist * (layer.height - pheight) / next_distance; if (next_top > highest_drawn) { + highest_drawn_same_square = true; + const toff = layer.horizontal_texture * @floatToInt(c_uint, constants.TextureDim); var top = std.math.ceil(std.math.min(std.math.min(next_top, lowest_drawn), PlaneHeight / 2 - 1)); - const thresh = std.math.ceil(highest_drawn); - - highest_drawn = top; - highest_drawn_same_square = true; + const thresh = highest_drawn; const itop = @floatToInt(usize, std.math.max(top, 0)); const ptop = @floatToInt(usize, PlaneHeight) - itop - 1; - var pix_index = ptop * @floatToInt(usize, PlaneWidth) + col - 1; - while (top >= thresh) : ({ + var pix_index = ptop * @floatToInt(usize, PlaneWidth) + col; + while (top > thresh) : ({ top -= 1; pix_index += @floatToInt(usize, PlaneWidth); }) { @@ -403,11 +397,13 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { const sy = ppos_y + row_dist * sinra; const rx = std.math.modf(sx).fpart; const ry = std.math.modf(sy).fpart; - if (@floatToInt(i32, sx) == ipos_x and @floatToInt(i32, sy) == ipos_y and pointInPoly(rx, ry, layer.vertices.constSlice()) and self.z_buffer[pix_index] == std.math.inf(f32)) { + if (@floatToInt(i32, sx) == ipos_x and @floatToInt(i32, sy) == ipos_y and pointInPoly(rx, ry, layer.vertices.constSlice())) { const px = @floatToInt(c_uint, constants.TextureDim * rx); const py = @floatToInt(c_uint, constants.TextureDim * ry); - const val = surfaces_image.getPixel(.{ .x = toff + px, .y = py }); - pixels[pix_index] = val; + pixels[pix_index] = surfaces_image.getPixel(.{ .x = toff + px, .y = py }); + if (top > highest_drawn) { + highest_drawn = top; + } if (layer.height > 0) self.z_buffer[pix_index] = row_dist; } } |
