1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-25 11:52:40 +01:00

rwengine,rwgame: Avoid loading models/gta3.img twice.

This commit is contained in:
Christoph Heiss 2020-05-15 16:56:10 +02:00 committed by Anonymous Maarten
parent 7d73e199c8
commit edaab68525
3 changed files with 16 additions and 14 deletions

View File

@ -41,7 +41,11 @@ GameData::GameData(Logger* log, const rwfs::path& path)
});
}
void GameData::load() {
bool GameData::load() {
if (!isValidGameDirectory()) {
return false;
}
index.indexTree(datpath);
loadIMG("models/gta3.img");
@ -78,6 +82,8 @@ void GameData::load() {
// Load ped groups after IDEs so they can resolve
loadPedGroups("data/pedgrp.dat");
return true;
}
void GameData::loadLevelFile(const std::string& path) {
@ -759,13 +765,11 @@ float GameData::getWaveHeightAt(const glm::vec3& ws) const {
WATER_HEIGHT;
}
bool GameData::isValidGameDirectory(const rwfs::path& path) {
bool GameData::isValidGameDirectory() const {
rwfs::error_code ec;
if (!rwfs::is_directory(path, ec)) {
std::cerr << "first test failed\n";
if (!rwfs::is_directory(datpath, ec)) {
return false;
}
LoaderIMG i;
return i.load(path / "models/gta3.img");
return !ec;
}

View File

@ -112,7 +112,7 @@ public:
void loadWaterpro(const std::string& path);
void loadWater(const std::string& path);
void load();
bool load();
/**
* Loads model, placement, models and textures from a level file
@ -359,10 +359,11 @@ public:
GameTexts texts;
private:
/**
* Determines whether the given path is a valid game directory.
*/
static bool isValidGameDirectory(const rwfs::path& path);
bool isValidGameDirectory() const;
};
#endif

View File

@ -72,17 +72,14 @@ RWGame::RWGame(Logger& log, const std::optional<RWArgConfigLayer> &args)
benchFile = args->benchmarkPath;
}
log.info("Game", "Game directory: " + config.gamedataPath());
imgui.init();
if (!GameData::isValidGameDirectory(config.gamedataPath())) {
log.info("Game", "Game directory: " + config.gamedataPath());
if (!data.load()) {
throw std::runtime_error("Invalid game directory path: " +
config.gamedataPath());
}
imgui.init();
data.load();
for (const auto& [specialModel, fileName, name] : kSpecialModels) {
auto model = data.loadClump(fileName, name);
renderer.setSpecialModel(specialModel, model);