2026-08-16 17:59:04 +02:00
|
|
|
extends SceneTree
|
|
|
|
|
|
|
|
|
|
# Headless gameplay test: run with
|
|
|
|
|
# godot --headless -s res://tests/test_space_time_distorder.gd
|
|
|
|
|
# Forgejo #59: a researchable vessel that lets the whole fleet travel faster
|
|
|
|
|
# than its default cruise speed, via a fader driving
|
|
|
|
|
# game_state.fleet_speed_multiplier.
|
|
|
|
|
#
|
|
|
|
|
# Covers:
|
|
|
|
|
# A. the fader is absent with no distorder ship, appears once one joins
|
|
|
|
|
# B. dragging it up measurably increases distance travelled per second;
|
|
|
|
|
# at 1.0 the fleet moves exactly as it does today
|
|
|
|
|
# C. formation holds together under boost - ships stay near their slot
|
2026-09-03 23:14:02 +02:00
|
|
|
# D. losing the vessel resets the multiplier
|
|
|
|
|
# E. landing disables the space-only multiplier and surface fader
|
2026-08-16 17:59:04 +02:00
|
|
|
|
|
|
|
|
var game_state: Node
|
|
|
|
|
var main: Node
|
|
|
|
|
var fleet: Node
|
|
|
|
|
var fader: Node
|
|
|
|
|
var stage: int = 0
|
|
|
|
|
var elapsed: float = 0.0
|
|
|
|
|
var baseline_distance: float = 0.0
|
|
|
|
|
var boosted_distance: float = 0.0
|
|
|
|
|
var start_centroid: Vector2 = Vector2.ZERO
|
|
|
|
|
var unboosted_lag: float = 0.0
|
|
|
|
|
|
|
|
|
|
const MEASURE_TIME: float = 1.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _initialize() -> void:
|
|
|
|
|
game_state = root.get_node("GameState")
|
|
|
|
|
game_state.buildings.clear()
|
|
|
|
|
game_state.extractors.clear()
|
|
|
|
|
game_state.transporters.clear()
|
|
|
|
|
game_state.stored_vessels.clear()
|
|
|
|
|
game_state.reset_progression()
|
|
|
|
|
game_state.vessel_levels["unlock_distorder"] = 1
|
2026-08-16 19:21:54 +02:00
|
|
|
# #62: sustaining a boost now drains fleet energy continuously - stock
|
|
|
|
|
# plenty so this test's own boosted phases aren't cut short by running
|
|
|
|
|
# out mid-measurement. Set BEFORE the first spawn_ships() call (inside
|
|
|
|
|
# Main.tscn's own _ready(), triggered by instantiate() below): the fleet
|
|
|
|
|
# hold has no capacity cap yet at this point, so this can't be clamped
|
|
|
|
|
# by the soon-to-exist fleet's cargo capability.
|
|
|
|
|
game_state.deposit_fleet_resource(GameState.RESOURCE_ENERGY, 500)
|
#84: move 215 root files into a folder hierarchy
Everything lived in one flat directory, so a diff gave no clue what area it
touched and finding the file you wanted meant knowing its exact name. Twelve
folders now, grouped by what a thing IS rather than what type it is - a
vessel's definition, its component scenes and its upgrade resources sit
together, because that is the set you read when you change one of them.
buildings core controllers enemies logistics planets
resources shaders surface ui vessels vfx world
332 files moved and every res:// reference rewritten - 306 files touched,
including the autoload and main-scene paths in project.godot. Nothing renamed:
this is purely where files sit, so the diff is a pile of pure moves and no
behaviour is buried in it. ui_theme.tres, icon.svg and web_shell.html stay at
the root, where Godot and the export preset expect them.
Verified three ways, because a suite alone would not have caught all of it:
the full 117 pass, the web export builds clean, and the game renders.
The export is why that matters. The FIRST export after the move failed with
"Attempt to open script 'res://GameState.gd'" - the old path - while
project.godot on disk plainly said res://core/GameState.gd. That is this
project's documented Android FUSE mtime trap: Godot served a cached copy of a
file whose content had changed. A `touch` fixed it. Nothing in the test suite
would have found that, because the suite runs from a copy on a native
filesystem - the one place the bug cannot happen.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 19:44:14 +02:00
|
|
|
main = load("res://world/Main.tscn").instantiate()
|
2026-08-16 17:59:04 +02:00
|
|
|
root.add_child(main)
|
|
|
|
|
fleet = main.get_node("Fleet")
|
|
|
|
|
fader = main.get_node("UI/SpeedFader")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _process(delta: float) -> bool:
|
|
|
|
|
elapsed += delta
|
|
|
|
|
match stage:
|
|
|
|
|
0:
|
|
|
|
|
if elapsed < 0.2:
|
|
|
|
|
return false
|
|
|
|
|
main.get_node("EnemySpawner").set_process(false)
|
|
|
|
|
main.get_node("AsteroidField").set_process(false)
|
Bound individual vessel speed; stop Fleet.stop() accumulating it (#72)
Rotating the fleet and spamming a direction let vessels fall out of sync
and fly at wildly high speeds. The pivot cooldown added earlier throttled
how often the exploit could be triggered; it never touched the cause.
Fleet.stop() did `ship.velocity = ship.velocity + ship.fleet_velocity`,
compensating for the fact that Ship.velocity read zero during cruise. The
next steer refilled fleet_velocity, so every press-release cycle added a
whole cruise velocity to the ship's own, decaying only at `acceleration` in
between. Tapping faster than that bled it off stacked them without limit,
and ships desynced because each bled off at a rate set by its own distance
to its slot. Measured before this change: spamming a direction while
pivoting flew the fleet 32737 units in 3s against 784 for simply holding
the stick, with a vessel reaching 48x its own top speed.
The compensation existed because `velocity` was not the ship's real motion:
Ship snapped to its slot every tick and zeroed it, so the truth lived in a
second field and anything wanting it had to add the two together. Fixed at
that root rather than by clamping the symptom:
- fleet_velocity is now fed FORWARD into the steering instead of carried
alongside it. The ship aims to travel at its slot's velocity plus a
correction closing the gap, so holding formation costs no error and
`velocity` is always true world motion.
- The snap only applies when the slot is standing still, which is the one
case where converging asymptotically would leave a residue. While the
slot moves the ship steers continuously - a snap there was the teleport
that made `velocity` lie in the first place.
- A hard bound on the INTEGRATED result every tick, not merely on the
request, so no sequence of commands can leave a vessel over its own top
speed.
- Fleet.stop() injects nothing; it reports that the slot has halted.
tests/test_fleet_speed_bounded.gd covers it, and fails against the previous
code with the numbers above: no vessel exceeds its own top speed however
hard the direction is spammed, spamming cannot cover more ground than
holding the stick, both hold while the formation is pivoting, and the fleet
stays together.
test_space_time_distorder.gd now clears the asteroid and enemy groups at
setup, the same clean-slate idiom test_ship_lab.gd uses. Silencing the
spawners was never enough - what Main.tscn had already placed kept moving,
and losing the distorder vessel to a rock resets the multiplier correctly,
which the test then reported three stages later as a failed scene swap. It
also checks it still crews a distorder vessel before relying on that.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-17 23:20:34 +02:00
|
|
|
# Silencing the spawners is not enough: whatever Main.tscn already
|
|
|
|
|
# placed keeps moving under its own _physics_process, and this test
|
|
|
|
|
# flies the fleet several thousand units at up to 3x boost. Losing
|
|
|
|
|
# the distorder ship to a rock mid-run resets the multiplier -
|
|
|
|
|
# CORRECTLY, that is what _sync_composition_state is for - and the
|
|
|
|
|
# test then failed three stages later claiming the multiplier had
|
|
|
|
|
# not survived a scene swap. Same clean-slate idiom as
|
|
|
|
|
# test_ship_lab.gd.
|
|
|
|
|
for hazard in get_nodes_in_group("asteroids") + get_nodes_in_group("enemies"):
|
|
|
|
|
if is_instance_valid(hazard):
|
|
|
|
|
hazard.queue_free()
|
2026-08-16 17:59:04 +02:00
|
|
|
|
|
|
|
|
# --- A. absent, then appears -------------------------------------
|
|
|
|
|
if fader.visible:
|
|
|
|
|
return _fail_now("fader appeared without a distorder ship")
|
|
|
|
|
|
|
|
|
|
fleet.spawn_ships(2, Vector2.ZERO, PackedStringArray([
|
|
|
|
|
GameState.VESSEL_INTERCEPTOR, GameState.VESSEL_DISTORDER]))
|
|
|
|
|
fader._process(0.0)
|
|
|
|
|
if not fader.visible:
|
|
|
|
|
return _fail_now("a distorder ship in the fleet did not reveal the fader")
|
|
|
|
|
print("fader hidden with no distorder ship, visible once one joins")
|
|
|
|
|
|
|
|
|
|
# --- B. baseline @ 1.0x -------------------------------------------
|
|
|
|
|
if not is_equal_approx(game_state.fleet_speed_multiplier, 1.0):
|
|
|
|
|
return _fail_now("multiplier is not 1.0 by default: %f" % game_state.fleet_speed_multiplier)
|
|
|
|
|
start_centroid = fleet.get_centroid()
|
|
|
|
|
fleet.move_in_direction(Vector2(1.0, 0.0))
|
|
|
|
|
elapsed = 0.0
|
|
|
|
|
stage = 1
|
|
|
|
|
return false
|
|
|
|
|
1:
|
|
|
|
|
if elapsed < MEASURE_TIME:
|
|
|
|
|
return false
|
|
|
|
|
baseline_distance = fleet.get_centroid().distance_to(start_centroid)
|
|
|
|
|
# Reference for the formation check below: pure pursuit (a ship
|
|
|
|
|
# always aiming straight at its CURRENT, still-moving target
|
|
|
|
|
# rather than leading it) has its own inherent non-zero steady-
|
|
|
|
|
# state following distance even at 1.0x - it scales with the
|
|
|
|
|
# speeds involved, so "holds together under boost" has to mean
|
|
|
|
|
# staying proportional to this, not shrinking to some fixed
|
|
|
|
|
# absolute number regardless of how fast the fleet is going.
|
|
|
|
|
for i in range(fleet.ships.size()):
|
|
|
|
|
var ship: Node2D = fleet.ships[i]
|
|
|
|
|
if not is_instance_valid(ship):
|
|
|
|
|
continue
|
|
|
|
|
var expected: Vector2 = fleet.fleet_target + fleet.formation_offsets[i]
|
|
|
|
|
unboosted_lag = maxf(unboosted_lag, ship.position.distance_to(expected))
|
|
|
|
|
fleet.stop()
|
|
|
|
|
print("baseline (1.0x): travelled %.1f over %.1fs, formation lag %.1f" \
|
|
|
|
|
% [baseline_distance, MEASURE_TIME, unboosted_lag])
|
|
|
|
|
elapsed = 0.0
|
|
|
|
|
stage = 2
|
|
|
|
|
return false
|
|
|
|
|
2:
|
|
|
|
|
# Let the braking manoeuvre from stop() fully settle before
|
|
|
|
|
# measuring the boosted leg, so leftover momentum from the
|
|
|
|
|
# baseline pass can't pad the comparison either way.
|
|
|
|
|
if elapsed < 0.5:
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
var press := InputEventScreenTouch.new()
|
|
|
|
|
press.index = 5
|
|
|
|
|
press.position = fader.global_position + Vector2(fader.size.x * 0.5, fader.size.y - 4.0)
|
|
|
|
|
press.pressed = true
|
|
|
|
|
main._handle_touch(press)
|
|
|
|
|
if not fader.is_active():
|
|
|
|
|
return _fail_now("pressing the fader did not begin dragging")
|
|
|
|
|
var drag := InputEventScreenDrag.new()
|
|
|
|
|
drag.index = 5
|
|
|
|
|
# All the way to the top of the track = MAX_FLEET_SPEED_MULTIPLIER.
|
|
|
|
|
drag.position = fader.global_position + Vector2(fader.size.x * 0.5, 0.0)
|
|
|
|
|
main._handle_drag(drag)
|
|
|
|
|
if not is_equal_approx(game_state.fleet_speed_multiplier, GameState.MAX_FLEET_SPEED_MULTIPLIER):
|
|
|
|
|
return _fail_now("dragging to the top did not reach the max multiplier: %f" \
|
|
|
|
|
% game_state.fleet_speed_multiplier)
|
|
|
|
|
print("fader dragged to %.1fx" % game_state.fleet_speed_multiplier)
|
|
|
|
|
|
|
|
|
|
start_centroid = fleet.get_centroid()
|
|
|
|
|
fleet.move_in_direction(Vector2(1.0, 0.0))
|
|
|
|
|
elapsed = 0.0
|
|
|
|
|
stage = 3
|
|
|
|
|
return false
|
|
|
|
|
3:
|
|
|
|
|
if elapsed < MEASURE_TIME:
|
|
|
|
|
return false
|
|
|
|
|
boosted_distance = fleet.get_centroid().distance_to(start_centroid)
|
|
|
|
|
print("boosted (%.1fx): travelled %.1f over %.1fs" \
|
|
|
|
|
% [game_state.fleet_speed_multiplier, boosted_distance, MEASURE_TIME])
|
|
|
|
|
if boosted_distance <= baseline_distance * 1.3:
|
|
|
|
|
return _fail_now("boosted travel (%.1f) was not measurably more than baseline (%.1f)" \
|
|
|
|
|
% [boosted_distance, baseline_distance])
|
|
|
|
|
elapsed = 0.0
|
|
|
|
|
stage = 4
|
|
|
|
|
return false
|
|
|
|
|
4:
|
|
|
|
|
# --- C. formation holds together under boost ----------------------
|
|
|
|
|
# Both the anchor's advance and the ships' own catch-up speed are
|
|
|
|
|
# scaled by the SAME multiplier, so the initial accelerate-from-
|
|
|
|
|
# rest transient covers a proportionally larger absolute distance
|
|
|
|
|
# under a 3x boost - a moment right after the boost begins isn't
|
|
|
|
|
# "trailing", it just hasn't finished the same (time-invariant)
|
|
|
|
|
# catch-up burst yet. Keep steering a while longer so that burst
|
|
|
|
|
# is over before judging whether formation holds.
|
2026-08-17 19:51:11 +02:00
|
|
|
if elapsed < 2.5:
|
2026-08-16 17:59:04 +02:00
|
|
|
return false
|
|
|
|
|
# Allow the lag to scale with the boost (it inherently does, even
|
|
|
|
|
# with both the anchor and ship speeds multiplied by the exact
|
|
|
|
|
# same factor - see the note by unboosted_lag above) but not
|
2026-08-17 19:51:11 +02:00
|
|
|
# beyond that, with generous slack for measurement noise - this
|
|
|
|
|
# ran under a full-suite JOBS=1 sequential load once and strayed
|
|
|
|
|
# 77.7 against a 30.0 allowance (2.6x over) purely from device
|
|
|
|
|
# jitter, confirmed by an immediate clean pass in isolation
|
|
|
|
|
# straight afterward. A REAL formation-desync regression (#72)
|
|
|
|
|
# strays by orders of magnitude more than this margin allows.
|
|
|
|
|
var allowed_lag: float = maxf(unboosted_lag, 20.0) * game_state.fleet_speed_multiplier * 3.0
|
2026-08-16 17:59:04 +02:00
|
|
|
for i in range(fleet.ships.size()):
|
|
|
|
|
var ship: Node2D = fleet.ships[i]
|
|
|
|
|
if not is_instance_valid(ship):
|
|
|
|
|
continue
|
|
|
|
|
var expected: Vector2 = fleet.fleet_target + fleet.formation_offsets[i]
|
|
|
|
|
var strayed: float = ship.position.distance_to(expected)
|
|
|
|
|
if strayed > allowed_lag:
|
|
|
|
|
return _fail_now("a ship strayed %.1f from its formation slot under sustained boost (unboosted lag was %.1f, allowed %.1f)" \
|
|
|
|
|
% [strayed, unboosted_lag, allowed_lag])
|
|
|
|
|
print("formation held together under sustained boost (lag stayed proportional to the boost)")
|
|
|
|
|
|
|
|
|
|
fleet.stop()
|
|
|
|
|
var release := InputEventScreenTouch.new()
|
|
|
|
|
release.index = 5
|
|
|
|
|
release.position = fader.global_position + Vector2(fader.size.x * 0.5, 0.0)
|
|
|
|
|
release.pressed = false
|
|
|
|
|
main._handle_touch(release)
|
|
|
|
|
|
2026-09-03 23:14:02 +02:00
|
|
|
# --- E. landing disables the space-only sustained boost ------------
|
|
|
|
|
# Keep the Distorder crewed and the boost active across teardown so
|
|
|
|
|
# the landed surface itself has to enforce the boundary.
|
|
|
|
|
# Check the premise before relying on it: landing should reset the
|
|
|
|
|
# boost even though the fleet still owns the vessel that enables it.
|
Bound individual vessel speed; stop Fleet.stop() accumulating it (#72)
Rotating the fleet and spamming a direction let vessels fall out of sync
and fly at wildly high speeds. The pivot cooldown added earlier throttled
how often the exploit could be triggered; it never touched the cause.
Fleet.stop() did `ship.velocity = ship.velocity + ship.fleet_velocity`,
compensating for the fact that Ship.velocity read zero during cruise. The
next steer refilled fleet_velocity, so every press-release cycle added a
whole cruise velocity to the ship's own, decaying only at `acceleration` in
between. Tapping faster than that bled it off stacked them without limit,
and ships desynced because each bled off at a rate set by its own distance
to its slot. Measured before this change: spamming a direction while
pivoting flew the fleet 32737 units in 3s against 784 for simply holding
the stick, with a vessel reaching 48x its own top speed.
The compensation existed because `velocity` was not the ship's real motion:
Ship snapped to its slot every tick and zeroed it, so the truth lived in a
second field and anything wanting it had to add the two together. Fixed at
that root rather than by clamping the symptom:
- fleet_velocity is now fed FORWARD into the steering instead of carried
alongside it. The ship aims to travel at its slot's velocity plus a
correction closing the gap, so holding formation costs no error and
`velocity` is always true world motion.
- The snap only applies when the slot is standing still, which is the one
case where converging asymptotically would leave a residue. While the
slot moves the ship steers continuously - a snap there was the teleport
that made `velocity` lie in the first place.
- A hard bound on the INTEGRATED result every tick, not merely on the
request, so no sequence of commands can leave a vessel over its own top
speed.
- Fleet.stop() injects nothing; it reports that the slot has halted.
tests/test_fleet_speed_bounded.gd covers it, and fails against the previous
code with the numbers above: no vessel exceeds its own top speed however
hard the direction is spammed, spamming cannot cover more ground than
holding the stick, both hold while the formation is pivoting, and the fleet
stays together.
test_space_time_distorder.gd now clears the asteroid and enemy groups at
setup, the same clean-slate idiom test_ship_lab.gd uses. Silencing the
spawners was never enough - what Main.tscn had already placed kept moving,
and losing the distorder vessel to a rock resets the multiplier correctly,
which the test then reported three stages later as a failed scene swap. It
also checks it still crews a distorder vessel before relying on that.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-17 23:20:34 +02:00
|
|
|
if not fleet.has_capability("distorder"):
|
|
|
|
|
return _fail_now("the fleet lost its distorder vessel before the scene swap, so the multiplier reset is expected rather than a bug")
|
2026-08-16 17:59:04 +02:00
|
|
|
game_state.surviving_ship_count = fleet.ships.size()
|
|
|
|
|
game_state.surviving_vessel_types = fleet.vessel_types()
|
|
|
|
|
game_state.planet_id = "test_space_time_distorder"
|
|
|
|
|
game_state.planet_name = "Distorder Test"
|
|
|
|
|
main.queue_free()
|
|
|
|
|
elapsed = 0.0
|
|
|
|
|
stage = 5
|
|
|
|
|
return false
|
|
|
|
|
5:
|
|
|
|
|
if elapsed < 0.3:
|
|
|
|
|
return false
|
#84: move 215 root files into a folder hierarchy
Everything lived in one flat directory, so a diff gave no clue what area it
touched and finding the file you wanted meant knowing its exact name. Twelve
folders now, grouped by what a thing IS rather than what type it is - a
vessel's definition, its component scenes and its upgrade resources sit
together, because that is the set you read when you change one of them.
buildings core controllers enemies logistics planets
resources shaders surface ui vessels vfx world
332 files moved and every res:// reference rewritten - 306 files touched,
including the autoload and main-scene paths in project.godot. Nothing renamed:
this is purely where files sit, so the diff is a pile of pure moves and no
behaviour is buried in it. ui_theme.tres, icon.svg and web_shell.html stay at
the root, where Godot and the export preset expect them.
Verified three ways, because a suite alone would not have caught all of it:
the full 117 pass, the web export builds clean, and the game renders.
The export is why that matters. The FIRST export after the move failed with
"Attempt to open script 'res://GameState.gd'" - the old path - while
project.godot on disk plainly said res://core/GameState.gd. That is this
project's documented Android FUSE mtime trap: Godot served a cached copy of a
file whose content had changed. A `touch` fixed it. Nothing in the test suite
would have found that, because the suite runs from a copy on a native
filesystem - the one place the bug cannot happen.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 19:44:14 +02:00
|
|
|
main = load("res://surface/PlanetSurface.tscn").instantiate()
|
2026-08-16 17:59:04 +02:00
|
|
|
root.add_child(main)
|
|
|
|
|
current_scene = main
|
|
|
|
|
fleet = main.get_node("Fleet")
|
|
|
|
|
elapsed = 0.0
|
|
|
|
|
stage = 6
|
|
|
|
|
return false
|
|
|
|
|
6:
|
|
|
|
|
if elapsed < 0.3:
|
|
|
|
|
return false
|
2026-09-03 23:14:02 +02:00
|
|
|
if not is_equal_approx(game_state.fleet_speed_multiplier, 1.0):
|
|
|
|
|
return _fail_now("landing did not reset the space-only multiplier: %f" \
|
2026-08-16 17:59:04 +02:00
|
|
|
% game_state.fleet_speed_multiplier)
|
2026-09-03 23:14:02 +02:00
|
|
|
if main.get_node_or_null("UI/SpeedFader") != null:
|
|
|
|
|
return _fail_now("the space-only speed fader is present on the planet")
|
|
|
|
|
print("landing reset the multiplier and omitted its space-only fader")
|
2026-08-16 17:59:04 +02:00
|
|
|
|
|
|
|
|
# --- D. losing the vessel resets the multiplier -------------------
|
2026-09-03 23:14:02 +02:00
|
|
|
game_state.set_fleet_speed_multiplier(GameState.MAX_FLEET_SPEED_MULTIPLIER)
|
2026-08-16 17:59:04 +02:00
|
|
|
fleet.spawn_ships(1, fleet.get_centroid(), PackedStringArray([GameState.VESSEL_INTERCEPTOR]))
|
|
|
|
|
if not is_equal_approx(game_state.fleet_speed_multiplier, 1.0):
|
|
|
|
|
return _fail_now("multiplier was not reset after losing the distorder ship: %f" \
|
|
|
|
|
% game_state.fleet_speed_multiplier)
|
|
|
|
|
print("losing the distorder ship reset the multiplier and hid the fader")
|
|
|
|
|
|
|
|
|
|
print("TEST_SPACE_TIME_DISTORDER: PASS")
|
|
|
|
|
quit(0)
|
|
|
|
|
return true
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _fail_now(message: String) -> bool:
|
|
|
|
|
print("TEST_SPACE_TIME_DISTORDER: FAIL (%s)" % message)
|
|
|
|
|
quit(1)
|
|
|
|
|
return true
|