Merge branch 'main' into SP3-5-ECS

This commit is contained in:
maverickdgg 2022-09-08 12:17:10 +08:00
commit 4c5c5f61e8
14 changed files with 663 additions and 27 deletions

View File

@ -98,12 +98,16 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\Application\SBApplication.h" />
<ClInclude Include="src\SBpch.h" /> <ClInclude Include="src\SBpch.h" />
<ClInclude Include="src\Scenes\SBTestScene.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\Application\SBApplication.cpp" />
<ClCompile Include="src\SBpch.cpp"> <ClCompile Include="src\SBpch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader> <PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile> </ClCompile>
<ClCompile Include="src\Scenes\SBTestScene.cpp" />
<ClCompile Include="src\WinMain.cpp" /> <ClCompile Include="src\WinMain.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -0,0 +1,43 @@
#include "SBpch.h"
#include "SBApplication.h"
#ifdef SHEDITOR
#include "Editor/SHEditor.h"
#include "Scenes/SBEditorScene.h"
#endif // SHEDITOR
#include <chrono>
#include <ratio>
#include <ctime>
namespace Sandbox
{
bool paused = false;
void SBApplication::Initialize(void)
{
#ifdef SHEDITOR
#else
#endif
}
void SBApplication::Update(void)
{
//TODO: Change true to window is open
while(true)
{
#ifdef SHEDITOR
#else
#endif
}
}
void SBApplication::Exit(void)
{
#ifdef SHEDITOR
#else
#endif
}
}

View File

@ -0,0 +1,23 @@
#ifndef SB_APPLICATION_H
#define SB_APPLICATION_H
//using namespace SHADE;
namespace Sandbox
{
class SBApplication
{
private:
//SHAppConfig config;
public:
SBApplication() = default;
void Initialize(void);
void Update(void);
void Exit(void);
private:
//std::common_type_t<double> collisionSystemTime, physicsSystemTime, transformSystemTime, audioSystemTime, renderSystemTime, gameTime;
//std::chrono::high_resolution_clock::time_point audioStart, audioEnd, transformStart, transformEnd, physicsStart, physicsEnd, collisionStart, collisionEnd, renderStart, renderEnd, gameStart, gameEnd;
};
}
#endif

View File

@ -0,0 +1,48 @@
#include "SBpch.h"
#include "SBTestScene.h"
using namespace SHADE;
namespace Sandbox
{
void SBTestScene::WindowFocusFunc([[maybe_unused]]void* window, int focused)
{
if(focused)
{
}
else
{
}
}
void SBTestScene::Load()
{
}
void SBTestScene::Init()
{
}
void SBTestScene::Update(float dt)
{
(void)dt;
}
void SBTestScene::Render()
{
}
void SBTestScene::Unload()
{
}
void SBTestScene::Free()
{
//SHSerialization::SerializeScene("resources/scenes/Scene01.SHADE");
}
}

View File

@ -0,0 +1,29 @@
#pragma once
#include "Scene/SHScene.h"
#include "Scene/SHSceneManager.h"
namespace Sandbox
{
class SBTestScene : public SHADE::SHScene
{
private:
EntityID camera;
public:
virtual void Load();
virtual void Init();
virtual void Update(float dt);
virtual void Render();
virtual void Free();
virtual void Unload();
//TODO: Change to new window DO IT IN CPP TOO
void WindowFocusFunc(void* window, int focused);
SBTestScene(void) = default;
};
}

View File

@ -1,7 +1,29 @@
#include "SBpch.h" #include "SBpch.h"
#include <Engine/SHEngine.h>
#include "Application/SBApplication.h"
#define _CRTDBG_MAP_ALLOC
#include <cstdlib>
#include <crtdbg.h>
#ifdef _DEBUG
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
// Replace _NORMAL_BLOCK with _CLIENT_BLOCK if you want the
// allocations to be of _CLIENT_BLOCK type
#else
#define DBG_NEW new
#endif
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR lpCmdLine, INT nCmdShow) PSTR lpCmdLine, INT nCmdShow)
{ {
#ifndef SHEDITOR
ShowWindow(::GetConsoleWindow(), SW_HIDE);
#endif
SHADE::SHEngine::Run<Sandbox::SBApplication>();
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
return 0; return 0;
} }

