Added a force reload feture in resource loading

This commit is contained in:
dean11 2013-11-28 13:43:11 +01:00
parent 5eec570768
commit d08644e8e1
5 changed files with 76 additions and 43 deletions

View File

@ -23,46 +23,71 @@ public:
} resourcePrivate; } 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; if(!filename) return 0;
OResource *resourceData = resourcePrivate.FindResource(filename); OResource *resourceData = resourcePrivate.FindResource(filename);
if(resourceData) if(resourceData)
{
if(force)
{
return OysterResource::ReloadResource(filename);
}
else
{ {
//Add new reference //Add new reference
resourcePrivate.SaveResource(resourceData, false); resourcePrivate.SaveResource(resourceData, false);
return resourceData->GetResourceHandle(); return resourceData->GetResourceHandle();
} }
}
else
{
resourceData = OResource::Load(filename, type); resourceData = OResource::Load(filename, type);
if(resourceData)
if(!resourceData) return 0; {
resourceData->SetResourceID(customID);
resourcePrivate.SaveResource(resourceData); resourcePrivate.SaveResource(resourceData);
}
}
return resourceData->GetResourceHandle(); 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(!filename)
if(!loadFnc) return 0; {
return 0;
}
if(!loadFnc)
{
return 0;
}
OResource *resourceData = resourcePrivate.FindResource(filename); OResource *resourceData = resourcePrivate.FindResource(filename);
if(resourceData) if(resourceData)
{
if(force)
{
return OysterResource::ReloadResource(filename);
}
else
{ {
//Add new reference //Add new reference
resourcePrivate.SaveResource(resourceData, false); resourcePrivate.SaveResource(resourceData, false);
return resourceData->GetResourceHandle(); return resourceData->GetResourceHandle();
} }
}
else
{
resourceData = OResource::Load(filename, loadFnc); resourceData = OResource::Load(filename, loadFnc);
if(resourceData)
if(!resourceData) return 0; {
resourceData->SetResourceID(customId);
resourceData->SetResourceID(CustomId);
resourcePrivate.SaveResource(resourceData); resourcePrivate.SaveResource(resourceData);
}
}
return (OHRESOURCE)resourceData->GetResourceHandle(); return (OHRESOURCE)resourceData->GetResourceHandle();
} }

View File

@ -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. * @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. * @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 * Load a resource with a custom loading function
* @param filename The path to the resource. * @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 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. * @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 * Reload a resource

View File

@ -8,6 +8,7 @@
#include <thread> #include <thread>
#include <future> #include <future>
using namespace Oyster::Thread;
OysterMutex::OysterMutex() OysterMutex::OysterMutex()

View File

@ -9,6 +9,10 @@
#include <thread> #include <thread>
#include <atomic> #include <atomic>
namespace Oyster
{
namespace Thread
{
class OysterMutex class OysterMutex
{ {
public: public:
@ -27,5 +31,7 @@ private:
OysterMutex(const OysterMutex&); OysterMutex(const OysterMutex&);
}; };
}
}
#endif // !MISC_OYSTER_MUTEX_H #endif // !MISC_OYSTER_MUTEX_H

View File

@ -62,7 +62,7 @@ using namespace Utility::DynamicMemory::SmartPointer;
~PrivateData() ~PrivateData()
{ {
//@todo TODO: Make detatch avalible. //@todo TODO: Make detatch avalible.
//this->threadData->workerThread->detach(); this->threadData->workerThread->detach();
this->threadData->owner = 0; this->threadData->owner = 0;