CmResource.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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::destroy()
  25. {
  26. RenderSystem::instancePtr()->queueCommand(boost::bind(&Texture::destroy_internal, this));
  27. }
  28. void Resource::waitUntilInitialized()
  29. {
  30. #if CM_DEBUG_MODE
  31. if(CM_THREAD_CURRENT_ID == RenderSystem::instancePtr()->getRenderThreadId())
  32. CM_EXCEPT(InternalErrorException, "You cannot call this method on the render thread. It will cause a deadlock!");
  33. #endif
  34. if(!mIsInitialized)
  35. {
  36. CM_LOCK_MUTEX_NAMED(mResourceLoadedMutex, lock);
  37. while(!mIsInitialized)
  38. {
  39. CM_THREAD_WAIT(mResourceLoadedCondition, mResourceLoadedMutex, lock);
  40. }
  41. }
  42. }
  43. RTTITypeBase* Resource::getRTTIStatic()
  44. {
  45. return ResourceRTTI::instance();
  46. }
  47. RTTITypeBase* Resource::getRTTI() const
  48. {
  49. return Resource::getRTTIStatic();
  50. }
  51. }