Added Scene Init Exit events #291

Merged
maverickdgg merged 6 commits from SP3-12-SceneGraph into main 2022-12-06 13:39:58 +08:00
3 changed files with 41 additions and 1 deletions
Showing only changes of commit 4f1007e6be - Show all commits

View File

@ -18,4 +18,8 @@ constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_REMOVED_EVENT { 9 };
constexpr SHEventIdentifier SH_EDITOR_ON_PLAY_EVENT { 10 }; constexpr SHEventIdentifier SH_EDITOR_ON_PLAY_EVENT { 10 };
constexpr SHEventIdentifier SH_EDITOR_ON_PAUSE_EVENT { 11 }; constexpr SHEventIdentifier SH_EDITOR_ON_PAUSE_EVENT { 11 };
constexpr SHEventIdentifier SH_EDITOR_ON_STOP_EVENT { 12 }; constexpr SHEventIdentifier SH_EDITOR_ON_STOP_EVENT { 12 };
constexpr SHEventIdentifier SH_SCENE_INIT_PRE { 13 };
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,4 +39,10 @@ namespace SHADE
SHSceneNode* childRemoved = nullptr; SHSceneNode* childRemoved = nullptr;
}; };
struct SHSceneInitExitEvent
{
AssetID sceneAssetID;
};
} // namespace SHADE } // namespace SHADE

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"
@ -54,9 +56,15 @@ namespace SHADE
{ {
if (currentScene) if (currentScene)
{ {
SHSceneInitExitEvent exitEvent;
exitEvent.sceneAssetID = currentScene->sceneAssetID;
SHEventManager::BroadcastEvent<SHSceneInitExitEvent>(exitEvent, SH_SCENE_EXIT_PRE);
currentScene->Free(); currentScene->Free();
currentScene->Unload(); currentScene->Unload();
SHEntityManager::DestroyAllEntity(); SHEntityManager::DestroyAllEntity();
SHEventManager::BroadcastEvent<SHSceneInitExitEvent>(exitEvent, SH_SCENE_EXIT_POST);
delete currentScene; delete currentScene;
} }
@ -82,27 +90,48 @@ namespace SHADE
nextSceneID = UINT32_MAX; nextSceneID = UINT32_MAX;
if (currentScene != nullptr) if (currentScene != nullptr)
{ {
currentScene->Load(); currentScene->Load();
SHSceneInitExitEvent initEvent;
initEvent.sceneAssetID = currentScene->sceneAssetID;
SHEventManager::BroadcastEvent<SHSceneInitExitEvent>(initEvent, SH_SCENE_INIT_PRE);
currentScene->Init(); 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();
if (cleanReload == true) if (cleanReload == true)
{ {
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<SHSceneInitExitEvent>(initEvent, SH_SCENE_INIT_POST);
} }
} }