ILevelSystem.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. // Description : Gathers level information. Loads a level.
  9. #pragma once
  10. #include <IXml.h>
  11. #include <AzCore/Asset/AssetCommon.h>
  12. struct IConsoleCmdArgs;
  13. namespace AZ::IO
  14. {
  15. struct IArchive;
  16. }
  17. // [LYN-2376] Remove once legacy slice support is removed
  18. struct ILevelInfo
  19. {
  20. virtual ~ILevelInfo() = default;
  21. virtual const char* GetName() const = 0;
  22. virtual const char* GetPath() const = 0;
  23. virtual const char* GetAssetName() const = 0;
  24. };
  25. /*!
  26. * @deprecated. Deprecated, use AzFramework::LevelSystemLifecycleNotificationBus instead
  27. * Extend this class and call ILevelSystem::AddListener() to receive level system related events.
  28. */
  29. struct ILevelSystemListener
  30. {
  31. virtual ~ILevelSystemListener() = default;
  32. //! Called when loading a level fails due to it not being found.
  33. virtual void OnLevelNotFound([[maybe_unused]] const char* levelName) {}
  34. //! Called after ILevelSystem::PrepareNextLevel() completes.
  35. virtual void OnPrepareNextLevel([[maybe_unused]] const char* levelName) {}
  36. //! Called after ILevelSystem::OnLoadingStart() completes, before the level actually starts loading.
  37. virtual void OnLoadingStart([[maybe_unused]] const char* levelName) {}
  38. //! Called after the level finished
  39. virtual void OnLoadingComplete([[maybe_unused]] const char* levelName) {}
  40. //! Called when there's an error loading a level, with the level info and a description of the error.
  41. virtual void OnLoadingError([[maybe_unused]] const char* levelName, [[maybe_unused]] const char* error) {}
  42. //! Called whenever the loading status of a level changes. progressAmount goes from 0->100.
  43. virtual void OnLoadingProgress([[maybe_unused]] const char* levelName, [[maybe_unused]] int progressAmount) {}
  44. //! Called after a level is unloaded, before the data is freed.
  45. virtual void OnUnloadComplete([[maybe_unused]] const char* levelName) {}
  46. };
  47. struct ILevelSystem
  48. {
  49. virtual ~ILevelSystem() = default;
  50. virtual void Release() = 0;
  51. virtual void AddListener(ILevelSystemListener* pListener) = 0;
  52. virtual void RemoveListener(ILevelSystemListener* pListener) = 0;
  53. virtual bool LoadLevel(const char* levelName) = 0;
  54. virtual void UnloadLevel() = 0;
  55. //! Deprecated.
  56. //! @deprecated ILevelSystem is part of the legacy CryCommon module, please use AzFramework::LevelSystemLifecycleInterface::Get()->IsLevelLoaded instead.
  57. //! O3DE_DEPRECATION_NOTICE(GHI-12715)
  58. virtual bool IsLevelLoaded() const = 0;
  59. //! Deprecated.
  60. //! @deprecated ILevelSystem is part of the legacy CryCommon module, please use AzFramework::LevelSystemLifecycleInterface::Get()->GetCurrentLevelName instead.
  61. //! O3DE_DEPRECATION_NOTICE(GHI-12715)
  62. virtual const char* GetCurrentLevelName() const = 0;
  63. // If the level load failed then we need to have a different shutdown procedure vs when a level is naturally unloaded
  64. virtual void SetLevelLoadFailed(bool loadFailed) = 0;
  65. virtual bool GetLevelLoadFailed() = 0;
  66. virtual AZ::Data::AssetType GetLevelAssetType() const = 0;
  67. static const char* GetLevelsDirectoryName()
  68. {
  69. return LevelsDirectoryName;
  70. }
  71. // [LYN-2376] Deprecated methods, to be removed once slices are removed:
  72. virtual void Rescan(const char* levelsFolder) = 0;
  73. virtual int GetLevelCount() = 0;
  74. virtual ILevelInfo* GetLevelInfo(int level) = 0;
  75. virtual ILevelInfo* GetLevelInfo(const char* levelName) = 0;
  76. protected:
  77. static constexpr const char* LevelsDirectoryName = "levels";
  78. };