45 lines
1.0 KiB
Odin
45 lines
1.0 KiB
Odin
package infrastructure
|
|
|
|
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,
|
|
pos = new_pos,
|
|
roads = nil,
|
|
}
|
|
}
|
|
|
|
// 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
|
|
} |