-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobals.h
More file actions
64 lines (53 loc) · 2.03 KB
/
Copy pathglobals.h
File metadata and controls
64 lines (53 loc) · 2.03 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
// globals.h - shared types, timing, and a small activity log for the
// professor / student / friend trio. All three modules live on the same
// Runtime, so the mailbox is touched on a single pump thread and needs no
// locking. The activity log (recent professor/friend/student lines) is read
// by the render thread, so it carries its own mutex.
#pragma once
#include "uniflow.hpp"
#include <chrono>
#include <mutex>
#include <string>
#include <vector>
using namespace std::chrono_literals;
struct Message
{
enum class Kind { Assignment, Play };
Kind kind = Kind::Assignment;
std::string name;
int need_ability = 0; // Assignment: required ability to do it
int need_time = 0; // Assignment: hours of actual work
int play_hours = 0; // Play: hours of playing
};
class GlobalConfig
{
public:
// One simulated hour on the pool. Keeps the demo finite.
static constexpr int kHourMs = 8;
// At or above this stress, the student must sleep before training.
static constexpr int kStressMax = 10;
static constexpr uniflow::Duration kProfMinGap = 200ms;
static constexpr uniflow::Duration kProfMaxGap = 800ms;
static constexpr uniflow::Duration kFriendMinGap = 350ms;
static constexpr uniflow::Duration kFriendMaxGap = 1100ms;
GlobalConfig() = delete;
};
// Quit signal: main sets this after the user presses Enter, and every flow's
// steps check it so they can return Done() and let WaitUntilIdle() return.
class GlobalEnv
{
public:
static bool Stop();
static void RequestStop();
GlobalEnv() = delete;
};
// Recent-activity log. The pump-thread steps append lines (the old stdout
// prints would corrupt the ANSI dashboard); the render thread reads the last
// few for the "recent activity" panel. Hence the mutex.
class GlobalLog
{
public:
static void Add(const std::string& line);
static std::vector<std::string> Recent(std::size_t n);
GlobalLog() = delete;
};