-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Host-side RTA timer, IL mode, Nihilanth/changelevel autostop, etc.
- Loading branch information
1 parent
5c1ed5b
commit 6c5580a
Showing
20 changed files
with
2,201 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014-2020 Ivan Molodetskikh | ||
Copyright (c) 2015-2018 Chong Jiang Wei | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#ifdef CTIMER_H_RECURSE_GUARD | ||
#error Recursive header files inclusion detected in CTimer.h | ||
#else //CTIMER_H_RECURSE_GUARD | ||
|
||
#define CTIMER_H_RECURSE_GUARD | ||
|
||
#ifndef CTIMER_H_GUARD | ||
#define CTIMER_H_GUARD | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
|
||
class CTimer | ||
{ | ||
public: | ||
CTimer() | ||
{ | ||
Init(); | ||
} | ||
|
||
void Init() | ||
{ | ||
ResetTimer(); | ||
} | ||
|
||
void StartTimer() | ||
{ | ||
m_bStarted = true; | ||
if (!m_bRunning) | ||
{ | ||
m_startTime = std::chrono::steady_clock::now(); | ||
m_bRunning = true; | ||
} | ||
} | ||
|
||
void StopTimer() | ||
{ | ||
if (m_bRunning) | ||
{ | ||
auto now = std::chrono::steady_clock::now(); | ||
m_elapsedTime += std::chrono::duration_cast<std::chrono::milliseconds>(now - m_startTime).count(); | ||
m_bRunning = false; | ||
} | ||
} | ||
|
||
void ResetTimer() | ||
{ | ||
m_bRunning = false; | ||
m_elapsedTime = 0; | ||
} | ||
|
||
void SetTime(long long time) | ||
{ | ||
m_elapsedTime = time; | ||
} | ||
|
||
|
||
void SyncTimer(long long serverTime, bool stop) | ||
{ | ||
if (stop) | ||
{ | ||
StopTimer(); | ||
SetTime(serverTime); | ||
} | ||
else | ||
{ | ||
if (m_bRunning) | ||
{ | ||
auto now = std::chrono::steady_clock::now(); | ||
long long currentElapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_startTime).count() + m_elapsedTime; | ||
long long adjustment = serverTime - currentElapsedTime; | ||
m_startTime += std::chrono::milliseconds(adjustment); | ||
} | ||
else | ||
{ | ||
SetTime(serverTime); | ||
StartTimer(); | ||
} | ||
} | ||
} | ||
|
||
long long GetTime() const | ||
{ | ||
if (m_bRunning) | ||
{ | ||
auto now = std::chrono::steady_clock::now(); | ||
return m_elapsedTime + std::chrono::duration_cast<std::chrono::milliseconds>(now - m_startTime).count(); | ||
} | ||
return m_elapsedTime; | ||
} | ||
|
||
int GetMilliseconds() const | ||
{ | ||
return static_cast<int>(fmod(GetTime(), 1000.0)); | ||
} | ||
|
||
int GetSeconds() const | ||
{ | ||
double seconds = GetTime() / 1000.0; | ||
return static_cast<int>(fmod(seconds, 60.0)); | ||
} | ||
|
||
int GetMinutes() const | ||
{ | ||
double minutes = GetTime() / 60000.0; | ||
return static_cast<int>(fmod(minutes, 60.0)); | ||
} | ||
|
||
int GetHours() const | ||
{ | ||
double hours = GetTime() / 3600000.0; | ||
return static_cast<int>(fmod(hours, 24.0)); | ||
} | ||
|
||
int GetDays() const | ||
{ | ||
double days = GetTime() / 86400000.0; | ||
return static_cast<int>(days); | ||
} | ||
|
||
bool IsStopped() const | ||
{ | ||
return m_bRunning ? false : true; | ||
} | ||
|
||
private: | ||
std::chrono::time_point<std::chrono::steady_clock> m_startTime; | ||
long long m_elapsedTime; // elapsed time in milliseconds | ||
bool m_bRunning, m_bStarted; | ||
}; | ||
|
||
#else //!__cplusplus | ||
#error C++ compiler required to compile CTimer.h | ||
#endif //__cplusplus | ||
|
||
#endif //CTIMER_H_GUARD | ||
|
||
#undef CTIMER_H_RECURSE_GUARD | ||
#endif //CTIMER_H_RECURSE_GUARD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.