Fully implemented road splitting

This commit is contained in:
2026-04-24 23:43:02 +02:00
parent b9b7f610ac
commit efa14bea7d
2 changed files with 85 additions and 15 deletions

View File

@@ -4,11 +4,16 @@ import "../common"
import rl "vendor:raylib"
Node :: struct {
// Whether the node is reachable
enabled: bool,
// This node's position
pos: rl.Vector2,
// All of the roads that are connected to the node itself;
// Stores the index of the Road object that is stored within Simulator struct in roads dynamic array
roads: [dynamic]u32,
}
// Node Initialisation
node_init :: proc(new_pos: rl.Vector2) -> Node {
return {
enabled = true,
@@ -17,10 +22,24 @@ node_init :: proc(new_pos: rl.Vector2) -> Node {
}
}
// Returns whether passed pos(ition) is within this node's snapping radius
node_within_snapping_radius :: proc(self: ^Node, pos: rl.Vector2) -> bool {
return rl.CheckCollisionPointCircle(
pos,
self.pos,
common.NODE_SNAP_RADIUS * common.NODE_RADIUS,
)
}
// Tries to remove the road reference from the node;
// Returns false if failed
node_unreference_road :: proc(self: ^Node, road_to_unref: u32) -> bool {
for i in 0..<len(self.roads) {
if self.roads[i] != road_to_unref do continue
unordered_remove(&self.roads, i)
return true
}
return false
}