aboutsummaryrefslogtreecommitdiff
path: root/src/raycast.zig
diff options
context:
space:
mode:
authortslil clingman <>2021-09-05 21:30:31 -0400
committertslil clingman <>2021-09-05 21:31:59 -0400
commit631c1226691505624c08995b6a2ac81e46a9b17e (patch)
tree88fce088399ba4f4880298729cf98592d631ac70 /src/raycast.zig
parenta35ac9be26a148a87283ba51ed92d8c2b95bcd24 (diff)
In response to issue #9629, correct usingnamespace usage
Diffstat (limited to 'src/raycast.zig')
-rw-r--r--src/raycast.zig31
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 });