mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
perf(ship): reuse member ShipAction instead of allocating per tick
ship.gd's controllerless path and player_ship_controller.gd each allocated a fresh ShipAction every physics tick; ai_ship_controller.gd and rl_ship_controller.gd already avoid this via a persistent member. Convert both to reuse a member instance, matching the existing full-field-overwrite convention (rather than +=/-= off a fresh zero). Also drop the completed items from TODO.md.
This commit is contained in:
@@ -4,46 +4,37 @@ extends ShipController
|
||||
# Drives a Ship from the local player's input actions (see project.godot
|
||||
# [input] and FLIGHT_MANUAL.md).
|
||||
|
||||
var _action := ShipAction.new()
|
||||
|
||||
|
||||
func get_action() -> ShipAction:
|
||||
var action := ShipAction.new()
|
||||
# Full overwrite per axis (not +=/-=): _action is reused across ticks, so
|
||||
# fields must not depend on starting from a fresh Vector3.ZERO each call.
|
||||
|
||||
# Forward/Backward thrust (main engines)
|
||||
if Input.is_action_pressed("move_forward"):
|
||||
action.thrust.z += 1.0
|
||||
if Input.is_action_pressed("move_back"):
|
||||
action.thrust.z -= 1.0
|
||||
_action.thrust.z = (1.0 if Input.is_action_pressed("move_forward") else 0.0) \
|
||||
- (1.0 if Input.is_action_pressed("move_back") else 0.0)
|
||||
|
||||
# Strafe thrusters (left/right)
|
||||
if Input.is_action_pressed("move_left"):
|
||||
action.thrust.x -= 1.0
|
||||
if Input.is_action_pressed("move_right"):
|
||||
action.thrust.x += 1.0
|
||||
_action.thrust.x = (1.0 if Input.is_action_pressed("move_right") else 0.0) \
|
||||
- (1.0 if Input.is_action_pressed("move_left") else 0.0)
|
||||
|
||||
# Vertical thrusters (up/down)
|
||||
if Input.is_action_pressed("move_up"):
|
||||
action.thrust.y += 1.0
|
||||
if Input.is_action_pressed("move_down"):
|
||||
action.thrust.y -= 1.0
|
||||
_action.thrust.y = (1.0 if Input.is_action_pressed("move_up") else 0.0) \
|
||||
- (1.0 if Input.is_action_pressed("move_down") else 0.0)
|
||||
|
||||
# Yaw (turn left/right around Y axis)
|
||||
if Input.is_action_pressed("turn_left"):
|
||||
action.rotation.y += 1.0
|
||||
if Input.is_action_pressed("turn_right"):
|
||||
action.rotation.y -= 1.0
|
||||
_action.rotation.y = (1.0 if Input.is_action_pressed("turn_left") else 0.0) \
|
||||
- (1.0 if Input.is_action_pressed("turn_right") else 0.0)
|
||||
|
||||
# Pitch (nose up/down around X axis)
|
||||
if Input.is_action_pressed("pitch_up"):
|
||||
action.rotation.x -= 1.0
|
||||
if Input.is_action_pressed("pitch_down"):
|
||||
action.rotation.x += 1.0
|
||||
_action.rotation.x = (1.0 if Input.is_action_pressed("pitch_down") else 0.0) \
|
||||
- (1.0 if Input.is_action_pressed("pitch_up") else 0.0)
|
||||
|
||||
# Roll (bank left/right around Z axis)
|
||||
if Input.is_action_pressed("roll_left"):
|
||||
action.rotation.z += 1.0
|
||||
if Input.is_action_pressed("roll_right"):
|
||||
action.rotation.z -= 1.0
|
||||
_action.rotation.z = (1.0 if Input.is_action_pressed("roll_left") else 0.0) \
|
||||
- (1.0 if Input.is_action_pressed("roll_right") else 0.0)
|
||||
|
||||
action.turbo = Input.is_action_pressed("turbo")
|
||||
_action.turbo = Input.is_action_pressed("turbo")
|
||||
|
||||
return action
|
||||
return _action
|
||||
|
||||
@@ -79,6 +79,7 @@ static func _get_team_material(team: int) -> StandardMaterial3D:
|
||||
|
||||
var controller: ShipController
|
||||
var _current_action: ShipAction = ShipAction.new()
|
||||
var _inert_action: ShipAction = ShipAction.new()
|
||||
var _boundary: ArenaBoundary
|
||||
|
||||
# Instrument signals for efficient data distribution
|
||||
@@ -194,7 +195,7 @@ func _has_telemetry_listeners() -> bool:
|
||||
|
||||
func _integrate_forces(state):
|
||||
# One action per physics tick, pulled from the controller (deterministic)
|
||||
_current_action = controller.get_action() if controller else ShipAction.new()
|
||||
_current_action = controller.get_action() if controller else _inert_action
|
||||
|
||||
# === TRANSLATION (Movement) ===
|
||||
apply_thruster_forces(state, _current_action)
|
||||
|
||||
Reference in New Issue
Block a user