View File

@ -116,6 +116,9 @@
<ClInclude Include="src\Engine\ECS_Base\System\SHSystem.h" /> <ClInclude Include="src\Engine\ECS_Base\System\SHSystem.h" />
<ClInclude Include="src\Engine\ECS_Base\System\SHSystemManager.h" /> <ClInclude Include="src\Engine\ECS_Base\System\SHSystemManager.h" />
<ClInclude Include="src\Engine\SHEngine.h" /> <ClInclude Include="src\Engine\SHEngine.h" />
<ClInclude Include="src\Meta\SHIsDetected.h" />
<ClInclude Include="src\Scene\SHScene.h" />
<ClInclude Include="src\Scene\SHSceneManager.h" />
<ClInclude Include="src\SHpch.h" /> <ClInclude Include="src\SHpch.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -126,6 +129,7 @@
<ClCompile Include="src\Engine\ECS_Base\System\SHEntityManager.cpp" /> <ClCompile Include="src\Engine\ECS_Base\System\SHEntityManager.cpp" />
<ClCompile Include="src\Engine\ECS_Base\System\SHSystemManager.cpp" /> <ClCompile Include="src\Engine\ECS_Base\System\SHSystemManager.cpp" />
<ClCompile Include="src\Engine\SHEngine.cpp" /> <ClCompile Include="src\Engine\SHEngine.cpp" />
<ClCompile Include="src\Scene\SHSceneManager.cpp" />
<ClCompile Include="src\SHpch.cpp"> <ClCompile Include="src\SHpch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader> <PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile> </ClCompile>

View File

