Language: 한국어 | English
A console simulator where several flows share one pump thread and one logical clock (VirtualClock). Five runners lap their tracks while the user controls the passage of logical time with commands.
uniflow simulator v1.0.0
------------------------------------------------------------
[RUNNING] speed x2.00 pause | resume | speed <n> | quit
------------------------------------------------------------
Atlas lap 3 [##############......] 72% Step2_Move
Bolt lap 5 [####................] 20% Step1_Gate
Comet lap 2 [####################] 100% Step3_Rest
Dash lap 4 [#########...........] 47% Step2_Move
Echo lap 1 [##......] ...
------------------------------------------------------------
>
This example is about time control and single-thread cooperation.
-
VirtualClock - scale / freeze. Runner progress is measured against
Runtime::clock()(the logical clock), not wall time.pausecallsclock().Freeze()once to stop every runner at the same instant;speed <n>callsclock().SetScale(n)once to stretch or compress the whole field. There is no per-flow plumbing - one clock governs them all. (seeVElapsedMsin uf_runner.cpp, command handling in main.cpp) -
One thread, no locks. Five runners plus the renderer are six flows on the same pump. A runner writes its row and the renderer reads it, but they share the thread and never overlap - which is why snapshot.h has no mutex (see the header note).
-
The renderer is just a flow.
Flow_Viewin uf_view.cpp is another module on the same pump. Its frame cadence uses a real-timeUFTimer: when the logical clock is frozen (pause), the runners stop yet the dashboard keeps redrawing and shows[PAUSED]. -
Console / ANSI render pattern. console.h / console.cpp is a dependency-free ANSI helper (works on Linux terminals and Windows Terminal / Windows 10+). The same pattern is reused by the Linux console renderers of city_traffic and pick_and_place.
| File | Role |
|---|---|
| uf_runner.h / .cpp | One runner. Loops Step1_Gate -> Step2_Move -> Step3_Rest forever (one lap per loop). Progress driven by the VirtualClock. |
| uf_view.h / .cpp | Dashboard renderer flow. Draws the snapshot at ~30 real fps. |
| snapshot.h / .cpp | Runner -> renderer hand-off (lock-free; reason in the header note). |
| console.h / .cpp | Reusable ANSI console helper. |
| app.h | Runtime + every module, two-phase init, silent observer. |
| main.cpp | stdin command loop (pause/resume/speed/quit). |
| Input | Effect |
|---|---|
pause |
Freeze logical time (runners stop, dashboard stays live) |
resume |
Resume logical time |
speed <n> |
Scale logical time (n > 0; 0.5 = half, 4 = 4x) |
quit |
Stop and exit |
Console only, nothing extra to install.
Linux / macOS (g++ or clang++):
cd cpp/examples/simulator
g++ -std=c++17 -O2 -I../.. *.cpp -o simulator -pthread
./simulatorWindows (MSVC, x64 Native Tools prompt):
cd cpp\examples\simulator
cl /std:c++17 /EHsc /O2 /I..\.. *.cpp /Fe:simulator.exe
simulator.exeNote: this demo assumes an ANSI terminal. On Windows,
console::EnableAnsi()turns on the console's VT processing (Windows Terminal recommended).