summaryrefslogtreecommitdiff
path: root/src/T2DLL/LPeriodical.cpp
blob: 429b8ece50a7e1035bf971fd79244edb313a417f (plain)
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
#include "StdAfx.h"
#include "LArray.h"
#include "LPeriodical.h"

/*static*/ LArray* LPeriodical::sIdlerQ = NULL;
/*static*/ LArray* LPeriodical::sRepeaterQ = NULL;

LPeriodical::LPeriodical() {
}

/*virtual*/ LPeriodical::~LPeriodical() {
	StopIdling();
	StopRepeating();
}

/*virtual*/ void LPeriodical::StartIdling() {
	if (!sIdlerQ)
		sIdlerQ = new LArray;

	// how the hell is this supposed to work??
	// surely it should pass &this...
	if (sIdlerQ->FetchIndexOf(this) == 0)
		sIdlerQ->Add(this);
}

/*virtual*/ void LPeriodical::StopIdling() {
	if (sIdlerQ)
		sIdlerQ->Remove(this);
}

/*static*/ void LPeriodical::DevoteTimeToIdlers() {
	if (sIdlerQ) {
		LArrayIterator iter(*sIdlerQ);
		LPeriodical *p;

		while (iter.Next(&p))
			p->SpendTime();
	}
}

/*virtual*/ void LPeriodical::StartRepeating() {
	if (!sRepeaterQ)
		sRepeaterQ = new LArray;

	// how the hell is this supposed to work??
	// surely it should pass &this...
	if (sRepeaterQ->FetchIndexOf(this) == 0)
		sRepeaterQ->Add(this);
}

/*virtual*/ void LPeriodical::StopRepeating() {
	if (sRepeaterQ)
		sRepeaterQ->Remove(this);
}

/*static*/ void LPeriodical::DevoteTimeToRepeaters() {
	if (sRepeaterQ) {
		LArrayIterator iter(*sRepeaterQ);
		LPeriodical *p;

		while (iter.Next(&p))
			p->SpendTime();
	}
}

/*static*/ void LPeriodical::DeleteIdlerAndRepeaterQueues() {
	delete sIdlerQ;
	sIdlerQ = NULL;

	delete sRepeaterQ;
	sRepeaterQ = NULL;
}