@ -4,36 +4,93 @@
<Filter Include="Engine"> <Filter Include="Engine">
<UniqueIdentifier>{DBC7D3B0-C769-FE86-B024-12DB9C6585D7}</UniqueIdentifier> <UniqueIdentifier>{DBC7D3B0-C769-FE86-B024-12DB9C6585D7}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Engine\ECS_Base">
<UniqueIdentifier>{7FF59BF8-EB80-09BD-F491-8CB1609C65BD}</UniqueIdentifier>
</Filter>
<Filter Include="Engine\ECS_Base\Components">
<UniqueIdentifier>{340D0110-201D-ADE0-89D6-11FF75059C79}</UniqueIdentifier>
</Filter>
<Filter Include="Engine\ECS_Base\Entity">
<UniqueIdentifier>{EBFC8BDC-D7F6-B42E-C063-4B3FACFC1A9B}</UniqueIdentifier>
</Filter>
<Filter Include="Engine\ECS_Base\General">
<UniqueIdentifier>{6CD692F2-D80D-DB89-E117-3FAD4DCE0183}</UniqueIdentifier>
</Filter>
<Filter Include="Engine\ECS_Base\System">
<UniqueIdentifier>{B3E3FAFD-9FDD-2350-884A-BA6074E389BC}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\Engine\ECS_Base\Components\SHComponent.h">
<Filter>Engine\ECS_Base\Components</Filter>
</ClInclude>
<ClInclude Include="src\Engine\ECS_Base\Components\SHComponentGroup.h">
<Filter>Engine\ECS_Base\Components</Filter>
</ClInclude>
<ClInclude Include="src\Engine\ECS_Base\Entity\SHEntity.h">
<Filter>Engine\ECS_Base\Entity</Filter>
</ClInclude>
<ClInclude Include="src\Engine\ECS_Base\General\SHFamily.h">
<Filter>Engine\ECS_Base\General</Filter>
</ClInclude>
<ClInclude Include="src\Engine\ECS_Base\General\SHHandleGenerator.h">
<Filter>Engine\ECS_Base\General</Filter>
</ClInclude>
<ClInclude Include="src\Engine\ECS_Base\General\SHSparseBase.h">
<Filter>Engine\ECS_Base\General</Filter>
</ClInclude>
<ClInclude Include="src\Engine\ECS_Base\General\SHSparseSet.h">
<Filter>Engine\ECS_Base\General</Filter>
</ClInclude>
<ClInclude Include="src\Engine\ECS_Base\General\SHSparseSetContainer.h">
<Filter>Engine\ECS_Base\General</Filter>
</ClInclude>
<ClInclude Include="src\Engine\ECS_Base\SHECSMacros.h">
<Filter>Engine\ECS_Base</Filter>
</ClInclude>
<ClInclude Include="src\Engine\ECS_Base\System\SHComponentManager.h">
<Filter>Engine\ECS_Base\System</Filter>
</ClInclude>
<ClInclude Include="src\Engine\ECS_Base\System\SHEntityManager.h">
<Filter>Engine\ECS_Base\System</Filter>
</ClInclude>
<ClInclude Include="src\Engine\ECS_Base\System\SHSystem.h">
<Filter>Engine\ECS_Base\System</Filter>
</ClInclude>
<ClInclude Include="src\Engine\ECS_Base\System\SHSystemManager.h">
<Filter>Engine\ECS_Base\System</Filter>
</ClInclude>
<ClInclude Include="src\Engine\SHEngine.h"> <ClInclude Include="src\Engine\SHEngine.h">
<Filter>Engine</Filter> <Filter>Engine</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\SHpch.h" /> <ClInclude Include="src\SHpch.h" />
<ClInclude Include="src\Engine\ECS_Base\Components\SHComponent.h" /> <ClInclude Include="src\Meta\SHIsDetected.h" />
<ClInclude Include="src\Engine\ECS_Base\Components\SHComponentGroup.h" /> <ClInclude Include="src\Scene\SHScene.h" />
<ClInclude Include="src\Engine\ECS_Base\Entity\SHEntity.h" /> <ClInclude Include="src\Scene\SHSceneManager.h" />
<ClInclude Include="src\Engine\ECS_Base\General\SHFamily.h" />
<ClInclude Include="src\Engine\ECS_Base\General\SHHandleGenerator.h" />
<ClInclude Include="src\Engine\ECS_Base\General\SHSparseBase.h" />
<ClInclude Include="src\Engine\ECS_Base\General\SHSparseSet.h" />
<ClInclude Include="src\Engine\ECS_Base\General\SHSparseSetContainer.h" />
<ClInclude Include="src\Engine\ECS_Base\System\SHComponentManager.h" />
<ClInclude Include="src\Engine\ECS_Base\System\SHEntityManager.h" />
<ClInclude Include="src\Engine\ECS_Base\System\SHSystem.h" />
<ClInclude Include="src\Engine\ECS_Base\System\SHSystemManager.h" />
<ClInclude Include="src\Engine\ECS_Base\SHECSMacros.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\Engine\ECS_Base\Components\SHComponent.cpp">
<Filter>Engine\ECS_Base\Components</Filter>
</ClCompile>
<ClCompile Include="src\Engine\ECS_Base\Components\SHComponentGroup.cpp">
<Filter>Engine\ECS_Base\Components</Filter>
</ClCompile>
<ClCompile Include="src\Engine\ECS_Base\Entity\SHEntity.cpp">
<Filter>Engine\ECS_Base\Entity</Filter>
</ClCompile>
<ClCompile Include="src\Engine\ECS_Base\System\SHComponentManager.cpp">
<Filter>Engine\ECS_Base\System</Filter>
</ClCompile>
<ClCompile Include="src\Engine\ECS_Base\System\SHEntityManager.cpp">
<Filter>Engine\ECS_Base\System</Filter>
</ClCompile>
<ClCompile Include="src\Engine\ECS_Base\System\SHSystemManager.cpp">
<Filter>Engine\ECS_Base\System</Filter>
</ClCompile>
<ClCompile Include="src\Engine\SHEngine.cpp"> <ClCompile Include="src\Engine\SHEngine.cpp">
<Filter>Engine</Filter> <Filter>Engine</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\SHpch.cpp" /> <ClCompile Include="src\SHpch.cpp" />
<ClCompile Include="src\Engine\ECS_Base\Components\SHComponent.cpp" /> <ClCompile Include="src\Scene\SHSceneManager.cpp" />
<ClCompile Include="src\Engine\ECS_Base\Components\SHComponentGroup.cpp" />
<ClCompile Include="src\Engine\ECS_Base\Entity\SHEntity.cpp" />
<ClCompile Include="src\Engine\ECS_Base\System\SHComponentManager.cpp" />
<ClCompile Include="src\Engine\ECS_Base\System\SHEntityManager.cpp" />
<ClCompile Include="src\Engine\ECS_Base\System\SHSystemManager.cpp" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,2 +1 @@
#include "SHpch.h" #include "SHpch.h"
#include "SHEngine.h"

