refactor: Wiedergabe-Geometrie als eigenes Objekt (PlaybackPose)

Etappe 8 der Controller-Zerlegung. `PlaybackPose.compute(entries, time,
previous_heading, delta, force_heading)` liefert Segment, Position,
Blickrichtung und Markergröße — inklusive der Markenlogik: Pirouetten drehen
mit der Standzeit, Sprünge drehen pro Umdrehung und wandern entlang des
Sprungvektors, Laufwege folgen der Kurve, Rückwärtsfahrt dreht die Richtung.

- Der Controller setzt das Ergebnis nur noch auf Canvas, 3D-Vorschau und
  Oberfläche; `_entry_arrival_heading` ist mit umgezogen.
- Die Umdrehungsrate für Altdaten ohne geplante Umdrehungen steht einmal in
  `PlaybackPose`; der Controller verweist darauf.
- Abgesichert durch die bestehenden Wiedergabetests (121 Assertions), die
  Positionen und Blickrichtungen über die ganze Kür prüfen.

Controller: 8.412 -> 8.304 Zeilen. Kein Verhalten geändert, Suite grün.

Offen: Steuerung, Musik, Timeline-Labels und die 3D-Anbindung.
This commit is contained in:
torsten 2026-11-13 14:25:03 +01:00
parent 5bec745825
commit 3e0c6e109d
5 changed files with 203 additions and 139 deletions

View file

@ -4,7 +4,7 @@ Stand: 2026-11-13
Ziel: Der Controller war mit **9.092 Zeilen und 465 Funktionen** der größte
Baustein im Projekt; die Roadmap nennt < 1.500 Zeilen pro Datei. Nach den
Etappen 1–7 sind es 8.412 Zeilen. Diese Notiz
Etappen 1–8 sind es 8.304 Zeilen. Diese Notiz
hält die Reihenfolge fest, damit der Umbau in Etappen mit grüner Suite
passiert und nicht als Big Bang.
@ -34,7 +34,8 @@ passiert und nicht als Big Bang.
| `SyncSummaryText` | Text der Sync-Zusammenfassung | 60 | keine | 7 ✅ |
| Sync-Orchestrierung | Threads, OAuth, Konflikte, Küren verwalten | ~700 | Dialoge, Threads | offen |
| `HubPanel` | Kür-Hub (Login, Upload, Downloads) | ~650 | Dialoge, Threads | 8 |
| `PlaybackPanel` | Wiedergabe, Musik, Timeline-Labels | ~600 | Canvas, Audio | 9 |
| `PlaybackPose` | Position und Blickrichtung zur Zeit | 130 | keine | 8 ✅ |
| Playback-Rest | Steuerung, Musik, Timeline, 3D-Anbindung | ~470 | Canvas, Audio | offen |
| `ElementInspector` | Element-Dialog, Features, Level, Kombinationen | ~800 | Dialog, Regeln | 10 |
Danach bleibt ein Controller von grob 2.000–2.500 Zeilen: Verdrahtung,
@ -123,10 +124,20 @@ braucht einen Node mit Signalen, weil Fortschritt, Dialoge und Threads
zusammenhängen, und sie ändert die Aufrufstellen in `run_sync_tests`. Das ist
ein eigener Durchgang, kein Nachtrag.
### 8–9. Hub, Playback
### 8. `PlaybackPose` ✅
Dieselbe Bauart: Dialoge und Threads als Node mit Signalen, reine Text- und
Rechenanteile vorher herausziehen.
Die Wiedergabe-Geometrie liegt in `src/whiteboard/view/playback_pose.gd`:
`compute(entries, time, previous_heading, delta, force_heading)` liefert
Segment, Position, Blickrichtung und Markergröße. Die Markenlogik (Pirouette
dreht mit der Standzeit, Sprung dreht pro Umdrehung und wandert entlang des
Sprungvektors, Laufwege folgen der Kurve) steckt vollständig dort.
Der Controller wendet das Ergebnis nur noch auf Canvas, 3D-Vorschau und
Oberfläche an. Abgesichert durch die bestehenden Wiedergabetests (121
Assertions).
**Offen:** Steuerung (Start/Pause/Reset, Geschwindigkeit), Musik und
Timeline-Labels sowie die 3D-Anbindung.
### 10. `ElementInspector`

View file

