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;
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();
}

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.
* @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

View File

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

View File

@ -9,23 +9,29 @@
#include <thread>
#include <atomic>
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

View File

@ -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;