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

View file

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

View file

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