#117: the crafter and the lab animate only while they are working

A factory whose cranes swing over an empty cradle reads as working on
nothing, and a lab sweeping instruments over a vessel it is not studying
reads the same way.

The CLOCK stops rather than the drawing. Every moving element is a NeonPiece
whose position is pushed from that clock, so a frozen clock leaves the
building standing with its cranes parked; stopping apply_animation() instead
would leave them wherever the last frame happened to put them, which is not
the same thing as idle.

The state is read by tree lookup rather than through the bare `GameState`
identifier. These visual scripts are reached through a BuildingDefinition's
visual_scene, which is preloaded while the definition catalog is still
loading - early enough that the autoload is not in the global class table
yet, and a bare reference fails to COMPILE the whole file. That failure also
hung test_building_redraw_cost, because a visual that never built its pieces
left a null crane being dereferenced every frame.

Both animation tests now say what they mean: the redraw-cost test queues an
order first, because its point is that animating is cheap rather than that
it happens unprompted, and the crafter test additionally pins that an idle
crafter really is still.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Loïc Wisniewski 2026-08-23 21:58:59 +02:00
commit 39ad050dc6
5 changed files with 146 additions and 2 deletions

View file

@ -32,6 +32,18 @@ const OUTPOST_COLOR: Color = Color(0.72, 0.86, 0.45)
# #106. A cool grey-blue: this is the one structure that does no work at all,
# it only decides what work the others do.
const PLANNING_COLOR: Color = Color(0.62, 0.74, 0.92)
# #116. Warm steel: the workshop is the only structure whose whole job is
# looking after the others, and it should read as a yard rather than a plant.
const WORKSHOP_COLOR: Color = Color(0.5, 0.95, 0.8)
# Workshop: an open service gantry with a cradle under it and drone berths
# either side. Deliberately unenclosed - what it holds is other people's
# buildings, arriving and leaving.
const YARD_GANTRY_W: float = 96.0
const YARD_GANTRY_H: float = 16.0
const YARD_LEG_DROP: float = 58.0
const YARD_CRADLE_R: float = 34.0
const YARD_BERTH_X: float = 78.0
# Planning centre: a standing board with rows of tallies on it, flanked by
# two slim pylons. Rectilinear on purpose - every other structure here is
@ -140,7 +152,42 @@ var _flash_ring: NeonPiece = null
var _wash: NeonPiece = null
# #117: "The ship crafter and the ship lab should only animate when
# something is being crafted in them."
#
# The clock stops rather than the drawing: every moving element is a NeonPiece
# whose position is pushed from this clock, so a frozen clock leaves the
# building standing exactly as it was with the cranes parked. Stopping
# apply_animation() instead would leave them wherever the last frame put
# them, which is not the same thing as idle.
#
# Default true: a mothership and a transport hub turn because that is what
# they are, not because they have an order in hand.
func is_working() -> bool:
return true
# The record this visual belongs to. The chain is Building -> VisualHost ->
# this, and the id lives on the Building.
# By tree lookup, not by the bare `GameState` identifier. These visual
# scripts are reached through a BuildingDefinition's visual_scene, which is
# preloaded while the definition catalog is still loading - early enough that
# the autoload is not yet in the global class table, and a bare reference
# fails to COMPILE the whole file. Same hazard GameState notes for WORLD_GEN.
func _state() -> Node:
var tree: SceneTree = get_tree()
return tree.root.get_node_or_null("GameState") if tree != null else null
func building_id() -> int:
var host: Node = get_parent()
var building: Node = host.get_parent() if host != null else null
return int(building.building_id) if building != null and "building_id" in building else 0
func _process(delta: float) -> void:
if not is_working():
return
anim_time = fmod(anim_time + delta, CYCLE)
phase_time += delta
apply_animation()
@ -387,6 +434,43 @@ func _draw_command_center() -> void:
NeonDraw.draw_glowing_polygon(self, _diamond(Vector2.ZERO, CMD_SCREEN_RADIUS), readout, 0.9)
func _draw_workshop() -> void:
var c: Color = WORKSHOP_COLOR
var lit: Color = Color(0.86, 1.0, 0.95)
# The gantry beam, and the legs it stands on.
NeonDraw.draw_glowing_polygon(self, PackedVector2Array([
Vector2(-YARD_GANTRY_W, -YARD_GANTRY_H - 40.0),
Vector2(YARD_GANTRY_W, -YARD_GANTRY_H - 40.0),
Vector2(YARD_GANTRY_W, -40.0), Vector2(-YARD_GANTRY_W, -40.0),
]), c, 1.0)
for side in [-1.0, 1.0]:
var x: float = YARD_GANTRY_W * side * 0.82
NeonDraw.draw_glowing_line(self, Vector2(x, -40.0),
Vector2(x, YARD_LEG_DROP), c, 0.8, 0.42)
# Cross-bracing, so it reads as a frame rather than two posts.
NeonDraw.draw_glowing_line(self, Vector2(x, -40.0),
Vector2(x * 0.35, YARD_LEG_DROP), c, 0.45, 0.26)
# The cradle: an open arc under the beam, with the thing being worked on
# implied by the lit core rather than drawn.
NeonDraw.draw_glowing_path(self, _arc(Vector2(0.0, 6.0), YARD_CRADLE_R,
0.0, PI, 14), c, 0.85, 0.4)
NeonDraw.draw_glowing_circle(self, Vector2(0.0, 6.0), 11.0, lit, 0.9)
# A hoist line down from the beam to what is in the cradle.
NeonDraw.draw_glowing_line(self, Vector2(0.0, -40.0), Vector2(0.0, -6.0),
c, 0.6, 0.3)
# Drone berths, one either side, drawn as open brackets.
for side in [-1.0, 1.0]:
var berth: Vector2 = Vector2(YARD_BERTH_X * side, -70.0)
NeonDraw.draw_glowing_path(self, PackedVector2Array([
berth + Vector2(-14.0 * side, -12.0), berth + Vector2(6.0 * side, -12.0),
berth + Vector2(6.0 * side, 12.0), berth + Vector2(-14.0 * side, 12.0),
]), c, 0.7, 0.32)
NeonDraw.draw_glowing_polygon(self, _diamond(berth, 7.0), lit, 0.85)
func _draw_planning_center() -> void:
var c: Color = PLANNING_COLOR
var lit: Color = Color(0.88, 0.94, 1.0)

