TrinityCore
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 "Util.h"
22#include "WowTime.h"
23
24namespace GameTime
25{
26 time_t const StartTime = time(nullptr);
27
28 time_t GameTime = time(nullptr);
30
31 SystemTimePoint GameTimeSystemPoint = SystemTimePoint::min();
32 TimePoint GameTimeSteadyPoint = TimePoint::min();
33
35
38
39 time_t GetStartTime()
40 {
41 return StartTime;
42 }
43
44 time_t GetGameTime()
45 {
46 return GameTime;
47 }
48
50 {
51 return GameMSTime;
52 }
53
55 {
57 }
58
60 {
62 }
63
64 template<typename Clock>
65 typename Clock::time_point GetTime()
66 {
67 static_assert(!std::is_same<Clock, Clock>::value, "Missing specialization for GetGameTimePoint");
68 }
69
70 template<>
71 TC_GAME_API SystemTimePoint GetTime<std::chrono::system_clock>()
72 {
73 return GetSystemTime();
74 }
75
76 template<>
77 TC_GAME_API TimePoint GetTime<std::chrono::steady_clock>()
78 {
79 return Now();
80 }
81
83 {
84 return uint32(GameTime - StartTime);
85 }
86
87 tm const* GetDateAndTime()
88 {
89 return &DateTime;
90 }
91
93 {
94 return &UtcWow;
95 }
96
98 {
99 return &Wow;
100 }
101
103 {
104 GameTime = time(nullptr);
106 GameTimeSystemPoint = std::chrono::system_clock::now();
107 GameTimeSteadyPoint = std::chrono::steady_clock::now();
108 localtime_r(&GameTime, &DateTime);
111 }
112}
#define TC_GAME_API
Definition: Define.h:123
uint32_t uint32
Definition: Define.h:142
std::chrono::system_clock::time_point SystemTimePoint
Definition: Duration.h:42
std::chrono::steady_clock::time_point TimePoint
time_point shorthand typedefs
Definition: Duration.h:41
uint32 getMSTime()
Definition: Timer.h:33
void SetUtcTimeFromUnixTime(std::time_t unixTime)
Definition: WowTime.cpp:86
WowTime UtcWow
Definition: GameTime.cpp:36
WowTime const * GetWowTime()
Definition: GameTime.cpp:97
WowTime const * GetUtcWowTime()
Definition: GameTime.cpp:92
Clock::time_point GetTime()
Current chrono Clock time point.
Definition: GameTime.cpp:65
void UpdateGameTimers()
Definition: GameTime.cpp:102
SystemTimePoint GetSystemTime()
Current chrono system_clock time point.
Definition: GameTime.cpp:54
tm DateTime
Definition: GameTime.cpp:34
TimePoint Now()
Current chrono steady_clock time point.
Definition: GameTime.cpp:59
WowTime Wow
Definition: GameTime.cpp:37
tm const * GetDateAndTime()
Definition: GameTime.cpp:87
time_t GetGameTime()
Definition: GameTime.cpp:44
TimePoint GameTimeSteadyPoint
Definition: GameTime.cpp:32
time_t GameTime
Definition: GameTime.cpp:28
time_t GetStartTime()
Definition: GameTime.cpp:39
uint32 GetUptime()
Uptime (in secs)
Definition: GameTime.cpp:82
SystemTimePoint GameTimeSystemPoint
Definition: GameTime.cpp:31
uint32 GetGameTimeMS()
Definition: GameTime.cpp:49
time_t const StartTime
Definition: GameTime.cpp:26
uint32 GameMSTime
Definition: GameTime.cpp:29
Minutes GetSystemZoneOffsetAt(SystemTimePoint date)
Definition: Timezone.cpp:132