2013-11-26 21:51:40 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
2013-11-26 10:55:51 +01:00
|
|
|
|
|
|
|
#include "..\OResource.h"
|
|
|
|
#include "..\..\Utilities.h"
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
using namespace Oyster::Resource;
|
|
|
|
|
|
|
|
|
|
|
|
OResource* OResource::CustomLoader(const wchar_t filename[], CustomLoadFunction fnc)
|
|
|
|
{
|
2013-11-27 21:12:37 +01:00
|
|
|
CustomData data;
|
|
|
|
memset(&data, 0, sizeof(CustomData));
|
2013-11-26 10:55:51 +01:00
|
|
|
|
2013-11-27 21:12:37 +01:00
|
|
|
fnc(filename, data);
|
2013-11-28 14:34:52 +01:00
|
|
|
OHRESOURCE n = (OHRESOURCE)data.loadedData;
|
2013-11-27 21:12:37 +01:00
|
|
|
if(!data.loadedData)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(!data.resourceUnloadFnc)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/** For some wierd reason that i don't understand when trying to send data.loadedData directly as a
|
|
|
|
* parameter to OResource constructor, the value is changed when it arrives in the constructor.
|
|
|
|
* Doing it like this, storing in a temporary variable, the value stays correct. (What the fuck! I must be overloking something...)*/
|
|
|
|
//OHRESOURCE temp = data.loadedData;
|
|
|
|
OResource *resource = new OResource(data.loadedData, ResourceType_UNKNOWN, 0, 0, filename);
|
2013-11-26 10:55:51 +01:00
|
|
|
|
|
|
|
resource->customData = new CustomResourceData();
|
|
|
|
resource->customData->unloadingFunction = data.resourceUnloadFnc;
|
|
|
|
resource->customData->loadingFunction = fnc;
|
|
|
|
|
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
void OResource::CustomUnloader()
|
|
|
|
{
|
2013-11-27 21:12:37 +01:00
|
|
|
this->customData->unloadingFunction(this->resourceData);
|
2013-11-26 10:55:51 +01:00
|
|
|
}
|
|
|
|
OResource* OResource::CustomReloader()
|
|
|
|
{
|
|
|
|
CustomUnloader();
|
|
|
|
|
2013-11-27 21:12:37 +01:00
|
|
|
CustomData data;
|
|
|
|
memset(&data, 0, sizeof(CustomData));
|
|
|
|
|
|
|
|
this->customData->loadingFunction(this->resourceFilename.c_str(), data);
|
2013-11-26 10:55:51 +01:00
|
|
|
this->resourceData = (OHRESOURCE)data.loadedData;
|
|
|
|
|
|
|
|
if(data.resourceUnloadFnc)
|
2013-11-27 21:12:37 +01:00
|
|
|
{
|
2013-11-26 10:55:51 +01:00
|
|
|
this->customData->unloadingFunction = data.resourceUnloadFnc;
|
2013-11-27 21:12:37 +01:00
|
|
|
}
|
2013-11-26 10:55:51 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|