100 lines
3.9 KiB
C++
100 lines
3.9 KiB
C++
#pragma once
|
|
|
|
#include "dtcore/inc/dtdefinitions.h"
|
|
#include "dtcore/inc/dtmemory.h"
|
|
|
|
#pragma warning(push)
|
|
#include <functional>
|
|
#pragma warning(pop)
|
|
|
|
struct eal_file_dll_interface;
|
|
struct eal_mem_dll_interface;
|
|
struct eal_log_dll_interface;
|
|
struct eal_net_dll_interface;
|
|
struct eal_thread_dll_interface;
|
|
|
|
namespace dt
|
|
{
|
|
|
|
#if defined(DT_CORE_DLL_EXPORT) || defined(DT_CORE_DLL_IMPORT)
|
|
DT_CORE_DLL_ENTRY void InitializeEalFileDll(const eal_file_dll_interface& dllinterface);
|
|
DT_CORE_DLL_ENTRY void InitializeEalLogDll(const eal_log_dll_interface& dllinterface);
|
|
DT_CORE_DLL_ENTRY void InitializeEalMemDll(const eal_mem_dll_interface& dllinterface);
|
|
DT_CORE_DLL_ENTRY void InitializeEalNetDll(const eal_net_dll_interface& dllinterface);
|
|
DT_CORE_DLL_ENTRY void InitializeEalThreadDll(const eal_thread_dll_interface& dllinterface);
|
|
#endif
|
|
|
|
class EngineImpl;
|
|
|
|
class Engine
|
|
{
|
|
public:
|
|
// Initialize the engine with the given parameters. Must be done prior any use of any interface.
|
|
// Use this function in the main modules that initializes DTest. If inside sub module and
|
|
// DTest has already been initialize, use the alternate form before any use in that sub module.
|
|
// Return false if initialization failed. Reason is mostly a EAL compatibility problem.
|
|
DT_CORE_DLL_ENTRY static bool Initialize();
|
|
|
|
// DEPRECATED - This will be removed in the next versions. Please use the dtcore DLL version instead.
|
|
// Initialize Engine in a secondary module or dll from an existing instance. Use Engine::GetInstance()
|
|
// to pass the existing instance here.
|
|
DT_DEPRECATED("This will be removed in the next versions. Please use the dtcore DLL version instead.")
|
|
DT_CORE_DLL_ENTRY static void Initialize(EngineImpl* existingInstance);
|
|
|
|
// Shutdown should be called once per module that called initialized.
|
|
DT_CORE_DLL_ENTRY static void Shutdown();
|
|
|
|
DT_CORE_DLL_ENTRY static EngineImpl* GetInstance();
|
|
|
|
// INTERNAL
|
|
|
|
// Singleton related
|
|
typedef void* (*NewSingletonFunction)();
|
|
typedef void (*DestroySingletonFunction)(void* instance);
|
|
|
|
DT_CORE_DLL_ENTRY static void* GetSingletonPointerFromRegistery(const char* uniqueName);
|
|
|
|
DT_CORE_DLL_ENTRY static void RegisterSingletonPointer(const char* uniqueName,
|
|
void* instance,
|
|
DestroySingletonFunction destroyFunction);
|
|
|
|
DT_CORE_DLL_ENTRY static void UnregisterSingletonPointer(void* instance);
|
|
|
|
DT_CORE_DLL_ENTRY static void* GetOrCreateSingletonPointerFromRegistery(const char* uniqueName,
|
|
NewSingletonFunction newFunction,
|
|
DestroySingletonFunction destroyFunction);
|
|
|
|
template <typename T> static T* GetSingletonFromRegistery(const char* uniqueName);
|
|
|
|
template <typename T> static T* GetOrCreateSingletonFromRegistery(const char* uniqueName,
|
|
NewSingletonFunction newFunction,
|
|
DestroySingletonFunction destroyFunction);
|
|
|
|
template <typename T> static T* CreateStatic()
|
|
{
|
|
T* result = DT_NEW(T);
|
|
RegisterShutdownFunction([result]() {DT_DELETE(result); });
|
|
return result;
|
|
}
|
|
DT_CORE_DLL_ENTRY static void RegisterShutdownFunction(std::function<void()> shutdown);
|
|
|
|
private:
|
|
// Prevent instantiation of Engine class
|
|
Engine();
|
|
~Engine();
|
|
};
|
|
|
|
template <typename T> inline T* Engine::GetSingletonFromRegistery(const char* uniqueName)
|
|
{
|
|
return reinterpret_cast<T*>(GetSingletonPointerFromRegistery(uniqueName));
|
|
}
|
|
|
|
template <typename T> inline T* Engine::GetOrCreateSingletonFromRegistery(const char* uniqueName,
|
|
NewSingletonFunction newFunction,
|
|
DestroySingletonFunction destroyFunction)
|
|
{
|
|
return reinterpret_cast<T*>(GetOrCreateSingletonPointerFromRegistery(uniqueName, newFunction, destroyFunction));
|
|
}
|
|
|
|
}
|
|
|