Danbias/Code/Misc/Resource/Loaders/CustomLoader.cpp

61 lines
1.6 KiB
C++
Raw Normal View History

2013-11-26 21:51:40 +01:00
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#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));
fnc(filename, data);
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);
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);
}
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);
this->resourceData = (OHRESOURCE)data.loadedData;
if(data.resourceUnloadFnc)
2013-11-27 21:12:37 +01:00
{
this->customData->unloadingFunction = data.resourceUnloadFnc;
2013-11-27 21:12:37 +01:00
}
return this;
}