Additional fixes and todo plans

This commit is contained in:
2026-04-28 22:50:04 +02:00
parent ccbf7344b5
commit 37e2f36ae9
5 changed files with 29 additions and 8 deletions

View File

@@ -1,13 +1,14 @@
const clr = @import("raylib").Color;
/// Screen Width
pub const WIDTH = 2560;
pub const WIDTH = 1366;
/// Screen Height
pub const HEIGHT = 1440;
pub const HEIGHT = 768;
pub const BACKGROUND_COLOR = clr.dark_gray;
pub const ALLOC_SIZE = 50;
/// Base node radius
pub const NODE_RADIUS = 20;
/// The radius around node center where no new node gets created but rather it snaps onto existing one
pub const NODE_SNAP_RADIUS = 3 * NODE_RADIUS;
/// Regular (finished) node colour

View File

@@ -31,7 +31,6 @@ pub const Node = struct {
return rl.checkCollisionPointCircle(pos, self.pos, c.NODE_SNAP_RADIUS);
}
pub fn referenceRoad(self: *Node, allocator: std.mem.Allocator, road_to_add: *Road) !void {
// Note the road_to_add pointer must be one from the roads list as otherwise the pointer is dangling one
for (self.roads.items) |road| {

View File

@@ -28,8 +28,8 @@ pub const RoadManager = struct {
try self.roads.append(allocator, road);
const ref = &self.roads.items[self.roads.items.len - 1];
try ref.*.nodes[0].referenceRoad(allocator, ref);
try ref.*.nodes[1].referenceRoad(allocator, ref);
try start.referenceRoad(allocator, ref);
try end.referenceRoad(allocator, ref);
}
fn getNextID(self: *RoadManager) usize {

View File

@@ -4,11 +4,26 @@ const rl = @import("raylib");
const c = @import("constants.zig");
const Simulator = @import("simulator.zig").Simulator;
// TODO PLANS
// Implement that roads, nodes in managers will be stored as pointers (allocated in heap)
// So when appending causes the list to relocate, nothing will have to change
// since the allocated nodes/roads will remain where they were
// Additionally add more robust error and test handling
pub fn main(init: std.process.Init) !void {
const allocator = init.gpa;
rl.setConfigFlags(.{
.msaa_4x_hint = true,
.window_highdpi = true,
});
rl.initWindow(c.WIDTH, c.HEIGHT, "Base Road Network");
defer rl.closeWindow();
const monitor = 0;
rl.setWindowMonitor(monitor);
rl.setTargetFPS(rl.getMonitorRefreshRate(monitor));
var sim: Simulator = .init(allocator);
defer sim.deinit();

View File

@@ -1,6 +1,7 @@
const std = @import("std");
const rl = @import("raylib");
const c = @import("constants.zig");
const NodeManager = @import("infrastructure/node_manager.zig").NodeManager;
const RoadManager = @import("infrastructure/road_manager.zig").RoadManager;
@@ -8,12 +9,15 @@ pub const Simulator = struct {
allocator: std.mem.Allocator,
node_man: NodeManager,
road_man: RoadManager,
// vars
auto_continue: bool,
pub fn init(new_allocator: std.mem.Allocator) Simulator {
return .{
.allocator = new_allocator,
.node_man = .init(),
.road_man = .init(),
.auto_continue = false,
};
}
@@ -23,7 +27,7 @@ pub const Simulator = struct {
}
pub fn draw(self: *const Simulator, pos: rl.Vector2) void {
rl.clearBackground(.light_gray);
rl.clearBackground(c.BACKGROUND_COLOR);
self.road_man.draw();
self.node_man.draw(pos);
@@ -35,6 +39,8 @@ pub const Simulator = struct {
}
fn handleKeyboardInput(self: *Simulator) void {
self.auto_continue = rl.isKeyDown(.left_control);
if (rl.isKeyReleased(.c)) self.clear();
}
@@ -54,7 +60,7 @@ pub const Simulator = struct {
std.debug.panic("Failed to add a new road or assigning its nodes: {}\n", .{err});
};
self.node_man.temp_node = null;
self.node_man.temp_node = if (self.auto_continue) cur_node else null;
return;
}