Comments to describe each functionality in-depth
This commit is contained in:
@@ -17,6 +17,7 @@ pub const RoadManager = struct {
|
||||
};
|
||||
}
|
||||
|
||||
/// Deinitialises every road (pointer) and then the list itself
|
||||
pub fn deinit(self: *RoadManager, allocator: std.mem.Allocator) void {
|
||||
for (self.roads.items) |road| {
|
||||
road.deinit(allocator);
|
||||
@@ -24,6 +25,7 @@ pub const RoadManager = struct {
|
||||
self.roads.deinit(allocator);
|
||||
}
|
||||
|
||||
/// Draws all the roads in the list, sends the information ahead whether the road drawn should be highlighted
|
||||
pub fn draw(self: *const RoadManager, delete_mode: bool) void {
|
||||
for (self.roads.items) |road| {
|
||||
const is_highlighted = delete_mode and self.highlighted_road != null and self.highlighted_road.? == road;
|
||||
@@ -31,6 +33,8 @@ pub const RoadManager = struct {
|
||||
}
|
||||
}
|
||||
|
||||
/// Function which creates the road object, its pointer, adds it to the list
|
||||
/// and then also references that same road to the bounding nodes
|
||||
pub fn addRoad(self: *RoadManager, allocator: std.mem.Allocator, start: *Node, end: *Node) !void {
|
||||
const road: Road = .init(self.getNextID(), start, end);
|
||||
const road_ptr = try allocator.create(Road);
|
||||
@@ -42,6 +46,7 @@ pub const RoadManager = struct {
|
||||
try end.referenceRoad(allocator, ref);
|
||||
}
|
||||
|
||||
/// Returns the id, and increases it by one; used for generating ID's for new entities
|
||||
fn getNextID(self: *RoadManager) usize {
|
||||
const id = self.next_id;
|
||||
self.next_id += 1;
|
||||
@@ -49,6 +54,7 @@ pub const RoadManager = struct {
|
||||
return id;
|
||||
}
|
||||
|
||||
/// Deinits all the roads, clears them but not deiniting the list itself; also resets the next ID var
|
||||
pub fn clear(self: *RoadManager, allocator: std.mem.Allocator) void {
|
||||
for (self.roads.items) |road| {
|
||||
road.deinit(allocator);
|
||||
@@ -57,6 +63,11 @@ pub const RoadManager = struct {
|
||||
self.next_id = 0;
|
||||
}
|
||||
|
||||
/// Removes the references of the road, from the nodes that bound that road
|
||||
///
|
||||
/// Then it deinitialises the road and removes it from the list
|
||||
///
|
||||
/// Will return an error if the road itself is not present in the list
|
||||
pub fn deleteRoad(self: *RoadManager, allocator: std.mem.Allocator, road_to_delete: *Road) !void {
|
||||
// unreference the road from its bounding functions
|
||||
road_to_delete.unreferenceNodes() catch |err| {
|
||||
|
||||
Reference in New Issue
Block a user