Added comments and slightly refactored code for deletion of temp node
This commit is contained in:
@@ -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});
|
||||
};
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user