diff --git a/infrastructure/road.odin b/infrastructure/road.odin index 2c24fc3..c0a18b2 100644 --- a/infrastructure/road.odin +++ b/infrastructure/road.odin @@ -1,9 +1,11 @@ package infrastructure Road :: struct { + // Index to nodes that limit the road nodes: [2]u32, } +// Road Initialisation road_init :: proc(start: u32, end: u32) -> Road { return { nodes = {start, end} diff --git a/simulator.odin b/simulator.odin index 7de753d..e6732b9 100644 --- a/simulator.odin +++ b/simulator.odin @@ -6,15 +6,24 @@ import "common" import "core:fmt" import inf "infrastructure" +// PLAN AREA +// TODO implement right click 'cancel building functionali' +// TODO implement deleting of roads + Simulator :: struct { + // Stores all nodes nodes: [dynamic]inf.Node, + // Stores all roads roads: [dynamic]inf.Road, + // Tracks the temporary node location temp_node_index: Maybe(u32), - // tracking variables + // Tracks whether the user wishes to see node's snapping radius show_details: bool, + // Tracks whether after placing a road new one will start being placed auto_continue: bool, } +// Constructor init :: proc() -> Simulator { return { nodes = nil, @@ -25,17 +34,20 @@ init :: proc() -> Simulator { } } +// Destructor deinit :: proc(self: ^Simulator) { self.temp_node_index = nil delete(self.roads) delete(self.nodes) } +// Public input function that gets called in graphics library loop handle_input :: proc(self: ^Simulator, pos: rl.Vector2) { handle_keyboard_input(self) handle_mouse_input(self, pos) } +// General keyboard input event handler @(private="file") handle_keyboard_input :: proc(self: ^Simulator) { self.show_details = rl.IsKeyDown(.LEFT_ALT) @@ -48,11 +60,13 @@ handle_keyboard_input :: proc(self: ^Simulator) { } } +// Generally mouse event handler @(private="file") handle_mouse_input :: proc(self: ^Simulator, pos: rl.Vector2) { if (rl.IsMouseButtonReleased(.LEFT)) do left_click_event(self, pos) } +// Handles left click functionality @(private="file") left_click_event :: proc(self: ^Simulator, pos: rl.Vector2) { cur_node_index := get_node_or_new(self, pos) @@ -68,6 +82,7 @@ left_click_event :: proc(self: ^Simulator, pos: rl.Vector2) { self.temp_node_index = cur_node_index } +// Main drawing function draw :: proc(self: ^Simulator, pos: rl.Vector2) { rl.ClearBackground(common.BACKGROUND_COLOUR) @@ -148,6 +163,8 @@ get_intersecting_roads :: proc(self: ^Simulator, start: u32, end: u32) -> []comm return intersections[:] } +// Given intersection data, the function splits all existing roads and adds new nodes on intersections +@(private="file") split_roads_by_points :: proc(self: ^Simulator, intersections: []common.Intersection_Data, start: u32, end: u32) { if len(intersections) == 0 { road := inf.road_init(start, end)