View File

@ -1,9 +1,39 @@
#pragma once #ifndef SH_ENGINE_H
#define SH_ENGINE_H
#include <utility>
#include "Meta/SHIsDetected.h"
namespace SHADE namespace SHADE
{ {
class SHEngine template <typename Application>
{ using GetInit_t = decltype (std::declval<Application&>().Initialize());
}; template <typename Application>
} using GetUpdate_t = decltype (std::declval<Application&>().Update());
template <typename Application>
using GetExit_t = decltype (std::declval<Application&>().Exit());
class SHEngine
{
public:
template <class Application>
static void Run(void)
{
static_assert(SHIsDetected<GetInit_t, Application>::value, "Init Not Detected");
static_assert(SHIsDetected<GetUpdate_t, Application>::value, "Update Not Detected");
static_assert(SHIsDetected<GetExit_t, Application>::value, "Exit Not Detected");
static Application application;
application.Initialize();
application.Update();
application.Exit();
};
};
};
#endif

View File

@ -0,0 +1,25 @@
#ifndef SH_HAS_MEMBER_H
#define SH_HAS_MEMBER_H
#include <type_traits>
namespace SHADE
{
template <template <typename...> typename InvocationCheckAlias, typename EvaluatedVoid, typename... ICAArgs>
struct IsDetected : std::false_type
{
using value = std::false_type;
};
template <template <typename...> typename InvocationCheckAlias, typename... ICAArgs>
struct IsDetected<InvocationCheckAlias, std::void_t<InvocationCheckAlias<ICAArgs...>>, ICAArgs...> : std::true_type
{
using value = std::true_type;
};
template <template <typename...> typename InvocationCheckAlias, typename... ICAArgs>
using SHIsDetected = typename IsDetected <InvocationCheckAlias, void, ICAArgs...>::value;
}
#endif

View File

@ -0,0 +1,44 @@
/*********************************************************************
* \file SHScene.h
* \author Daniel Chua Yee Chen
* \brief Declaration for the SHScene abstract base class
*
* \copyright Copyright (c) 2021 DigiPen Institute of Technology. Reproduction
or disclosure of this file or its contents without the prior written
consent of DigiPen Institute of Technology is prohibited.
*********************************************************************/
#ifndef SH_SCENE_H
#define SH_SCENE_H
#include <string>
namespace SHADE
{
class SHScene
{
private:
protected:
SHScene() = default;
public:
std::string sceneName;
virtual ~SHScene() = default;
virtual void Load() = 0;
virtual void Init() = 0;
virtual void Update(float dt) = 0;
virtual void Render() = 0;
virtual void Free() = 0;
virtual void Unload() = 0;
};
}
#endif

