Added comments and slightly refactored code for deletion of temp node
This commit is contained in:
@@ -25,6 +25,9 @@ pub const ROAD_COLOUR = clr.black;
|
|||||||
/// Colour of the road that is highlighted
|
/// Colour of the road that is highlighted
|
||||||
pub const ROAD_HIGHLIGHTED_COLOUR = clr.green;
|
pub const ROAD_HIGHLIGHTED_COLOUR = clr.green;
|
||||||
|
|
||||||
|
/// Regular text size
|
||||||
pub const TEXT_SIZE = 50;
|
pub const TEXT_SIZE = 50;
|
||||||
|
/// Text size that is used for displaying entity IDs
|
||||||
pub const ENTITY_DATA_TEXT_SIZE = TEXT_SIZE / 2;
|
pub const ENTITY_DATA_TEXT_SIZE = TEXT_SIZE / 2;
|
||||||
|
/// Text colour in which entity IDs are displayed if toggled
|
||||||
pub const ENTITY_DATA_TEXT_COLOUR = clr.orange;
|
pub const ENTITY_DATA_TEXT_COLOUR = clr.orange;
|
||||||
@@ -118,16 +118,20 @@ pub const NodeManager = struct {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Essentially what it does is it sets temp node pointer to null and
|
||||||
|
/// if the node it pointed at had no road references (essentially it was a new node for road building),
|
||||||
|
/// it deletes the node from the node list as well
|
||||||
pub fn deleteTempNode(self: *NodeManager, allocator: std.mem.Allocator) void {
|
pub fn deleteTempNode(self: *NodeManager, allocator: std.mem.Allocator) void {
|
||||||
if (self.temp_node == null) return;
|
if (self.temp_node == null) return;
|
||||||
|
|
||||||
const node = self.temp_node.?;
|
const node = self.temp_node.?;
|
||||||
if (node.roads.items.len == 0)
|
self.temp_node = null;
|
||||||
|
|
||||||
|
if (node.roads.items.len != 0) return;
|
||||||
self.deleteNode(allocator, node) catch |err| {
|
self.deleteNode(allocator, node) catch |err| {
|
||||||
std.debug.panic("Failed to delete the temporary node: {}\n", .{err});
|
std.debug.panic("Failed to delete the temporary node: {}\n", .{err});
|
||||||
};
|
};
|
||||||
|
|
||||||
self.temp_node = null;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -219,6 +219,7 @@ pub const Simulator = struct {
|
|||||||
self.highlighted_entity = null;
|
self.highlighted_entity = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns array of IntersectionData struct, containing pointers to roads that got intersected and exact position
|
||||||
fn getIntersectingRoads(self: *const Simulator, allocator: std.mem.Allocator, start: *const Node, end: *const Node) ![]st.IntersectionData {
|
fn getIntersectingRoads(self: *const Simulator, allocator: std.mem.Allocator, start: *const Node, end: *const Node) ![]st.IntersectionData {
|
||||||
var intersections: std.ArrayList(st.IntersectionData) = .empty;
|
var intersections: std.ArrayList(st.IntersectionData) = .empty;
|
||||||
var collision_point: rl.Vector2 = undefined;
|
var collision_point: rl.Vector2 = undefined;
|
||||||
@@ -286,6 +287,7 @@ pub const Simulator = struct {
|
|||||||
return sorted_intersection;
|
return sorted_intersection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Takes the data about intersections and adds new nodes there alongside with linking existing roads to them
|
||||||
fn splitRoadsByIntersections(self: *Simulator, intersections: []st.IntersectionData, start: *Node, end: *Node) void {
|
fn splitRoadsByIntersections(self: *Simulator, intersections: []st.IntersectionData, start: *Node, end: *Node) void {
|
||||||
if (intersections.len == 0) {
|
if (intersections.len == 0) {
|
||||||
self.road_man.addRoad(self.allocator, start, end) catch |err| {
|
self.road_man.addRoad(self.allocator, start, end) catch |err| {
|
||||||
|
|||||||
Reference in New Issue
Block a user