From 631c1226691505624c08995b6a2ac81e46a9b17e Mon Sep 17 00:00:00 2001 From: tslil clingman <> Date: Sun, 5 Sep 2021 21:30:31 -0400 Subject: In response to issue #9629, correct usingnamespace usage --- src/main.zig | 62 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index cf3839d..2def0e8 100644 --- a/src/main.zig +++ b/src/main.zig @@ -16,17 +16,17 @@ // along with this program. If not, see . const sf = struct { - pub usingnamespace @import("sfml"); - pub usingnamespace graphics; - pub usingnamespace window; + usingnamespace @import("sfml"); + usingnamespace sf.graphics; + usingnamespace sf.window; }; const isKeyPressed = sf.window.keyboard.isKeyPressed; const std = @import("std"); -usingnamespace @import("raycast.zig"); -usingnamespace @import("renderConstants.zig"); -usingnamespace @import("map.zig"); +const constants = @import("constants.zig"); +const raycast = @import("raycast.zig"); +const level = @import("level.zig"); // TODO: is there anyway i can say fn renderSlice : RenderSliceFunction? fn renderSlice( @@ -41,17 +41,17 @@ fn renderSlice( ) void { // we need ceil here so that we draw always to or past the edge of the screen - const draw_height = @floatToInt(c_int, std.math.ceil(draw_frac * TextureDim)); - const total_length = total_height * VFact; + const draw_height = @floatToInt(c_int, std.math.ceil(draw_frac * constants.TextureDim)); + const total_length = total_height * constants.VFact; - const xpos = @intToFloat(f32, col) * HFact; - const ypos = ScreenHeight / 2 + (PlaneHeight / 2 - top) * VFact; + const xpos = @intToFloat(f32, col) * constants.HFact; + const ypos = constants.ScreenHeight / 2 + (constants.PlaneHeight / 2 - top) * constants.VFact; - const tind = @as(c_int, texture) * @floatToInt(c_int, TextureDim); - const left = tind + @floatToInt(c_int, texfrac * TextureDim); + const tind = @as(c_int, texture) * @floatToInt(c_int, constants.TextureDim); + const left = tind + @floatToInt(c_int, texfrac * constants.TextureDim); sprite.setPosition(.{ .x = xpos, .y = ypos }); - sprite.setScale(.{ .x = HFact, .y = total_length / TextureDim }); + sprite.setScale(.{ .x = constants.HFact, .y = total_length / constants.TextureDim }); sprite.setTextureRect(.{ .top = 0, .left = left, .width = 1, .height = draw_height }); window.draw(sprite, null); } @@ -62,7 +62,7 @@ pub fn main() !void { // Setup player and map //-------------------------------------------------------------------------- - var player = try Player(PlaneWidth, PlaneHeight).new( + var player = try raycast.Player(constants.PlaneWidth, constants.PlaneHeight).new( 7, // x coord 1.5, // y coord PI / 2.0, // angle @@ -71,27 +71,27 @@ pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); - var map = try Map.new(16, 16, &gpa.allocator); + 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] = Cell{ .height = MAX_HEIGHT }; - map.cells.items[y * 16 + 15] = Cell{ .height = MAX_HEIGHT, .wall_texture = 2 }; - map.cells.items[15 * 16 + y] = Cell{ .height = MAX_HEIGHT }; - map.cells.items[00 * 16 + y] = Cell{ .height = MAX_HEIGHT }; + map.cells.items[y * 16 + 00] = level.Cell{ .height = constants.MAX_HEIGHT }; + map.cells.items[y * 16 + 15] = level.Cell{ .height = constants.MAX_HEIGHT, .wall_texture = 2 }; + map.cells.items[15 * 16 + y] = level.Cell{ .height = constants.MAX_HEIGHT }; + map.cells.items[00 * 16 + y] = level.Cell{ .height = constants.MAX_HEIGHT }; } - map.cells.items[16 * 7 + 7] = Cell{ .height = MAX_HEIGHT, .wall_texture = 1 }; - map.cells.items[16 * 7 + 6] = Cell{ .height = MAX_HEIGHT / 3, .wall_texture = 1, .floor_texture = 1 }; + map.cells.items[16 * 7 + 7] = level.Cell{ .height = constants.MAX_HEIGHT, .wall_texture = 1 }; + map.cells.items[16 * 7 + 6] = level.Cell{ .height = constants.MAX_HEIGHT / 3, .wall_texture = 1, .floor_texture = 1 }; - try map.objects.append(Object{.pos_x = 6.5, .pos_y = 8.5, .texture = 0, .height = 1, .width = 1}); - try map.objects.append(Object{.pos_x = 4, .pos_y = 8.5, .texture = 1, .height = 1, .width = 1}); + try map.objects.append(level.Object{ .pos_x = 6.5, .pos_y = 8.5, .texture = 0, .height = 1, .width = 1 }); + try map.objects.append(level.Object{ .pos_x = 4, .pos_y = 8.5, .texture = 1, .height = 1, .width = 1 }); // Initialise SFML //-------------------------------------------------------------------------- - var window = try sf.RenderWindow.create(.{ .x = ScreenWidth, .y = ScreenHeight }, 32, "zirc", sf.window.Style.none); + var window = try sf.RenderWindow.create(.{ .x = constants.ScreenWidth, .y = constants.ScreenHeight }, 32, "zirc", sf.window.Style.none); defer window.destroy(); window.setFramerateLimit(60); @@ -110,7 +110,7 @@ pub fn main() !void { var back_sprite = try sf.Sprite.createFromTexture(back_texture); defer back_sprite.destroy(); - back_sprite.setScale(.{ .x = 4.0 * ScreenWidth / BackTextureWidth, .y = ScreenHeight / (2 * BackTextureHeight) }); + back_sprite.setScale(.{ .x = 4.0 * constants.ScreenWidth / constants.BackTextureWidth, .y = constants.ScreenHeight / (2 * constants.BackTextureHeight) }); // Load wall textures var wall_textures = try sf.Texture.createFromFile("walls.png"); @@ -132,15 +132,15 @@ pub fn main() !void { var floors_image = try sf.Image.createFromFile("floors.png"); defer floors_image.destroy(); - var rendered_floors_texture = try sf.Texture.create(.{ .x = PlaneWidth, .y = PlaneHeight / 2 }); + var rendered_floors_texture = try sf.Texture.create(.{ .x = constants.PlaneWidth, .y = constants.PlaneHeight / 2 }); defer rendered_floors_texture.destroy(); rendered_floors_texture.setSmooth(false); var rendered_floors_sprite = try sf.Sprite.createFromTexture(rendered_floors_texture); defer rendered_floors_sprite.destroy(); - rendered_floors_sprite.setPosition(.{ .x = 0, .y = ScreenHeight / 2 }); - rendered_floors_sprite.setScale(.{ .x = HFact, .y = VFact }); + rendered_floors_sprite.setPosition(.{ .x = 0, .y = constants.ScreenHeight / 2 }); + rendered_floors_sprite.setScale(.{ .x = constants.HFact, .y = constants.VFact }); // Start your engines! //-------------------------------------------------------------------------- @@ -182,14 +182,14 @@ pub fn main() !void { window.clear(sf.Color.fromRGB(100, 100, 100)); // First the background - const back_scroll = @floatToInt(i32, -BackTextureWidth * player.ang / (2 * PI)); + const back_scroll = @floatToInt(i32, -constants.BackTextureWidth * player.ang / (2 * PI)); back_sprite.setTextureRect(sf.IntRect{ .left = back_scroll, // fix location of texture in the sky .top = 0, // scaling ensures that the next two dimensions paint it across the // width of the Screen, and for half the height of the screen - .width = BackTextureWidth / 4.0, // 1/4 of texture per screen - .height = BackTextureHeight, // full height of texture visible + .width = constants.BackTextureWidth / 4.0, // 1/4 of texture per screen + .height = constants.BackTextureHeight, // full height of texture visible }); window.draw(back_sprite, null); -- cgit v1.3.1