-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.h
More file actions
79 lines (70 loc) · 2.44 KB
/
Copy pathapp.h
File metadata and controls
79 lines (70 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// app.h - the Runtime plus every module. Two-phase init, same shape as the
// other reference examples: members construct first (Phase 1), then Start()
// launches the flows (Phase 2).
//
// REFERENCE NOTE: one Runtime, one pump thread, six flows (five runners + the
// renderer). They cooperate without a single lock between them.
#pragma once
#include "uf_runner.h"
#include "uf_view.h"
#include "uniflow.hpp"
#include <memory>
// Silent observer: this app OWNS the console (the dashboard), so the default
// ConsoleObserver's trace output must be suppressed. IUniflowObserver's hooks
// are all empty by default, so an empty subclass prints nothing.
struct SilentObserver : uniflow::IUniflowObserver
{
};
class App
{
public:
static App& inst()
{
static App a;
return a;
}
// Phase 1: construct. Order is renderer then runners; ctor bodies only touch
// their own state, so cross-module order does not matter here.
uniflow::Runtime rt{MakeOpts()};
Flow_View view{rt};
Flow_Runner atlas{rt, "Atlas", 0, 3800.0};
Flow_Runner bolt{rt, "Bolt", 1, 2600.0};
Flow_Runner comet{rt, "Comet", 2, 4600.0};
Flow_Runner dash{rt, "Dash", 3, 3200.0};
Flow_Runner echo{rt, "Echo", 4, 5200.0};
// Phase 2: launch every task. Each StartFlow() puts one task on the pump.
void Start()
{
view.ctx_draw_.StartFlow();
atlas.ctx_run_.StartFlow();
bolt.ctx_run_.StartFlow();
comet.ctx_run_.StartFlow();
dash.ctx_run_.StartFlow();
echo.ctx_run_.StartFlow();
}
void Shutdown()
{
sim::g_stop.store(true); // every step checks this and returns Done()
rt.Wake(); // nudge the pump out of any sleep
atlas.WaitUntilIdle();
bolt.WaitUntilIdle();
comet.WaitUntilIdle();
dash.WaitUntilIdle();
echo.WaitUntilIdle();
view.WaitUntilIdle();
}
private:
App() = default;
static uniflow::Runtime::Opts MakeOpts()
{
using namespace std::chrono_literals;
uniflow::Runtime::Opts opts;
opts.observer = std::make_unique<SilentObserver>();
// All-Stay rounds (everyone polling) should be short so motion and the
// ~30 fps renderer stay smooth.
opts.config.step_interval_sleep_ms = 0ms;
opts.config.stay_sleep_ms = 5ms;
opts.config.idle_sleep_ms = 1ms;
return opts;
}
};