Merge remote-tracking branch 'origin/main' into PhySH

This commit is contained in:
Diren D Bharwani 2022-12-11 20:44:25 +08:00
commit 60409b47cb
5 changed files with 61 additions and 24 deletions

View File

@ -13,11 +13,13 @@ constexpr SHEventIdentifier SH_COMPONENT_REMOVED_EVENT { 4 };
constexpr SHEventIdentifier SH_SCENEGRAPH_CHANGE_PARENT_EVENT { 5 }; constexpr SHEventIdentifier SH_SCENEGRAPH_CHANGE_PARENT_EVENT { 5 };
constexpr SHEventIdentifier SH_SCENEGRAPH_ADD_CHILD_EVENT { 6 }; constexpr SHEventIdentifier SH_SCENEGRAPH_ADD_CHILD_EVENT { 6 };
constexpr SHEventIdentifier SH_SCENEGRAPH_REMOVE_CHILD_EVENT { 7 }; constexpr SHEventIdentifier SH_SCENEGRAPH_REMOVE_CHILD_EVENT { 7 };
constexpr SHEventIdentifier SH_SCENE_ON_INIT_EVENT { 8 }; constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_ADDED_EVENT { 8 };
constexpr SHEventIdentifier SH_SCENE_ON_EXIT_EVENT { 9 }; constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_REMOVED_EVENT { 9 };
constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_ADDED_EVENT { 10 }; constexpr SHEventIdentifier SH_EDITOR_ON_PLAY_EVENT { 10 };
constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_REMOVED_EVENT { 11 }; constexpr SHEventIdentifier SH_EDITOR_ON_PAUSE_EVENT { 11 };
constexpr SHEventIdentifier SH_EDITOR_ON_PLAY_EVENT { 12 }; constexpr SHEventIdentifier SH_EDITOR_ON_STOP_EVENT { 12 };
constexpr SHEventIdentifier SH_EDITOR_ON_PAUSE_EVENT { 13 }; constexpr SHEventIdentifier SH_SCENE_INIT_PRE { 13 };
constexpr SHEventIdentifier SH_EDITOR_ON_STOP_EVENT { 14 }; constexpr SHEventIdentifier SH_SCENE_INIT_POST { 14 };
constexpr SHEventIdentifier SH_SCENE_EXIT_PRE { 15 };
constexpr SHEventIdentifier SH_SCENE_EXIT_POST { 16 };

View File

@ -12,6 +12,7 @@
// Project Headers // Project Headers
#include "SHSceneNode.h" #include "SHSceneNode.h"
#include "Assets/SHAssetMacros.h"
namespace SHADE namespace SHADE
{ {
@ -38,14 +39,10 @@ namespace SHADE
SHSceneNode* childRemoved = nullptr; SHSceneNode* childRemoved = nullptr;
}; };
struct SHSceneInitEvent
{
uint32_t sceneID = std::numeric_limits<uint32_t>::max();
};
struct SHSceneExitEvent struct SHSceneInitExitEvent
{ {
uint32_t sceneID = std::numeric_limits<uint32_t>::max(); AssetID sceneAssetID;
}; };
} // namespace SHADE } // namespace SHADE

View File

@ -204,7 +204,24 @@ namespace SHADE
} }
//////////////////////////////////////// ////////////////////////////////////////
return NODE_ITER->second->IsActive(); // Recurse up the tree until the root. If any parent is inactive, this node is inactive in the hierarchy.
const SHSceneNode* PARENT_NODE = NODE_ITER->second->parent;
while (PARENT_NODE->GetEntityID() != root->GetEntityID())
{
if (!PARENT_NODE->IsActive())
return false;
if (!PARENT_NODE->parent)
{
SHLOGV_ERROR("Entity {}'s node that is not the root has no parent!", PARENT_NODE->GetEntityID())
return false;
}
PARENT_NODE = PARENT_NODE->parent;
}
return true;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/

View File

