-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeManager.cpp
115 lines (94 loc) · 1.91 KB
/
TimeManager.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "stdafx.h"
#include "TimeManager.h"
TimeManager::TimeManager()
{
}
TimeManager::~TimeManager()
{
}
HRESULT TimeManager::initialize()
{
_timer = new Timer;
_timer->initialize();
return S_OK;
}
void TimeManager::release()
{
if (_timer != NULL)
{
//_timer->release();
SAFE_DELETE(_timer);
}
for (_miCT = _mCT.begin(); _miCT != _mCT.end();)
{
_miCT = _mCT.erase(_miCT);
}
_mCT.clear();
}
void TimeManager::update(float lock)
{
if(_timer != NULL) _timer->tick(lock);
}
void TimeManager::render(HDC hdc)
{
char str[128];
std::string strFrame;
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(0, 0, 0));
#ifdef _DEBUG
if(_timer != NULL)
{
sprintf_s(str, "Frame per Second : %d", _timer->getFrameRate());
TextOut(hdc, 10, 10, str, strlen(str));
sprintf_s(str, "World Time : %f", _timer->getWorldTime());
TextOut(hdc, 10, 30, str, strlen(str));
sprintf_s(str, "Elapsed Time : %f", _timer->getElapsedTime());
TextOut(hdc, 10, 50, str, strlen(str));
}
#else
//if (_timer != NULL)
//{
// sprintf_s(str, "Frame per Second : %f", _timer->getFrameRate());
// TextOut(hdc, 10, 10, str, strlen(str));
//}
#endif
}
TimeManager::CheckTimer* TimeManager::addTimer(std::string key)
{
static int i = 0;
std::string k = key;
TimeManager::CheckTimer* timer = NULL;
if (k.empty())
{
k = "my standard timer " + to_string(i++);
}
else
{
timer = findTimer(k);
}
if (timer == NULL)
{
timer = new TimeManager::CheckTimer;
_mCT.insert(std::make_pair(k, timer));
}
return timer;
}
TimeManager::CheckTimer* TimeManager::findTimer(std::string key)
{
MICheckTimer iter = _mCT.find(key);
TimeManager::CheckTimer* timer = NULL;
if (iter != _mCT.end())
{
timer = iter->second;
}
return timer;
}
bool TimeManager::checkTime(std::string key, float time)
{
TimeManager::CheckTimer* timer = findTimer(key);
if (timer == NULL)
{
timer = addTimer();
}
return timer->checkTime(time);
}