Implemented a few debugging/inspecting tools
This commit is contained in:
@@ -66,6 +66,7 @@ pub const Simulator = struct {
|
||||
.b => .BUILD,
|
||||
else => self.mode,
|
||||
};
|
||||
if (self.mode != .BUILD) self.cancelBuildingRoad();
|
||||
}
|
||||
|
||||
/// every mouse event is checked here
|
||||
@@ -76,10 +77,7 @@ pub const Simulator = struct {
|
||||
self.leftClickEvent(pos);
|
||||
}
|
||||
else if (self.mode == .BUILD and rl.isMouseButtonReleased(.right)) {
|
||||
if (self.node_man.temp_node) |node| {
|
||||
// todo proper error handling
|
||||
self.node_man.removeNode(node) catch {};
|
||||
}
|
||||
self.cancelBuildingRoad();
|
||||
}
|
||||
else if (self.mode == .DELETE and rl.isMouseButtonReleased(.left) and self.road_man.highlighted_road != null) {
|
||||
const nodes = self.road_man.highlighted_road.?.nodes;
|
||||
@@ -87,9 +85,12 @@ pub const Simulator = struct {
|
||||
std.debug.panic("Failed to remove the road: {}\n", .{err});
|
||||
};
|
||||
|
||||
// todo proper error handling
|
||||
self.node_man.removeNode(nodes[0]) catch {};
|
||||
self.node_man.removeNode(nodes[1]) catch {};
|
||||
self.node_man.remove(nodes[0]) catch |err| {
|
||||
std.debug.panic("Failed to remove the first node of the road to be deleted: {}\n", .{err});
|
||||
};
|
||||
self.node_man.remove(nodes[1]) catch |err| {
|
||||
std.debug.panic("Failed to remove the second node of the road to be deleted: {}\n", .{err});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,8 +112,17 @@ pub const Simulator = struct {
|
||||
}
|
||||
}
|
||||
|
||||
fn cancelBuildingRoad(self: *Simulator) void {
|
||||
if (self.node_man.temp_node == null) return;
|
||||
|
||||
self.node_man.remove(self.node_man.temp_node.?) catch |err| {
|
||||
std.debug.panic("Node doesn't exist: {}\n", .{err});
|
||||
};
|
||||
self.node_man.temp_node = null;
|
||||
}
|
||||
|
||||
/// The main drawing function that is exposed upwards
|
||||
pub fn draw(self: *Simulator) void {
|
||||
pub fn draw(self: *const Simulator) void {
|
||||
self.road_man.draw(self.mode == .DELETE);
|
||||
self.node_man.draw(self.display_details);
|
||||
self.drawUI();
|
||||
@@ -147,6 +157,13 @@ pub const Simulator = struct {
|
||||
|
||||
// Displays the mode the simulation is currently in
|
||||
rl.drawText(@tagName(self.mode), 10, c.HEIGHT - c.TEXT_SIZE, c.TEXT_SIZE, .black);
|
||||
|
||||
// displays id of the element we hover over over
|
||||
const entityInfo = self.getHighlightedEntityInfo() catch |err| {
|
||||
std.debug.panic("Failed to capture highlighted entity info: {}\n", .{err});
|
||||
};
|
||||
|
||||
rl.drawText(entityInfo, c.WIDTH - (c.TEXT_SIZE / 2) * @as(i32, @intCast(entityInfo.len)), c.TEXT_SIZE, c.TEXT_SIZE, .black);
|
||||
}
|
||||
|
||||
/// Gets list of pointers of all roads that 'collide' with the road bounded by the nodes we pass into it
|
||||
@@ -170,4 +187,31 @@ pub const Simulator = struct {
|
||||
if (self.node_man.getNodeWithinRadius(intersection.point) == null) try self.debug_intersection_data.append(self.allocator, intersection);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO verify pointers
|
||||
// TODO display road/node id
|
||||
|
||||
fn verifyPointerIntegrity() void {
|
||||
|
||||
}
|
||||
|
||||
pub fn update(self: *Simulator) void {
|
||||
const pos = rl.getMousePosition();
|
||||
|
||||
self.road_man.highlighted_road = self.road_man.getSelectedRoad(pos);
|
||||
self.node_man.highlighted_node = self.node_man.getNodeWithinRadius(pos);
|
||||
}
|
||||
|
||||
/// Get ID info of the highlighted info and returns it
|
||||
fn getHighlightedEntityInfo(self: *const Simulator) ![:0]u8 {
|
||||
var buf: [10 * 1024]u8 = undefined;
|
||||
|
||||
if (self.node_man.highlighted_node) |node|
|
||||
return std.fmt.bufPrintZ(&buf, "Node ID: {d}\nRoad refs: {d}", .{node.id, node.roads.items.len});
|
||||
|
||||
if (self.road_man.highlighted_road) |road|
|
||||
return std.fmt.bufPrintZ(&buf, "Road ID: {d}", .{road.id});
|
||||
|
||||
return std.fmt.bufPrintZ(&buf, "", .{});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user