Implementation of adding new roads, bug incoming, TODO entity viewer, something akin to imgui
This commit is contained in:
@@ -156,7 +156,6 @@ pub const Simulator = struct {
|
||||
c.HEIGHT - 2 * c.TEXT_SIZE,
|
||||
c.TEXT_SIZE, .black);
|
||||
|
||||
|
||||
// Displays the mode the simulation is currently in
|
||||
rl.drawText(@tagName(self.mode), 10, c.HEIGHT - c.TEXT_SIZE, c.TEXT_SIZE, .black);
|
||||
|
||||
@@ -210,10 +209,14 @@ pub const Simulator = struct {
|
||||
}
|
||||
|
||||
fn splitRoadsByPoints(self: *Simulator, intersections: []const st.IntersectionData, start: *const Node, end: *const Node) void {
|
||||
_ = end; // autofix
|
||||
_ = start; // autofix
|
||||
// todo plan it out
|
||||
if (intersections.len == 0) return;
|
||||
|
||||
const first_intersection_road = intersections[0];
|
||||
const first_intersection_node = self.node_man.getSelectedNode(first_intersection_road.point);
|
||||
const first_road = self.road_man.add(self.allocator, start, first_intersection_node) catch |err| {
|
||||
std.debug.panic("Failed to create the first split road: {}\n", .{err});
|
||||
};
|
||||
first_intersection_node.referenceRoad(self.allocator, first_road);
|
||||
|
||||
// We have done that every intersection creates new node and reconnects existing connections
|
||||
// TODO
|
||||
@@ -233,11 +236,31 @@ pub const Simulator = struct {
|
||||
// As is the end node's road reference
|
||||
road_old_node.unreferenceRoad(intersection.road);
|
||||
|
||||
self.road_man.add(self.allocator, new_node, road_old_node) catch |err| {
|
||||
std.debug.panic("Failed to create the new split road: {}\n", .{err});
|
||||
_ = self.road_man.add(self.allocator, new_node, road_old_node) catch |err| {
|
||||
std.debug.panic("Failed to create the last split road: {}\n", .{err});
|
||||
};
|
||||
|
||||
if (i == intersections.len - 1) continue;
|
||||
|
||||
const connecting_road = self.road_man.add(
|
||||
self.allocator,
|
||||
self.node_man.getSelectedNode(intersection.point),
|
||||
self.node_man.getSelectedNode(intersections[i+1].point)) catch |err| {
|
||||
std.debug.panic("Failed to create the connecting road: {}\n", .{err});
|
||||
};
|
||||
|
||||
// todo
|
||||
// okay so here we connect the road to current and next node
|
||||
// and then this should hopefully be it
|
||||
// 20 new bugs incoming
|
||||
}
|
||||
|
||||
const last_intersection_road = intersections[intersections.len - 1];
|
||||
const last_intersection_node = self.node_man.getSelectedNode(last_intersection_road.point);
|
||||
const road = self.road_man.add(self.allocator, last_intersection_node, end) catch |err| {
|
||||
std.debug.panic("Failed to add the road: {}\n", .{err});
|
||||
};
|
||||
last_intersection_node.referenceRoad(self.allocator, road);
|
||||
}
|
||||
|
||||
pub fn update(self: *Simulator) void {
|
||||
|
||||
Reference in New Issue
Block a user