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, } // Constructor node_init :: proc(new_pos: rl.Vector2) -> Node { return { enabled = true, pos = new_pos, roads = nil, } } // Destructor node_deinit :: proc(self: ^Node) { delete(self.roads) } // 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..