Further implementation plans

This commit is contained in:
2026-04-08 23:08:15 +02:00
parent 288cfd6b50
commit dc0d91997a
3 changed files with 22 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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();