@ -15,6 +15,8 @@
//#include "Rendering/Window/SHRenderingWindow.h" //#include "Rendering/Window/SHRenderingWindow.h"
#include "ECS_Base/Managers/SHEntityManager.h" #include "ECS_Base/Managers/SHEntityManager.h"
#include "ECS_Base/Managers/SHSystemManager.h" #include "ECS_Base/Managers/SHSystemManager.h"
#include "SHSceneEvents.h"
#include "Events/SHEventManager.hpp"
//#include "FRC/SHFrameRateController.h" //#include "FRC/SHFrameRateController.h"
//#include "ECS_Base/System/SHApplication.h" //#include "ECS_Base/System/SHApplication.h"
#include "SHSceneEvents.h" #include "SHSceneEvents.h"
@ -55,11 +57,17 @@ namespace SHADE
{ {
if (currentScene) if (currentScene)
{ {
SHSceneInitExitEvent exitEvent;
exitEvent.sceneAssetID = currentScene->sceneAssetID;
SHEventManager::BroadcastEvent<SHSceneInitExitEvent>(exitEvent, SH_SCENE_EXIT_PRE);
currentScene->Free(); currentScene->Free();
SHEventManager::BroadcastEvent<SHSceneExitEvent>(SHSceneExitEvent{ currentSceneID }, SH_SCENE_ON_EXIT_EVENT); SHEventManager::BroadcastEvent<SHSceneExitEvent>(SHSceneExitEvent{ currentSceneID }, SH_SCENE_ON_EXIT_EVENT);
currentScene->Unload(); currentScene->Unload();
SHEntityManager::DestroyAllEntity(); SHEntityManager::DestroyAllEntity();
SHEventManager::BroadcastEvent<SHSceneInitExitEvent>(exitEvent, SH_SCENE_EXIT_POST);
delete currentScene; delete currentScene;
} }
if (!prevSceneReload) if (!prevSceneReload)
@ -84,16 +92,25 @@ namespace SHADE
nextSceneID = UINT32_MAX; nextSceneID = UINT32_MAX;
if (currentScene != nullptr) if (currentScene != nullptr)
{ {
currentScene->Load();
currentScene->Init();
SHEventManager::BroadcastEvent<SHSceneInitEvent>(SHSceneInitEvent{ currentSceneID }, SH_SCENE_ON_INIT_EVENT); currentScene->Load();
SHSceneInitExitEvent initEvent;
initEvent.sceneAssetID = currentScene->sceneAssetID;
SHEventManager::BroadcastEvent<SHSceneInitExitEvent>(initEvent, SH_SCENE_INIT_PRE);
currentScene->Init();
SHEventManager::BroadcastEvent<SHSceneInitExitEvent>(initEvent, SH_SCENE_INIT_POST);
} }
} }
else // restarting scene else // restarting scene
{ {
nextSceneID = UINT32_MAX; nextSceneID = UINT32_MAX;
SHSceneInitExitEvent exitEvent;
exitEvent.sceneAssetID = currentScene->sceneAssetID;
SHEventManager::BroadcastEvent<SHSceneInitExitEvent>(exitEvent, SH_SCENE_EXIT_PRE);
currentScene->Free(); currentScene->Free();
SHEventManager::BroadcastEvent<SHSceneExitEvent>(SHSceneExitEvent{ currentSceneID }, SH_SCENE_ON_EXIT_EVENT); SHEventManager::BroadcastEvent<SHSceneExitEvent>(SHSceneExitEvent{ currentSceneID }, SH_SCENE_ON_EXIT_EVENT);
@ -102,14 +119,23 @@ namespace SHADE
cleanReload = false; cleanReload = false;
currentScene->Unload(); currentScene->Unload();
SHEntityManager::DestroyAllEntity(); SHEntityManager::DestroyAllEntity();
SHEventManager::BroadcastEvent<SHSceneInitExitEvent>(exitEvent, SH_SCENE_EXIT_POST);
currentScene->sceneName = newSceneName; currentScene->sceneName = newSceneName;
currentScene->Load(); currentScene->Load();
} }
else else
{
SHEntityManager::DestroyAllEntity(); SHEntityManager::DestroyAllEntity();
SHEventManager::BroadcastEvent<SHSceneInitExitEvent>(exitEvent, SH_SCENE_EXIT_POST);
}
SHSceneInitExitEvent initEvent;
initEvent.sceneAssetID = currentScene->sceneAssetID;
SHEventManager::BroadcastEvent<SHSceneInitExitEvent>(initEvent, SH_SCENE_INIT_PRE);
currentScene->Init(); currentScene->Init();
SHEventManager::BroadcastEvent<SHSceneInitEvent>(SHSceneInitEvent{ currentSceneID }, SH_SCENE_ON_INIT_EVENT); SHEventManager::BroadcastEvent<SHSceneInitExitEvent>(initEvent, SH_SCENE_INIT_POST);
} }
} }

View File

@ -133,11 +133,6 @@ namespace SHADE
void SHSceneNode::SetActive(bool newActiveState) noexcept void SHSceneNode::SetActive(bool newActiveState) noexcept
{ {
active = newActiveState; active = newActiveState;
for (auto* child : children)
{
child->SetActive(newActiveState);
}
} }
} // namespace SHADE } // namespace SHADE