CmResource.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. {
  20. CM_LOCK_MUTEX(mResourceLoadedMutex);
  21. mIsInitialized = true;
  22. }
  23. CM_THREAD_NOTIFY_ALL(mResourceLoadedCondition);
  24. }
  25. void Resource::waitUntilInitialized()
  26. {
  27. #if CM_DEBUG_MODE
  28. if(CM_THREAD_CURRENT_ID == RenderSystemManager::getActive()->getRenderThreadId())
  29. CM_EXCEPT(InternalErrorException, "You cannot call this method on the render thread. It will cause a deadlock!");
  30. #endif
  31. if(!mIsInitialized)
  32. {
  33. CM_LOCK_MUTEX_NAMED(mResourceLoadedMutex, lock);
  34. while(!mIsInitialized)
  35. {
  36. CM_THREAD_WAIT(mResourceLoadedCondition, mResourceLoadedMutex, lock);
  37. }
  38. }
  39. }
  40. RTTITypeBase* Resource::getRTTIStatic()
  41. {
  42. return ResourceRTTI::instance();
  43. }
  44. RTTITypeBase* Resource::getRTTI() const
  45. {
  46. return Resource::getRTTIStatic();
  47. }
  48. }