BsGameResourceManager.h 1.6 KB

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