Error maxxing

This commit is contained in:
2026-04-27 09:52:31 +02:00
parent 620d3b56e0
commit 205c630dbf
4 changed files with 9 additions and 7 deletions

View File

@@ -99,7 +99,7 @@ delete_entity :: proc(self: ^Simulator, entity_index: u32, type: common.Entity)
}
// Returns a random node that has no cars on it
get_free_node :: proc(self: ^Simulator) -> u32 {
get_free_node :: proc(self: ^Simulator) -> Maybe(u32) {
car_occupied_nodes: [dynamic]u32
for car in self.cars {
@@ -110,6 +110,8 @@ get_free_node :: proc(self: ^Simulator) -> u32 {
append(&car_occupied_nodes, node)
}
if len(car_occupied_nodes) == len(self.nodes) do return nil
for {
node := rand.uint32_max(u32(len(self.nodes)))

View File

@@ -27,7 +27,7 @@ handle_keyboard_input :: proc(self: ^Simulator) {
if !rl.IsKeyReleased(.N) || len(self.nodes) == 0 do return
car := v.car_init(u32(len(self.nodes)))
car := v.car_init(get_free_node(self), self.nodes[:])
append(&self.cars, car)
}

View File

@@ -12,7 +12,7 @@ get_path_to_destination :: proc(self: ^Simulator, source: u32, destination: u32)
}
// Returns if path is reachable from node => destination
get_destination_reachable :: proc(self: ^Simulator, node_to_search: u32, destination: u32, nodes_to_ignore: ^[]u32) -> bool {
get_destination_reachable :: proc(self: ^Simulator, node_to_search: u32, destination: u32, nodes_to_ignore: ^[dynamic]u32) -> bool {
if !self.nodes[node_to_search].enabled || common.list_contains(nodes_to_ignore[:], node_to_search) do return false
append(nodes_to_ignore, node_to_search)

View File

@@ -29,13 +29,13 @@ Car :: struct {
}
// Constructor
car_init :: proc(node: u32, nodes: []inf.Node) -> Car {
car_init :: proc(spawn_node: u32, nodes: []inf.Node) -> Car {
return {
fuel_level = common.FUEL_MAX,
max_speed = common.CAR_MAX_SPEED,
origin = node,
node_pos = node,
actual_pos = nodes[node].pos
origin = spawn_node,
node_pos = spawn_node,
actual_pos = nodes[spawn_node].pos
}
}