Fixed SHFamilyID for SHSystem and SHComponent but still have issues with SHScene

This commit is contained in:
maverickdgg 2022-09-30 20:13:18 +08:00
parent b1a799cf05
commit 114ae86a9f
10 changed files with 47 additions and 25 deletions

View File

@ -87,6 +87,11 @@ namespace Sandbox
SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonBag_Color_Ver4.dds");
SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.dds");
SHADE::SHAssetManager::LoadDataTemp("../../Assets/TD_Checker_Base_Color.dds");
auto id = SHFamilyID<SHSystem>::GetID<SHGraphicsSystem>();
auto id2 = SHFamilyID<SHSystem>::GetID<SHGraphicsSystem>();
auto id3 = SHFamilyID<SHSystem>::GetID<SHGraphicsSystem>();
//TODO: REMOVE AFTER PRESENTATION
//SHADE::SHSystemManager::RegisterRoutine<SHADE::SHAudioSystem, SHADE::SHAudioSystem::AudioRoutine>();
@ -102,7 +107,9 @@ namespace Sandbox
#else
#endif
SHSceneManager::InitSceneManager<SBTestScene>("TestScene");
SHFrameRateController::UpdateFRC();
}
@ -112,8 +119,6 @@ namespace Sandbox
//TODO: Change true to window is open
while (!window.WindowShouldClose())
{
auto id = SystemFamily::GetID<SHTransformSystem>();
SHLOG_INFO("Transform system id in application : {} {}", id, SystemFamily::currentID);
SHFrameRateController::UpdateFRC();
SHSceneManager::UpdateSceneManager();
SHSceneManager::SceneUpdate(1/60.0f);

View File

@ -14,6 +14,7 @@
#include "SHpch.h"
#include "../SHECSMacros.h"
#include "SH_API.h"
#include "ECS_Base/General/SHFamily.h"
namespace SHADE
{
@ -117,4 +118,7 @@ namespace SHADE
};
template class SH_API SHFamilyID<SHComponent>;
}

View File

@ -1,5 +1,4 @@
#pragma once
#define COMPULING_THE_DLL
#include "SHFamily.h"
#include "SHpch.h"

View File

@ -14,13 +14,14 @@
#pragma once
#include "../SHECSMacros.h"
#include "SH_API.h"
namespace SHADE
{
template<typename BaseClass>
class SHFamilyID
class SH_API SHFamilyID
{
private:
@ -47,7 +48,7 @@ namespace SHADE
public:
//this is used to keep track of the new current ID to be assign to a new Derived class type.
static MY_DLL_EXPORT ComponentTypeID currentID;
static inline ComponentTypeID currentID = 0;
/*!*************************************************************************
* \brief
@ -70,20 +71,27 @@ namespace SHADE
* @tparam DerivedClass
* The derived class type that we are trying to get the ID of.
***************************************************************************/
#ifdef SH_API_EXPORT
template<typename DerivedClass>
static ENABLE_IF_DERIVED(ComponentTypeID, BaseClass, DerivedClass) GetID() noexcept
static SH_API ENABLE_IF_DERIVED(ComponentTypeID, BaseClass, DerivedClass) GetID() noexcept
{
//The first time a new derived class type call this get id, it will initialize id using the currentID from familyID class.
static ComponentTypeID id = currentID++;
static ComponentTypeID id = SHFamilyID<BaseClass>::currentID++;
return id;
//return 0;
}
#else
template<typename DerivedClass>
static SH_API ENABLE_IF_DERIVED(ComponentTypeID, BaseClass, DerivedClass) GetID() noexcept;
#endif // SH_API_EXPORT
};
#ifdef COMPILING_THE_DLL
template<typename BaseClass>
ComponentTypeID SHFamilyID<BaseClass>::currentID = 0;
#endif
}

View File

@ -68,6 +68,9 @@ namespace SHADE
id = ((SystemID)version << sizeof(SystemVersionID) * CHAR_BIT) + typeID;
}
systemContainer.emplace(id, std::make_unique<T>());
auto size = systemContainer.size();
systemContainer[id].get()->systemID = id;
return id;

View File

@ -26,14 +26,6 @@ const EntityIndex MAX_EID = 51000;
#define ENABLE_IF_UINT(_TYPE, _RETURN)\
typename std::enable_if<(std::is_integral<_TYPE>::value && !std::is_signed<_TYPE>::value),_RETURN>::type
#ifdef COMPILING_THE_DLL
#ifndef MY_DLL_EXPORT
#define MY_DLL_EXPORT __declspec(dllexport)
#endif
#else
#ifndef MY_DLL_EXPORT
#define MY_DLL_EXPORT __declspec(dllimport)
#endif
#endif
#endif

View File

@ -12,6 +12,7 @@
#include "../SHECSMacros.h"
#include "SH_API.h"
#include "ECS_Base/General/SHFamily.h"
namespace SHADE
{
@ -69,5 +70,9 @@ namespace SHADE
};
template class SH_API SHFamilyID<SHSystem>;
}

View File

@ -89,6 +89,11 @@ namespace SHADE
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; //Enable docking
InitFonts();
auto id = SHFamilyID<SHSystem>::GetID<SHGraphicsSystem>();
auto id2 = SHFamilyID<SHSystem>::GetID<SHTransformSystem>();
auto id3 = SHFamilyID<SHSystem>::GetID<SHGraphicsSystem>();
InitBackend(sdlWindow);
SetStyle(Style::SHADE);
@ -106,8 +111,6 @@ namespace SHADE
{
(void)dt;
NewFrame();
auto id = SystemFamily::GetID<SHTransformSystem>();
SHLOG_INFO("Transform system id in Editor Update : {} {}", id, SystemFamily::currentID);
for (const auto& window : editorWindows | std::views::values)
{
if(window->isOpen)

View File

@ -13,6 +13,7 @@
#include <string>
#include "SHSceneGraph.h"
#include "ECS_Base/General/SHFamily.h"
namespace SHADE
{
@ -42,6 +43,7 @@ namespace SHADE
virtual void Unload() = 0;
};
template class SH_API SHFamilyID<SHScene>;
}

View File

@ -84,7 +84,8 @@ namespace SHADE
{
//prevSceneCreate = newScene;
newScene = [sceneName]() { currentScene = new T(); currentScene->sceneName = sceneName; };
nextSceneID = SHFamilyID<SHScene>::template GetID<T>();
//nextSceneID = SHFamilyID<SHScene>::GetID<T>();
nextSceneID = 0;
sceneChanged = true;
}
@ -101,13 +102,13 @@ namespace SHADE
static std::enable_if_t<std::is_base_of_v<SHScene, T>, void> ChangeScene(std::string const& sceneName) noexcept
{
//check if this new Scene is current Scene (Use RestartScene instead)
if (currentSceneID == SHFamilyID<SHScene>::template GetID<T>())
if (currentSceneID == SHFamilyID<SHScene>::GetID<T>())
{
return;
}
//prevSceneCreate = newScene;
newScene = [sceneName]() { currentScene = new T(); currentScene->sceneName; };
nextSceneID = SHFamilyID<SHScene>::template GetID<T>();
nextSceneID = SHFamilyID<SHScene>::GetID<T>();
sceneChanged = true;
}