Using implicit pointer derefs + fixing crashes on clearing entities
This commit is contained in:
@@ -33,8 +33,8 @@ pub const Road = struct {
|
||||
const start = self.nodes[0];
|
||||
const end = self.nodes[1];
|
||||
|
||||
const x_diff = end.*.pos.x - start.*.pos.x;
|
||||
const y_diff = end.*.pos.y - start.*.pos.y;
|
||||
const x_diff = end.pos.x - start.pos.x;
|
||||
const y_diff = end.pos.y - start.pos.y;
|
||||
const square_diff = x_diff * x_diff + y_diff * y_diff;
|
||||
|
||||
return @sqrt(square_diff);
|
||||
@@ -46,7 +46,7 @@ pub const Road = struct {
|
||||
/// it will gradually become more complex
|
||||
pub fn draw(self: *const Road, highlighted: bool) void {
|
||||
const colour = if (highlighted) c.ROAD_HIGHLIGHTED_COLOUR else c.ROAD_COLOUR;
|
||||
rl.drawLineEx(self.nodes[0].*.pos, self.nodes[1].*.pos, c.ROAD_SIZE, colour);
|
||||
rl.drawLineEx(self.nodes[0].pos, self.nodes[1].pos, c.ROAD_SIZE, colour);
|
||||
}
|
||||
|
||||
/// Important: after this function executes, this road is no longer reachable from its bounding nodes
|
||||
@@ -59,7 +59,7 @@ pub const Road = struct {
|
||||
|
||||
/// Checks whether pos coordinate is on the referenced road
|
||||
pub fn isHighlighted(self: *const Road, pos: rl.Vector2) bool {
|
||||
return rl.checkCollisionPointLine(pos, self.nodes[0].*.pos, self.nodes[1].*.pos, c.ROAD_SIZE);
|
||||
return rl.checkCollisionPointLine(pos, self.nodes[0].pos, self.nodes[1].pos, c.ROAD_SIZE);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -74,7 +74,7 @@ test "valid road nodes" {
|
||||
const start: Node = .init(34, .{.x = 500, .y = 500});
|
||||
const start_ptr = try allocator.create(Node);
|
||||
defer {
|
||||
start_ptr.*.deinit(allocator);
|
||||
start_ptr.deinit(allocator);
|
||||
allocator.destroy(start_ptr);
|
||||
}
|
||||
start_ptr.* = start;
|
||||
@@ -82,7 +82,7 @@ test "valid road nodes" {
|
||||
const end: Node = .init(227, .{.x = 600, .y = 500});
|
||||
const end_ptr = try allocator.create(Node);
|
||||
defer {
|
||||
end_ptr.*.deinit(allocator);
|
||||
end_ptr.deinit(allocator);
|
||||
allocator.destroy(end_ptr);
|
||||
}
|
||||
end_ptr.* = end;
|
||||
|
||||
Reference in New Issue
Block a user