CmResource.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "CmResource.h"
  2. #include "CmResourceRTTI.h"
  3. #include "CmUUID.h"
  4. #include "CmRenderSystem.h"
  5. namespace CamelotEngine
  6. {
  7. CM_STATIC_THREAD_SYNCHRONISER_CLASS_INSTANCE(mResourceLoadedCondition, Resource)
  8. CM_STATIC_MUTEX_CLASS_INSTANCE(mResourceLoadedMutex, Resource)
  9. Resource::Resource()
  10. :mSize(0), mIsInitialized(false)
  11. {
  12. // We always generate a random UUID, and then overwrite it with the actual one
  13. // during loading if one was previously generated and saved.
  14. mUUID = UUIDGenerator::generateRandom();
  15. }
  16. void Resource::initialize_internal()
  17. {
  18. {
  19. CM_LOCK_MUTEX(mResourceLoadedMutex);
  20. mIsInitialized = true;
  21. }
  22. CM_THREAD_NOTIFY_ALL(mResourceLoadedCondition);
  23. }
  24. void Resource::waitUntilInitialized()
  25. {
  26. #if CM_DEBUG_MODE
  27. if(CM_THREAD_CURRENT_ID == RenderSystem::instancePtr()->getRenderThreadId())
  28. CM_EXCEPT(InternalErrorException, "You cannot call this method on the render thread. It will cause a deadlock!");
  29. #endif
  30. if(!mIsInitialized)
  31. {
  32. CM_LOCK_MUTEX_NAMED(mResourceLoadedMutex, lock);
  33. while(!mIsInitialized)
  34. {
  35. CM_THREAD_WAIT(mResourceLoadedCondition, mResourceLoadedMutex, lock);
  36. }
  37. }
  38. }
  39. RTTITypeBase* Resource::getRTTIStatic()
  40. {
  41. return ResourceRTTI::instance();
  42. }
  43. RTTITypeBase* Resource::getRTTI() const
  44. {
  45. return Resource::getRTTIStatic();
  46. }
  47. }