3#include "../IBaseApi.h"
19 static Timer instance;
25 const auto now =
std::chrono::system_clock::now();
26 const auto exec_time = now +
std::chrono::seconds(delay_seconds);
32 int execution_counter,
bool async)
36 std::thread([callback, execution_interval, execution_counter]()
38 if (execution_counter == -1)
43 std::this_thread::sleep_for(
std::chrono::seconds(execution_interval));
47 for (
int i = 0; i < execution_counter; ++i)
50 std::this_thread::sleep_for(
std::chrono::seconds(execution_interval));
56 const auto now =
std::chrono::system_clock::now();
58 std::make_unique<
TimerFunc>(now, callback,
false, execution_counter, execution_interval));
69 const auto now =
std::chrono::system_clock::now();
75 if (data ==
nullptr)
continue;
106 return (now >= data->next_time && data->exec_once) ||
107 (!data->exec_once && data->execution_counter == 0);
virtual std::unique_ptr< ArkApi::ICommands > & GetCommands()=0
ARK_API void RecurringExecuteInternal(const std::function< void()> &callback, int execution_interval, int execution_counter, bool async)
ARK_API void DelayExecuteInternal(const std::function< void()> &callback, int delay_seconds)
static ARK_API Timer & Get()
std::vector< std::unique_ptr< TimerFunc > > timer_funcs_
virtual bool RemoveOnTimerCallback(const FString &id)=0
Removes an on-timer callback.
virtual void AddOnTimerCallback(const FString &id, const std::function< void()> &callback)=0
Added function will be called every second.
std::unique_ptr< IBaseApi > game_api
std::function< void()> callback
std::chrono::time_point< std::chrono::system_clock > next_time