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 "Util.h"
21
22namespace GameTime
23{
24 time_t const StartTime = time(nullptr);
25
26 time_t GameTime = time(nullptr);
28
29 SystemTimePoint GameTimeSystemPoint = SystemTimePoint::min();
30 TimePoint GameTimeSteadyPoint = TimePoint::min();
31
33
34 time_t GetStartTime()
35 {
36 return StartTime;
37 }
38
39 time_t GetGameTime()
40 {
41 return GameTime;
42 }
43
45 {
46 return GameMSTime;
47 }
48
50 {
52 }
53
55 {
57 }
58
59 template<typename Clock>
60 typename Clock::time_point GetTime()
61 {
62 static_assert(!std::is_same<Clock, Clock>::value, "Missing specialization for GetGameTimePoint");
63 }
64
65 template<>
67 {
68 return GetSystemTime();
69 }
70
71 template<>
73 {
74 return Now();
75 }
76
78 {
79 return uint32(GameTime - StartTime);
80 }
81
82 tm const* GetDateAndTime()
83 {
84 return &DateTime;
85 }
86
88 {
89 GameTime = time(nullptr);
91 GameTimeSystemPoint = std::chrono::system_clock::now();
92 GameTimeSteadyPoint = std::chrono::steady_clock::now();
93 localtime_r(&GameTime, &DateTime);
94 }
95}
#define TC_GAME_API
Definition: Define.h:124
uint32_t uint32
Definition: Define.h:143
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
TC_GAME_API SystemTimePoint GetTime< std::chrono::system_clock >()
Definition: GameTime.cpp:66
Clock::time_point GetTime()
Current chrono Clock time point.
Definition: GameTime.cpp:60
void UpdateGameTimers()
Definition: GameTime.cpp:87
SystemTimePoint GetSystemTime()
Current chrono system_clock time point.
Definition: GameTime.cpp:49
TC_GAME_API TimePoint GetTime< std::chrono::steady_clock >()
Definition: GameTime.cpp:72
tm DateTime
Definition: GameTime.cpp:32
TimePoint Now()
Current chrono steady_clock time point.
Definition: GameTime.cpp:54
tm const * GetDateAndTime()
Definition: GameTime.cpp:82
time_t GetGameTime()
Definition: GameTime.cpp:39
TimePoint GameTimeSteadyPoint
Definition: GameTime.cpp:30
time_t GameTime
Definition: GameTime.cpp:26
time_t GetStartTime()
Definition: GameTime.cpp:34
uint32 GetUptime()
Uptime (in secs)
Definition: GameTime.cpp:77
SystemTimePoint GameTimeSystemPoint
Definition: GameTime.cpp:29
uint32 GetGameTimeMS()
Definition: GameTime.cpp:44
time_t const StartTime
Definition: GameTime.cpp:24
uint32 GameMSTime
Definition: GameTime.cpp:27