mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-07 19:32:49 +01:00
d1e7dcdcd1
- Replace background model loader with generic background loader - Replace ModelHandle object with generic resource handle
41 lines
800 B
C++
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;
|
|
};
|