1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 02:12:45 +01:00

Make loadTXD synchronous only

This commit is contained in:
Daniel Evans 2016-12-02 00:42:38 +00:00
parent 6ef99c0de9
commit 7ad8ae5e40
5 changed files with 16 additions and 53 deletions

View File

@ -295,21 +295,23 @@ void GameData::loadWater(const std::string& path) {
}
}
void GameData::loadTXD(const std::string& name, bool async) {
void GameData::loadTXD(const std::string& name) {
if (loadedFiles.find(name) != loadedFiles.end()) {
return;
}
loadedFiles[name] = true;
auto j = new LoadTextureArchiveJob(workContext, &index, textures, name);
/// @todo refactor loadTXD to use correct file locations
auto file = index.openFile(name);
if (!file) {
logger->error("Data", "Failed to open txd: " + name);
return;
}
if (async) {
workContext->queueJob(j);
} else {
j->work();
j->complete();
delete j;
TextureLoader l;
if (!l.loadFromMemory(file, textures)) {
logger->error("Data", "Error loading txd: " + name);
}
}
@ -493,7 +495,7 @@ void GameData::loadSplash(const std::string& name) {
std::string lower(name);
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
loadTXD(lower + ".txd", false);
loadTXD(lower + ".txd");
engine->state->currentSplash = lower;
}

View File

@ -18,6 +18,7 @@ class Logger;
#include <audio/MADStream.hpp>
#include <gl/TextureData.hpp>
#include <platform/FileIndex.hpp>
#include <job/WorkContext.hpp>
#include <memory>
@ -115,7 +116,7 @@ public:
/**
* Attempts to load a TXD, or does nothing if it has already been loaded
*/
void loadTXD(const std::string& name, bool async = false);
void loadTXD(const std::string& name);
/**
* Converts combined {name}_l{LOD} into name and lod.

View File

@ -168,7 +168,7 @@ InstanceObject* GameWorld::createInstance(const uint16_t id,
std::begin(texturename), tolower);
if (!texturename.empty()) {
data->loadTXD(texturename + ".txd", true);
data->loadTXD(texturename + ".txd");
}
// Check for dynamic data.
@ -261,7 +261,7 @@ CutsceneObject* GameWorld::createCutsceneObject(const uint16_t id,
}
if (!texturename.empty()) {
data->loadTXD(texturename + ".txd", true);
data->loadTXD(texturename + ".txd");
}
auto instance = new CutsceneObject(this, pos, rot, model, modelinfo);

View File

@ -3,6 +3,7 @@
#include <algorithm>
#include <iostream>
#include <vector>
GLuint gErrorTextureData[] = {0xFFFF00FF, 0xFF000000, 0xFF000000, 0xFFFF00FF};
GLuint gDebugTextureData[] = {0xFF0000FF, 0xFF00FF00};
@ -190,25 +191,3 @@ bool TextureLoader::loadFromMemory(FileHandle file,
return true;
}
// TODO Move the Job system out of the loading code
#include <platform/FileIndex.hpp>
LoadTextureArchiveJob::LoadTextureArchiveJob(WorkContext* context,
FileIndex* index,
TextureArchive& inTextures,
const std::string& file)
: WorkJob(context), archive(inTextures), fileIndex(index), _file(file) {
}
void LoadTextureArchiveJob::work() {
data = fileIndex->openFile(_file);
}
void LoadTextureArchiveJob::complete() {
// TODO error status
if (data) {
TextureLoader loader;
loader.loadFromMemory(data, archive);
}
}

View File

@ -5,7 +5,6 @@
#include <loaders/RWBinaryStream.hpp>
#include <functional>
#include <job/WorkContext.hpp>
#include <map>
#include <platform/FileHandle.hpp>
#include <string>
@ -22,22 +21,4 @@ public:
bool loadFromMemory(FileHandle file, TextureArchive& inTextures);
};
// TODO: refactor this interface to be more like ModelLoader so they can be
// rolled into one.
class LoadTextureArchiveJob : public WorkJob {
private:
TextureArchive& archive;
FileIndex* fileIndex;
std::string _file;
FileHandle data;
public:
LoadTextureArchiveJob(WorkContext* context, FileIndex* index,
TextureArchive& inTextures, const std::string& file);
void work();
void complete();
};
#endif