1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-20 17:31:44 +02:00
openrw/rwengine/include/loaders/BackgroundLoader.hpp

41 lines
808 B
C++

#pragma once
#include <job/WorkContext.hpp>
#include <data/ResourceHandle.hpp>
#include <platform/FileIndex.hpp>
/**
* Implementation of a worker that loads a resource in the background.
*/
template<class T, class L> class BackgroundLoaderJob : public WorkJob
{
public:
typedef typename ResourceHandle<T>::Ref TypeRef;
BackgroundLoaderJob(WorkContext* context, FileIndex* index, const std::string& file, const TypeRef& ref)
:WorkJob(context), index(index), filename(file), resourceRef(ref)
{ }
void work()
{
data = index->openFile(filename);
}
void complete()
{
if( data )
{
L loader;
resourceRef->resource = loader.loadFromMemory(data);
resourceRef->state = RW::Loaded;
}
}
private:
FileIndex* index;
std::string filename;
FileHandle data;
TypeRef resourceRef;
};