1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 19:32:49 +01:00
openrw/rwengine/include/loaders/BackgroundLoader.hpp
Daniel Evans d1e7dcdcd1 Overhaul Loader framework for Models
- Replace background model loader with generic background loader
- Replace ModelHandle object with generic resource handle
2015-04-03 03:04:50 +01:00

41 lines
800 B
C++

#pragma once
#include <WorkContext.hpp>
#include <data/ResourceHandle.hpp>
#include <core/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;
};