Skip to content

Commit 45e0a57

Browse files
CopilotbedaHovorka
andauthored
docs: restore stacked speed control documentation
Agent-Logs-Url: https://github.com/bedaHovorka/interlockSim/sessions/943bd48f-c5aa-4ff9-9008-4338e3578772 Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
1 parent 1166adc commit 45e0a57

4 files changed

Lines changed: 107 additions & 52 deletions

File tree

CLAUDE.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,37 @@ This project uses Gradle with Kotlin DSL. Java 21 LTS is required.
5252
./gradlew runEditor # Launch editor GUI
5353
./gradlew runExampleGui # Animated GUI simulation (Issue #268, milestone complete 2026-02-04)
5454

55+
# Goal 7 speed-control shortcuts (simulation mode only)
56+
# 1-5 -> 0.5x, 1x, 2x, 5x, 10x
57+
# +/- -> multiply or divide speed by 1.5
58+
# Space -> pause/resume toggle (Goal 8 integration point)
59+
5560
# Other tasks
5661
./gradlew javadoc # Generate documentation
5762
./gradlew dependencies # Show dependency tree
5863
```
5964

6065
For complete build system documentation including dependency management, GitHub Packages authentication, manual JAR execution, and Gradle configuration files, see **[docs/KOTLIN_STYLE_GUIDE.md](docs/KOTLIN_STYLE_GUIDE.md)** under "Build & Development Environment".
6166

62-
### Running Animated Simulation (Current Branch)
67+
### Running Simulation with Speed Control
6368

64-
Use the animated GUI when you need the current real-time animated desktop view:
69+
Use the animated GUI when you need live speed changes:
6570

6671
```bash
67-
# Built-in animated example
72+
# Built-in animated example with speed controls
6873
./gradlew runExampleGui
6974

