BsGameResourceManager.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEnginePrerequisites.h"
  5. #include "BsModule.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Interface that can be implemented by the resource loaders required
  10. * by GameResources.
  11. */
  12. class BS_SCR_BE_EXPORT IGameResourceLoader
  13. {
  14. public:
  15. virtual ~IGameResourceLoader() { }
  16. /**
  17. * @brief Loads the resource at the specified path.
  18. */
  19. virtual HResource load(const Path& path, bool keepLoaded) const = 0;
  20. };
  21. /**
  22. * @brief Handles loading of game resources when the standalone game is running.
  23. */
  24. class BS_SCR_BE_EXPORT StandaloneResourceLoader : public IGameResourceLoader
  25. {
  26. public:
  27. /**
  28. * @copydoc IGameResourceLoader::load
  29. */
  30. HResource load(const Path& path, bool keepLoaded) const override;
  31. };
  32. /**
  33. * @brief Keeps track of resources that can be dynamically loaded
  34. * during runtime. These resources will be packed with the game
  35. * build so that they're available on demand.
  36. *
  37. * Internal resource handle can be overridden so that editor or other
  38. * systems can handle resource loading more directly.
  39. */
  40. class BS_SCR_BE_EXPORT GameResourceManager : public Module<GameResourceManager>
  41. {
  42. public:
  43. GameResourceManager();
  44. /**
  45. * @brief Loads the resource at the specified path.
  46. *
  47. * @see Resources::load
  48. */
  49. HResource load(const Path& path, bool keepLoaded) const;
  50. /**
  51. * @copydoc load
  52. */
  53. template <class T>
  54. ResourceHandle<T> load(const Path& filePath, bool keepLoaded)
  55. {
  56. return static_resource_cast<T>(load(filePath, keepLoaded));
  57. }
  58. /**
  59. * @brief Sets the resource loader implementation that determines how are the
  60. * paths provided to ::load loaded.
  61. */
  62. void setLoader(const SPtr<IGameResourceLoader>& loader);
  63. private:
  64. SPtr<IGameResourceLoader> mLoader;
  65. };
  66. }