-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GameInitialized Message, Rework Task interface, add AutoRemovable…
… tasks
- Loading branch information
Showing
8 changed files
with
129 additions
and
43 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
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
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
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 |
---|---|---|
@@ -1,39 +1,57 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <vector> | ||
#include <typeinfo> | ||
|
||
typedef void (* TaskFunc)(); | ||
|
||
template<typename T> | ||
concept IsIntOrVoid = std::is_same<T, bool>::value || std::is_same<T, void>::value; | ||
|
||
|
||
template<IsIntOrVoid T> using TaskFuncT = T (*)(); | ||
|
||
using TaskFunc = TaskFuncT<void>; | ||
|
||
template<IsIntOrVoid T> | ||
class Task { | ||
TaskFunc task; | ||
TaskFuncT<T> task; | ||
|
||
public: | ||
Task(TaskFunc task) : task(task) {} | ||
void Run(); | ||
Task(TaskFuncT<T> task) noexcept: task(task) {} | ||
T Run() noexcept; | ||
}; | ||
|
||
class TaskManager { | ||
public: | ||
static bool HasTasks() { return !s_taskQueue.empty(); } | ||
static void Enqueue(Task* task); | ||
static Task* Enqueue(TaskFunc task); | ||
static bool IsTaskEnqueued(Task* task); | ||
static void Remove(Task* task); | ||
static bool HasTasks() noexcept { return !s_taskQueue.empty(); } | ||
template<IsIntOrVoid T> static void Enqueue(Task<T>* task); | ||
template<IsIntOrVoid T> static Task<T>* Enqueue(TaskFuncT<T> task); | ||
template<IsIntOrVoid T> static bool IsTaskEnqueued(Task<T>* task); | ||
template<IsIntOrVoid T> static void Remove(Task<T>* task); | ||
static void Run(); | ||
|
||
private: | ||
TaskManager(); | ||
template<IsIntOrVoid T> static std::vector<Task<T>*>& getQueue(Task<T>* task); | ||
|
||
static std::vector<Task<void>*> s_taskQueue; | ||
static std::vector<Task<bool>*> taskRemovableQueue; | ||
|
||
static std::vector<Task*> s_taskQueue; | ||
}; | ||
|
||
|
||
namespace PluginAPI{ | ||
void EnqueueT(Task* task); | ||
Task* EnqueueTask(TaskFunc task); | ||
bool IsTaskEnqueued(Task* task); | ||
void Remove(Task* task); | ||
void ReEnqueueTask(Task<void>* task); | ||
Task<void>* EnqueueTask(TaskFuncT<void> task); | ||
bool IsTaskEnqueued(Task<void>* task); | ||
void Remove(Task<void>* task); | ||
void ReEnqueueTask(Task<bool>* task); | ||
Task<bool>* EnqueueTask(TaskFuncT<bool> task); | ||
bool IsTaskEnqueued(Task<bool>* task); | ||
void Remove(Task<bool>* task); | ||
|
||
bool HasTasks(); | ||
} | ||
|
||
|
||
|
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