SP3-5 ECS #27
|
@ -55,6 +55,7 @@ namespace SHADE
|
||||||
virtual void Exit() = 0;
|
virtual void Exit() = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -19,17 +19,6 @@ namespace SHADE
|
||||||
SHSystemManager::SystemContainer SHSystemManager::systemContainer;
|
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
|
void SHSystemManager::Init() noexcept
|
||||||
{
|
{
|
||||||
for (auto& system : systemContainer)
|
for (auto& system : systemContainer)
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <climits>
|
||||||
#include "../System/SHSystem.h"
|
#include "../System/SHSystem.h"
|
||||||
#include "../General/SHFamily.h"
|
#include "../General/SHFamily.h"
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ namespace SHADE
|
||||||
class SHSystemManager
|
class SHSystemManager
|
||||||
{
|
{
|
||||||
//type definition for the container we use to store our system
|
//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:
|
private:
|
||||||
static SystemContainer systemContainer;
|
static SystemContainer systemContainer;
|
||||||
|
@ -57,14 +58,18 @@ namespace SHADE
|
||||||
* none
|
* none
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
template<typename T>
|
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())
|
SystemTypeID typeID = SystemFamily::GetID<T>();
|
||||||
{
|
|
||||||
assert("System Creation Error: System with the same name already exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
* \return
|
||||||
* Base System pointer.
|
* 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
|
* \brief
|
||||||
|
|
Loading…
Reference in New Issue