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