-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTicking.cpp
53 lines (46 loc) · 852 Bytes
/
Ticking.cpp
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
#include "Ticking.h"
struct TickList {
Ticking * ticker;
TickList * next = nullptr;
};
TickList * firstTicker = nullptr;
TickList * lastTicker = nullptr;
Ticking::Ticking()
{
TickList * newList = new TickList{
this
};
if (firstTicker == nullptr) {
firstTicker = newList;
lastTicker = newList;
}
else {
lastTicker->next = newList;
lastTicker = newList;
}
}
Ticking::~Ticking()
{
TickList * curMon = firstTicker;
TickList * lastTicker = nullptr;
while (curMon->ticker != this) {
lastTicker = curMon;
curMon = curMon->next;
}
if (firstTicker == curMon) {
firstTicker = nullptr;
lastTicker = nullptr;
}
else {
lastTicker->next = curMon->next;
delete curMon;
}
}
void Ticking::doTick()
{
TickList * curTick = firstTicker;
while (curTick != nullptr) {
curTick->ticker->tick();
curTick = curTick->next;
}
}