完成复活

This commit is contained in:
Huoji's
2023-10-04 22:49:16 +08:00
parent 06acf8b24d
commit dd0456b064
9 changed files with 162 additions and 43 deletions

View File

@@ -1,7 +1,8 @@
#include "timer.h"
namespace ScriptApis {
extern auto TimerCallBack(_GameTimer* timer) -> void;
};
extern auto TimerCallBack(_GameTimer* timer) -> void;
extern auto RunTickCallBack(_GameTickRunTime* timer) -> void;
}; // namespace ScriptApis
namespace GameTimer {
std::shared_mutex mutex_timerList;
std::vector<_GameTimer*> timerList;
@@ -27,7 +28,8 @@ auto ExcuteTimers() -> void {
if ((*it)->m_flLastExecute == -1) {
(*it)->m_flLastExecute = global::m_flUniversalTime;
}
if ((*it)->m_flLastExecute + (*it)->m_flTime <= global::m_flUniversalTime) {
if ((*it)->m_flLastExecute + (*it)->m_flTime <=
global::m_flUniversalTime) {
ScriptApis::TimerCallBack(*it);
if ((*it)->m_bRepeat) {
(*it)->m_flLastExecute = global::m_flUniversalTime;
@@ -41,3 +43,26 @@ auto ExcuteTimers() -> void {
}
}
}; // namespace GameTimer
namespace GameTickRunTime {
std::shared_mutex mutex_tickRunList;
std::vector<_GameTickRunTime*> tickRunList;
auto AddTickFunction(_GameTickRunTime* timer) -> void {
std::unique_lock<std::shared_mutex> lock(mutex_tickRunList);
tickRunList.push_back(timer);
};
auto CleanUpTickFunctions() -> void {
std::unique_lock<std::shared_mutex> lock(mutex_tickRunList);
for (auto it = tickRunList.begin(); it != tickRunList.end();) {
delete (*it);
it = tickRunList.erase(it);
}
};
auto ExcuteTickFunctions() -> void {
std::shared_lock<std::shared_mutex> lock(mutex_tickRunList);
for (auto it = tickRunList.begin(); it != tickRunList.end();) {
ScriptApis::RunTickCallBack(*it);
delete (*it);
it = tickRunList.erase(it);
}
}
}; // namespace GameTickRunTime