diff options
Diffstat (limited to 'src/raycast.zig')
| -rw-r--r-- | src/raycast.zig | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/raycast.zig b/src/raycast.zig index 41458c7..e1bfce0 100644 --- a/src/raycast.zig +++ b/src/raycast.zig @@ -23,8 +23,8 @@ const Texture = @import("sfml").graphics.Texture; const Image = @import("sfml").graphics.Image; const Colour = @import("sfml").graphics.Color; -usingnamespace @import("map.zig"); -usingnamespace @import("renderConstants.zig"); +const level = @import("level.zig"); +const constants = @import("constants.zig"); pub const RenderSliceFunction: type = fn ( window: RenderWindow, @@ -92,7 +92,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { walls_sprite: Sprite, objects_sprite: Sprite, renderSlice: RenderSliceFunction, - map: Map, + map: level.Map, ) void { // reset the z_buffer var i: usize = 0; @@ -107,7 +107,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { self.renderObjects(window, objects_sprite, renderSlice, map); } - fn playerDistComp(pos : [2]f32, lhs: Object, rhs: Object) bool { + fn playerDistComp(pos: [2]f32, lhs: level.Object, rhs: level.Object) bool { const lx = lhs.pos_x - pos[0]; const ly = lhs.pos_y - pos[1]; const rx = rhs.pos_x - pos[0]; @@ -121,13 +121,12 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { window: RenderWindow, objects_sprite: Sprite, renderSlice: RenderSliceFunction, - map: Map, + map: level.Map, ) void { - std.sort.sort(Object, map.objects.items, - // Wow, context with an arbitrary type! No macros, just - // Zig all the way down! - [2]f32{self.pos_x, self.pos_y}, - playerDistComp); + std.sort.sort(level.Object, map.objects.items, + // Wow, context with an arbitrary type! No macros, just + // Zig all the way down! + [2]f32{ self.pos_x, self.pos_y }, playerDistComp); const self_cos = std.math.cos(self.ang); const self_sin = std.math.sin(self.ang); @@ -186,7 +185,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { break; } } - const draw_frac = std.math.clamp((top - bottom) / height, 0 , 1); + const draw_frac = std.math.clamp((top - bottom) / height, 0, 1); renderSlice(window, objects_sprite, col, top, height, draw_frac, tex_frac, obj.texture); } } @@ -197,7 +196,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { window: RenderWindow, walls_sprite: Sprite, renderSlice: RenderSliceFunction, - map: Map, + map: level.Map, ) void { // This is a TERRIBLE hack: for whatever reason *linearly* // interpolating on the direction vectors gives @@ -315,7 +314,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { } } - pub fn renderFloorsToTexture(self: @This(), floors_image: Image, rendered_floors_texture: Texture, map: Map) !void { + pub fn renderFloorsToTexture(self: @This(), floors_image: Image, rendered_floors_texture: Texture, map: level.Map) !void { var pixels = [_]Colour{Colour.Black} ** (PlaneWidth * PlaneHeight / 2); // Again, another TERRIBLE hack: we do the same nasty linear @@ -352,9 +351,9 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { if (map.inBounds(ix, iy)) { const tex = @as(c_uint, map.lookup(ix, iy).floor_texture); - const toff = tex * @floatToInt(c_uint, TextureDim); - const px = @floatToInt(c_uint, TextureDim * std.math.fabs(sx.fpart)); - const py = @floatToInt(c_uint, TextureDim * std.math.fabs(sy.fpart)); + const toff = tex * @floatToInt(c_uint, constants.TextureDim); + 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 = floors_image.getPixel(.{ .x = toff + px, .y = py }); |
