mirror of
https://github.com/redstrate/Novus.git
synced 2025-05-19 06:47:44 +00:00
Be a little bit more efficient when loading static map objects
Still not great loading times, but it's now somewhat bearable on debug builds. It now doesn't try to load duplicate models at all. Most of the time is actually spent inside of Physis parsing the model, which I'll have to tackle there.
This commit is contained in:
parent
79f26babd0
commit
80f1e2c1dd
3 changed files with 48 additions and 26 deletions
|
@ -58,34 +58,40 @@ MapView::MapView(GameData *data, FileCache &cache, AppState *appState, QWidget *
|
||||||
case physis_LayerEntry::Tag::BG: {
|
case physis_LayerEntry::Tag::BG: {
|
||||||
std::string assetPath = object.data.bg._0.asset_path;
|
std::string assetPath = object.data.bg._0.asset_path;
|
||||||
if (!assetPath.empty()) {
|
if (!assetPath.empty()) {
|
||||||
auto plateMdlFile = physis_gamedata_extract_file(m_data, assetPath.c_str());
|
if (!mdlPart->modelExists(QString::fromStdString(assetPath))) {
|
||||||
if (plateMdlFile.size == 0) {
|
auto plateMdlFile = physis_gamedata_extract_file(m_data, assetPath.c_str());
|
||||||
continue;
|
if (plateMdlFile.size == 0) {
|
||||||
}
|
continue;
|
||||||
|
|
||||||
auto plateMdl = physis_mdl_parse(plateMdlFile);
|
|
||||||
if (plateMdl.p_ptr != nullptr) {
|
|
||||||
std::vector<physis_Material> materials;
|
|
||||||
for (uint32_t j = 0; j < plateMdl.num_material_names; j++) {
|
|
||||||
const char *material_name = plateMdl.material_names[j];
|
|
||||||
|
|
||||||
auto mat = physis_material_parse(m_cache.lookupFile(QLatin1String(material_name)));
|
|
||||||
materials.push_back(mat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mdlPart->addModel(
|
auto plateMdl = physis_mdl_parse(plateMdlFile);
|
||||||
plateMdl,
|
if (plateMdl.p_ptr != nullptr) {
|
||||||
false,
|
std::vector<physis_Material> materials;
|
||||||
glm::vec3(object.transform.translation[0], object.transform.translation[1], object.transform.translation[2]),
|
for (uint32_t j = 0; j < plateMdl.num_material_names; j++) {
|
||||||
|
const char *material_name = plateMdl.material_names[j];
|
||||||
|
|
||||||
|
auto mat = physis_material_parse(m_cache.lookupFile(QLatin1String(material_name)));
|
||||||
|
materials.push_back(mat);
|
||||||
|
}
|
||||||
|
|
||||||
|
mdlPart->addModel(
|
||||||
|
plateMdl,
|
||||||
|
false,
|
||||||
|
glm::vec3(object.transform.translation[0], object.transform.translation[1], object.transform.translation[2]),
|
||||||
|
QString::fromStdString(assetPath),
|
||||||
|
materials,
|
||||||
|
0);
|
||||||
|
|
||||||
|
// We don't need this, and it will just take up memory
|
||||||
|
physis_mdl_free(&plateMdl);
|
||||||
|
}
|
||||||
|
|
||||||
|
physis_free_file(&plateMdlFile);
|
||||||
|
} else {
|
||||||
|
mdlPart->addExistingModel(
|
||||||
QString::fromStdString(assetPath),
|
QString::fromStdString(assetPath),
|
||||||
materials,
|
glm::vec3(object.transform.translation[0], object.transform.translation[1], object.transform.translation[2]));
|
||||||
0);
|
|
||||||
|
|
||||||
// We don't need this, and it will just take up memory
|
|
||||||
physis_mdl_free(&plateMdl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
physis_free_file(&plateMdlFile);
|
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ void MDLPart::addModel(physis_MDL mdl,
|
||||||
uint16_t fromBodyId,
|
uint16_t fromBodyId,
|
||||||
uint16_t toBodyId)
|
uint16_t toBodyId)
|
||||||
{
|
{
|
||||||
DrawObject *model;
|
DrawObject *model = nullptr;
|
||||||
if (vkWindow->sourceModels.contains(name)) {
|
if (vkWindow->sourceModels.contains(name)) {
|
||||||
model = vkWindow->sourceModels[name];
|
model = vkWindow->sourceModels[name];
|
||||||
} else {
|
} else {
|
||||||
|
@ -102,6 +102,7 @@ void MDLPart::addModel(physis_MDL mdl,
|
||||||
vkWindow->sourceModels[name] = model;
|
vkWindow->sourceModels[name] = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_ASSERT(model != nullptr);
|
||||||
vkWindow->models.push_back(DrawObjectInstance{name, model, position});
|
vkWindow->models.push_back(DrawObjectInstance{name, model, position});
|
||||||
|
|
||||||
Q_EMIT modelChanged();
|
Q_EMIT modelChanged();
|
||||||
|
@ -432,4 +433,15 @@ RenderManager *MDLPart::manager() const
|
||||||
return renderer;
|
return renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MDLPart::modelExists(const QString &name)
|
||||||
|
{
|
||||||
|
return vkWindow->sourceModels.contains(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MDLPart::addExistingModel(const QString &name, glm::vec3 position)
|
||||||
|
{
|
||||||
|
auto model = vkWindow->sourceModels[name];
|
||||||
|
vkWindow->models.push_back(DrawObjectInstance{name, model, position});
|
||||||
|
}
|
||||||
|
|
||||||
#include "moc_mdlpart.cpp"
|
#include "moc_mdlpart.cpp"
|
||||||
|
|
|
@ -65,7 +65,9 @@ public Q_SLOTS:
|
||||||
/// Clears all stored MDLs.
|
/// Clears all stored MDLs.
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
/// Adds a new MDL with a list of materials used.
|
// TODO: all of this API is terrible and should be redone
|
||||||
|
bool modelExists(const QString &name);
|
||||||
|
|
||||||
void addModel(physis_MDL mdl,
|
void addModel(physis_MDL mdl,
|
||||||
bool skinned,
|
bool skinned,
|
||||||
glm::vec3 position,
|
glm::vec3 position,
|
||||||
|
@ -75,6 +77,8 @@ public Q_SLOTS:
|
||||||
uint16_t fromBodyId = 101,
|
uint16_t fromBodyId = 101,
|
||||||
uint16_t toBodyId = 101);
|
uint16_t toBodyId = 101);
|
||||||
|
|
||||||
|
void addExistingModel(const QString &name, glm::vec3 position);
|
||||||
|
|
||||||
void removeModel(const physis_MDL &mdl);
|
void removeModel(const physis_MDL &mdl);
|
||||||
|
|
||||||
/// Sets the skeleton any skinned MDLs should bind to.
|
/// Sets the skeleton any skinned MDLs should bind to.
|
||||||
|
|
Loading…
Add table
Reference in a new issue