Skip to content

Commit

Permalink
Create a Task2Interface for better handling the new features for Task…
Browse files Browse the repository at this point in the history
…s exeuction. Fix some issues
  • Loading branch information
llde committed Sep 2, 2023
1 parent 23939fc commit d062910
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 19 deletions.
2 changes: 2 additions & 0 deletions obse/obse/EventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,8 @@ UInt32 EventIDForMessage(UInt32 msgID)
return kEventID_ExitToMainMenu;
case OBSEMessagingInterface::kMessage_PostLoadGame:
return kEventID_PostLoadGame;
case OBSEMessagingInterface::kMessage_GameInitialized:
_MESSAGE("kMessage_GameInitialized Unhandled"); //FIXME
default:
return kEventID_INVALID;
}
Expand Down
19 changes: 16 additions & 3 deletions obse/obse/PluginAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum
kInterface_Tasks,
kInterface_Input,
kInterface_EventManager,
kInterface_Tasks2,
kInterface_Max
};

Expand Down Expand Up @@ -181,7 +182,7 @@ struct OBSEMessagingInterface
void * data;
};

typedef void (* EventCallback)(Message* msg);
using EventCallback = void (*)(Message*);

enum {
kVersion = 1
Expand Down Expand Up @@ -593,11 +594,23 @@ struct OBSESerializationInterface
*/
#if OBLIVION
struct OBSETasksInterface {
Task<void>* (*EnqueueTask)(TaskFunc f);
Task<void>* (*EnqueueTask)(TaskFunc<void> f);
void (*RemoveTask)(Task<void>* f);
bool (*IsTaskPresent)(Task<void>* f);
};

struct OBSETasks2Interface {
enum {
kVersion = 1,
};


UInt32 version;
Task<void>* (*EnqueueTask)(TaskFunc<void> f);
void (*RemoveTask)(Task<void>* f);
bool (*IsTaskPresent)(Task<void>* f);
void (*ReEnqueueTask)(Task<void>* f);
Task<bool>* (*EnqueueTaskRemovable)(TaskFuncT<bool> f);
Task<bool>* (*EnqueueTaskRemovable)(TaskFunc<bool> f);
void (*RemoveTaskRemovable)(Task<bool>* f);
bool (*IsTaskPresentRemovable)(Task<bool>* f);
void (*ReEnqueueTaskRemovable)(Task<bool>* f);
Expand Down
11 changes: 11 additions & 0 deletions obse/obse/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ static OBSETasksInterface g_TasksInterface = {
PluginAPI::EnqueueTask,
PluginAPI::Remove,
PluginAPI::IsTaskEnqueued,
};

static OBSETasks2Interface g_Tasks2Interface = {
OBSETasks2Interface::kVersion,
PluginAPI::EnqueueTask,
PluginAPI::Remove,
PluginAPI::IsTaskEnqueued,
PluginAPI::ReEnqueueTask,
PluginAPI::EnqueueTask,
PluginAPI::Remove,
Expand All @@ -88,6 +95,7 @@ static OBSETasksInterface g_TasksInterface = {
PluginAPI::HasTasks
};


static OBSEInputInterface g_InputInterface = {
PluginAPI::DisableKey,
PluginAPI::EnableKey,
Expand Down Expand Up @@ -407,6 +415,9 @@ void * PluginManager::QueryInterface(UInt32 id)
case kInterface_Tasks:
result = &g_TasksInterface;
break;
case kInterface_Tasks2:
result = &g_Tasks2Interface;
break;
case kInterface_Input:
result = &g_InputInterface;
break;
Expand Down
10 changes: 5 additions & 5 deletions obse/obse/Tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ void Task<void>::Run() noexcept {
///TODO put CS in place.
template<IsIntOrVoid T>
void TaskManager::Enqueue(Task<T>* task) {
auto queue = TaskManager::getQueue(task);
auto& queue = TaskManager::getQueue(task);
queue.push_back(task);
}

template<IsIntOrVoid T>
Task<T>* TaskManager::Enqueue(TaskFuncT<T> task) {
Task<T>* TaskManager::Enqueue(TaskFunc<T> task) {
Task<T>* func = new Task(task);
auto queue = TaskManager::getQueue(func);
auto& queue = TaskManager::getQueue(func);
queue.push_back(func);
return func;
}
Expand Down Expand Up @@ -94,11 +94,11 @@ void TaskManager::Run() {

namespace PluginAPI {
void ReEnqueueTask(Task<void>* task) { return TaskManager::Enqueue(task); }
Task<void>* EnqueueTask(TaskFuncT<void> task) { return TaskManager::Enqueue(task); }
Task<void>* EnqueueTask(TaskFunc<void> task) { return TaskManager::Enqueue(task); }
bool IsTaskEnqueued(Task<void>* task) { return TaskManager::IsTaskEnqueued(task); }
void Remove(Task<void>* toRemove) { return TaskManager::Remove(toRemove); }
void ReEnqueueTask(Task<bool>* task) { return TaskManager::Enqueue(task); }
Task<bool>* EnqueueTask(TaskFuncT<bool> task) { return TaskManager::Enqueue(task); }
Task<bool>* EnqueueTask(TaskFunc<bool> task) { return TaskManager::Enqueue(task); }
bool IsTaskEnqueued(Task<bool>* task) { return TaskManager::IsTaskEnqueued(task); }
void Remove(Task<bool>* toRemove) { return TaskManager::Remove(toRemove); }

Expand Down
15 changes: 7 additions & 8 deletions obse/obse/Tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@ template<typename T>
concept IsIntOrVoid = std::is_same<T, bool>::value || std::is_same<T, void>::value;


template<IsIntOrVoid T> using TaskFuncT = T (*)();
template<IsIntOrVoid T> using TaskFunc = T (*)();

using TaskFunc = TaskFuncT<void>;

template<IsIntOrVoid T>
class Task {
TaskFuncT<T> task;
TaskFunc<T> task;

public:
Task(TaskFuncT<T> task) noexcept: task(task) {}
Task(TaskFunc<T> task) noexcept: task(task) {}
T Run() noexcept;
};

class TaskManager {
public:
static bool HasTasks() noexcept { return !s_taskQueue.empty(); }
static bool HasTasks() noexcept { return !s_taskQueue.empty() || !taskRemovableQueue.empty(); }
template<IsIntOrVoid T> static void Enqueue(Task<T>* task);
template<IsIntOrVoid T> static Task<T>* Enqueue(TaskFuncT<T> task);
template<IsIntOrVoid T> static Task<T>* Enqueue(TaskFunc<T> task);
template<IsIntOrVoid T> static bool IsTaskEnqueued(Task<T>* task);
template<IsIntOrVoid T> static void Remove(Task<T>* task);
static void Run();
Expand All @@ -42,11 +41,11 @@ class TaskManager {

namespace PluginAPI{
void ReEnqueueTask(Task<void>* task);
Task<void>* EnqueueTask(TaskFuncT<void> task);
Task<void>* EnqueueTask(TaskFunc<void> task);
bool IsTaskEnqueued(Task<void>* task);
void Remove(Task<void>* task);
void ReEnqueueTask(Task<bool>* task);
Task<bool>* EnqueueTask(TaskFuncT<bool> task);
Task<bool>* EnqueueTask(TaskFunc<bool> task);
bool IsTaskEnqueued(Task<bool>* task);
void Remove(Task<bool>* task);

Expand Down
4 changes: 3 additions & 1 deletion obse/obse/obse.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@
<ForcedIncludeFiles>StdAfx.h;obse_common/obse_prefix.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<ControlFlowGuard>false</ControlFlowGuard>
<LanguageStandard>stdcpplatest</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<ConformanceMode>true</ConformanceMode>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
</ClCompile>
<Link>
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
Expand Down Expand Up @@ -127,6 +128,7 @@
<ConformanceMode>true</ConformanceMode>
<EnableModules>true</EnableModules>
<ExceptionHandling>Sync</ExceptionHandling>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand Down
6 changes: 4 additions & 2 deletions obse/obse_editor/obse_editor.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@
<ForcedIncludeFiles>StdAfx.h;obse_common/obse_prefix.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand Down Expand Up @@ -110,9 +111,10 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<BufferSecurityCheck>false</BufferSecurityCheck>
<LanguageStandard>stdcpplatest</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<ExceptionHandling>Sync</ExceptionHandling>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand Down

0 comments on commit d062910

Please sign in to comment.