소스 검색

Merge pull request #12630 from aws-lumberyard-dev/GHI_9666_ExposeCurrentLevelNameWithoutCryModule

Removing Cry Dependency for Getting the Current Level Name
Gene Walters 2 년 전
부모
커밋
04800f8b01

+ 22 - 5
Code/Framework/AzFramework/AzFramework/API/ApplicationAPI.h

@@ -189,19 +189,36 @@ namespace AzFramework
         virtual void OnApplicationAboutToStop() {}
         virtual void OnApplicationAboutToStop() {}
     };
     };
 
 
-    class LevelSystemLifecycleRequests
+    class LevelLoadBlockerRequests
         : public AZ::EBusTraits
         : public AZ::EBusTraits
     {
     {
     public:
     public:
-        // Bus Configuration
         static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
         static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
         static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
         static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
 
 
-        // Gives handlers the opportunity to block the loadlevel command.
-        // Return true to stop loading.
+        //! Gives handlers the opportunity to block the loadlevel command.
+        //! There can be multiple handlers for this bus; if any one of them return true the loadlevel command will be stopped.
+        //! @return Return true to stop loading.
         virtual bool ShouldBlockLevelLoading([[maybe_unused]]const char* levelName) { return false; }
         virtual bool ShouldBlockLevelLoading([[maybe_unused]]const char* levelName) { return false; }
     };
     };
-    using LevelSystemLifecycleRequestBus = AZ::EBus<LevelSystemLifecycleRequests>;
+    using LevelLoadBlockerBus = AZ::EBus<LevelLoadBlockerRequests>;
+
+    class ILevelSystemLifecycle
+    {
+    public:
+        AZ_TYPE_INFO(ILevelSystemLifecycle, "{BDF3616A-4725-4B5D-AB71-34DFCDF9C5B0}");
+        virtual ~ILevelSystemLifecycle() = default;
+
+        //! Returns the name of the currently loaded level.
+        //! Note: for spawnable level system, this is the cache folder path to the level asset. Example: levels/mylevel/mylevel.spawnable
+        //! @return Level name or empty string if no level loaded.
+        virtual const char* GetCurrentLevelName() const = 0;
+
+        //! Checks if a level is loaded
+        //! @return true if a level is loaded; otherwise false.
+        virtual bool IsLevelLoaded() const = 0;
+    };
+    using LevelSystemLifecycleInterface = AZ::Interface<ILevelSystemLifecycle>;
 
 
     class LevelSystemLifecycleNotifications
     class LevelSystemLifecycleNotifications
         : public AZ::EBusTraits
         : public AZ::EBusTraits

+ 9 - 1
Code/Legacy/CryCommon/ILevelSystem.h

@@ -65,7 +65,15 @@ struct ILevelSystem
 
 
     virtual bool LoadLevel(const char* levelName) = 0;
     virtual bool LoadLevel(const char* levelName) = 0;
     virtual void UnloadLevel() = 0;
     virtual void UnloadLevel() = 0;
-    virtual bool IsLevelLoaded() = 0;
+
+    //! Deprecated.
+    //! @deprecated ILevelSystem is part of the legacy CryCommon module, please use AzFramework::LevelSystemLifecycleInterface::Get()->IsLevelLoaded instead.
+    //! O3DE_DEPRECATION_NOTICE(GHI-12715)
+    virtual bool IsLevelLoaded() const = 0;
+
+    //! Deprecated.
+    //! @deprecated ILevelSystem is part of the legacy CryCommon module, please use AzFramework::LevelSystemLifecycleInterface::Get()->GetCurrentLevelName instead.
+    //! O3DE_DEPRECATION_NOTICE(GHI-12715)
     virtual const char* GetCurrentLevelName() const = 0;
     virtual const char* GetCurrentLevelName() const = 0;
 
 
     // If the level load failed then we need to have a different shutdown procedure vs when a level is naturally unloaded
     // If the level load failed then we need to have a different shutdown procedure vs when a level is naturally unloaded

+ 3 - 0
Code/Legacy/CrySystem/LevelSystem/LevelSystem.cpp

@@ -200,6 +200,9 @@ CLevelSystem::CLevelSystem(ISystem* pSystem, const char* levelsFolder)
         });
         });
         m_levelPackCloseHandler.Connect(*levelPakCloseEvent);
         m_levelPackCloseHandler.Connect(*levelPakCloseEvent);
     }
     }
+
+    AZ_Error("LevelSystem", AzFramework::LevelSystemLifecycleInterface::Get() == this,
+        "Failed to register the LevelSystem with the LevelSystemLifecycleInterface.");
 }
 }
 
 
 //------------------------------------------------------------------------
 //------------------------------------------------------------------------

