BsResource.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsIReflectable.h"
  6. #include "BsCoreObject.h"
  7. namespace bs
  8. {
  9. /** @addtogroup Resources
  10. * @{
  11. */
  12. /** Base class for all resources. */
  13. class BS_CORE_EXPORT Resource : public IReflectable, public CoreObject
  14. {
  15. public:
  16. Resource(bool requiresGpuInitialization = true);
  17. virtual ~Resource() {};
  18. /** Returns the name of the resource. */
  19. const WString& getName() const;
  20. /** Sets the name of the resource. */
  21. void setName(const WString& name);
  22. /** Retrieves meta-data containing various information describing a resource. */
  23. SPtr<ResourceMetaData> getMetaData() const { return mMetaData; }
  24. /** Returns whether or not this resource is allowed to be asynchronously loaded. */
  25. virtual bool allowAsyncLoading() const { return true; }
  26. protected:
  27. friend class Resources;
  28. friend class ResourceHandleBase;
  29. /** Retrieves a list of all resources that this resource depends on. */
  30. virtual void getResourceDependencies(FrameVector<HResource>& dependencies) const { }
  31. /** Checks if all the resources this object is dependent on are fully loaded. */
  32. bool areDependenciesLoaded() const;
  33. /**
  34. * Returns true if the resource can be compressed using a generic compression when saved on a storage device.
  35. * Certain resources already have their contents compressed (like audio files) and will not benefit from further
  36. * compression. Resources supporting streaming should never be compressed, instead such resources can handle
  37. * compression/decompression locally through their streams.
  38. */
  39. virtual bool isCompressible() const { return true; }
  40. UINT32 mSize;
  41. SPtr<ResourceMetaData> mMetaData;
  42. /**
  43. * Signal to the resource implementation if original data should be kept in memory. This is sometimes needed if
  44. * the resource destroys original data during normal usage, but it might still be required for special purposes
  45. * (like saving in the editor).
  46. */
  47. bool mKeepSourceData;
  48. /************************************************************************/
  49. /* SERIALIZATION */
  50. /************************************************************************/
  51. public:
  52. friend class ResourceRTTI;
  53. static RTTITypeBase* getRTTIStatic();
  54. RTTITypeBase* getRTTI() const override;
  55. };
  56. /** @} */
  57. }