Sp3 209 system manager rework #22

Merged
maverickdgg merged 6 commits from SP3-209-System-Manager-Rework into SP3-5-ECS 2022-09-15 12:14:15 +08:00
3 changed files with 28 additions and 19 deletions
Showing only changes of commit d483916cc5 - Show all commits

View File

@ -55,6 +55,7 @@ namespace SHADE
virtual void Exit() = 0;
};
}
#endif

View File

@ -19,17 +19,6 @@ namespace SHADE
SHSystemManager::SystemContainer SHSystemManager::systemContainer;
SHSystem* SHSystemManager::GetSystem(std::string name)
{
if (systemContainer.find(name) == systemContainer.end())
{
assert("Get System Error: No system with such name exist.");
return nullptr;
}
return systemContainer.find(name)->second.get();
}
void SHSystemManager::Init() noexcept
{
for (auto& system : systemContainer)

View File

@ -19,6 +19,7 @@
#include <memory>
#include <string>
#include <cassert>
#include <climits>
#include "../System/SHSystem.h"
#include "../General/SHFamily.h"
@ -33,7 +34,7 @@ namespace SHADE
class SHSystemManager
{
//type definition for the container we use to store our system
using SystemContainer = std::unordered_map<std::string, std::unique_ptr<SHSystem>>;
using SystemContainer = std::unordered_map<SystemID, std::unique_ptr<SHSystem>>;
private:
static SystemContainer systemContainer;
@ -57,14 +58,18 @@ namespace SHADE
* none
***************************************************************************/
template<typename T>
static std::enable_if_t<std::is_base_of_v<SHSystem, T>, void> CreateSystem(std::string const& name)
static std::enable_if_t<std::is_base_of_v<SHSystem, T>, void> CreateSystem()
{
if (systemContainer.find(name) != systemContainer.end())
{
assert("System Creation Error: System with the same name already exist.");
}
SystemTypeID typeID = SystemFamily::GetID<T>();
systemContainer.emplace(name, std::make_unique<T>());
SystemVersionID version = 0;
SystemID id = ((SystemID)version << sizeof(SystemVersionID) * CHAR_BIT) + typeID;
while (systemContainer.find(id) != systemContainer.end())
{
++version;
SystemID id = ((SystemID)version << sizeof(SystemVersionID) * CHAR_BIT) + typeID;
}
systemContainer.emplace(id, std::make_unique<T>());
}
@ -77,7 +82,21 @@ namespace SHADE
* \return
* Base System pointer.
***************************************************************************/
static SHSystem* GetSystem(std::string name);
template<typename T>
static std::enable_if_t<std::is_base_of_v<SHSystem, T>, T*> GetSystem(SystemVersionID version = 0)
{
SystemTypeID typeID = SystemFamily::GetID<T>();
SystemID id = ((SystemID)version << sizeof(SystemVersionID) * CHAR_BIT) + typeID;
if (systemContainer.find(id) == systemContainer.end())
{
std::cout << "System Manager error: System Version " << version << " does not exit." << std::endl;
return nullptr;
}
return (T*)systemContainer.find(id)->second.get();
}
/**************************************************************************
* \brief