2017-05-31 09:45:12 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class Scheduler : public Component
|
|
|
|
{
|
|
|
|
public:
|
2022-05-05 10:03:14 -04:00
|
|
|
enum Pipeline
|
|
|
|
{
|
|
|
|
ASYNC,
|
|
|
|
RENDERER,
|
|
|
|
SERVER,
|
|
|
|
CLIENT,
|
|
|
|
MAIN,
|
|
|
|
QUIT,
|
|
|
|
COUNT,
|
|
|
|
};
|
2017-05-31 09:45:12 -04:00
|
|
|
|
|
|
|
Scheduler();
|
|
|
|
|
2017-07-03 09:07:47 -04:00
|
|
|
void preDestroy() override;
|
|
|
|
|
2022-06-13 13:59:32 -04:00
|
|
|
static void Schedule(const std::function<bool()>& callback, Pipeline type,
|
2022-05-05 10:03:14 -04:00
|
|
|
std::chrono::milliseconds delay = 0ms);
|
2022-06-13 13:59:32 -04:00
|
|
|
static void Loop(const std::function<void()>& callback, Pipeline type,
|
2022-05-05 10:03:14 -04:00
|
|
|
std::chrono::milliseconds delay = 0ms);
|
2022-06-13 13:59:32 -04:00
|
|
|
static void Once(const std::function<void()>& callback, Pipeline type,
|
2022-05-05 10:03:14 -04:00
|
|
|
std::chrono::milliseconds delay = 0ms);
|
2022-06-13 13:59:32 -04:00
|
|
|
static void OnGameInitialized(const std::function<void()>& callback, Pipeline type,
|
2022-05-05 10:03:14 -04:00
|
|
|
std::chrono::milliseconds delay = 0ms);
|
|
|
|
static void OnGameShutdown(const std::function<void()>& callback);
|
2017-05-31 09:45:12 -04:00
|
|
|
|
|
|
|
private:
|
2022-05-05 10:03:14 -04:00
|
|
|
struct Task
|
2017-05-31 09:45:12 -04:00
|
|
|
{
|
2022-05-05 10:03:14 -04:00
|
|
|
std::function<bool()> handler{};
|
|
|
|
std::chrono::milliseconds interval{};
|
|
|
|
std::chrono::high_resolution_clock::time_point lastCall{};
|
2017-05-31 09:45:12 -04:00
|
|
|
};
|
|
|
|
|
2022-05-05 10:03:14 -04:00
|
|
|
using taskList = std::vector<Task>;
|
2017-07-03 09:07:47 -04:00
|
|
|
|
2022-05-05 10:03:14 -04:00
|
|
|
class TaskPipeline
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void add(Task&& task);
|
|
|
|
void execute();
|
2017-05-31 09:45:12 -04:00
|
|
|
|
2022-05-05 10:03:14 -04:00
|
|
|
private:
|
|
|
|
Utils::Concurrency::Container<taskList> newCallbacks_;
|
|
|
|
Utils::Concurrency::Container<taskList, std::recursive_mutex> callbacks_;
|
|
|
|
|
|
|
|
void mergeCallbacks();
|
|
|
|
};
|
2017-05-31 09:45:12 -04:00
|
|
|
|
2022-05-05 10:03:14 -04:00
|
|
|
static volatile bool Kill;
|
|
|
|
static std::thread Thread;
|
|
|
|
static TaskPipeline Pipelines[];
|
2017-07-03 09:07:47 -04:00
|
|
|
|
2022-05-05 10:03:14 -04:00
|
|
|
static void Execute(Pipeline type);
|
2017-05-31 10:09:41 -04:00
|
|
|
|
2022-07-02 06:17:08 -04:00
|
|
|
static void ScrPlace_EndFrame_Hk();
|
2022-05-05 10:03:14 -04:00
|
|
|
static void ServerFrame_Hk();
|
|
|
|
static void ClientFrame_Hk(int localClientNum);
|
|
|
|
static void MainFrame_Hk();
|
|
|
|
static void SysSetBlockSystemHotkeys_Hk(int block);
|
2017-05-31 09:45:12 -04:00
|
|
|
};
|
|
|
|
}
|