-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameTime.cpp
More file actions
72 lines (61 loc) · 1.3 KB
/
Copy pathGameTime.cpp
File metadata and controls
72 lines (61 loc) · 1.3 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
#include "GameTime.h"
#include "InputManager.h"
GameTime::GameTime()
{
m_nHourOffset = 0;
m_nMinuteOffset = 0;
}
void GameTime::updateToSystemTime()
{
time_t t = time(0);
struct tm * now = localtime( & t );
if (InputManager::getInstance()->isKeyDownOnce('-'))
{
m_nHourOffset -= 1;
}
if (InputManager::getInstance()->isKeyDownOnce('='))
{
m_nHourOffset += 1;
}
if (InputManager::getInstance()->isKeyDown('['))
{
m_nMinuteOffset -= 1.0;
}
if (InputManager::getInstance()->isKeyDown(']'))
{
m_nMinuteOffset += 1.0;
}
m_datetime = boost::posix_time::second_clock::local_time() + boost::posix_time::hours(m_nHourOffset) + boost::posix_time::minutes((long)m_nMinuteOffset);
}
int GameTime::getYear()
{
return m_datetime.date().year();
}
int GameTime::getMonth()
{
return m_datetime.date().month();
}
int GameTime::getDay()
{
return m_datetime.date().day();
}
int GameTime::getHours()
{
return m_datetime.time_of_day().hours();
}
int GameTime::getMinutes()
{
return m_datetime.time_of_day().minutes();
}
int GameTime::getSeconds()
{
return m_datetime.time_of_day().seconds();
}
int GameTime::getMilliseconds()
{
return m_datetime.time_of_day().total_milliseconds();
}
int GameTime::getSecondsSinceMidnight()
{
return getHours()*60*60+getMinutes()*60+getSeconds();
}