diff --git a/Code/Misc/Resource/OResourceHandler.cpp b/Code/Misc/Resource/OResourceHandler.cpp index 21653d4e..36154d09 100644 --- a/Code/Misc/Resource/OResourceHandler.cpp +++ b/Code/Misc/Resource/OResourceHandler.cpp @@ -23,46 +23,71 @@ public: } resourcePrivate; -OHRESOURCE OysterResource::LoadResource(const wchar_t* filename, ResourceType type) +OHRESOURCE OysterResource::LoadResource(const wchar_t* filename, ResourceType type, int customID, bool force) { if(!filename) return 0; OResource *resourceData = resourcePrivate.FindResource(filename); + if(resourceData) { - //Add new reference - resourcePrivate.SaveResource(resourceData, false); - return resourceData->GetResourceHandle(); + if(force) + { + return OysterResource::ReloadResource(filename); + } + else + { + //Add new reference + resourcePrivate.SaveResource(resourceData, false); + return resourceData->GetResourceHandle(); + } + } + else + { + resourceData = OResource::Load(filename, type); + if(resourceData) + { + resourceData->SetResourceID(customID); + resourcePrivate.SaveResource(resourceData); + } } - - resourceData = OResource::Load(filename, type); - - if(!resourceData) return 0; - - resourcePrivate.SaveResource(resourceData); return resourceData->GetResourceHandle(); } -OHRESOURCE OysterResource::LoadResource(const wchar_t filename[], CustomLoadFunction loadFnc, int CustomId) +OHRESOURCE OysterResource::LoadResource(const wchar_t filename[], CustomLoadFunction loadFnc, int customId, bool force) { - if(!filename) return 0; - if(!loadFnc) return 0; + if(!filename) + { + return 0; + } + if(!loadFnc) + { + return 0; + } OResource *resourceData = resourcePrivate.FindResource(filename); if(resourceData) { - //Add new reference - resourcePrivate.SaveResource(resourceData, false); - return resourceData->GetResourceHandle(); + if(force) + { + return OysterResource::ReloadResource(filename); + } + else + { + //Add new reference + resourcePrivate.SaveResource(resourceData, false); + return resourceData->GetResourceHandle(); + } + } + else + { + resourceData = OResource::Load(filename, loadFnc); + if(resourceData) + { + resourceData->SetResourceID(customId); + resourcePrivate.SaveResource(resourceData); + } } - - resourceData = OResource::Load(filename, loadFnc); - - if(!resourceData) return 0; - - resourceData->SetResourceID(CustomId); - - resourcePrivate.SaveResource(resourceData); return (OHRESOURCE)resourceData->GetResourceHandle(); } diff --git a/Code/Misc/Resource/OysterResource.h b/Code/Misc/Resource/OysterResource.h index 8fc0e560..4906e6c7 100644 --- a/Code/Misc/Resource/OysterResource.h +++ b/Code/Misc/Resource/OysterResource.h @@ -54,16 +54,17 @@ namespace Oyster * @param force If set to true, the resource will be reloaded if it already exists. If it does not, nothing happens. * @return If function suceeds, a handle to the resource will be returned. If failed 0 is returned. */ - static OHRESOURCE LoadResource(const wchar_t filename[], ResourceType type); + static OHRESOURCE LoadResource(const wchar_t filename[], ResourceType type, int customId = -1, bool force = false); /** * Load a resource with a custom loading function * @param filename The path to the resource. - * @param force If set to true, the resource will be reloaded even if exists. * @param loadFnc If set, this gives you the right to do custom resource loading if your recource type is not supported. + * @param customId A custom ID that can be used. + * @param force If set to true, the resource will be reloaded even if exists. * @return If function suceeds, a handle to the resource will be returned. If failed 0 is returned. */ - static OHRESOURCE LoadResource(const wchar_t filename[], CustomLoadFunction loadFnc = 0, int CustomId = -1); + static OHRESOURCE LoadResource(const wchar_t filename[], CustomLoadFunction loadFnc = 0, int customId = -1, bool force = false); /** * Reload a resource diff --git a/Code/Misc/Thread/OysterMutex.cpp b/Code/Misc/Thread/OysterMutex.cpp index 089323ce..b02ef344 100644 --- a/Code/Misc/Thread/OysterMutex.cpp +++ b/Code/Misc/Thread/OysterMutex.cpp @@ -8,6 +8,7 @@ #include #include +using namespace Oyster::Thread; OysterMutex::OysterMutex() diff --git a/Code/Misc/Thread/OysterMutex.h b/Code/Misc/Thread/OysterMutex.h index 18282499..d9f29d95 100644 --- a/Code/Misc/Thread/OysterMutex.h +++ b/Code/Misc/Thread/OysterMutex.h @@ -9,23 +9,29 @@ #include #include -class OysterMutex +namespace Oyster { -public: - OysterMutex(); - OysterMutex(bool initialOwnership); - virtual~OysterMutex(); - void LockMutex(); - void LockMutex(unsigned int timeSpan); - void UnlockMutex(); - /** Returns true if mutex is taken */ - bool IsTaken(); + namespace Thread + { + class OysterMutex + { + public: + OysterMutex(); + OysterMutex(bool initialOwnership); + virtual~OysterMutex(); + void LockMutex(); + void LockMutex(unsigned int timeSpan); + void UnlockMutex(); + /** Returns true if mutex is taken */ + bool IsTaken(); -private: - std::mutex mutex; - std::thread::id id; + private: + std::mutex mutex; + std::thread::id id; - OysterMutex(const OysterMutex&); -}; + OysterMutex(const OysterMutex&); + }; + } +} #endif // !MISC_OYSTER_MUTEX_H diff --git a/Code/Misc/Thread/OysterThread_Impl.cpp b/Code/Misc/Thread/OysterThread_Impl.cpp index 9b01e6d5..46b889fe 100644 --- a/Code/Misc/Thread/OysterThread_Impl.cpp +++ b/Code/Misc/Thread/OysterThread_Impl.cpp @@ -62,7 +62,7 @@ using namespace Utility::DynamicMemory::SmartPointer; ~PrivateData() { //@todo TODO: Make detatch avalible. - //this->threadData->workerThread->detach(); + this->threadData->workerThread->detach(); this->threadData->owner = 0;