CmResource.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmIReflectable.h"
  4. namespace CamelotEngine
  5. {
  6. /**
  7. * @brief Base class for all resources used in the engine.
  8. */
  9. class CM_EXPORT Resource : public IReflectable
  10. {
  11. public:
  12. Resource();
  13. virtual ~Resource() {};
  14. const String& getUUID() const { return mUUID; }
  15. /**
  16. * @brief Returns true if the object has been properly initialized. You are not
  17. * allowed to call any methods on the resource until you are sure resource is initialized.
  18. */
  19. bool isInitialized() const { return mIsInitialized; }
  20. /**
  21. * @brief Blocks the current thread until the resource is fully initialized.
  22. */
  23. void waitUntilInitialized();
  24. protected:
  25. friend class Resources;
  26. //virtual void unload() = 0;
  27. //virtual void calculateSize() = 0;
  28. //virtual void reload();
  29. /**
  30. * @brief Finishes up resource initialization. Usually called right after the resource is created.
  31. * Make sure that derived classes implement their own initialize_internal, and make sure
  32. * they call this implementation from it.
  33. */
  34. virtual void initialize_internal();
  35. /**
  36. * @brief Marks the resource as initialized.
  37. */
  38. void setInitialized() { mIsInitialized = true; }
  39. String mUUID;
  40. UINT32 mSize;
  41. // Transient
  42. bool mIsInitialized;
  43. CM_STATIC_THREAD_SYNCHRONISER(mResourceLoadedCondition)
  44. CM_STATIC_MUTEX(mResourceLoadedMutex)
  45. /************************************************************************/
  46. /* SERIALIZATION */
  47. /************************************************************************/
  48. public:
  49. friend class ResourceRTTI;
  50. static RTTITypeBase* getRTTIStatic();
  51. virtual RTTITypeBase* getRTTI() const;
  52. };
  53. }