Added comments and slightly refactored code for deletion of temp node

This commit is contained in:
2026-05-01 16:44:52 +02:00
parent 643712f529
commit afd7aa50c4
3 changed files with 14 additions and 5 deletions

View File

@@ -118,16 +118,20 @@ pub const NodeManager = struct {
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 {
if (self.temp_node == null) return;
const node = self.temp_node.?;
if (node.roads.items.len == 0)
self.deleteNode(allocator, node) catch |err| {
std.debug.panic("Failed to delete the temporary node: {}\n", .{err});
};
self.temp_node = null;
if (node.roads.items.len != 0) return;
self.deleteNode(allocator, node) catch |err| {
std.debug.panic("Failed to delete the temporary node: {}\n", .{err});
};
}
};