Record original-alignment implementation and traceability checkpoint
Capture current source, content data, tests, asset licenses, and original-specification traceability. Original implementation remains incomplete. The accepted matching UI generation passed 154 suites and 12,253 checks, with eight rendered staff-contract screens reviewed. Latest native Windows and full-original acceptance remain outstanding.
This commit is contained in:
@@ -107,6 +107,9 @@ var _processed_requests: Dictionary = {}
|
||||
var _quarantined := false
|
||||
var _quarantine_reason: StringName = &""
|
||||
var _transaction_active := false
|
||||
# Private serialized copy: equality is checked against a fresh snapshot on every
|
||||
# validation. Live dependency checks remain unconditional, even on a cache hit.
|
||||
var _validated_owned_snapshot: Dictionary = {}
|
||||
|
||||
|
||||
## The explicit three-way binding is intentional: exact rollback must restore
|
||||
@@ -503,14 +506,24 @@ func restore_snapshot(snapshot: Dictionary) -> bool:
|
||||
return true
|
||||
|
||||
|
||||
func is_bound_to(adapter: RouteSubslotPathAdapter, source: SpatialSubslotService, path: PathService) -> bool:
|
||||
return _configured and _adapter == adapter and _source == source and _path == path
|
||||
|
||||
|
||||
func validate_invariants() -> Dictionary:
|
||||
var errors: Array[String] = []
|
||||
if not _configured or _adapter == null or _source == null or _path == null:
|
||||
errors.append("Facility infrastructure projector is not configured.")
|
||||
return {&"ok": false, &"errors": errors}
|
||||
var parsed := _parse_snapshot(create_snapshot())
|
||||
if not bool(parsed[&"ok"]):
|
||||
errors.append(String(parsed[&"message"]))
|
||||
var owned_snapshot := create_snapshot()
|
||||
if owned_snapshot != _validated_owned_snapshot:
|
||||
var parsed := _parse_snapshot(owned_snapshot)
|
||||
if not bool(parsed[&"ok"]):
|
||||
errors.append(String(parsed[&"message"]))
|
||||
else:
|
||||
# create_snapshot allocates every container; no caller or live state
|
||||
# retains a mutable reference to this successful validation input.
|
||||
_validated_owned_snapshot = owned_snapshot
|
||||
if not _quarantined and not _dependencies_match_current_state():
|
||||
errors.append("Facility infrastructure live crosslinks are stale.")
|
||||
return {&"ok": errors.is_empty(), &"errors": errors}
|
||||
@@ -991,9 +1004,11 @@ func _dependencies_match_projection_map(projections: Dictionary) -> bool:
|
||||
if _adapter == null or _source == null or _path == null:
|
||||
return false
|
||||
if not _adapter.is_bound_to(_source, _path) \
|
||||
or _adapter.is_quarantined() \
|
||||
or _adapter.is_projection_stale():
|
||||
or _adapter.is_quarantined():
|
||||
return false
|
||||
# For this exact, non-quarantined binding, adapter validation also checks
|
||||
# projection staleness. Keep the independent source invariant audit, but
|
||||
# avoid repeating the same live projection scan through is_projection_stale().
|
||||
if not bool(_source.validate_invariants().get(&"ok", false)) \
|
||||
or not bool(_adapter.validate_invariants().get(&"ok", false)):
|
||||
return false
|
||||
|
||||
+126
-33
@@ -14,7 +14,7 @@ const ORTHOGONAL_MOVE_COST := 100
|
||||
const DEFAULT_CONNECTOR_COST := 150
|
||||
const DEFAULT_CELL_CAPACITY := 4
|
||||
const CONGESTION_COST_PER_EXCESS := 75
|
||||
const MINIMUM_SPEED_MULTIPLIER := 0.25
|
||||
const MINIMUM_SPEED_MULTIPLIER := 0.5
|
||||
const STUCK_THRESHOLD_MINUTES := 30
|
||||
const ELEVATOR_STARVATION_MINUTES := 60
|
||||
const SNAPSHOT_VERSION := 5
|
||||
@@ -569,13 +569,10 @@ func get_speed_multiplier(cell: Vector3i) -> float:
|
||||
var traffic: Dictionary = _cell_traffic.get(cell, {})
|
||||
if traffic.is_empty():
|
||||
return 1.0
|
||||
var capacity := int(traffic[&"base_capacity"])
|
||||
var density := int(traffic[&"current_density"])
|
||||
return clampf(
|
||||
float(capacity) / float(maxi(capacity, density)),
|
||||
MINIMUM_SPEED_MULTIPLIER,
|
||||
1.0
|
||||
)
|
||||
# Original 4.3: overlapping units move at half speed. A wide corridor's
|
||||
# pathfinding capacity must not silently redefine this movement debuff.
|
||||
return MINIMUM_SPEED_MULTIPLIER if int(traffic[&"current_density"]) > 1 else 1.0
|
||||
|
||||
|
||||
|
||||
func project_actor_position(
|
||||
@@ -839,7 +836,8 @@ func dequeue_elevator_boarding(
|
||||
connector_id: StringName,
|
||||
current_floor: int,
|
||||
absolute_minute: int,
|
||||
available_capacity: int = -1
|
||||
available_capacity: int = -1,
|
||||
companions: Dictionary = {}
|
||||
) -> Array[Dictionary]:
|
||||
var boarded: Array[Dictionary] = []
|
||||
if not _connectors.has(connector_id):
|
||||
@@ -860,12 +858,27 @@ func dequeue_elevator_boarding(
|
||||
return boarded
|
||||
|
||||
var queue := get_elevator_queue(connector_id, absolute_minute)
|
||||
var selected: Dictionary = {}
|
||||
var by_actor: Dictionary = {}
|
||||
for request: Dictionary in queue: by_actor[request[&"unit_id"]] = request
|
||||
for request: Dictionary in queue:
|
||||
var actor: StringName = request[&"unit_id"]
|
||||
if selected.has(actor) or int(request[&"floor_from"]) != current_floor: continue
|
||||
var partner: StringName = companions.get(actor, &"")
|
||||
var group: Array[Dictionary] = [request]
|
||||
if not partner.is_empty():
|
||||
if companions.get(partner, &"") != actor or not by_actor.has(partner): continue
|
||||
var other: Dictionary = by_actor[partner]
|
||||
if other[&"floor_from"] != current_floor or other[&"floor_to"] != request[&"floor_to"]: continue
|
||||
group.append(other)
|
||||
if boarded.size() + group.size() > boarding_capacity:
|
||||
break # Keep the oldest pair together and ahead of later requests.
|
||||
for member: Dictionary in group:
|
||||
selected[member[&"unit_id"]] = true
|
||||
boarded.append(member.duplicate(true))
|
||||
var remaining: Array = []
|
||||
for request: Dictionary in queue:
|
||||
if boarded.size() < boarding_capacity and int(request[&"floor_from"]) == current_floor:
|
||||
boarded.append(request.duplicate(true))
|
||||
else:
|
||||
remaining.append(request.duplicate(true))
|
||||
if not selected.has(request[&"unit_id"]): remaining.append(request.duplicate(true))
|
||||
connector[&"request_queue"] = remaining
|
||||
connector[&"current_floor"] = current_floor
|
||||
connector[&"cabin_state"] = CABIN_DOOR_OPEN if not boarded.is_empty() else CABIN_IDLE
|
||||
@@ -1100,6 +1113,19 @@ func cached_path_count() -> int:
|
||||
return _path_cache.size()
|
||||
|
||||
|
||||
## Compare graph membership without serializing traffic, actors and connectors.
|
||||
## Duplicate expected cells are invalid, just as in snapshot crosslink validation.
|
||||
func matches_passable_cells(expected_cells: Array[Vector3i]) -> bool:
|
||||
if expected_cells.size() != _passable_cells.size():
|
||||
return false
|
||||
var seen: Dictionary = {}
|
||||
for cell: Vector3i in expected_cells:
|
||||
if seen.has(cell) or not _passable_cells.has(cell):
|
||||
return false
|
||||
seen[cell] = true
|
||||
return true
|
||||
|
||||
|
||||
func has_cell(cell: Vector3i) -> bool:
|
||||
return _passable_cells.has(cell)
|
||||
|
||||
@@ -1295,7 +1321,7 @@ func create_snapshot() -> Dictionary:
|
||||
var saved_cell_traffic: Array = []
|
||||
for cell_value: Variant in cells:
|
||||
var cell: Vector3i = cell_value
|
||||
var traffic: Dictionary = _cell_traffic.get(cell, _default_cell_traffic())
|
||||
var traffic: Dictionary = _cell_traffic[cell] if _cell_traffic.has(cell) else _default_cell_traffic()
|
||||
saved_cell_traffic.append({
|
||||
&"cell": cell,
|
||||
&"base_capacity": int(traffic[&"base_capacity"]),
|
||||
@@ -1579,17 +1605,20 @@ func _run_a_star(
|
||||
if start == goal:
|
||||
return [start]
|
||||
|
||||
var open_set: Dictionary = {start: true}
|
||||
var frontier: Array[Array] = []
|
||||
_heap_push(frontier, [start, 0, _heuristic(start, goal)])
|
||||
var closed_set: Dictionary = {}
|
||||
var came_from: Dictionary = {}
|
||||
var g_score: Dictionary = {start: 0}
|
||||
|
||||
while not open_set.is_empty():
|
||||
var current := _select_best_open_node(open_set, g_score, goal)
|
||||
while not frontier.is_empty():
|
||||
var entry := _heap_pop(frontier)
|
||||
var current: Vector3i = entry[0]
|
||||
if closed_set.has(current) or int(entry[1]) != int(g_score[current]):
|
||||
continue
|
||||
if current == goal:
|
||||
return _reconstruct_path(came_from, current)
|
||||
|
||||
open_set.erase(current)
|
||||
closed_set[current] = true
|
||||
var edges: Array = _adjacency.get(current, [])
|
||||
for edge_value: Variant in edges:
|
||||
@@ -1612,25 +1641,45 @@ func _run_a_star(
|
||||
g_score[neighbor] = tentative_cost
|
||||
if closed_set.has(neighbor):
|
||||
closed_set.erase(neighbor)
|
||||
open_set[neighbor] = true
|
||||
_heap_push(frontier, [neighbor, tentative_cost, tentative_cost + _heuristic(neighbor, goal)])
|
||||
|
||||
return []
|
||||
|
||||
|
||||
func _select_best_open_node(open_set: Dictionary, g_score: Dictionary, goal: Vector3i) -> Vector3i:
|
||||
var best := Vector3i.ZERO
|
||||
var has_best := false
|
||||
var best_score := _INFINITE_COST
|
||||
for candidate_value: Variant in open_set:
|
||||
var candidate: Vector3i = candidate_value
|
||||
var score: int = int(g_score[candidate]) + _heuristic(candidate, goal)
|
||||
if not has_best or score < best_score:
|
||||
best = candidate
|
||||
best_score = score
|
||||
has_best = true
|
||||
elif score == best_score and _coordinate_less(candidate, best):
|
||||
best = candidate
|
||||
return best
|
||||
# Query-local heap. Stale improved-cost entries are skipped on removal.
|
||||
# Keep the original f-score / x / y / layer order, including reopened nodes.
|
||||
func _heap_less(left: Array, right: Array) -> bool:
|
||||
return int(left[2]) < int(right[2]) or (int(left[2]) == int(right[2]) and _coordinate_less(left[0], right[0]))
|
||||
|
||||
|
||||
func _heap_push(heap: Array[Array], entry: Array) -> void:
|
||||
heap.append(entry)
|
||||
var index := heap.size() - 1
|
||||
while index > 0:
|
||||
var parent := (index - 1) >> 1
|
||||
if not _heap_less(entry, heap[parent]):
|
||||
break
|
||||
heap[index] = heap[parent]
|
||||
index = parent
|
||||
heap[index] = entry
|
||||
|
||||
|
||||
func _heap_pop(heap: Array[Array]) -> Array:
|
||||
var first := heap[0]
|
||||
var last: Array = heap.pop_back()
|
||||
if heap.is_empty():
|
||||
return first
|
||||
var index := 0
|
||||
while index * 2 + 1 < heap.size():
|
||||
var child := index * 2 + 1
|
||||
if child + 1 < heap.size() and _heap_less(heap[child + 1], heap[child]):
|
||||
child += 1
|
||||
if not _heap_less(heap[child], last):
|
||||
break
|
||||
heap[index] = heap[child]
|
||||
index = child
|
||||
heap[index] = last
|
||||
return first
|
||||
|
||||
|
||||
func _heuristic(from_cell: Vector3i, to_cell: Vector3i) -> int:
|
||||
@@ -2607,3 +2656,47 @@ func _dictionary_value(source: Dictionary, key: StringName, default_value: Varia
|
||||
return source[key]
|
||||
var string_key := str(key)
|
||||
return source.get(string_key, default_value)
|
||||
|
||||
|
||||
## Rescue uses BACK circulation, with FRONT access legs at either endpoint.
|
||||
## Optional managed elevators must have room for both patient and carrier.
|
||||
func find_backyard_path(start: Vector3i, goal: Vector3i, allow_elevators := false) -> Array[Vector3i]:
|
||||
if not has_cell(start) or not has_cell(goal) or _cell_is_temporarily_blocked(start) or _cell_is_temporarily_blocked(goal):
|
||||
return []
|
||||
if start == goal:
|
||||
return [start]
|
||||
var first := Vector4i(start.x, start.y, start.z, 2 if start.z == 1 else 0)
|
||||
var frontier: Array[Vector4i] = [first]
|
||||
var visited := {first: true}
|
||||
var parents: Dictionary = {}
|
||||
var cursor := 0
|
||||
while cursor < frontier.size():
|
||||
var state := frontier[cursor]
|
||||
cursor += 1
|
||||
var cell := Vector3i(state.x,state.y,state.z)
|
||||
for edge: Dictionary in _adjacency.get(cell, []):
|
||||
var next: Vector3i = edge[&"to"]
|
||||
if _cell_is_temporarily_blocked(next) or not _edge_meets_vertical_policy(cell, edge) or not _edge_is_accessible(edge, [&"staff"]):
|
||||
continue
|
||||
var connector: Dictionary = _connectors.get(edge[&"connector_id"], {})
|
||||
if connector.get(&"movement_type", &"") == MOVEMENT_ELEVATOR:
|
||||
if not allow_elevators or cell.z != 1 or next.z != 1 or not String(edge[&"connector_id"]).begins_with("transport.") or int(connector.get(&"cabin_capacity", 0)) < 2:
|
||||
continue
|
||||
if state.w == 3 and next.z == 1:
|
||||
continue
|
||||
var phase := state.w
|
||||
if next.z == 1: phase = 1 if state.w == 0 else 2
|
||||
elif state.w == 1: continue
|
||||
elif state.w == 2: phase = 3
|
||||
var key := Vector4i(next.x,next.y,next.z,phase)
|
||||
if visited.has(key): continue
|
||||
visited[key] = true
|
||||
parents[key] = state
|
||||
if next == goal and phase > 0:
|
||||
var result: Array[Vector3i] = [next]
|
||||
while parents.has(key):
|
||||
key = parents[key]
|
||||
result.push_front(Vector3i(key.x,key.y,key.z))
|
||||
return result
|
||||
frontier.append(key)
|
||||
return []
|
||||
|
||||
@@ -53,6 +53,8 @@ var _processed_requests: Dictionary = {}
|
||||
var _quarantined := false
|
||||
var _quarantine_reason: StringName = &""
|
||||
var _transaction_active := false
|
||||
# One private successful parse input; live graph/source checks still run each time.
|
||||
var _validated_owned_snapshot: Dictionary = {}
|
||||
|
||||
|
||||
## Binds the two authoritative services once and establishes projection 1.
|
||||
@@ -283,9 +285,13 @@ func validate_invariants() -> Dictionary:
|
||||
if not _configured or _source == null or _path == null:
|
||||
errors.append("Route projection adapter is not configured.")
|
||||
return {&"ok": false, &"errors": errors}
|
||||
var parsed := _parse_snapshot(create_snapshot())
|
||||
if not bool(parsed[&"ok"]):
|
||||
errors.append(String(parsed[&"message"]))
|
||||
var owned_snapshot := create_snapshot()
|
||||
if owned_snapshot != _validated_owned_snapshot:
|
||||
var parsed := _parse_snapshot(owned_snapshot)
|
||||
if not bool(parsed[&"ok"]):
|
||||
errors.append(String(parsed[&"message"]))
|
||||
else:
|
||||
_validated_owned_snapshot = owned_snapshot
|
||||
if not _quarantine_state_is_valid(_quarantined, _quarantine_reason):
|
||||
errors.append("Route projection quarantine state is inconsistent.")
|
||||
if not _quarantined:
|
||||
|
||||
@@ -51,12 +51,16 @@ var _excavated: Dictionary = {}
|
||||
var _support_capacity: Dictionary = {}
|
||||
var _support_anchors: Dictionary = {}
|
||||
var _dirty_cells: Dictionary = {}
|
||||
var _snapshot_geometry: Dictionary = {}
|
||||
var _snapshot_geometry_revision := -1
|
||||
|
||||
|
||||
func reset(bounds: Variant) -> bool:
|
||||
var normalized := _normalize_bounds(bounds)
|
||||
if normalized.is_empty():
|
||||
return false
|
||||
_snapshot_geometry.clear()
|
||||
_snapshot_geometry_revision = -1
|
||||
_bounds = normalized
|
||||
_occupants.clear()
|
||||
_entity_cells.clear()
|
||||
@@ -298,11 +302,15 @@ func is_support_anchor(cell: Vector3i) -> bool:
|
||||
|
||||
## Validates connected structural components touched by the proposed cells.
|
||||
## Existing structural occupant kinds contribute their configured capacity/load.
|
||||
func validate_support(cells: Array, weight_per_cell := 1) -> Dictionary:
|
||||
func validate_support(cells: Array, weight_per_cell := 1, entity_weights: Dictionary = {}) -> Dictionary:
|
||||
var base_report := _validate_cells(cells)
|
||||
var errors: Array[StringName] = base_report[&"errors"].duplicate()
|
||||
if weight_per_cell <= 0:
|
||||
_add_error(errors, ERROR_INVALID_WEIGHT)
|
||||
# Optional definition weights are read-only and apply to existing occupants.
|
||||
for id: Variant in entity_weights:
|
||||
if typeof(id) not in [TYPE_STRING, TYPE_STRING_NAME] or not _entity_cells.has(id) or typeof(entity_weights[id]) != TYPE_INT or int(entity_weights[id]) <= 0:
|
||||
_add_error(errors, ERROR_INVALID_WEIGHT)
|
||||
var proposed: Array[Vector3i] = base_report[&"valid_cells"].duplicate()
|
||||
proposed.sort_custom(_cell_less)
|
||||
var result := {
|
||||
@@ -325,7 +333,7 @@ func validate_support(cells: Array, weight_per_cell := 1) -> Dictionary:
|
||||
structural_set[cell] = true
|
||||
for entity_id: StringName in _sorted_entity_ids():
|
||||
var kind: StringName = _entity_kinds[entity_id]
|
||||
if _kind_support_capacity(kind) <= 0 and _kind_weight(kind) <= 0 and not _kind_is_anchor(kind):
|
||||
if _kind_support_capacity(kind) <= 0 and int(entity_weights.get(entity_id, _kind_weight(kind))) <= 0 and not _kind_is_anchor(kind):
|
||||
continue
|
||||
for occupied_cell: Vector3i in _entity_cells[entity_id]:
|
||||
structural_set[occupied_cell] = true
|
||||
@@ -351,7 +359,7 @@ func validate_support(cells: Array, weight_per_cell := 1) -> Dictionary:
|
||||
component_proposed.append(component_cell)
|
||||
required += weight_per_cell
|
||||
if _occupants.has(component_cell) and not proposed_set.has(component_cell):
|
||||
required += _kind_weight(get_occupant_kind(component_cell))
|
||||
required += int(entity_weights.get(get_occupant(component_cell), _kind_weight(get_occupant_kind(component_cell))))
|
||||
capacity += get_support_capacity(component_cell)
|
||||
anchored = anchored or is_support_anchor(component_cell)
|
||||
component_proposed.sort_custom(_cell_less)
|
||||
@@ -393,6 +401,22 @@ func consume_dirty_cells() -> Array[Vector3i]:
|
||||
|
||||
|
||||
func create_snapshot() -> Dictionary:
|
||||
# Geometry only changes through world mutations. Dirty-cell consumption and
|
||||
# public revision counters are sampled separately on every read.
|
||||
if _snapshot_geometry_revision != revision or _snapshot_geometry.is_empty():
|
||||
_snapshot_geometry = _create_geometry_snapshot()
|
||||
_snapshot_geometry_revision = revision
|
||||
var snapshot := _snapshot_geometry.duplicate(true)
|
||||
snapshot[&"dirty_cells"] = get_dirty_cells()
|
||||
snapshot[&"revisions"] = {
|
||||
&"world": revision, &"occupancy": occupancy_revision,
|
||||
&"walkability": walkability_revision, &"excavation": excavation_revision,
|
||||
&"support": support_revision,
|
||||
}
|
||||
return snapshot
|
||||
|
||||
|
||||
func _create_geometry_snapshot() -> Dictionary:
|
||||
var occupancies: Array[Dictionary] = []
|
||||
for entity_id: StringName in _sorted_entity_ids():
|
||||
occupancies.append({
|
||||
@@ -426,14 +450,6 @@ func create_snapshot() -> Dictionary:
|
||||
&"walkable_cells": _sorted_dictionary_cells(_walkable),
|
||||
&"excavation_overrides": excavation_overrides,
|
||||
&"support": support_entries,
|
||||
&"dirty_cells": get_dirty_cells(),
|
||||
&"revisions": {
|
||||
&"world": revision,
|
||||
&"occupancy": occupancy_revision,
|
||||
&"walkability": walkability_revision,
|
||||
&"excavation": excavation_revision,
|
||||
&"support": support_revision,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -548,6 +564,8 @@ func restore_snapshot(snapshot: Dictionary) -> bool:
|
||||
):
|
||||
return false
|
||||
|
||||
_snapshot_geometry.clear()
|
||||
_snapshot_geometry_revision = -1
|
||||
_bounds = new_bounds
|
||||
_occupants = new_occupants
|
||||
_entity_cells = new_entity_cells
|
||||
|
||||
Reference in New Issue
Block a user