+ 8 - 1
Code/Legacy/CrySystem/LevelSystem/LevelSystem.h

@@ -10,6 +10,7 @@
 #pragma once
 #pragma once
 
 
 #include "ILevelSystem.h"
 #include "ILevelSystem.h"
+#include <AzFramework/API/ApplicationAPI.h>
 #include <AzFramework/Archive/IArchive.h>
 #include <AzFramework/Archive/IArchive.h>
 #include <CryCommon/TimeValue.h>
 #include <CryCommon/TimeValue.h>
 
 
@@ -73,6 +74,7 @@ private:
 
 
 class CLevelSystem
 class CLevelSystem
     : public ILevelSystem
     : public ILevelSystem
+    , AzFramework::LevelSystemLifecycleInterface::Registrar
 {
 {
 public:
 public:
     CLevelSystem(ISystem* pSystem, const char* levelsFolder);
     CLevelSystem(ISystem* pSystem, const char* levelsFolder);
@@ -91,7 +93,11 @@ public:
 
 
     bool LoadLevel(const char* levelName) override;
     bool LoadLevel(const char* levelName) override;
     void UnloadLevel() override;
     void UnloadLevel() override;
-    bool IsLevelLoaded() override { return m_bLevelLoaded; }
+
+    //! AzFramework::LevelSystemLifecycleInterface overrides.
+    //! @{
+    bool IsLevelLoaded() const override { return m_bLevelLoaded; }
+
     const char* GetCurrentLevelName() const override
     const char* GetCurrentLevelName() const override
     {
     {
         if (m_pCurrentLevel && m_pCurrentLevel->GetLevelInfo())
         if (m_pCurrentLevel && m_pCurrentLevel->GetLevelInfo())
@@ -100,6 +106,7 @@ public:
         }
         }
         return "";
         return "";
     }
     }
+    //! @}
 
 
     // If the level load failed then we need to have a different shutdown procedure vs when a level is naturally unloaded
     // If the level load failed then we need to have a different shutdown procedure vs when a level is naturally unloaded
     void SetLevelLoadFailed(bool loadFailed) override { m_levelLoadFailed = loadFailed; }
     void SetLevelLoadFailed(bool loadFailed) override { m_levelLoadFailed = loadFailed; }

+ 6 - 3
Code/Legacy/CrySystem/LevelSystem/SpawnableLevelSystem.cpp

@@ -83,6 +83,9 @@ namespace LegacyLevelSystem
 
 
         AzFramework::RootSpawnableNotificationBus::Handler::BusConnect();
         AzFramework::RootSpawnableNotificationBus::Handler::BusConnect();
 
 
+        AZ_Error("SpawnableLevelSystem", AzFramework::LevelSystemLifecycleInterface::Get() == this,
+            "Failed to register the SpawnableLevelSystem with the LevelSystemLifecycleInterface.");
+
         // If there were LoadLevel command invocations before the creation of the level system
         // If there were LoadLevel command invocations before the creation of the level system
         // then those invocations were queued.
         // then those invocations were queued.
         // load the last level in the queue, since only one level can be loaded at a time
         // load the last level in the queue, since only one level can be loaded at a time
@@ -113,7 +116,7 @@ namespace LegacyLevelSystem
         delete this;
         delete this;
     }
     }
 
 
-    bool SpawnableLevelSystem::IsLevelLoaded()
+    bool SpawnableLevelSystem::IsLevelLoaded() const
     {
     {
         return m_bLevelLoaded;
         return m_bLevelLoaded;
     }
     }
@@ -237,8 +240,8 @@ namespace LegacyLevelSystem
 
 
         // This is a valid level, find out if any systems need to stop level loading before proceeding
         // This is a valid level, find out if any systems need to stop level loading before proceeding
         bool blockLoading = false;
         bool blockLoading = false;
