Initial refractoring attempt

Slight refractor attempt by moving some initializing to view module, sadly it crashes.
This commit is contained in:
Tony Bark 2024-05-13 23:25:17 -04:00
parent 017d5ef1a7
commit 6c8e36d99f
2 changed files with 29 additions and 10 deletions

View file

@ -1,8 +1,10 @@
/// Still in the proof of concept phase, don't mind the mess
const std = @import("std"); const std = @import("std");
const rl = @import("raylib"); const rl = @import("raylib");
const world = @import("world.zig"); const world = @import("world.zig");
const nso = @import("niotso.zig"); const nso = @import("niotso.zig");
const clap = @import("clap"); const clap = @import("clap");
const view = @import("view.zig");
const dbg = std.debug; const dbg = std.debug;
@ -57,13 +59,11 @@ const RotationManager = struct {
} }
}; };
/// Still in the proof of concept phase, don't mind the mess
pub fn main() anyerror!void { pub fn main() anyerror!void {
const screen_width = 800; const screen_width = 800;
const screen_height = 600; const screen_height = 600;
rl.initWindow(screen_width, screen_height, "My Simulation"); view.init(true, screen_width, screen_height, "My Simulation");
defer rl.closeWindow();
var current_screen: GameScreen = .login; var current_screen: GameScreen = .login;
var frame_counter: i32 = 0; var frame_counter: i32 = 0;
@ -95,8 +95,6 @@ pub fn main() anyerror!void {
.Direction = CardinalDirection.SouthEast, .Direction = CardinalDirection.SouthEast,
}); });
rl.setTargetFPS(60);
const logo = rl.Texture.init("resources/logo.png"); const logo = rl.Texture.init("resources/logo.png");
const splash = rl.Texture.init("resources/tsosplash.png"); const splash = rl.Texture.init("resources/tsosplash.png");
const chair1 = rl.Texture.init("resources/items/dorm/chair/chair_1.png"); const chair1 = rl.Texture.init("resources/items/dorm/chair/chair_1.png");
@ -179,8 +177,7 @@ pub fn main() anyerror!void {
// ------------------ // ------------------
// Draw // Draw
rl.beginDrawing(); view.render();
defer rl.endDrawing();
switch (current_screen) { switch (current_screen) {
// Mockup loading screen, skips straight to world // Mockup loading screen, skips straight to world
@ -225,10 +222,8 @@ pub fn main() anyerror!void {
}, },
} }
// rl.drawGrid(64, 1.0); rl.drawGrid(64, 1.0);
}, },
} }
rl.drawFPS(10, 10);
} }
} }

24
src/view.zig Normal file
View file

@ -0,0 +1,24 @@
const rl = @import("raylib");
var is_debug: bool = false;
pub fn init(dbg: bool, width: i32, height: i32, title: [:0]const u8) void {
if (dbg == true) {
is_debug = dbg;
}
rl.initWindow(width, height, title);
defer rl.closeWindow();
rl.setTargetFPS(60);
}
/// Setup basic rendering
pub fn render() void {
rl.beginDrawing();
defer rl.endDrawing();
if (is_debug == true) {
rl.drawFPS(10, 10);
}
}