CmResource.cpp 1.3 KB

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