-        AzFramework::LevelSystemLifecycleRequestBus::EnumerateHandlers(
-            [&blockLoading, &validLevelName](AzFramework::LevelSystemLifecycleRequests* handler)->bool
+        AzFramework::LevelLoadBlockerBus::EnumerateHandlers(
+            [&blockLoading, &validLevelName](AzFramework::LevelLoadBlockerRequests* handler) -> bool
             {
             {
                 if (handler->ShouldBlockLevelLoading(validLevelName.c_str()))
                 if (handler->ShouldBlockLevelLoading(validLevelName.c_str()))
                 {
                 {

+ 11 - 6
Code/Legacy/CrySystem/LevelSystem/SpawnableLevelSystem.h

@@ -9,8 +9,7 @@
 #pragma once
 #pragma once
 
 
 #include "ILevelSystem.h"
 #include "ILevelSystem.h"
-#include <AzCore/Console/IConsole.h>
-#include <AzFramework/Archive/IArchive.h>
+#include <AzFramework/API/ApplicationAPI.h>
 #include <AzFramework/Spawnable/RootSpawnableInterface.h>
 #include <AzFramework/Spawnable/RootSpawnableInterface.h>
 #include <CryCommon/TimeValue.h>
 #include <CryCommon/TimeValue.h>
 
 
@@ -20,12 +19,14 @@ namespace LegacyLevelSystem
 class SpawnableLevelSystem
 class SpawnableLevelSystem
         : public ILevelSystem
         : public ILevelSystem
         , public AzFramework::RootSpawnableNotificationBus::Handler
         , public AzFramework::RootSpawnableNotificationBus::Handler
+        , AzFramework::LevelSystemLifecycleInterface::Registrar
     {
     {
     public:
     public:
         explicit SpawnableLevelSystem(ISystem* pSystem);
         explicit SpawnableLevelSystem(ISystem* pSystem);
         ~SpawnableLevelSystem() override;
         ~SpawnableLevelSystem() override;
 
 
-        // ILevelSystem
+        //! ILevelSystem overrides.
+        //! @{
         void Release() override;
         void Release() override;
 
 
         void AddListener(ILevelSystemListener* pListener) override;
         void AddListener(ILevelSystemListener* pListener) override;
@@ -33,8 +34,6 @@ class SpawnableLevelSystem
 
 
         bool LoadLevel(const char* levelName) override;
         bool LoadLevel(const char* levelName) override;
         void UnloadLevel() override;
         void UnloadLevel() override;
-        bool IsLevelLoaded() override;
-        const char* GetCurrentLevelName() const override;
 
 
         // If the level load failed then we need to have a different shutdown procedure vs when a level is naturally unloaded
         // If the level load failed then we need to have a different shutdown procedure vs when a level is naturally unloaded
         void SetLevelLoadFailed(bool loadFailed) override;
         void SetLevelLoadFailed(bool loadFailed) override;
@@ -42,12 +41,18 @@ class SpawnableLevelSystem
         AZ::Data::AssetType GetLevelAssetType() const override;
         AZ::Data::AssetType GetLevelAssetType() const override;
 
 
         // The following methods are deprecated from ILevelSystem and will be removed once slice support is removed.
         // The following methods are deprecated from ILevelSystem and will be removed once slice support is removed.
-
         // [LYN-2376] Remove once legacy slice support is removed
         // [LYN-2376] Remove once legacy slice support is removed
         void Rescan([[maybe_unused]] const char* levelsFolder) override;
         void Rescan([[maybe_unused]] const char* levelsFolder) override;
         int GetLevelCount() override;
         int GetLevelCount() override;
         ILevelInfo* GetLevelInfo([[maybe_unused]] int level) override;
         ILevelInfo* GetLevelInfo([[maybe_unused]] int level) override;
         ILevelInfo* GetLevelInfo([[maybe_unused]] const char* levelName) override;
         ILevelInfo* GetLevelInfo([[maybe_unused]] const char* levelName) override;
+        //! @}
+
+        //! AzFramework::LevelSystemLifecycleInterface overrides.
+        //! @{
+        const char* GetCurrentLevelName() const override;
+        bool IsLevelLoaded() const override;
+        //! @}
 
 
     private:
     private:
         void OnRootSpawnableAssigned(AZ::Data::Asset<AzFramework::Spawnable> rootSpawnable, uint32_t generation) override;
         void OnRootSpawnableAssigned(AZ::Data::Asset<AzFramework::Spawnable> rootSpawnable, uint32_t generation) override;

+ 6 - 3
Gems/ImGui/Code/Source/LYCommonMenu/ImGuiLYCommonMenu.cpp

@@ -303,13 +303,16 @@ namespace ImGui
 
 
                 // View Maps ( pending valid ILevelSystem )
                 // View Maps ( pending valid ILevelSystem )
                 auto lvlSystem = (gEnv && gEnv->pSystem) ? gEnv->pSystem->GetILevelSystem() : nullptr;
                 auto lvlSystem = (gEnv && gEnv->pSystem) ? gEnv->pSystem->GetILevelSystem() : nullptr;
-                if (lvlSystem && ImGui::BeginMenu("Levels"))
+                if (lvlSystem && AzFramework::LevelSystemLifecycleInterface::Get() && ImGui::BeginMenu("Levels"))
                 {
                 {
-                    if (lvlSystem->IsLevelLoaded())
+                    if (AzFramework::LevelSystemLifecycleInterface::Get()->IsLevelLoaded())
                     {
                     {
                         ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "Current Level: ");
                         ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "Current Level: ");
                         ImGui::SameLine();
                         ImGui::SameLine();
-                        ImGui::TextColored(ImGui::Colors::s_NiceLabelColor, "%s", lvlSystem->GetCurrentLevelName());
+                        ImGui::TextColored(
+                            ImGui::Colors::s_NiceLabelColor,
+                            "%s",
+                            AzFramework::LevelSystemLifecycleInterface::Get()->GetCurrentLevelName());
                     }
                     }
 
 
                     bool usePrefabSystemForLevels = false;
                     bool usePrefabSystemForLevels = false;

+ 2 - 2
Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp

@@ -237,7 +237,7 @@ namespace Multiplayer
         AzFramework::RootSpawnableNotificationBus::Handler::BusConnect();
         AzFramework::RootSpawnableNotificationBus::Handler::BusConnect();
         AZ::TickBus::Handler::BusConnect();
         AZ::TickBus::Handler::BusConnect();
         SessionNotificationBus::Handler::BusConnect();
         SessionNotificationBus::Handler::BusConnect();
-        AzFramework::LevelSystemLifecycleRequestBus::Handler::BusConnect();
+        AzFramework::LevelLoadBlockerBus::Handler::BusConnect();
         const AZ::Name interfaceName = AZ::Name(MpNetworkInterfaceName);
         const AZ::Name interfaceName = AZ::Name(MpNetworkInterfaceName);
         m_networkInterface = AZ::Interface<INetworking>::Get()->CreateNetworkInterface(interfaceName, sv_protocol, TrustZone::ExternalClientToServer, *this);
         m_networkInterface = AZ::Interface<INetworking>::Get()->CreateNetworkInterface(interfaceName, sv_protocol, TrustZone::ExternalClientToServer, *this);
 
 
@@ -263,7 +263,7 @@ namespace Multiplayer
         m_consoleCommandHandler.Disconnect();
         m_consoleCommandHandler.Disconnect();
         const AZ::Name interfaceName = AZ::Name(MpNetworkInterfaceName);
         const AZ::Name interfaceName = AZ::Name(MpNetworkInterfaceName);
         AZ::Interface<INetworking>::Get()->DestroyNetworkInterface(interfaceName);
         AZ::Interface<INetworking>::Get()->DestroyNetworkInterface(interfaceName);
-        AzFramework::LevelSystemLifecycleRequestBus::Handler::BusDisconnect();
+        AzFramework::LevelLoadBlockerBus::Handler::BusDisconnect();
         SessionNotificationBus::Handler::BusDisconnect();
         SessionNotificationBus::Handler::BusDisconnect();
         AZ::TickBus::Handler::BusDisconnect();
         AZ::TickBus::Handler::BusDisconnect();
         AzFramework::RootSpawnableNotificationBus::Handler::BusDisconnect();
         AzFramework::RootSpawnableNotificationBus::Handler::BusDisconnect();

+ 2 - 2
Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.h

@@ -45,7 +45,7 @@ namespace Multiplayer
         , public AzNetworking::IConnectionListener
         , public AzNetworking::IConnectionListener
         , public IMultiplayer
         , public IMultiplayer
         , AzFramework::RootSpawnableNotificationBus::Handler
         , AzFramework::RootSpawnableNotificationBus::Handler
-        , AzFramework::LevelSystemLifecycleRequestBus::Handler
+        , AzFramework::LevelLoadBlockerBus::Handler
     {
     {
     public:
     public:
         AZ_COMPONENT(MultiplayerSystemComponent, "{7C99C4C1-1103-43F9-AD62-8B91CF7C1981}");
         AZ_COMPONENT(MultiplayerSystemComponent, "{7C99C4C1-1103-43F9-AD62-8B91CF7C1981}");
@@ -148,7 +148,7 @@ namespace Multiplayer
         void OnRootSpawnableReady(AZ::Data::Asset<AzFramework::Spawnable> rootSpawnable, uint32_t generation) override;
         void OnRootSpawnableReady(AZ::Data::Asset<AzFramework::Spawnable> rootSpawnable, uint32_t generation) override;
         //! @}
         //! @}
 
 
-        //! AzFramework::LevelSystemLifecycleRequestBus::Handler overrides.
+        //! AzFramework::LevelLoadBlockerBus::Handler overrides.
         //! @{
         //! @{
         bool ShouldBlockLevelLoading(const char* levelName) override;
         bool ShouldBlockLevelLoading(const char* levelName) override;
         //! @}
         //! @}