View file

@ -6,6 +6,16 @@ func _ready() -> void:
_build_crafter_pieces()
queue_redraw()
# #117: the line runs when there is something on it. An idle crafter with
# its cranes swinging read as a factory working on nothing.
func is_working() -> bool:
var id: int = building_id()
if id == 0:
return false
var state: Node = _state()
return state != null and state.pending_orders(id) > 0
func apply_animation() -> void:
_animate_crafter()

View file

@ -4,6 +4,16 @@ func _ready() -> void:
_build_lab_pieces()
queue_redraw()
# #117: the instruments sweep while something is being researched, and are
# parked otherwise.
func is_working() -> bool:
var id: int = building_id()
if id == 0:
return false
var state: Node = _state()
return state != null and not state.lab_research_order(id).is_empty()
func apply_animation() -> void:
_animate_ship_lab()

View file

@ -30,10 +30,11 @@ var stage: int = 0
var elapsed: float = 0.0
var crane_x_start: float = 0.0
var satellite_rotation_start: float = 0.0
var game_state: Node
func _initialize() -> void:
var game_state: Node = root.get_node("GameState")
game_state = root.get_node("GameState")
game_state.buildings.clear()
game_state.extractors.clear()
scene = load("res://world/Main.tscn").instantiate()
@ -71,6 +72,10 @@ func _process(delta: float) -> bool:
quit(1)
return true
# #117: an idle crafter holds its clock, so there would be no
# animation to measure the cost of. The point of this test is
# that animating is CHEAP, not that it happens unprompted.
game_state.queue_order(int(_crafter_id(field)), GameState.VESSEL_INTERCEPTOR)
crane_x_start = crafter._crane.position.x
satellite_rotation_start = mothership._satellites.rotation
elapsed = 0.0
@ -108,3 +113,10 @@ func _process(delta: float) -> bool:
quit(0)
return true
return false
func _crafter_id(building_field: Node) -> int:
for b in building_field.spawned:
if is_instance_valid(b) and b.building_type == GameState.BUILDING_SHIP_CRAFTER:
return int(b.building_id)
return 0

View file

@ -12,7 +12,11 @@ extends SceneTree
# that never changes were a measurable framerate cost earlier on
# 3. the hull assembles progressively over the cycle rather than popping
# in whole, and every piece is on before the assembly phase ends
# 4. the cycle loops without anim_time growing without bound
# 4. the cycle loops without anim_time growing without bound, WHILE THERE
# IS SOMETHING ON THE LINE - #117 stops the clock on an idle crafter,
# because a factory whose cranes swing over an empty cradle reads as
# working on nothing
# 5. and an idle crafter really is still
var scene: Node
var game_state: Node
@ -99,11 +103,35 @@ func _process(delta: float) -> bool:
quit(1)
return true
# --- #117: idle means idle --------------------------------
if crafter.is_working():
print("TEST_CRAFTER_ANIMATION: FAIL (a crafter with an empty queue calls itself working)")
quit(1)
return true
time_at_start = crafter.anim_time
elapsed = 0.0
stage = 2
return false
2:
if elapsed < 0.4:
return false
if crafter.anim_time != time_at_start:
print("TEST_CRAFTER_ANIMATION: FAIL (an idle crafter kept animating)")
quit(1)
return true
print("idle crafter held its clock at %.3f" % crafter.anim_time)
# Put something on the line, and it should run again.
game_state.queue_order(int(_find(GameState.BUILDING_SHIP_CRAFTER).building_id),
GameState.VESSEL_INTERCEPTOR)
if not crafter.is_working():
print("TEST_CRAFTER_ANIMATION: FAIL (an order was queued and the crafter is still idle)")
quit(1)
return true
time_at_start = crafter.anim_time
elapsed = 0.0
stage = 3
return false
3:
if elapsed < 0.4:
return false
var advanced: bool = crafter.anim_time != time_at_start