7075
# Equivalent manual JAR launch
7176
java -jar build/libs/interlockSim.jar exampleGui shuntingLoop 300
7277
```
7378

74-
Current branch behavior:
79+
For XML files loaded from the desktop UI, use **Simulation → Start...** and then adjust speed with:
80+
81+
- the speed slider (`0.1x` to `10.0x`)
82+
- preset buttons/menu items (`0.1x`, `0.5x`, `1x`, `2x`, `5x`, `10x`, `50x`)
83+
- global keyboard shortcuts (`1`-`5`, `+`, `-`, `Space`)
7584

76-
- `runExampleGui` uses fixed real-time synchronization for the built-in GUI example
77-
- the top `ControlPanel` shows time and status only
78-
- `StatusBar` is hidden in simulation mode
79-
- interactive Goal 7 speed controls are not wired into the current desktop UI on this branch
85+
The status bar shows `Speed: X.Xx` whenever the speed differs from `1.0x`.
8086

8187
### Directory Structure
8288

@@ -189,9 +195,12 @@ For complete navigation services architecture, Koin DI integration patterns, and
189195
- AnimatedSim: Real-time animated GUI simulation (Issue #268, milestone complete 2026-02-04)
190196
- Physics-accurate rendering with velocity/acceleration visualization
191197
- Visual train movement with smooth interpolation
192-
- `runExampleGui` currently starts a fixed `1.0x` real-time synchronized `ShuntingLoop` for the built-in GUI example
193-
- `Frame` shows the animation `ControlPanel` and `EventTimelinePanel` in simulation mode and hides `StatusBar`
194-
- Interactive Goal 7 speed controls are not currently wired into `Frame` on this branch
198+
- Goal 7 speed control is built around `SimulationRunner`, which applies wall-clock throttling without changing event semantics
199+
- `SimulationController` owns lifecycle, persists the selected speed, and reapplies it on the next simulation start
200+
- `SimulationControlPanel` provides a `0.1x`-`10.0x` slider plus preset buttons up to `50x`
201+
- `StatusBar.updateSpeedIndicator()` shows the live multiplier whenever speed is not `1.0x`
202+
- `SimulationKeyBindings` installs global shortcuts (`1`-`5`, `+`, `-`, `Space`) while the frame is in simulation mode
203+
- `Space` currently toggles `SimulationRunner.isPaused` directly as Goal 8 pause-feature groundwork
195204
- See `docs/ANIMATION_ARCHITECTURE.md` for technical details
196205

197206
**XML Configuration:**

docs/SIMULATION_SPEED_CONTROL.md

Lines changed: 87 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
# Simulation Speed Control
22

3-
This branch does **not** expose interactive Goal 7 speed controls in the desktop GUI yet.
3+
Goal 7 adds live wall-clock speed control to the animated simulation GUI.
44

5-
What is currently available is a fixed real-time animated simulation mode for built-in GUI examples. This document describes the current user-visible behavior so the desktop UI is not documented more broadly than it is implemented.
5+
The control changes how fast events are presented to the user. It does **not** change simulation semantics, event ordering, or physics calculations.
66

7-
## Current Status
7+
## Overview
88

9-
The animated GUI currently provides:
9+
Use speed control when you want to:
1010

11-
- a top `ControlPanel` with **Time** and **Status**
12-
- an `EventTimelinePanel` for simulation events
13-
- real-time synchronization for the built-in GUI example path
11+
- slow the model down for teaching or demos
12+
- run near real time while watching train movement
13+
- fast-forward through long scenarios
14+
- pause temporarily while preparing for deeper Goal 8 debugging workflows
1415

15-
The animated GUI currently does **not** provide:
16+
Supported range:
1617

17-
- a speed slider
18-
- speed preset buttons
19-
- speed-related menu items
20-
- keyboard shortcuts for speed changes
21-
- pause/resume controls
22-
- a speed indicator in the status bar during simulation mode
18+
- **0.1x** minimum speed
19+
- **50x** highest one-click preset
20+
- **100x** absolute runner limit
2321

2422
## Quick Start
2523

26-
Launch the animated GUI example:
24+
Start the animated GUI:
2725

2826
```bash
2927
./gradlew runExampleGui
@@ -35,46 +33,94 @@ Or run the JAR directly after building:
3533
java -jar build/libs/interlockSim.jar exampleGui shuntingLoop 300
3634
```
3735

38-
## Current GUI Behavior
36+
For your own XML file, open the desktop UI and use **Simulation → Start...**.
3937

40-
When `exampleGui` starts, the application shows:
38+
When simulation mode is active, the GUI shows:
4139

42-
- the animated railway canvas
43-
- the top control panel with `Time` and `Status`
44-
- the event timeline
40+
- the animated control panel (`Time`, `Status`, `Stop`)
41+
- the speed control panel (`Speed` slider, presets, live speed label)
42+
- the status bar speed indicator when speed is not `1.0x`
4543

46-
During simulation mode, `Frame` hides the `StatusBar`, so there is no separate speed readout in the current UI.
44+
## GUI Controls
4745

48-
## What “Speed Control” Means on This Branch
46+
### Speed slider
4947

50-
For the built-in animated GUI example, `ExampleRegistry` creates `ShuntingLoop` with:
48+
- Range: **0.1x to 10.0x**
49+
- Step: **0.1x**
50+
- Best for fine adjustment while the simulation is already running
5151

52-
- `enableRealTimeSync = true`
53-
- `speedMultiplier = 1.0`
52+
### Preset buttons
5453

55-
That means the current GUI example runs at a fixed real-time rate intended for observation, not live user adjustment.
54+
The panel and **Simulation → Speed** menu provide these presets:
5655

57-
The console example path still runs without this GUI-specific real-time synchronization.
56+
- `0.1x`
57+
- `0.5x`
58+
- `1x`
59+
- `2x`
60+
- `5x`
61+
- `10x`
62+
- `50x`
63+
64+
`50x` is intentionally above the slider range. The slider stays clamped at its maximum visual position while the runner continues at `50x`.
65+
66+
### Status indicator
67+
68+
The status bar shows `Speed: X.Xx` whenever the current speed differs from `1.0x`. At the default speed the indicator is hidden to keep the bar uncluttered.
69+
70+
![Simulation speed control panel](images/simulation-speed-control-panel.png)
71+
72+
![Simulation speed status indicator](images/simulation-speed-status-indicator.png)
73+
74+
## Keyboard Shortcuts
75+
76+
Shortcuts are active in **simulation mode** while the application window has focus.
77+
78+
| Shortcut | Action |
79+
| --- | --- |
80+
| `1` | Set speed to `0.5x` |
81+
| `2` | Set speed to `1x` |
82+
| `3` | Set speed to `2x` |
83+
| `4` | Set speed to `5x` |
84+
| `5` | Set speed to `10x` |
85+
| `+` | Increase speed by `×1.5` |
86+
| `-` | Decrease speed by `÷1.5` |
87+
| `Space` | Pause or resume the active simulation |
88+
89+
Notes:
90+
91+
- On most keyboards, `+` is **Shift+`=`**.
92+
- Numpad `+` and `-` are also supported.
93+
- `Space` is the current Goal 8 integration point: it toggles the runner pause flag directly.
94+
95+
## Common Use Cases
96+
97+
- **Educational demo:** start at `0.5x` or `1x`, then drop to `0.1x` before a switch or semaphore change.
98+
- **Normal observation:** keep the model at `1x` or `2x` and watch the event timeline.
99+
- **Long scenario review:** jump to `10x` or `50x` to move through uneventful periods quickly.
100+
- **Pre-debug pause workflow:** press `Space`, inspect the current state, then resume.
58101

59102
## Technical Details
60103

61-
- `exampleGui` launches the animated desktop UI from `Main.runExampleGui(...)`.
62-
- The GUI example uses `ShuntingLoop(..., enableRealTimeSync = true, speedMultiplier = 1.0)`.
63-
- `Main.runExampleGui(...)` starts `context.run()` on a background thread.
64-
- `Frame` updates the animated `ControlPanel` time display with a 10 Hz Swing timer.
65-
- `Frame.switchToSimulationMode()` hides `StatusBar` and shows `ControlPanel` plus `EventTimelinePanel`.
66-
- A standalone `SimulationRunner` class exists in `desktop-ui`, but it is not wired into `Frame` or the current animated GUI flow on this branch.
104+
- Speed control is implemented by `SimulationRunner`.
105+
- The runner wraps `SimulationContext.run()` on a dedicated simulation thread.
106+
- Wall-clock throttling uses `sleep(simDelta / speedMultiplier)`.
107+
- `SimulationController` owns lifecycle, remembers the desired speed, and reapplies it on the next run.
108+
- Swing updates stay on the EDT; simulation execution stays off the EDT.
109+
- Pause blocks the simulation thread without advancing simulation time.
67110

68111
## Limitations
69112

70-
- No runtime speed adjustment is available in the desktop UI.
71-
- No keyboard shortcut support is available for speed changes or pause/resume.
72-
- No speed indicator is visible during simulation mode because `StatusBar` is hidden there.
73-
- The built-in animated GUI example is fixed to `1.0x` real-time synchronization.
113+
- The slider stops at **10x** even though the runner supports up to **100x**.
114+
- `50x` is available from presets and the menu; reaching speeds above that requires incremental shortcuts or programmatic control.
115+
- Speeds above roughly **10x** are useful for throughput, but animation becomes progressively harder to follow visually.
116+
- At **50x** and especially **100x**, small simulation deltas often round down to **0 ms sleep**, so execution becomes effectively CPU-bound.
117+
- In CPU-bound ranges, expect higher processor usage and less visually smooth animation than at `1x`.
118+
- Console-mode runs do not expose the GUI speed controls.
74119

75120
## Troubleshooting
76121

77-
- **I expected a speed slider or preset buttons:** they are not part of the current GUI on this branch.
78-
- **I cannot find a speed indicator:** the status bar is hidden in simulation mode.
79-
- **The simulation seems fixed to real time:** that is the current behavior of `exampleGui`.
80-
- **I need a faster run:** use the console example path when animation is not required.
122+
- **I cannot see the controls:** make sure you started the animated GUI, not the console example.
123+
- **The speed indicator disappeared:** that is expected at `1.0x`.
124+
- **`Space` does nothing:** a simulation must be running and the frame must have keyboard focus.
125+
- **The simulation feels too fast to follow:** use a preset such as `1x`, `0.5x`, or `0.1x`.
126+
- **CPU usage is high at very high speeds:** reduce speed to re-enable more wall-clock throttling.
3.87 KB
Loading
2.11 KB
Loading

0 commit comments

Comments
 (0)