From dc0d91997a74289426ba580d3dc01ff9cd715685 Mon Sep 17 00:00:00 2001 From: Marto Date: Wed, 8 Apr 2026 23:08:15 +0200 Subject: [PATCH] Further implementation plans --- src/infrastructure/node_manager.zig | 4 ++-- src/infrastructure/road_manager.zig | 2 +- src/simulator.zig | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/infrastructure/node_manager.zig b/src/infrastructure/node_manager.zig index dacc3d2..a17a208 100644 --- a/src/infrastructure/node_manager.zig +++ b/src/infrastructure/node_manager.zig @@ -61,7 +61,7 @@ pub const NodeManager = struct { /// Returns the pointer to the node that is in the snapping node radius of the pos /// or creates a new node and returns pointer to it - fn getSelectedNode(self: *NodeManager, pos: rl.Vector2) *Node { + pub fn getSelectedNode(self: *NodeManager, pos: rl.Vector2) *Node { if (self.getNodeWithinRadius(pos)) |node| return node; // We couldn't find the existing node and as such must create a new one @@ -81,7 +81,7 @@ pub const NodeManager = struct { } /// generates finds the last element in the list and returns id + 1 or 0 if there are no elements in the list - fn getNewID(self: *const NodeManager) usize { + pub fn getNewID(self: *const NodeManager) usize { return if (self.nodes.getLastOrNull()) |last| last.id + 1 else 0; } diff --git a/src/infrastructure/road_manager.zig b/src/infrastructure/road_manager.zig index b1afada..0ed3372 100644 --- a/src/infrastructure/road_manager.zig +++ b/src/infrastructure/road_manager.zig @@ -56,7 +56,7 @@ pub const RoadManager = struct { } /// Generates finds the last element in the list and returns id + 1 or 0 if there are no elements in the list - fn getNewID(self: *const RoadManager) usize { + pub fn getNewID(self: *const RoadManager) usize { return if (self.roads.getLastOrNull()) |last| last.id + 1 else 0; } diff --git a/src/simulator.zig b/src/simulator.zig index 04d6cb3..9f9d226 100644 --- a/src/simulator.zig +++ b/src/simulator.zig @@ -9,6 +9,7 @@ const NodeManager = @import("infrastructure/node_manager.zig").NodeManager; const RoadManager = @import("infrastructure/road_manager.zig").RoadManager; const Node = @import("infrastructure/node.zig").Node; +const Road = @import("infrastructure/road.zig").Road; pub const Simulator = struct { allocator: std.mem.Allocator, @@ -95,11 +96,17 @@ pub const Simulator = struct { const temp = self.node_man.temp_node.?; if (temp.id == node.id) return; + // todo remove self.road_man.add(self.allocator, temp, node) catch |err| { std.debug.panic("Error while attempting to add a road: {}\n", .{err}); }; // get intersections made + // todo plan out the implementation + // add both nodes to the intersection array + // first in front, second in last + // all of the road connections will not be added here but rather in the split_roads function as it will + // create road connection for each nodes that are to be connected via connection const data = self.getIntersectingRoads(self.allocator, temp, node) catch |err| { std.debug.panic("Failed to save intersection data: {}\n", .{err}); }; @@ -205,6 +212,18 @@ pub const Simulator = struct { return sorted_intersections; } + fn splitRoadsByPoints(self: *Simulator, intersections: []const st.IntersectionData) void { + _ = self; // autofix + // todo plan it out + if (intersections.len == 0) return; + + for (0..intersections.len) |i| { + const intersection = intersections[i]; + _ = intersection; // autofix + } + + } + pub fn update(self: *Simulator) void { const pos = rl.getMousePosition();