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