View File

@ -0,0 +1,148 @@
/*********************************************************************
* \file SHSceneManager.cpp
* \author Daniel Chua Yee Chen
* \brief Definition of functions for the SHSceneManager class
* This class handles the changing of game scenes.
*
* \copyright Copyright (c) 2021 DigiPen Institute of Technology. Reproduction
or disclosure of this file or its contents without the prior written
consent of DigiPen Institute of Technology is prohibited.
*********************************************************************/
#include "SHpch.h"
#include "SHSceneManager.h"
#include "Engine/ECS_Base/System/SHComponentManager.h"
//#include "Input/SHInputManager.h"
//#include "Engine/Rendering/Window/SHRenderingWindow.h"
#include "Engine/ECS_Base/System/SHEntityManager.h"
#include "Engine/ECS_Base/System/SHSystemManager.h"
//#include "FRC/SHFrameRateController.h"
//#include "ECS_Base/System/SHApplication.h"
#include <iostream>
namespace SHADE
{
bool SHSceneManager::quit = false;
bool SHSceneManager::sceneChanged = false;
bool SHSceneManager::prevSceneReload = false;
bool SHSceneManager::cleanReload = false;
std::string SHSceneManager::newSceneName{};
uint32_t SHSceneManager::currentSceneID = UINT32_MAX;
uint32_t SHSceneManager::nextSceneID = UINT32_MAX;
SHScene* SHSceneManager::currentScene = nullptr;
//SHScene* SHSceneManager::nextScene = nullptr;
std::function<void()> SHSceneManager::newScene = []() {};
//void (*SHSceneManager::prevSceneCreate)() = []() {};
void SHSceneManager::UpdateSceneManager() noexcept
{
if (sceneChanged == false)
{
return;
}
sceneChanged = false;
if (nextSceneID != currentSceneID)
{
if (currentScene)
{
currentScene->Free();
currentScene->Unload();
SHEntityManager::DestroyAllEntity();
delete currentScene;
}
if (!prevSceneReload)
{
newScene();
}
else
{
//prevSceneCreate();
void (*temp)();
//temp = prevSceneCreate;
//prevSceneCreate = newScene;
newScene = temp;
prevSceneReload = false;
}
//prevSceneID = currentSceneID;
currentSceneID = nextSceneID;
nextSceneID = UINT32_MAX;
if (currentScene != nullptr)
{
currentScene->Load();
currentScene->Init();
}
}
else // restarting scene
{
nextSceneID = UINT32_MAX;
currentScene->Free();
if (cleanReload == true)
{
cleanReload = false;
currentScene->Unload();
SHEntityManager::DestroyAllEntity();
currentScene->sceneName = newSceneName;
currentScene->Load();
}
else
SHEntityManager::DestroyAllEntity();
currentScene->Init();
}
}
void SHSceneManager::RestartScene(std::string const& sceneName) noexcept
{
if (currentScene->sceneName != sceneName)
{
cleanReload = true;
newSceneName = sceneName;
}
else
cleanReload = false;
nextSceneID = currentSceneID;
sceneChanged = true;
}
void SHSceneManager::RestartScene() noexcept
{
cleanReload = false;
nextSceneID = currentSceneID;
sceneChanged = true;
}
void SHSceneManager::SceneUpdate(float dt) noexcept
{
currentScene->Update(dt);
//currentScene->Update(0.016);
}
void SHSceneManager::SceneRender() noexcept
{
currentScene->Render();
}
void SHSceneManager::Exit() noexcept
{
currentScene->Free();
currentScene->Unload();
SHEntityManager::DestroyAllEntity();
delete currentScene;
}
std::string SHSceneManager::GetSceneName() noexcept
{
return currentScene->sceneName;
}
}

View File

@ -0,0 +1,160 @@
/*********************************************************************
* \file SHSceneManager.h
* \author Daniel Chua Yee Chen
* \brief Declaration for the SHSceneManager class
* This class handles the changing of game scenes.
*
* \copyright Copyright (c) 2021 DigiPen Institute of Technology. Reproduction
or disclosure of this file or its contents without the prior written
consent of DigiPen Institute of Technology is prohibited.
*********************************************************************/
#ifndef SH_SCENE_MANAGER_H
#define SH_SCENE_MANAGER_H
#include "Engine/ECS_Base/General/SHFamily.h"
#include "SHScene.h"
#include <functional>
namespace SHADE
{
class SHSceneManager
{
private:
//boolean to check if the scene has been changed
static bool sceneChanged;
//boolean to toggle to reload scene previous scene
static bool prevSceneReload;
//boolean to toggle reload scene while calling Load and Unload.
static bool cleanReload;
//The sceneID of the current scene
static uint32_t currentSceneID;
//The sceneID of the next scene
static uint32_t nextSceneID;
//The sceneID of the previous scene(DISABLED)
//static uint32_t prevSceneID;
//pointer to the current scene
static SHScene* currentScene;
//Used in reloading scene.
static std::string newSceneName;
//function pointer to store the new scene creation
static std::function<void()>newScene;
//function pointer that stores the creation of the previous scene. (DISABLED)
//static void(*prevSceneCreate)();
protected:
public:
//boolean to check if the programme has been terminated.
static bool quit;
/*!*************************************************************************
* \brief
* Initialize scene manager and loads a default scene
* @tparam T
* The type of the default scene
*
* \return
* None.
***************************************************************************/
template<typename T>
static std::enable_if_t<std::is_base_of_v<SHScene, T>, void> InitSceneManager(std::string const& sceneName) noexcept
{
//prevSceneCreate = newScene;
newScene = [sceneName]() { currentScene = new T(); currentScene->sceneName = sceneName; };
nextSceneID = SHFamilyID<SHScene>::template GetID<T>();
sceneChanged = true;
}
/*!*************************************************************************
* \brief
* Change the next scene to a specified scene
* @tparam T
* The type of the next scene.
* \return
* None.
***************************************************************************/
template<typename T>
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>())
{
return;
}
//prevSceneCreate = newScene;
newScene = [sceneName]() { currentScene = new T(); currentScene->sceneName; };
nextSceneID = SHFamilyID<SHScene>::template GetID<T>();
sceneChanged = true;
}
/*!*************************************************************************
* \brief
* Checks if the scene has to be change and Updates the
* scenemanager accordingly
***************************************************************************/
static void UpdateSceneManager() noexcept;
/*!*************************************************************************
* \brief
* Calls the cuurrent scene to run the Update function
***************************************************************************/
static void SceneUpdate(float dt) noexcept;
/*!*************************************************************************
* \brief
* Calls the current scene to run the Render function
***************************************************************************/
static void SceneRender() noexcept;
/*!*************************************************************************
* \brief
* Restarts current scene. Only Scene::Init() and Scene::Free()
* Scene::Load() and Scene::Unload() will not be called.
* Edit: allows for RestartScene to restart the scene with a different
* scene name.
* If a sceneName is different from the current one, Load and Unload will
* run.
***************************************************************************/
static void RestartScene(std::string const& sceneName ) noexcept;
/*!*************************************************************************
* \brief
* Restarts current scene. Only Scene::Init() and Scene::Free()
* Scene::Load() and Scene::Unload() will not be called.
* Reuse current scene name and Unload and Load will not run.
***************************************************************************/
static void RestartScene() noexcept;
/*!*************************************************************************
* \brief
* Change the scene to the previous scene (DISABLED)
***************************************************************************/
//static void ReloadPrevScene() noexcept;
/*!*************************************************************************
* \brief
* Cleans up memory usued by the SceneManager.
***************************************************************************/
static void Exit() noexcept;
static std::string GetSceneName() noexcept;
};
}
#endif