SpawnableLevelSystem.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include "ILevelSystem.h"
  10. #include <AzFramework/API/ApplicationAPI.h>
  11. #include <AzFramework/Spawnable/RootSpawnableInterface.h>
  12. #include <CryCommon/TimeValue.h>
  13. namespace LegacyLevelSystem
  14. {
  15. class SpawnableLevelSystem
  16. : public ILevelSystem
  17. , public AzFramework::RootSpawnableNotificationBus::Handler
  18. , AzFramework::LevelSystemLifecycleInterface::Registrar
  19. {
  20. public:
  21. explicit SpawnableLevelSystem(ISystem* pSystem);
  22. ~SpawnableLevelSystem() override;
  23. //! ILevelSystem overrides.
  24. //! @{
  25. void Release() override;
  26. void AddListener(ILevelSystemListener* pListener) override;
  27. void RemoveListener(ILevelSystemListener* pListener) override;
  28. bool LoadLevel(const char* levelName) override;
  29. void UnloadLevel() override;
  30. // If the level load failed then we need to have a different shutdown procedure vs when a level is naturally unloaded
  31. void SetLevelLoadFailed(bool loadFailed) override;
  32. bool GetLevelLoadFailed() override;
  33. AZ::Data::AssetType GetLevelAssetType() const override;
  34. // The following methods are deprecated from ILevelSystem and will be removed once slice support is removed.
  35. // [LYN-2376] Remove once legacy slice support is removed
  36. void Rescan([[maybe_unused]] const char* levelsFolder) override;
  37. int GetLevelCount() override;
  38. ILevelInfo* GetLevelInfo([[maybe_unused]] int level) override;
  39. ILevelInfo* GetLevelInfo([[maybe_unused]] const char* levelName) override;
  40. //! @}
  41. //! AzFramework::LevelSystemLifecycleInterface overrides.
  42. //! @{
  43. const char* GetCurrentLevelName() const override;
  44. bool IsLevelLoaded() const override;
  45. //! @}
  46. private:
  47. void OnRootSpawnableAssigned(AZ::Data::Asset<AzFramework::Spawnable> rootSpawnable, uint32_t generation) override;
  48. void OnRootSpawnableReleased(uint32_t generation) override;
  49. void PrepareNextLevel(const char* levelName);
  50. bool LoadLevelInternal(const char* levelName);
  51. // Methods to notify ILevelSystemListener
  52. void OnPrepareNextLevel(const char* levelName);
  53. void OnLevelNotFound(const char* levelName);
  54. void OnLoadingStart(const char* levelName);
  55. void OnLoadingComplete(const char* levelName);
  56. void OnLoadingError(const char* levelName, const char* error);
  57. void OnLoadingProgress(const char* levelName, int progressAmount);
  58. void OnUnloadComplete(const char* levelName);
  59. void LogLoadingTime();
  60. AZStd::string m_lastLevelName;
  61. float m_fLastLevelLoadTime{0.0f};
  62. float m_fLastTime{0.0f};
  63. bool m_bLevelLoaded{false};
  64. bool m_levelLoadFailed{false};
  65. int m_nLoadedLevelsCount{0};
  66. CTimeValue m_levelLoadStartTime;
  67. AZStd::vector<ILevelSystemListener*> m_listeners;
  68. // Information about the currently-loaded root spawnable, used for tracking loads and unloads.
  69. uint64_t m_rootSpawnableGeneration{0};
  70. AZ::Data::AssetId m_rootSpawnableId{};
  71. };
  72. } // namespace LegacyLevelSystem