@ -270,9 +270,9 @@ Schritte.
- [ ] `WhiteboardController` in Services/Panels zerlegen: Datei-I/O, Sync,
Playback, Validierung, Element-Inspector, Section-Liste. Ziel: < 1.500
Zeilen pro Datei, keine 100 `%`-Lookups in einem Skript. In Etappen nach
`docs/refactor-whiteboard-controller.md`; Stand 2026-11-13: 8.412 Zeilen; `HelpContent`, `SeasonComparisonText`,
`docs/refactor-whiteboard-controller.md`; Stand 2026-11-13: 8.304 Zeilen; `HelpContent`, `SeasonComparisonText`,
`ValidationReportView`, `ExportService`, `RulesContext`,
`SeasonPanelModel` und `SyncSummaryText` ausgelagert.
`SeasonPanelModel`, `SyncSummaryText` und `PlaybackPose` ausgelagert.
- [ ] Gemeinsamer Test-Harness (oder gdUnit4), Timeout pro Testlauf,
Coverage; CI auf dem Gitea-/Forgejo-Remote mit `tools/test.sh` und
`tools/check_export.sh`.

View file

@ -57,7 +57,7 @@ const DEFAULT_PROFILE_INDEX := 2
## spin marker. Modern spins rotate around 2-3 rev/s (elite upright/scratch
## spins up to 5); 1.5 rev/s looked too sluggish. See
## docs/speed-assumptions.md, section 8.
const SPIN_REVOLUTIONS_PER_SECOND := 2.5
const SPIN_REVOLUTIONS_PER_SECOND := PlaybackPose.SPIN_REVOLUTIONS_PER_SECOND
const ELEMENT_DEFAULT_DURATIONS := {
PathSegment.ElementType.JUMP: 0.7,
PathSegment.ElementType.SPIN: 4.0,
@ -4056,7 +4056,14 @@ func _update_playback_state(
delta: float,
force_heading: bool = false
) -> void:
if _playback_entries.is_empty() or _routine == null:
var pose := PlaybackPose.compute(
_playback_entries,
_playback_time,
_playback_heading,
delta,
force_heading
)
if not pose.found or _routine == null:
_playback_section_id = ""
rink_canvas.clear_playback_state()
_update_section_buttons()
@ -4064,151 +4071,36 @@ func _update_playback_state(
_presentation_3d.clear_pose()
return
var entry: Dictionary = _playback_entries[_playback_entries.size() - 1]
var entry_index := _playback_entries.size() - 1
for index: int in range(_playback_entries.size()):
var candidate: Dictionary = _playback_entries[index]
var candidate_start: float = candidate["start"]
var candidate_duration: float = candidate["duration"]
if _playback_time < candidate_start + candidate_duration - 0.0001:
entry = candidate
entry_index = index
break
var segment: PathSegment = entry["segment"]
var section_id: String = entry["section_id"]
var start: float = entry["start"]
var duration: float = entry["duration"]
var local_time := clampf(_playback_time - start, 0.0, duration)
var fraction := 0.0 if duration <= 0.0 else local_time / duration
var curve := segment.curve
var length := segment.get_length_m()
var position := Vector2.ZERO
var tangent := Vector2.RIGHT
if curve != null and length > 0.0:
var offset := clampf(fraction, 0.0, 1.0) * length
position = curve.sample_baked(offset)
var epsilon := maxf(0.01, length * 0.01)
var before := curve.sample_baked(maxf(0.0, offset - epsilon))
var after := curve.sample_baked(minf(length, offset + epsilon))
var direction_vector := after - before
if direction_vector.length_squared() > 0.0:
tangent = direction_vector.normalized()
elif curve != null and curve.point_count > 0:
position = curve.get_point_position(0)
var facing := tangent
if segment.direction == PathSegment.Direction.BACKWARD:
facing = -facing
var marker_scale := 1.0
if segment.is_element_marker():
# Markers have no tangent: keep facing the way the skater arrived. Spins
# and jumps rotate in place, so the heading follows the elapsed stand
# time.
facing = _entry_arrival_heading(entry_index)
var progress := 0.0
if duration > 0.0:
progress = clampf(local_time / duration, 0.0, 1.0)
if segment.element_type == PathSegment.ElementType.SPIN:
var spin_rate := segment.get_spin_revolutions_per_second()
if spin_rate <= 0.0:
# Legacy files without a planned revolution count.
spin_rate = SPIN_REVOLUTIONS_PER_SECOND
facing = facing.rotated(
segment.get_rotation_sign()
* TAU
* spin_rate
* local_time
)
_playback_heading = facing
elif segment.element_type == PathSegment.ElementType.JUMP:
# Jumps turn once per revolution in the air; the count is taken from
# the jump code (3Lz = 3, 2A = 2.5). The marker grows towards the
# middle of the air time and travels along the jump vector to the
# landing point.
var jump_vector := segment.element_jump_vector
if jump_vector.length_squared() <= 0.000001:
jump_vector = facing * segment.get_jump_distance_m()
var travel_heading := facing
if jump_vector.length_squared() > 0.000001:
travel_heading = jump_vector.normalized()
facing = travel_heading.rotated(
segment.get_rotation_sign()
* TAU
* segment.get_jump_revolutions()
* progress
)
_playback_heading = facing
position += jump_vector * progress
marker_scale = 1.0 + 0.85 * sin(PI * progress)
elif force_heading or _playback_heading.length_squared() <= 0.0:
_playback_heading = facing
elif force_heading or delta <= 0.0 or _playback_heading.length_squared() <= 0.0:
_playback_heading = facing
else:
var turn := clampf(delta * 12.0, 0.0, 1.0)
_playback_heading = Vector2.from_angle(
lerp_angle(_playback_heading.angle(), facing.angle(), turn)
)
_playback_position = position
var section_changed := _playback_section_id != section_id
_playback_section_id = section_id
_playback_segment_id = segment.segment_id
_playback_position = pose.position
_playback_heading = pose.heading
var section_changed := _playback_section_id != pose.section_id
_playback_section_id = pose.section_id
_playback_segment_id = pose.segment_id
if section_changed:
var section := _routine.get_section_by_id(section_id)
var section := _routine.get_section_by_id(pose.section_id)
if section != null:
rink_canvas.show_section_banner(I18n.section_title(section.title))
_update_section_buttons()
rink_canvas.set_playback_state(
position,
_playback_heading,
section_id,
segment.edge,
segment.direction,
marker_scale
pose.position,
pose.heading,
pose.section_id,
pose.segment.edge,
pose.segment.direction,
pose.marker_scale
)
if _view_3d_active and _presentation_3d != null:
_presentation_3d.update_pose(
position,
_playback_heading,
segment,
pose.position,
pose.heading,
pose.segment,
_playback_time
)
_update_playback_ui()
## Heading with which the skater arrives at the timed entry [param entry_index].
## Walks back to the last entry with a real path so a marker keeps facing the
## direction of travel.
func _entry_arrival_heading(entry_index: int) -> Vector2:
var index := entry_index - 1
while index >= 0:
var previous: Dictionary = _playback_entries[index]
var previous_segment: PathSegment = previous["segment"]
if previous_segment != null:
var length := previous_segment.get_length_m()
if length > 0.0 and previous_segment.curve != null:
var epsilon := maxf(0.01, length * 0.01)
var before := previous_segment.curve.sample_baked(
maxf(0.0, length - epsilon)
)
var end := previous_segment.curve.sample_baked(length)
var direction := end - before
if direction.length_squared() > 0.0:
direction = direction.normalized()
if previous_segment.direction == PathSegment.Direction.BACKWARD:
direction = -direction
return direction
index -= 1
return Vector2.RIGHT
func _update_playback_ui() -> void:
_updating_timeline = true
playback_timeline.max_value = maxf(_playback_total_duration, 0.0)

View file

@ -0,0 +1,160 @@
class_name PlaybackPose
extends RefCounted
## Where the skater is and which way it faces at a given playback time.
##
## Pure: the timed entries and the previous heading go in, position, heading
## and marker scale come out. The controller applies the result to the canvas,
## the 3D preview and the UI, so the timing and geometry logic can be reasoned
## about without a scene.
## Fallback rotation rate for legacy files without a planned revolution count.
const SPIN_REVOLUTIONS_PER_SECOND := 2.5
class Result extends RefCounted:
var found: bool = false
var segment: PathSegment
var position: Vector2 = Vector2.ZERO
var heading: Vector2 = Vector2.RIGHT
var marker_scale: float = 1.0
var section_id: String = ""
var segment_id: String = ""
static func compute(
entries: Array,
time: float,
previous_heading: Vector2,
delta: float,
force_heading: bool = false
) -> Result:
var result := Result.new()
if entries.is_empty():
return result
var entry: Dictionary = entries[entries.size() - 1]
var entry_index := entries.size() - 1
for index: int in range(entries.size()):
var candidate: Dictionary = entries[index]
var candidate_start: float = candidate["start"]
var candidate_duration: float = candidate["duration"]
if time < candidate_start + candidate_duration - 0.0001:
entry = candidate
entry_index = index
break
var segment: PathSegment = entry["segment"]
if segment == null:
return result
var start: float = entry["start"]
var duration: float = entry["duration"]
var local_time := clampf(time - start, 0.0, duration)
var fraction := 0.0 if duration <= 0.0 else local_time / duration
var curve := segment.curve
var length := segment.get_length_m()
var position := Vector2.ZERO
var tangent := Vector2.RIGHT
if curve != null and length > 0.0:
var offset := clampf(fraction, 0.0, 1.0) * length
position = curve.sample_baked(offset)
var epsilon := maxf(0.01, length * 0.01)
var before := curve.sample_baked(maxf(0.0, offset - epsilon))
var after := curve.sample_baked(minf(length, offset + epsilon))
var direction_vector := after - before
if direction_vector.length_squared() > 0.0:
tangent = direction_vector.normalized()
elif curve != null and curve.point_count > 0:
position = curve.get_point_position(0)
var facing := tangent
if segment.direction == PathSegment.Direction.BACKWARD:
facing = -facing
var heading := previous_heading
var marker_scale := 1.0
if segment.is_element_marker():
# Markers have no tangent: keep facing the way the skater arrived. Spins
# and jumps rotate in place, so the heading follows the elapsed stand
# time.
facing = _arrival_heading(entries, entry_index)
var progress := 0.0
if duration > 0.0:
progress = clampf(local_time / duration, 0.0, 1.0)
if segment.element_type == PathSegment.ElementType.SPIN:
var spin_rate := segment.get_spin_revolutions_per_second()
if spin_rate <= 0.0:
# Legacy files without a planned revolution count.
spin_rate = SPIN_REVOLUTIONS_PER_SECOND
heading = facing.rotated(
segment.get_rotation_sign()
* TAU
* spin_rate
* local_time
)
elif segment.element_type == PathSegment.ElementType.JUMP:
# Jumps turn once per revolution in the air; the count is taken from
# the jump code (3Lz = 3, 2A = 2.5). The marker grows towards the
# middle of the air time and travels along the jump vector to the
# landing point.
var jump_vector := segment.element_jump_vector
if jump_vector.length_squared() <= 0.000001:
jump_vector = facing * segment.get_jump_distance_m()
var travel_heading := facing
if jump_vector.length_squared() > 0.000001:
travel_heading = jump_vector.normalized()
heading = travel_heading.rotated(
segment.get_rotation_sign()
* TAU
* segment.get_jump_revolutions()
* progress
)
position += jump_vector * progress
marker_scale = 1.0 + 0.85 * sin(PI * progress)
elif force_heading or heading.length_squared() <= 0.0:
heading = facing
elif force_heading or delta <= 0.0 or heading.length_squared() <= 0.0:
heading = facing
else:
var turn := clampf(delta * 12.0, 0.0, 1.0)
heading = Vector2.from_angle(
lerp_angle(heading.angle(), facing.angle(), turn)
)
result.found = true
result.segment = segment
result.position = position
result.heading = heading
result.marker_scale = marker_scale
result.section_id = str(entry["section_id"])
result.segment_id = segment.segment_id
return result
## Heading with which the skater arrives at the timed entry [param entry_index].
## Walks back to the last entry with a real path so a marker keeps facing the
## direction of travel.
static func _arrival_heading(entries: Array, entry_index: int) -> Vector2:
var index := entry_index - 1
while index >= 0:
var previous: Dictionary = entries[index]
var previous_segment: PathSegment = previous["segment"]
if previous_segment != null:
var length := previous_segment.get_length_m()
if length > 0.0 and previous_segment.curve != null:
var epsilon := maxf(0.01, length * 0.01)
var before := previous_segment.curve.sample_baked(
maxf(0.0, length - epsilon)
)
var end := previous_segment.curve.sample_baked(length)
var direction := end - before
if direction.length_squared() > 0.0:
direction = direction.normalized()
if previous_segment.direction == PathSegment.Direction.BACKWARD:
direction = -direction
return direction
index -= 1
return Vector2.RIGHT

View file

@ -0,0 +1 @@
uid://chf1qjwr1ajff