Added a force reload feture in resource loading
This commit is contained in:
parent
5eec570768
commit
d08644e8e1
|
@ -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)
|
||||
{
|
||||
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) return 0;
|
||||
|
||||
if(resourceData)
|
||||
{
|
||||
resourceData->SetResourceID(customID);
|
||||
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)
|
||||
{
|
||||
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) return 0;
|
||||
|
||||
resourceData->SetResourceID(CustomId);
|
||||
|
||||
if(resourceData)
|
||||
{
|
||||
resourceData->SetResourceID(customId);
|
||||
resourcePrivate.SaveResource(resourceData);
|
||||
}
|
||||
}
|
||||
|
||||
return (OHRESOURCE)resourceData->GetResourceHandle();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <thread>
|
||||
#include <future>
|
||||
|
||||
using namespace Oyster::Thread;
|
||||
|
||||
|
||||
OysterMutex::OysterMutex()
|
||||
|
|
|
@ -9,9 +9,13 @@
|
|||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
class OysterMutex
|
||||
namespace Oyster
|
||||
{
|
||||
public:
|
||||
namespace Thread
|
||||
{
|
||||
class OysterMutex
|
||||
{
|
||||
public:
|
||||
OysterMutex();
|
||||
OysterMutex(bool initialOwnership);
|
||||
virtual~OysterMutex();
|
||||
|
@ -21,11 +25,13 @@ public:
|
|||
/** Returns true if mutex is taken */
|
||||
bool IsTaken();
|
||||
|
||||
private:
|
||||
private:
|
||||
std::mutex mutex;
|
||||
std::thread::id id;
|
||||
|
||||
OysterMutex(const OysterMutex&);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !MISC_OYSTER_MUTEX_H
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue