perf: harden runtime for weaker hardware

This commit is contained in:
Rijad Zuzo
2026-08-12 10:02:45 +02:00
parent cd29da95e0
commit 34428d836a
47 changed files with 2164 additions and 243 deletions
+43 -5
View File
@@ -6,6 +6,8 @@ signal arrived_at_sim_position(creature_id: StringName)
const ARRIVAL_DISTANCE := 0.5
const PATH_RETARGET_DISTANCE := 0.8
const PATH_RETRY_BASE_SECONDS := 0.5
const PATH_RETRY_MAX_SECONDS := 4.0
@export_range(0.5, 12.0, 0.1) var move_speed := 3.5
@export_range(0.05, 1.0, 0.05) var waypoint_reached_distance := 0.3
@@ -20,6 +22,9 @@ var path_index := 0
var path_target := Vector3.INF
var path_request_id := 0
var path_pending := false
var path_query_count := 0
var path_retry_remaining := 0.0
var path_retry_delay := PATH_RETRY_BASE_SECONDS
func _physics_process(delta: float) -> void:
@@ -30,6 +35,10 @@ func _physics_process(delta: float) -> void:
if _horizontal_distance_to(sim_position) <= ARRIVAL_DISTANCE:
_stop_moving()
return
if path_retry_remaining > 0.0:
path_retry_remaining = maxf(path_retry_remaining - delta, 0.0)
if path_retry_remaining > 0.0:
return
_ensure_path()
if path_pending:
return
@@ -51,12 +60,17 @@ func _physics_process(delta: float) -> void:
func set_sim_position(position: Vector3) -> void:
if not position.is_finite():
return
var moved := (
not path_target.is_finite()
var target_changed := (
not sim_position.is_finite()
or _horizontal_distance_to_position(sim_position, position) > PATH_RETARGET_DISTANCE
)
sim_position = position
if moved and not is_dead_visual:
if target_changed and not is_dead_visual:
path_retry_remaining = 0.0
path_retry_delay = PATH_RETRY_BASE_SECONDS
if _horizontal_distance_to(sim_position) <= ARRIVAL_DISTANCE:
_stop_moving()
return
_request_path()
@@ -104,17 +118,41 @@ func _request_path() -> void:
current_path = NavigationServer3D.map_get_path(
get_world_3d().navigation_map, global_position, sim_position, true
)
path_query_count += 1
path_pending = false
if current_path.is_empty():
_stop_moving()
_schedule_path_retry()
return
path_retry_remaining = 0.0
path_retry_delay = PATH_RETRY_BASE_SECONDS
func _schedule_path_retry() -> void:
current_path = PackedVector3Array()
path_index = 0
path_pending = false
path_target = sim_position
path_retry_remaining = path_retry_delay
path_retry_delay = minf(path_retry_delay * 2.0, PATH_RETRY_MAX_SECONDS)
func _stop_moving() -> void:
if (
current_path.is_empty()
and not path_pending
and path_retry_remaining <= 0.0
and path_target.is_finite()
and sim_position.is_finite()
and _horizontal_distance_to_position(path_target, sim_position) <= PATH_RETARGET_DISTANCE
):
return
path_request_id += 1
current_path = PackedVector3Array()
path_index = 0
path_pending = false
path_target = Vector3.INF
path_target = sim_position
path_retry_remaining = 0.0
path_retry_delay = PATH_RETRY_BASE_SECONDS
func _horizontal_distance_to(target_position: Vector3) -> float: