From d483916cc59c0cf17ed48677d8d804be74b267c3 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 13 Sep 2022 14:28:32 +0800 Subject: [PATCH 1/6] Changed SystemManager to use SystemID map instead of using a string map --- SHADE_Engine/src/ECS_Base/System/SHSystem.h | 1 + .../src/ECS_Base/System/SHSystemManager.cpp | 11 ------ .../src/ECS_Base/System/SHSystemManager.h | 35 ++++++++++++++----- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystem.h b/SHADE_Engine/src/ECS_Base/System/SHSystem.h index 817b9718..dd84fe64 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHSystem.h +++ b/SHADE_Engine/src/ECS_Base/System/SHSystem.h @@ -55,6 +55,7 @@ namespace SHADE virtual void Exit() = 0; }; + } #endif \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystemManager.cpp b/SHADE_Engine/src/ECS_Base/System/SHSystemManager.cpp index 67d6f781..5b861161 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHSystemManager.cpp +++ b/SHADE_Engine/src/ECS_Base/System/SHSystemManager.cpp @@ -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) diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystemManager.h b/SHADE_Engine/src/ECS_Base/System/SHSystemManager.h index a81370e9..dada878b 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHSystemManager.h +++ b/SHADE_Engine/src/ECS_Base/System/SHSystemManager.h @@ -19,6 +19,7 @@ #include #include #include +#include #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>; + using SystemContainer = std::unordered_map>; private: static SystemContainer systemContainer; @@ -57,14 +58,18 @@ namespace SHADE * none ***************************************************************************/ template - static std::enable_if_t, void> CreateSystem(std::string const& name) + static std::enable_if_t, void> CreateSystem() { - if (systemContainer.find(name) != systemContainer.end()) - { - assert("System Creation Error: System with the same name already exist."); - } + SystemTypeID typeID = SystemFamily::GetID(); - systemContainer.emplace(name, std::make_unique()); + 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()); } @@ -77,7 +82,21 @@ namespace SHADE * \return * Base System pointer. ***************************************************************************/ - static SHSystem* GetSystem(std::string name); + template + static std::enable_if_t, T*> GetSystem(SystemVersionID version = 0) + { + SystemTypeID typeID = SystemFamily::GetID(); + + 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 -- 2.40.1 From e9241feb69608b5cd4f6ceedc958473d0dea6714 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 13 Sep 2022 15:26:23 +0800 Subject: [PATCH 2/6] moved all managers to their own folder --- .../SHComponentManager.cpp | 0 .../{System => Managers}/SHComponentManager.h | 0 .../{System => Managers}/SHEntityManager.cpp | 0 .../{System => Managers}/SHEntityManager.h | 0 .../{System => Managers}/SHSystemManager.cpp | 0 .../{System => Managers}/SHSystemManager.h | 0 SHADE_Engine/src/ECS_Base/System/SHSystem.h | 36 ++++++++++++++++++- 7 files changed, 35 insertions(+), 1 deletion(-) rename SHADE_Engine/src/ECS_Base/{System => Managers}/SHComponentManager.cpp (100%) rename SHADE_Engine/src/ECS_Base/{System => Managers}/SHComponentManager.h (100%) rename SHADE_Engine/src/ECS_Base/{System => Managers}/SHEntityManager.cpp (100%) rename SHADE_Engine/src/ECS_Base/{System => Managers}/SHEntityManager.h (100%) rename SHADE_Engine/src/ECS_Base/{System => Managers}/SHSystemManager.cpp (100%) rename SHADE_Engine/src/ECS_Base/{System => Managers}/SHSystemManager.h (100%) diff --git a/SHADE_Engine/src/ECS_Base/System/SHComponentManager.cpp b/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.cpp similarity index 100% rename from SHADE_Engine/src/ECS_Base/System/SHComponentManager.cpp rename to SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.cpp diff --git a/SHADE_Engine/src/ECS_Base/System/SHComponentManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h similarity index 100% rename from SHADE_Engine/src/ECS_Base/System/SHComponentManager.h rename to SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h diff --git a/SHADE_Engine/src/ECS_Base/System/SHEntityManager.cpp b/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp similarity index 100% rename from SHADE_Engine/src/ECS_Base/System/SHEntityManager.cpp rename to SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp diff --git a/SHADE_Engine/src/ECS_Base/System/SHEntityManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.h similarity index 100% rename from SHADE_Engine/src/ECS_Base/System/SHEntityManager.h rename to SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.h diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystemManager.cpp b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp similarity index 100% rename from SHADE_Engine/src/ECS_Base/System/SHSystemManager.cpp rename to SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystemManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h similarity index 100% rename from SHADE_Engine/src/ECS_Base/System/SHSystemManager.h rename to SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystem.h b/SHADE_Engine/src/ECS_Base/System/SHSystem.h index dd84fe64..dd25db69 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHSystem.h +++ b/SHADE_Engine/src/ECS_Base/System/SHSystem.h @@ -16,7 +16,7 @@ namespace SHADE { - + class SHSystemManager; class SHSystem { @@ -54,8 +54,42 @@ namespace SHADE ***************************************************************************/ virtual void Exit() = 0; + + protected: + SystemID systemID{}; + }; + + + + + class SHTestSystem : public SHSystem + { + public: + + SHTestSystem() = default; + ~SHTestSystem() = default; + + int value{5}; + + void Init() + { + + } + + void Run(float dt) + { + + } + + void Exit() + { + + } + }; + + } #endif \ No newline at end of file -- 2.40.1 From 8842269c6d3baa4a764e2a9e86bc7a0ae1520616 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 13 Sep 2022 15:36:03 +0800 Subject: [PATCH 3/6] Changed everything to use pragma once --- SHADE_Engine/SHADE_Engine.vcxproj | 12 +++---- SHADE_Engine/SHADE_Engine.vcxproj.filters | 33 ++++++++++--------- .../src/ECS_Base/Components/SHComponent.h | 3 +- .../ECS_Base/Components/SHComponentGroup.cpp | 2 +- .../ECS_Base/Components/SHComponentGroup.h | 7 +--- SHADE_Engine/src/ECS_Base/Entity/SHEntity.cpp | 4 +-- SHADE_Engine/src/ECS_Base/Entity/SHEntity.h | 8 ++--- .../src/ECS_Base/General/SHSparseBase.h | 3 +- .../src/ECS_Base/General/SHSparseSet.h | 3 +- .../ECS_Base/General/SHSparseSetContainer.h | 3 +- .../ECS_Base/Managers/SHComponentManager.h | 8 ++--- .../src/ECS_Base/Managers/SHEntityManager.h | 8 +---- SHADE_Engine/src/ECS_Base/System/SHSystem.h | 2 +- .../src/ECS_Base/System/SHSystemRoutine.h | 1 + SHADE_Engine/src/Scene/SHSceneGraph.cpp | 2 +- SHADE_Engine/src/Scene/SHSceneManager.cpp | 6 ++-- 16 files changed, 43 insertions(+), 62 deletions(-) create mode 100644 SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.h diff --git a/SHADE_Engine/SHADE_Engine.vcxproj b/SHADE_Engine/SHADE_Engine.vcxproj index e54c82ec..663c60aa 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj +++ b/SHADE_Engine/SHADE_Engine.vcxproj @@ -110,11 +110,11 @@ + + + - - - @@ -196,9 +196,9 @@ - - - + + + diff --git a/SHADE_Engine/SHADE_Engine.vcxproj.filters b/SHADE_Engine/SHADE_Engine.vcxproj.filters index 7486fad4..19ff17bf 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj.filters +++ b/SHADE_Engine/SHADE_Engine.vcxproj.filters @@ -13,6 +13,9 @@ {07FEB307-F3F6-D259-1C29-B8DE0881B265} + + {37718753-A387-85E9-ECFE-100B58545671} + {EE037863-5A8F-E527-63A0-681CCFAA4128} @@ -141,21 +144,21 @@ ECS_Base\General + + ECS_Base\Managers + + + ECS_Base\Managers + + + ECS_Base\Managers + ECS_Base - - ECS_Base\System - - - ECS_Base\System - ECS_Base\System - - ECS_Base\System - Engine @@ -393,14 +396,14 @@ ECS_Base\Entity - - ECS_Base\System + + ECS_Base\Managers - - ECS_Base\System + + ECS_Base\Managers - - ECS_Base\System + + ECS_Base\Managers Engine diff --git a/SHADE_Engine/src/ECS_Base/Components/SHComponent.h b/SHADE_Engine/src/ECS_Base/Components/SHComponent.h index c9c5e6f1..20335eab 100644 --- a/SHADE_Engine/src/ECS_Base/Components/SHComponent.h +++ b/SHADE_Engine/src/ECS_Base/Components/SHComponent.h @@ -9,8 +9,7 @@ *********************************************************************/ -#ifndef SH_COMPONENT_H -#define SH_COMPONENT_H +#pragma once #include "SHpch.h" #include "../SHECSMacros.h" diff --git a/SHADE_Engine/src/ECS_Base/Components/SHComponentGroup.cpp b/SHADE_Engine/src/ECS_Base/Components/SHComponentGroup.cpp index 3ccb7778..2627d9fb 100644 --- a/SHADE_Engine/src/ECS_Base/Components/SHComponentGroup.cpp +++ b/SHADE_Engine/src/ECS_Base/Components/SHComponentGroup.cpp @@ -14,7 +14,7 @@ #include "SHpch.h" #include "SHComponentGroup.h" -#include "../System/SHComponentManager.h" +#include "../Managers/SHComponentManager.h" namespace SHADE diff --git a/SHADE_Engine/src/ECS_Base/Components/SHComponentGroup.h b/SHADE_Engine/src/ECS_Base/Components/SHComponentGroup.h index 3f67aff0..2b20ec13 100644 --- a/SHADE_Engine/src/ECS_Base/Components/SHComponentGroup.h +++ b/SHADE_Engine/src/ECS_Base/Components/SHComponentGroup.h @@ -12,9 +12,7 @@ consent of DigiPen Institute of Technology is prohibited. *********************************************************************/ - -#ifndef SH_COMPONENT_GROUP -#define SH_COMPONENT_GROUP +#pragma once #include "../SHECSMacros.h" #include "../General/SHFamily.h" @@ -180,6 +178,3 @@ namespace SHADE }; } - - -#endif diff --git a/SHADE_Engine/src/ECS_Base/Entity/SHEntity.cpp b/SHADE_Engine/src/ECS_Base/Entity/SHEntity.cpp index 08139158..ef613390 100644 --- a/SHADE_Engine/src/ECS_Base/Entity/SHEntity.cpp +++ b/SHADE_Engine/src/ECS_Base/Entity/SHEntity.cpp @@ -9,9 +9,9 @@ *********************************************************************/ #include "SHpch.h" #include "SHEntity.h" -#include "../System/SHEntityManager.h" +#include "../Managers/SHEntityManager.h" //#include "Scene/SHSceneGraph.h" -#include "../System/SHComponentManager.h" +#include "../Managers/SHComponentManager.h" namespace SHADE { diff --git a/SHADE_Engine/src/ECS_Base/Entity/SHEntity.h b/SHADE_Engine/src/ECS_Base/Entity/SHEntity.h index 0e00c8af..ab73f45f 100644 --- a/SHADE_Engine/src/ECS_Base/Entity/SHEntity.h +++ b/SHADE_Engine/src/ECS_Base/Entity/SHEntity.h @@ -8,12 +8,11 @@ consent of DigiPen Institute of Technology is prohibited. *********************************************************************/ -#ifndef SH_ENTITY_H -#define SH_ENTITY_H +#pragma once #include "../SHECSMacros.h" #include "../Components/SHComponent.h" -#include "../System/SHComponentManager.h" +#include "../Managers/SHComponentManager.h" //#include "../../Scene/SHSceneNode.h" @@ -166,6 +165,3 @@ namespace SHADE }; } - - -#endif diff --git a/SHADE_Engine/src/ECS_Base/General/SHSparseBase.h b/SHADE_Engine/src/ECS_Base/General/SHSparseBase.h index 2deebe74..f83d3052 100644 --- a/SHADE_Engine/src/ECS_Base/General/SHSparseBase.h +++ b/SHADE_Engine/src/ECS_Base/General/SHSparseBase.h @@ -10,8 +10,7 @@ consent of DigiPen Institute of Technology is prohibited. *********************************************************************/ -#ifndef SH_SPARSE_BASE_H -#define SH_SPARSE_BASE_H +#pragma once #include "../SHECSMacros.h" diff --git a/SHADE_Engine/src/ECS_Base/General/SHSparseSet.h b/SHADE_Engine/src/ECS_Base/General/SHSparseSet.h index 3473eb37..6dada871 100644 --- a/SHADE_Engine/src/ECS_Base/General/SHSparseSet.h +++ b/SHADE_Engine/src/ECS_Base/General/SHSparseSet.h @@ -9,8 +9,7 @@ or disclosure of this file or its contents without the prior written consent of DigiPen Institute of Technology is prohibited. *********************************************************************/ -#ifndef SH_SPARSE_SET_H -#define SH_SPARSE_SET_H +#pragma once #include "../SHECSMacros.h" #include "../General/SHSparseBase.h" diff --git a/SHADE_Engine/src/ECS_Base/General/SHSparseSetContainer.h b/SHADE_Engine/src/ECS_Base/General/SHSparseSetContainer.h index 8698d1f5..dbba0021 100644 --- a/SHADE_Engine/src/ECS_Base/General/SHSparseSetContainer.h +++ b/SHADE_Engine/src/ECS_Base/General/SHSparseSetContainer.h @@ -10,8 +10,7 @@ consent of DigiPen Institute of Technology is prohibited. *********************************************************************/ -#ifndef SH_SPARSE_SET_CONTAINER_H -#define SH_SPARSE_SET_CONTAINER_H +#pragma once #include "SHSparseSet.h" #include "SHFamily.h" diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h index 2c747663..995e8b24 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h +++ b/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h @@ -12,8 +12,7 @@ consent of DigiPen Institute of Technology is prohibited. *********************************************************************/ -#ifndef SH_ENGINE_H -#define SH_ENGINE_H +#pragma once #include "../General/SHSparseSetContainer.h" #include "../Components/SHComponent.h" @@ -477,7 +476,4 @@ namespace SHADE -} - - -#endif +} \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.h index 7afece52..bec60a17 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.h +++ b/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.h @@ -12,9 +12,7 @@ or disclosure of this file or its contents without the prior written consent of DigiPen Institute of Technology is prohibited. *********************************************************************/ - -#ifndef SH_ENTITY_MANAGER_H -#define SH_ENTITY_MANAGER_H +#pragma once #include #include @@ -198,7 +196,3 @@ namespace SHADE } - - - -#endif diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystem.h b/SHADE_Engine/src/ECS_Base/System/SHSystem.h index dd25db69..0d48c721 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHSystem.h +++ b/SHADE_Engine/src/ECS_Base/System/SHSystem.h @@ -56,7 +56,7 @@ namespace SHADE protected: - SystemID systemID{}; + }; diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.h b/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.h new file mode 100644 index 00000000..6f70f09b --- /dev/null +++ b/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.h @@ -0,0 +1 @@ +#pragma once diff --git a/SHADE_Engine/src/Scene/SHSceneGraph.cpp b/SHADE_Engine/src/Scene/SHSceneGraph.cpp index 9c99fb5a..9fddf10e 100644 --- a/SHADE_Engine/src/Scene/SHSceneGraph.cpp +++ b/SHADE_Engine/src/Scene/SHSceneGraph.cpp @@ -14,7 +14,7 @@ #include "SHSceneGraph.h" // Project Headers -#include "ECS_Base/System/SHEntityManager.h" +#include "ECS_Base/Managers/SHEntityManager.h" #include "Tools/SHLogger.h" #include "Tools/SHException.h" diff --git a/SHADE_Engine/src/Scene/SHSceneManager.cpp b/SHADE_Engine/src/Scene/SHSceneManager.cpp index a60df922..d5223af8 100644 --- a/SHADE_Engine/src/Scene/SHSceneManager.cpp +++ b/SHADE_Engine/src/Scene/SHSceneManager.cpp @@ -10,11 +10,11 @@ *********************************************************************/ #include "SHpch.h" #include "SHSceneManager.h" -#include "ECS_Base/System/SHComponentManager.h" +#include "ECS_Base/Managers/SHComponentManager.h" //#include "Input/SHInputManager.h" //#include "Rendering/Window/SHRenderingWindow.h" -#include "ECS_Base/System/SHEntityManager.h" -#include "ECS_Base/System/SHSystemManager.h" +#include "ECS_Base/Managers/SHEntityManager.h" +#include "ECS_Base/Managers/SHSystemManager.h" //#include "FRC/SHFrameRateController.h" //#include "ECS_Base/System/SHApplication.h" -- 2.40.1 From f342fdcb950ef3276b73353ae5bd22954ed04893 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 13 Sep 2022 15:36:34 +0800 Subject: [PATCH 4/6] changed more stuff to pragma once --- SHADE_Engine/SHADE_Engine.vcxproj | 1 + SHADE_Engine/SHADE_Engine.vcxproj.filters | 1 + SHADE_Engine/src/ECS_Base/Components/SHComponent.h | 1 - SHADE_Engine/src/ECS_Base/General/SHFamily.h | 9 ++------- SHADE_Engine/src/ECS_Base/General/SHHandleGenerator.h | 8 ++------ SHADE_Engine/src/ECS_Base/General/SHSparseBase.h | 5 +---- SHADE_Engine/src/ECS_Base/General/SHSparseSet.h | 4 +--- .../src/ECS_Base/General/SHSparseSetContainer.h | 3 --- SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h | 10 ++-------- SHADE_Engine/src/ECS_Base/System/SHSystem.h | 9 ++------- SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.h | 3 +++ 11 files changed, 15 insertions(+), 39 deletions(-) diff --git a/SHADE_Engine/SHADE_Engine.vcxproj b/SHADE_Engine/SHADE_Engine.vcxproj index 663c60aa..1831bff6 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj +++ b/SHADE_Engine/SHADE_Engine.vcxproj @@ -115,6 +115,7 @@ + diff --git a/SHADE_Engine/SHADE_Engine.vcxproj.filters b/SHADE_Engine/SHADE_Engine.vcxproj.filters index 19ff17bf..70a5b407 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj.filters +++ b/SHADE_Engine/SHADE_Engine.vcxproj.filters @@ -385,6 +385,7 @@ Tools + diff --git a/SHADE_Engine/src/ECS_Base/Components/SHComponent.h b/SHADE_Engine/src/ECS_Base/Components/SHComponent.h index 20335eab..66d1d8c4 100644 --- a/SHADE_Engine/src/ECS_Base/Components/SHComponent.h +++ b/SHADE_Engine/src/ECS_Base/Components/SHComponent.h @@ -117,4 +117,3 @@ namespace SHADE }; } -#endif diff --git a/SHADE_Engine/src/ECS_Base/General/SHFamily.h b/SHADE_Engine/src/ECS_Base/General/SHFamily.h index f97bbe0e..5815703f 100644 --- a/SHADE_Engine/src/ECS_Base/General/SHFamily.h +++ b/SHADE_Engine/src/ECS_Base/General/SHFamily.h @@ -11,8 +11,7 @@ consent of DigiPen Institute of Technology is prohibited. *********************************************************************/ -#ifndef SH_FAMILY_H -#define SH_FAMILY_H +#pragma once #include "../SHECSMacros.h" @@ -81,8 +80,4 @@ namespace SHADE template ComponentTypeID SHFamilyID::currentID = 0; -} - - - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/General/SHHandleGenerator.h b/SHADE_Engine/src/ECS_Base/General/SHHandleGenerator.h index 48ae2132..7c68f66d 100644 --- a/SHADE_Engine/src/ECS_Base/General/SHHandleGenerator.h +++ b/SHADE_Engine/src/ECS_Base/General/SHHandleGenerator.h @@ -11,8 +11,7 @@ or disclosure of this file or its contents without the prior written consent of DigiPen Institute of Technology is prohibited. *********************************************************************/ -#ifndef SH_HANDLE_GENERATOR_H -#define SH_HANDLE_GENERATOR_H +#pragma once #include #include @@ -299,7 +298,4 @@ namespace SHADE typedef SHHandleGenerator EntityHandleGenerator; -} - - -#endif +} \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/General/SHSparseBase.h b/SHADE_Engine/src/ECS_Base/General/SHSparseBase.h index f83d3052..913fca5a 100644 --- a/SHADE_Engine/src/ECS_Base/General/SHSparseBase.h +++ b/SHADE_Engine/src/ECS_Base/General/SHSparseBase.h @@ -43,7 +43,4 @@ namespace SHADE }; -} - - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/General/SHSparseSet.h b/SHADE_Engine/src/ECS_Base/General/SHSparseSet.h index 6dada871..8e096a37 100644 --- a/SHADE_Engine/src/ECS_Base/General/SHSparseSet.h +++ b/SHADE_Engine/src/ECS_Base/General/SHSparseSet.h @@ -350,6 +350,4 @@ namespace SHADE } }; -} - -#endif +} \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/General/SHSparseSetContainer.h b/SHADE_Engine/src/ECS_Base/General/SHSparseSetContainer.h index dbba0021..8f8814f6 100644 --- a/SHADE_Engine/src/ECS_Base/General/SHSparseSetContainer.h +++ b/SHADE_Engine/src/ECS_Base/General/SHSparseSetContainer.h @@ -242,6 +242,3 @@ namespace SHADE }; } - - -#endif diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h index dada878b..7d4e8c27 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h +++ b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h @@ -10,9 +10,7 @@ consent of DigiPen Institute of Technology is prohibited. *********************************************************************/ - -#ifndef SH_SYSTEM_MANAGER_H -#define SH_SYSTEM_MANAGER_H +#pragma once #include @@ -119,8 +117,4 @@ namespace SHADE }; -} - - - -#endif +} \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystem.h b/SHADE_Engine/src/ECS_Base/System/SHSystem.h index 0d48c721..3a0694e2 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHSystem.h +++ b/SHADE_Engine/src/ECS_Base/System/SHSystem.h @@ -8,10 +8,7 @@ consent of DigiPen Institute of Technology is prohibited. *********************************************************************/ -#ifndef SH_SYSTEM_H -#define SH_SYSTEM_H - - +#pragma once namespace SHADE { @@ -90,6 +87,4 @@ namespace SHADE }; -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.h b/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.h index 6f70f09b..531a62b0 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.h +++ b/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.h @@ -1 +1,4 @@ #pragma once + + + -- 2.40.1 From b7cd1bed48c0daeada4df0ece694fea8ce7fa6fe Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Wed, 14 Sep 2022 10:32:50 +0800 Subject: [PATCH 5/6] Added System Routines --- SHADE_Engine/SHADE_Engine.vcxproj | 4 ++ SHADE_Engine/SHADE_Engine.vcxproj.filters | 4 ++ .../src/ECS_Base/Managers/SHSystemManager.cpp | 35 +++++++++++-- .../src/ECS_Base/Managers/SHSystemManager.h | 40 +++++++++------ SHADE_Engine/src/ECS_Base/SHECSMacros.h | 4 +- .../ECS_Base/System/SHFixedSystemRoutine.cpp | 20 ++++++++ .../ECS_Base/System/SHFixedSystemRoutine.h | 31 ++++++++++++ .../src/ECS_Base/System/SHRoutineStats.h | 27 ++++++++++ SHADE_Engine/src/ECS_Base/System/SHSystem.h | 17 +++---- .../src/ECS_Base/System/SHSystemRoutine.cpp | 21 ++++++++ .../src/ECS_Base/System/SHSystemRoutine.h | 49 +++++++++++++++++++ 11 files changed, 224 insertions(+), 28 deletions(-) create mode 100644 SHADE_Engine/src/ECS_Base/System/SHFixedSystemRoutine.cpp create mode 100644 SHADE_Engine/src/ECS_Base/System/SHFixedSystemRoutine.h create mode 100644 SHADE_Engine/src/ECS_Base/System/SHRoutineStats.h create mode 100644 SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.cpp diff --git a/SHADE_Engine/SHADE_Engine.vcxproj b/SHADE_Engine/SHADE_Engine.vcxproj index 1831bff6..d84f3c05 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj +++ b/SHADE_Engine/SHADE_Engine.vcxproj @@ -114,6 +114,8 @@ + + @@ -200,6 +202,8 @@ + + diff --git a/SHADE_Engine/SHADE_Engine.vcxproj.filters b/SHADE_Engine/SHADE_Engine.vcxproj.filters index 70a5b407..8fc412c5 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj.filters +++ b/SHADE_Engine/SHADE_Engine.vcxproj.filters @@ -386,6 +386,8 @@ Tools + + @@ -587,5 +589,7 @@ Tools + + \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp index 5b861161..acf7cba3 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp +++ b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp @@ -14,10 +14,14 @@ #include "SHSystemManager.h" #include +#include +#include +#include + namespace SHADE { SHSystemManager::SystemContainer SHSystemManager::systemContainer; - + SHSystemManager::SystemRoutineContainer SHSystemManager::systemRoutineContainer; void SHSystemManager::Init() noexcept { @@ -30,11 +34,36 @@ namespace SHADE } } + void SHSystemManager::RunRoutines(bool editorPause) noexcept + { + for (auto& routine : systemRoutineContainer) + { + if (editorPause == true) + { + if (routine.get()->IsRunInEditorPause) + { + std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now(); + routine.get()->Execute(0.0); + std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now(); + routine.get()->stats.executionTime = std::chrono::duration(end - start).count(); + } + } + else + { + std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now(); + routine.get()->Execute(0.0); + std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now(); + routine.get()->stats.executionTime = std::chrono::duration(end - start).count(); + } + } + } + + void SHSystemManager::Exit() noexcept { - for (auto& system : systemContainer) + for (SystemContainer::reverse_iterator it = systemContainer.rbegin(); it != systemContainer.rend(); ++it) { - system.second->Exit(); + (*it).second->Exit(); //delete system.second; } diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h index 7d4e8c27..616a8db3 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h +++ b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h @@ -13,30 +13,29 @@ #pragma once -#include +#include #include #include #include #include #include "../System/SHSystem.h" #include "../General/SHFamily.h" +#include "../System/SHSystemRoutine.h" namespace SHADE { - typedef uint32_t SystemTypeID; - typedef uint32_t SystemVersionID; - typedef uint64_t SystemID; + typedef SHFamilyID SystemFamily; class SHSystemManager { //type definition for the container we use to store our system - using SystemContainer = std::unordered_map>; - + using SystemContainer = std::map>; + using SystemRoutineContainer = std::vector>; private: static SystemContainer systemContainer; - + static SystemRoutineContainer systemRoutineContainer; public: /*!************************************************************************* @@ -47,12 +46,12 @@ namespace SHADE ~SHSystemManager() = delete; /************************************************************************** - * \brief + * \brief * Create a system of type T and map it to a name. * throws an error if a system with the same name already exists. * \param name * name of the system - * \return + * \return * none ***************************************************************************/ template @@ -61,7 +60,7 @@ namespace SHADE SystemTypeID typeID = SystemFamily::GetID(); SystemVersionID version = 0; - SystemID id = ((SystemID)version << sizeof(SystemVersionID) * CHAR_BIT) + typeID; + SystemID id = ((SystemID)version << sizeof(SystemVersionID) * CHAR_BIT) + typeID; while (systemContainer.find(id) != systemContainer.end()) { ++version; @@ -73,11 +72,11 @@ namespace SHADE } /************************************************************************** - * \brief + * \brief * Get a pointer to the System with a specified name. * \param name * Name of the system in the map - * \return + * \return * Base System pointer. ***************************************************************************/ template @@ -97,13 +96,26 @@ namespace SHADE } /************************************************************************** - * \brief + * \brief * Call the Init function of all systems. - * \return + * \return * none ***************************************************************************/ static void Init() noexcept; + static void RunRoutines(bool editorPause) noexcept; + + template + static void RegisterRoutine(SystemVersionID version = 0) noexcept + { + SHSystem* system = GetSystem(version); + if (system == nullptr) + return; + systemRoutineContainer.emplace_back(std::make_unique()); + + } + + /************************************************************************** * \brief * Call the Exit function of all systems. diff --git a/SHADE_Engine/src/ECS_Base/SHECSMacros.h b/SHADE_Engine/src/ECS_Base/SHECSMacros.h index 0a8971e7..02615ca4 100644 --- a/SHADE_Engine/src/ECS_Base/SHECSMacros.h +++ b/SHADE_Engine/src/ECS_Base/SHECSMacros.h @@ -9,7 +9,9 @@ typedef uint32_t EntityID; typedef uint16_t EntityIndex; typedef uint32_t ComponentTypeID; - +typedef uint32_t SystemTypeID; +typedef uint32_t SystemVersionID; +typedef uint64_t SystemID; diff --git a/SHADE_Engine/src/ECS_Base/System/SHFixedSystemRoutine.cpp b/SHADE_Engine/src/ECS_Base/System/SHFixedSystemRoutine.cpp new file mode 100644 index 00000000..2c97bfb4 --- /dev/null +++ b/SHADE_Engine/src/ECS_Base/System/SHFixedSystemRoutine.cpp @@ -0,0 +1,20 @@ +#include "SHFixedSystemRoutine.h" +#include "../SHECSMacros.h" + +namespace SHADE +{ + + void SHFixedSystemRoutine::Execute(double dt) + { + accumulatedTime += dt; + int counter = 0; + while (accumulatedTime >= fixedTimeStep) + { + ++counter; + accumulatedTime -= fixedTimeStep; + FixedExecute(fixedTimeStep); + } + stats.numSteps = counter; + } + +} \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/System/SHFixedSystemRoutine.h b/SHADE_Engine/src/ECS_Base/System/SHFixedSystemRoutine.h new file mode 100644 index 00000000..d9a2b510 --- /dev/null +++ b/SHADE_Engine/src/ECS_Base/System/SHFixedSystemRoutine.h @@ -0,0 +1,31 @@ +#pragma once + + +#include "SHSystemRoutine.h" +#define DEFAULT_FIXED_STEP 1.0/60.0 + +namespace SHADE +{ + class SHFixedSystemRoutine: public SHSystemRoutine + { + private: + double accumulatedTime; + double fixedTimeStep; + + protected: + SHFixedSystemRoutine(double timeStep = DEFAULT_FIXED_STEP, std::string routineName = "Default Fixed Routine Name", bool editorPause = false) + :SHSystemRoutine(routineName, editorPause), accumulatedTime(0.0), fixedTimeStep(timeStep){} + + + + public: + ~SHFixedSystemRoutine() = default; + + virtual void Execute(double dt) noexcept; + + virtual void FixedExecute(double dt) noexcept {}; + + }; + + +} \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/System/SHRoutineStats.h b/SHADE_Engine/src/ECS_Base/System/SHRoutineStats.h new file mode 100644 index 00000000..e294264a --- /dev/null +++ b/SHADE_Engine/src/ECS_Base/System/SHRoutineStats.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +namespace SHADE +{ + struct SHRoutineStats + { + SHRoutineStats(std::string name) + :name(name) + { + } + std::string name; + double executionTime; + int numSteps{1}; + + friend std::ostream& operator<<(std::ostream& os, const SHRoutineStats& stats); + }; + + std::ostream& operator<<(std::ostream& os, const SHRoutineStats& stats) + { + os << stats.name << ": Execution Time: " << stats.executionTime << " Number of steps: " << stats.numSteps << std::endl; + } + + +} \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystem.h b/SHADE_Engine/src/ECS_Base/System/SHSystem.h index 3a0694e2..a2964a91 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHSystem.h +++ b/SHADE_Engine/src/ECS_Base/System/SHSystem.h @@ -37,13 +37,13 @@ namespace SHADE ***************************************************************************/ virtual void Init() = 0; - /*!************************************************************************* - * \brief - * Pure virtual Run function. Derived class must implement this - * \param dt - * Delta time - ***************************************************************************/ - virtual void Run(float dt) = 0; + ///*!************************************************************************* + // * \brief + // * Pure virtual Run function. Derived class must implement this + // * \param dt + // * Delta time + //***************************************************************************/ + //virtual void Run(float dt) = 0; /*!************************************************************************* * \brief @@ -75,10 +75,7 @@ namespace SHADE } - void Run(float dt) - { - } void Exit() { diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.cpp b/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.cpp new file mode 100644 index 00000000..83107c60 --- /dev/null +++ b/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.cpp @@ -0,0 +1,21 @@ +#include "SHSystemRoutine.h" + +namespace SHADE +{ + + SHSystem* SHSystemRoutine::GetSystem() const noexcept + { + return system; + } + + std::string const SHSystemRoutine::GetName()const noexcept + { + return name; + } + + SHRoutineStats const& SHSystemRoutine::GetStats()const noexcept + { + return stats; + } + +} diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.h b/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.h index 531a62b0..cdb62438 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.h +++ b/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.h @@ -1,4 +1,53 @@ + + + #pragma once +#include "../SHECSMacros.h" +#include "SHRoutineStats.h" +#include "SHSystem.h" +#include + + +namespace SHADE +{ + + class SHSystemManager; + + + class SHSystemRoutine + { + friend class SHSystemManager; + protected: + + SHSystemRoutine(std::string routineName = "Default Routine Name", bool editorPause = false) + :system(nullptr), name(routineName), stats(routineName),IsRunInEditorPause(editorPause){}; + + + SHSystem* system; + std::string name; + SHRoutineStats stats; + + //Whether or not this routine should run when the editor is still in pause + bool IsRunInEditorPause; + + + public: + ~SHSystemRoutine() = default; + + + SHSystem* GetSystem()const noexcept; + std::string const GetName() const noexcept; + SHRoutineStats const& GetStats()const noexcept; + + virtual void Execute(double dt) noexcept {}; + }; + + + + +} + + -- 2.40.1 From a90c13744543c80005dada71c61ab7877938816e Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Thu, 15 Sep 2022 12:10:06 +0800 Subject: [PATCH 6/6] #comment Completed System Routine Added Unit Test version 1 --- .../src/Application/SBApplication.cpp | 5 +- SHADE_Engine/SHADE_Engine.vcxproj | 4 + SHADE_Engine/SHADE_Engine.vcxproj.filters | 4 + .../src/ECS_Base/Managers/SHSystemManager.cpp | 8 +- .../src/ECS_Base/Managers/SHSystemManager.h | 9 +- .../ECS_Base/System/SHFixedSystemRoutine.cpp | 3 +- .../src/ECS_Base/System/SHRoutineStats.h | 11 +- SHADE_Engine/src/ECS_Base/System/SHSystem.h | 39 ++-- .../src/ECS_Base/System/SHSystemRoutine.cpp | 2 + .../ECS_Base/UnitTesting/SHECSUnitTest.cpp | 181 ++++++++++++++++++ .../src/ECS_Base/UnitTesting/SHECSUnitTest.h | 22 +++ .../ECS_Base/UnitTesting/SHTestComponents.h | 30 +++ .../src/ECS_Base/UnitTesting/SHTestSystems.h | 40 ++++ 13 files changed, 318 insertions(+), 40 deletions(-) create mode 100644 SHADE_Engine/src/ECS_Base/UnitTesting/SHECSUnitTest.cpp create mode 100644 SHADE_Engine/src/ECS_Base/UnitTesting/SHECSUnitTest.h create mode 100644 SHADE_Engine/src/ECS_Base/UnitTesting/SHTestComponents.h create mode 100644 SHADE_Engine/src/ECS_Base/UnitTesting/SHTestSystems.h diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 184b9611..3577475d 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -1,5 +1,6 @@ #include "SBpch.h" #include "SBApplication.h" +#include "ECS_Base/UnitTesting/SHECSUnitTest.h" #ifdef SHEDITOR #include "Editor/SHEditor.h" @@ -23,11 +24,13 @@ namespace Sandbox { window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow); - + #ifdef SHEDITOR #else #endif + + } void SBApplication::Update(void) diff --git a/SHADE_Engine/SHADE_Engine.vcxproj b/SHADE_Engine/SHADE_Engine.vcxproj index d84f3c05..2b2541bb 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj +++ b/SHADE_Engine/SHADE_Engine.vcxproj @@ -118,6 +118,9 @@ + + + @@ -204,6 +207,7 @@ + diff --git a/SHADE_Engine/SHADE_Engine.vcxproj.filters b/SHADE_Engine/SHADE_Engine.vcxproj.filters index 8fc412c5..4f80a4f8 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj.filters +++ b/SHADE_Engine/SHADE_Engine.vcxproj.filters @@ -388,6 +388,9 @@ + + + @@ -591,5 +594,6 @@ + \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp index acf7cba3..551233db 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp +++ b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.cpp @@ -34,7 +34,7 @@ namespace SHADE } } - void SHSystemManager::RunRoutines(bool editorPause) noexcept + void SHSystemManager::RunRoutines(bool editorPause, double deltaTime) noexcept { for (auto& routine : systemRoutineContainer) { @@ -43,7 +43,7 @@ namespace SHADE if (routine.get()->IsRunInEditorPause) { std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now(); - routine.get()->Execute(0.0); + routine.get()->Execute(deltaTime); std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now(); routine.get()->stats.executionTime = std::chrono::duration(end - start).count(); } @@ -51,7 +51,7 @@ namespace SHADE else { std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now(); - routine.get()->Execute(0.0); + routine.get()->Execute(deltaTime); std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now(); routine.get()->stats.executionTime = std::chrono::duration(end - start).count(); } @@ -61,6 +61,8 @@ namespace SHADE void SHSystemManager::Exit() noexcept { + systemRoutineContainer.clear(); + for (SystemContainer::reverse_iterator it = systemContainer.rbegin(); it != systemContainer.rend(); ++it) { (*it).second->Exit(); diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h index 616a8db3..f97d98a2 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h +++ b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h @@ -55,7 +55,7 @@ namespace SHADE * none ***************************************************************************/ template - static std::enable_if_t, void> CreateSystem() + static std::enable_if_t, SystemID> CreateSystem() { SystemTypeID typeID = SystemFamily::GetID(); @@ -64,10 +64,12 @@ namespace SHADE while (systemContainer.find(id) != systemContainer.end()) { ++version; - SystemID id = ((SystemID)version << sizeof(SystemVersionID) * CHAR_BIT) + typeID; + id = ((SystemID)version << sizeof(SystemVersionID) * CHAR_BIT) + typeID; } systemContainer.emplace(id, std::make_unique()); + systemContainer[id].get()->systemID = id; + return id; } @@ -103,7 +105,7 @@ namespace SHADE ***************************************************************************/ static void Init() noexcept; - static void RunRoutines(bool editorPause) noexcept; + static void RunRoutines(bool editorPause, double deltaTime) noexcept; template static void RegisterRoutine(SystemVersionID version = 0) noexcept @@ -112,6 +114,7 @@ namespace SHADE if (system == nullptr) return; systemRoutineContainer.emplace_back(std::make_unique()); + systemRoutineContainer.back().get()->system = system; } diff --git a/SHADE_Engine/src/ECS_Base/System/SHFixedSystemRoutine.cpp b/SHADE_Engine/src/ECS_Base/System/SHFixedSystemRoutine.cpp index 2c97bfb4..fa34a5cf 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHFixedSystemRoutine.cpp +++ b/SHADE_Engine/src/ECS_Base/System/SHFixedSystemRoutine.cpp @@ -1,10 +1,11 @@ +#include "SHpch.h" #include "SHFixedSystemRoutine.h" #include "../SHECSMacros.h" namespace SHADE { - void SHFixedSystemRoutine::Execute(double dt) + void SHFixedSystemRoutine::Execute(double dt) noexcept { accumulatedTime += dt; int counter = 0; diff --git a/SHADE_Engine/src/ECS_Base/System/SHRoutineStats.h b/SHADE_Engine/src/ECS_Base/System/SHRoutineStats.h index e294264a..513358ee 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHRoutineStats.h +++ b/SHADE_Engine/src/ECS_Base/System/SHRoutineStats.h @@ -15,13 +15,14 @@ namespace SHADE double executionTime; int numSteps{1}; - friend std::ostream& operator<<(std::ostream& os, const SHRoutineStats& stats); + //friend std::ostream& operator<<(std::ostream& os, const SHRoutineStats& stats); }; - std::ostream& operator<<(std::ostream& os, const SHRoutineStats& stats) - { - os << stats.name << ": Execution Time: " << stats.executionTime << " Number of steps: " << stats.numSteps << std::endl; - } + //std::ostream& operator<<(std::ostream& os, const SHRoutineStats& stats) + //{ + // os << stats.name << ": Execution Time: " << stats.executionTime << " Number of steps: " << stats.numSteps << std::endl; + // return os; + //} } \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystem.h b/SHADE_Engine/src/ECS_Base/System/SHSystem.h index a2964a91..19b16f72 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHSystem.h +++ b/SHADE_Engine/src/ECS_Base/System/SHSystem.h @@ -10,6 +10,8 @@ #pragma once +#include "../SHECSMacros.h" + namespace SHADE { @@ -17,12 +19,18 @@ namespace SHADE class SHSystem { + private: + SystemID systemID; + protected: /*!************************************************************************* * \brief * Protected default constructor for SHSytem class ***************************************************************************/ SHSystem()= default; + + + public: /*!************************************************************************* @@ -51,37 +59,14 @@ namespace SHADE ***************************************************************************/ virtual void Exit() = 0; + friend class SHSystemManager; + + inline SystemID GetSystemID(void) const noexcept { return systemID; } + inline SystemVersionID GetSystemVersion(void) const noexcept { return static_cast(systemID >> sizeof(SystemVersionID) * CHAR_BIT); } - protected: - }; - - - class SHTestSystem : public SHSystem - { - public: - - SHTestSystem() = default; - ~SHTestSystem() = default; - - int value{5}; - - void Init() - { - - } - - - - void Exit() - { - - } - }; - - } \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.cpp b/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.cpp index 83107c60..73157e8b 100644 --- a/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.cpp +++ b/SHADE_Engine/src/ECS_Base/System/SHSystemRoutine.cpp @@ -1,5 +1,7 @@ +#include "SHpch.h" #include "SHSystemRoutine.h" + namespace SHADE { diff --git a/SHADE_Engine/src/ECS_Base/UnitTesting/SHECSUnitTest.cpp b/SHADE_Engine/src/ECS_Base/UnitTesting/SHECSUnitTest.cpp new file mode 100644 index 00000000..c9d8477b --- /dev/null +++ b/SHADE_Engine/src/ECS_Base/UnitTesting/SHECSUnitTest.cpp @@ -0,0 +1,181 @@ +#include "SHpch.h" +#include "SHECSUnitTest.h" +#include "../Managers/SHComponentManager.h" +#include "../Managers/SHEntityManager.h" +#include "../Managers/SHSystemManager.h" +#include "SHTestComponents.h" +#include "SHTestSystems.h" +#include "Tools/SHLogger.h" + + + +namespace SHADE +{ + void SHECSUnitTest::TestAll(void) noexcept + { + TestBasicEntityCreate(); + TestEntityCreateTemplate(); + TestEntityDestroy(); + TestSystemRoutine(); + } + + + void SHECSUnitTest::TestBasicEntityCreate(void) noexcept + { + + SHComponentManager::CreateComponentSparseSet(); + SHComponentManager::CreateComponentSparseSet(); + SHComponentManager::CreateComponentSparseSet(); + + SHLOG_INFO("Test for add and remove component") + + EntityID id1 = SHEntityManager::CreateEntity(); + EntityID id2 = SHEntityManager::CreateEntity(); + EntityID id3 = SHEntityManager::CreateEntity(); + + + SHComponentManager::AddComponent(id1); + } + + + void SHECSUnitTest::TestEntityCreateTemplate(void) noexcept + { + std::cout << "\nTest2" << std::endl; + //Test entity Creation. + + SHComponentManager::CreateComponentSparseSet(); + SHComponentManager::CreateComponentSparseSet(); + SHComponentManager::CreateComponentSparseSet(); + + + + for (size_t i = 0; i < 10000; ++i) + { + switch (i % 3) + { + case 0: + { + SHEntityManager::CreateEntity(); + }break; + case 1: + { + SHEntityManager::CreateEntity(); + }break; + + case 2: + { + SHEntityManager::CreateEntity(); + }break; + default: + break; + } + + + } + + + auto& denseA = SHComponentManager::GetDense(); + auto& denseB = SHComponentManager::GetDense(); + auto& denseC = SHComponentManager::GetDense(); + + std::cout << "Test Entity Creation" << std::endl; + std::cout << "dense A size: " << denseA.size() << ((denseA.size() == 10000) ? " Success" : " Failure") << std::endl; + std::cout << "dense B size: " << denseB.size() << ((denseB.size() == 3334) ? " Success" : " Failure") << std::endl; + std::cout << "dense C size: " << denseC.size() << ((denseC.size() == 3333) ? " Success" : " Failure") << std::endl; + std::cout << "Number of entities: " << SHEntityManager::GetEntityCount() << (SHEntityManager::GetEntityCount() == 10000 ? " Success" : " Failure") << std::endl; + + SHEntityManager::DestroyAllEntity(); + std::cout << std::endl << "Test Destroy All Entity" << std::endl; + std::cout << "dense A size: " << denseA.size() << ((denseA.size() == 0) ? " Success" : " Failure") << std::endl; + std::cout << "dense B size: " << denseB.size() << ((denseB.size() == 0) ? " Success" : " Failure") << std::endl; + std::cout << "dense C size: " << denseC.size() << ((denseC.size() == 0) ? " Success" : " Failure") << std::endl; + std::cout << "Number of entities: " << SHEntityManager::GetEntityCount() << (SHEntityManager::GetEntityCount() == 0 ? " Success" : " Failure") << std::endl; + + + } + + + void SHECSUnitTest::TestEntityDestroy(void) noexcept + { + std::cout << "\nTest3" << std::endl; + SHComponentManager::CreateComponentSparseSet(); + SHComponentManager::CreateComponentSparseSet(); + SHComponentManager::CreateComponentSparseSet(); + + + + for (size_t i = 0; i < 10000; ++i) + { + switch (i % 3) + { + case 0: + { + SHEntityManager::CreateEntity(); + }break; + case 1: + { + SHEntityManager::CreateEntity(); + }break; + + case 2: + { + SHEntityManager::CreateEntity(); + }break; + default: + break; + } + + + } + + SHEntityManager::DestroyEntity(5000); + SHEntityManager::DestroyEntity(5001); + + + + + auto& denseA = SHComponentManager::GetDense(); + auto& denseB = SHComponentManager::GetDense(); + auto& denseC = SHComponentManager::GetDense(); + + + std::cout << "Test Entity Deletion" << std::endl; + std::cout << "dense A size: " << denseA.size() << ((denseA.size() == 9998) ? " Success" : " Failure") << std::endl; + std::cout << "dense B size: " << denseB.size() << ((denseB.size() == 3333) ? " Success" : " Failure") << std::endl; + std::cout << "dense C size: " << denseC.size() << ((denseC.size() == 3333) ? " Success" : " Failure") << std::endl; + std::cout << "Number of entities: " << SHEntityManager::GetEntityCount() << (SHEntityManager::GetEntityCount() == 9998 ? " Success" : " Failure") << std::endl; + + + std::cout << std::endl << "Test Entity Recreation" << std::endl; + EntityID id = SHEntityManager::CreateEntity(); + std::cout << "dense A size: " << denseA.size() << ((denseA.size() == 9998) ? " Success" : " Failure") << std::endl; + std::cout << "dense B size: " << denseB.size() << ((denseB.size() == 3333) ? " Success" : " Failure") << std::endl; + std::cout << "dense C size: " << denseC.size() << ((denseC.size() == 3334) ? " Success" : " Failure") << std::endl; + std::cout << "Entity ID: " << id << " EntityIndex: " << EntityHandleGenerator::GetIndex(id) << (EntityHandleGenerator::GetIndex(id) == 5001 ? " Success" : " Failure") << std::endl; + std::cout << "Number of entities: " << SHEntityManager::GetEntityCount() << (SHEntityManager::GetEntityCount() == 9999 ? " Success" : " Failure") << std::endl; + + + SHEntityManager::DestroyAllEntity(); + std::cout << std::endl << "Check Destroy All Entity" << std::endl; + std::cout << "dense A size: " << denseA.size() << ((denseA.size() == 0) ? " Success" : " Failure") << std::endl; + std::cout << "dense B size: " << denseB.size() << ((denseB.size() == 0) ? " Success" : " Failure") << std::endl; + std::cout << "dense C size: " << denseC.size() << ((denseC.size() == 0) ? " Success" : " Failure") << std::endl; + std::cout << "Number of entities: " << SHEntityManager::GetEntityCount() << (SHEntityManager::GetEntityCount() == 0 ? " Success" : " Failure") << std::endl; + + } + + void SHECSUnitTest::TestSystemRoutine(void) noexcept + { + SHSystemManager::CreateSystem(); + SHSystemManager::CreateSystem(); + + + SHSystemManager::RegisterRoutine(1); + + SHSystemManager::RunRoutines(false, 1.0 / 120.0); + + SHSystemManager::Exit(); + } + + +} \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/UnitTesting/SHECSUnitTest.h b/SHADE_Engine/src/ECS_Base/UnitTesting/SHECSUnitTest.h new file mode 100644 index 00000000..938ba865 --- /dev/null +++ b/SHADE_Engine/src/ECS_Base/UnitTesting/SHECSUnitTest.h @@ -0,0 +1,22 @@ +#pragma once + +namespace SHADE +{ + class SHECSUnitTest + { + public: + SHECSUnitTest() = delete; + ~SHECSUnitTest() = delete; + + static void TestBasicEntityCreate(void) noexcept; + static void TestEntityCreateTemplate(void) noexcept; + static void TestEntityDestroy(void) noexcept; + static void TestSystemRoutine(void) noexcept; + + static void TestAll(void) noexcept; + + + + + }; +} \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/UnitTesting/SHTestComponents.h b/SHADE_Engine/src/ECS_Base/UnitTesting/SHTestComponents.h new file mode 100644 index 00000000..e2e53d6b --- /dev/null +++ b/SHADE_Engine/src/ECS_Base/UnitTesting/SHTestComponents.h @@ -0,0 +1,30 @@ +#pragma once + +#include "../Components/SHComponent.h" + +namespace SHADE +{ + + class SHComponent_A :public SHComponent + { + public: + int value{}; + + }; + + + class SHComponent_B :public SHComponent + { + public: + float x{}; + float y{}; + float z{}; + }; + + class SHComponent_C :public SHComponent + { + public: + std::string value{}; + }; + +} \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/UnitTesting/SHTestSystems.h b/SHADE_Engine/src/ECS_Base/UnitTesting/SHTestSystems.h new file mode 100644 index 00000000..7231b323 --- /dev/null +++ b/SHADE_Engine/src/ECS_Base/UnitTesting/SHTestSystems.h @@ -0,0 +1,40 @@ +#pragma once + + +#include +#include "../System/SHSystem.h" +#include "../System/SHSystemRoutine.h" + +namespace SHADE +{ + + class SHTestSystem : public SHSystem + { + public: + SHTestSystem() {}; + ~SHTestSystem() {}; + + + + std::string test{ "Test system" }; + + void Init() {}; + void Exit() {}; + + class SHTestRoutine : public SHSystemRoutine + { + public: + SHTestRoutine() + :SHSystemRoutine("Test System Routine", false) {} + + + virtual void Execute(double dt) noexcept + { + + std::cout << GetName() << " System Version: " << GetSystem()->GetSystemVersion() << std::endl; + } + }; + + + }; +} \ No newline at end of file -- 2.40.1