perf: harden runtime for weaker hardware
This commit is contained in:
@@ -8,7 +8,7 @@ const SLASH_REST_ANGLE := Vector3(-0.35, 0.0, 0.0)
|
||||
@export var combat_presentation: Node
|
||||
@export var sword: Node3D
|
||||
|
||||
@export_range(0.5, 4.0, 0.1) var attack_range := 2.6
|
||||
var attack_range := 2.4
|
||||
@export_range(30.0, 160.0, 5.0) var attack_angle := 90.0
|
||||
@export var dash_speed := 22.0
|
||||
@export var dash_duration := 0.18
|
||||
@@ -16,7 +16,8 @@ const SLASH_REST_ANGLE := Vector3(-0.35, 0.0, 0.0)
|
||||
|
||||
var attack_cooldown_seconds := 0.55
|
||||
var attack_timer := 0.0
|
||||
var dash_timer := 0.0
|
||||
var dash_duration_remaining := 0.0
|
||||
var dash_cooldown_remaining := 0.0
|
||||
var dashing := false
|
||||
var dash_velocity := Vector3.ZERO
|
||||
var _swing_tween: Tween
|
||||
@@ -24,13 +25,13 @@ var _references_resolved := false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if sword == null:
|
||||
return
|
||||
sword.rotation = SLASH_REST_ANGLE
|
||||
process_physics_priority = -1
|
||||
if sword != null:
|
||||
sword.rotation = SLASH_REST_ANGLE
|
||||
var definition := SimulationItems.get_weapon(SimulationIds.ITEM_SWORD)
|
||||
if definition != null:
|
||||
attack_cooldown_seconds = definition.attack_cooldown
|
||||
attack_range = maxf(definition.reach + 0.2, attack_range)
|
||||
attack_range = definition.reach
|
||||
|
||||
|
||||
func _resolve_references() -> void:
|
||||
@@ -46,25 +47,31 @@ func _physics_process(delta: float) -> void:
|
||||
_resolve_references()
|
||||
if simulation_manager != null and simulation_manager.has_method("update_player_combatant"):
|
||||
simulation_manager.update_player_combatant(player.global_position)
|
||||
attack_timer = maxf(attack_timer - delta, 0.0)
|
||||
dash_timer = maxf(dash_timer - delta, 0.0)
|
||||
_advance_timers(delta)
|
||||
if _player_is_downed():
|
||||
attack_timer = 0.0
|
||||
dash_timer = 0.0
|
||||
dash_duration_remaining = 0.0
|
||||
dash_cooldown_remaining = 0.0
|
||||
dashing = false
|
||||
return
|
||||
if dashing:
|
||||
player.velocity = dash_velocity
|
||||
if dash_timer <= 0.0:
|
||||
dashing = false
|
||||
player.move_and_slide()
|
||||
return
|
||||
if Input.is_action_just_pressed("attack") and attack_timer <= 0.0:
|
||||
if Input.is_action_just_pressed("attack"):
|
||||
_perform_attack()
|
||||
if Input.is_action_just_pressed("dash") and dash_timer <= 0.0:
|
||||
if Input.is_action_just_pressed("dash"):
|
||||
_perform_dash()
|
||||
|
||||
|
||||
func _advance_timers(delta: float) -> void:
|
||||
if not is_finite(delta) or delta <= 0.0:
|
||||
return
|
||||
attack_timer = maxf(attack_timer - delta, 0.0)
|
||||
dash_duration_remaining = maxf(dash_duration_remaining - delta, 0.0)
|
||||
dash_cooldown_remaining = maxf(dash_cooldown_remaining - delta, 0.0)
|
||||
if dashing and dash_duration_remaining <= 0.0:
|
||||
dashing = false
|
||||
|
||||
|
||||
func _player_is_downed() -> bool:
|
||||
return (
|
||||
simulation_manager != null
|
||||
@@ -74,6 +81,8 @@ func _player_is_downed() -> bool:
|
||||
|
||||
|
||||
func _perform_attack() -> void:
|
||||
if attack_timer > 0.0 or not _simulation_attack_ready():
|
||||
return
|
||||
attack_timer = attack_cooldown_seconds
|
||||
_play_swing()
|
||||
var facing := -player.global_transform.basis.z
|
||||
@@ -91,7 +100,10 @@ func _perform_attack() -> void:
|
||||
|
||||
|
||||
func _perform_dash() -> void:
|
||||
dash_timer = dash_duration
|
||||
if dash_cooldown_remaining > 0.0 or _player_is_downed():
|
||||
return
|
||||
dash_duration_remaining = dash_duration
|
||||
dash_cooldown_remaining = maxf(dash_cooldown_seconds, dash_duration)
|
||||
dashing = true
|
||||
var facing := -player.global_transform.basis.z
|
||||
facing.y = 0.0
|
||||
@@ -100,6 +112,12 @@ func _perform_dash() -> void:
|
||||
dash_velocity.y = 0.0
|
||||
|
||||
|
||||
func _simulation_attack_ready() -> bool:
|
||||
if simulation_manager == null or not simulation_manager.has_method("player_attack_ready"):
|
||||
return true
|
||||
return simulation_manager.player_attack_ready()
|
||||
|
||||
|
||||
func _play_swing() -> void:
|
||||
if sword == null:
|
||||
return
|
||||
@@ -123,3 +141,11 @@ func is_attacking() -> bool:
|
||||
|
||||
func is_dashing() -> bool:
|
||||
return dashing
|
||||
|
||||
|
||||
func get_dash_velocity() -> Vector3:
|
||||
return dash_velocity if dashing else Vector3.ZERO
|
||||
|
||||
|
||||
func get_dash_cooldown_remaining() -> float:
|
||||
return dash_cooldown_remaining
|
||||
|
||||
+13
-3
@@ -19,6 +19,8 @@ signal interaction_feedback(heading: String, message: String, succeeded: bool)
|
||||
@export var interaction_range := 3.0
|
||||
@export var villager_inspection_range := 3.0
|
||||
|
||||
@onready var combat_controller: Node = get_node_or_null("PlayerCombatController")
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("grass_interactors")
|
||||
@@ -44,9 +46,17 @@ func _physics_process(delta: float) -> void:
|
||||
var direction := (right * input.x + forward * -input.y).normalized()
|
||||
|
||||
var target_velocity := direction * move_speed
|
||||
|
||||
velocity.x = move_toward(velocity.x, target_velocity.x, acceleration * delta)
|
||||
velocity.z = move_toward(velocity.z, target_velocity.z, acceleration * delta)
|
||||
var dash_velocity := Vector3.ZERO
|
||||
if combat_controller != null and combat_controller.has_method("get_dash_velocity"):
|
||||
dash_velocity = combat_controller.get_dash_velocity()
|
||||
if not dash_velocity.is_zero_approx():
|
||||
target_velocity = dash_velocity
|
||||
direction = dash_velocity.normalized()
|
||||
velocity.x = target_velocity.x
|
||||
velocity.z = target_velocity.z
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, target_velocity.x, acceleration * delta)
|
||||
velocity.z = move_toward(velocity.z, target_velocity.z, acceleration * delta)
|
||||
|
||||
if not is_on_floor():
|
||||
velocity.y -= 30.0 * delta
|
||||
|
||||
Reference in New Issue
Block a user