mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-25 03:42:48 +01:00
Load and associate MODELFILE entries
This commit is contained in:
parent
996a82c4bf
commit
6888fa3558
@ -99,6 +99,9 @@ void GameData::loadLevelFile(const std::string& path) {
|
||||
std::transform(name.begin(), name.end(), name.begin(),
|
||||
::tolower);
|
||||
loadTXD(name);
|
||||
} else if (cmd == "MODELFILE") {
|
||||
auto path = line.substr(space + 1);
|
||||
loadModelFile(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -333,6 +336,42 @@ void GameData::loadDFF(const std::string& name, bool async) {
|
||||
}
|
||||
}
|
||||
|
||||
void GameData::loadModelFile(const std::string& name) {
|
||||
LoaderDFF l;
|
||||
auto file = index.openFilePath(name);
|
||||
if (!file) {
|
||||
logger->log("Data", Logger::Error, "Failed to load model file " + name);
|
||||
return;
|
||||
}
|
||||
auto m = l.loadFromMemory(file);
|
||||
if (!m) {
|
||||
logger->log("Data", Logger::Error, "Error loading model file " + name);
|
||||
return;
|
||||
}
|
||||
|
||||
// Associate the frames with models.
|
||||
for (auto& frame : m->frames) {
|
||||
/// @todo this is useful elsewhere, please move elsewhere
|
||||
std::string name = frame->getName();
|
||||
auto lodpos = name.rfind("_l");
|
||||
int lod = 0;
|
||||
if (lodpos != std::string::npos) {
|
||||
lod = std::atoi(name.substr(lodpos + 1).c_str());
|
||||
name = name.substr(0, lodpos);
|
||||
}
|
||||
for (auto& model : modelinfo) {
|
||||
auto info = model.second.get();
|
||||
if (info->type() != ModelDataType::SimpleInfo) {
|
||||
continue;
|
||||
}
|
||||
if (boost::iequals(info->name, name)) {
|
||||
auto simple = static_cast<SimpleModelInfo*>(info);
|
||||
simple->setAtomic(m, lod, frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameData::loadIFP(const std::string& name) {
|
||||
auto f = index.openFile(name);
|
||||
|
||||
|
@ -123,6 +123,11 @@ public:
|
||||
*/
|
||||
void loadDFF(const std::string& name, bool async = false);
|
||||
|
||||
/**
|
||||
* Loads a DFF and associates its atomics with models.
|
||||
*/
|
||||
void loadModelFile(const std::string& name);
|
||||
|
||||
/**
|
||||
* Loads an IFP file containing animations
|
||||
*/
|
||||
|
@ -83,6 +83,16 @@ BOOST_AUTO_TEST_CASE(test_handling_data_loader) {
|
||||
BOOST_CHECK_EQUAL(handling.driveType, VehicleHandlingInfo::All);
|
||||
BOOST_CHECK_EQUAL(handling.engineType, VehicleHandlingInfo::Petrol);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_model_files_loaded) {
|
||||
auto& d = Global::get().d;
|
||||
|
||||
// The weapon models should be associated by the MODELFILE entries
|
||||
auto ak47 = d->findModelInfo<SimpleModelInfo>(171);
|
||||
|
||||
BOOST_CHECK_EQUAL(ak47->name, "ak47");
|
||||
BOOST_CHECK_NE(ak47->getAtomic(0), nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
Reference in New Issue
Block a user