TrinityCore
Loading...
Searching...
No Matches
GameTime.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "GameTime.h"
19#include "Timer.h"
20#include "Timezone.h"
21#include "Types.h"
22#include "Util.h"
23#include "WowTime.h"
24
25namespace GameTime
26{
27namespace
28{
29 time_t GameTime;
30 uint32 GameMSTime;
31
32 SystemTimePoint GameTimeSystemPoint;
33 TimePoint GameTimeSteadyPoint;
34
35 tm DateTime;
36
37 WowTime UtcWow;
38 WowTime Wow;
39
40 time_t const StartTime = []
41 {
43 return time(nullptr);
44 }();
45}
46
47 time_t GetStartTime()
48 {
49 return StartTime;
50 }
51
52 time_t GetGameTime()
53 {
54 return GameTime;
55 }
56
58 {
59 return GameMSTime;
60 }
61
63 {
64 return GameTimeSystemPoint;
65 }
66
68 {
69 return GameTimeSteadyPoint;
70 }
71
72 template<typename Clock>
73 typename Clock::time_point GetTime()
74 {
75 static_assert(Trinity::dependant_false_v<Clock>, "Missing specialization for GetGameTimePoint");
76 return { };
77 }
78
79 template<>
84
85 template<>
90
92 {
93 return uint32(GameTime - StartTime);
94 }
95
96 tm const* GetDateAndTime()
97 {
98 return &DateTime;
99 }
100
102 {
103 return &UtcWow;
104 }
105
107 {
108 return &Wow;
109 }
110
112 {
113 GameTime = time(nullptr);
114 GameMSTime = getMSTime();
115 GameTimeSystemPoint = std::chrono::system_clock::now();
116 GameTimeSteadyPoint = std::chrono::steady_clock::now();
117 localtime_r(&GameTime, &DateTime);
118 UtcWow.SetUtcTimeFromUnixTime(GameTime);
119 Wow = UtcWow + Trinity::Timezone::GetSystemZoneOffsetAt(GameTimeSystemPoint);
120 }
121}
uint32_t uint32
Definition Define.h:154
std::chrono::system_clock::time_point SystemTimePoint
Definition Duration.h:41
std::chrono::steady_clock::time_point TimePoint
time_point shorthand typedefs
Definition Duration.h:40
uint32 getMSTime()
Definition Timer.h:33
WowTime const * GetWowTime()
Definition GameTime.cpp:106
SystemTimePoint GetTime< std::chrono::system_clock >()
Definition GameTime.cpp:80
WowTime const * GetUtcWowTime()
Definition GameTime.cpp:101
Clock::time_point GetTime()
Current chrono Clock time point.
Definition GameTime.cpp:73
void UpdateGameTimers()
Definition GameTime.cpp:111
SystemTimePoint GetSystemTime()
Current chrono system_clock time point.
Definition GameTime.cpp:62
TimePoint Now()
Current chrono steady_clock time point.
Definition GameTime.cpp:67
tm const * GetDateAndTime()
Definition GameTime.cpp:96
time_t GetGameTime()
Definition GameTime.cpp:52
time_t GetStartTime()
Definition GameTime.cpp:47
uint32 GetUptime()
Uptime (in secs)
Definition GameTime.cpp:91
TimePoint GetTime< std::chrono::steady_clock >()
Definition GameTime.cpp:86
uint32 GetGameTimeMS()
Definition GameTime.cpp:57
Minutes GetSystemZoneOffsetAt(SystemTimePoint date)
Definition Timezone.cpp:138