1
Fork 0
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:
Joshua Goins 2025-05-17 10:43:08 -04:00
parent 79f26babd0
commit 80f1e2c1dd
3 changed files with 48 additions and 26 deletions

View file

@ -58,6 +58,7 @@ MapView::MapView(GameData *data, FileCache &cache, AppState *appState, QWidget *
case physis_LayerEntry::Tag::BG: {
std::string assetPath = object.data.bg._0.asset_path;
if (!assetPath.empty()) {
if (!mdlPart->modelExists(QString::fromStdString(assetPath))) {
auto plateMdlFile = physis_gamedata_extract_file(m_data, assetPath.c_str());
if (plateMdlFile.size == 0) {
continue;
@ -86,6 +87,11 @@ MapView::MapView(GameData *data, FileCache &cache, AppState *appState, QWidget *
}
physis_free_file(&plateMdlFile);
} else {
mdlPart->addExistingModel(
QString::fromStdString(assetPath),
glm::vec3(object.transform.translation[0], object.transform.translation[1], object.transform.translation[2]));
}
}
} break;
}

View file

@ -82,7 +82,7 @@ void MDLPart::addModel(physis_MDL mdl,
uint16_t fromBodyId,
uint16_t toBodyId)
{
DrawObject *model;
DrawObject *model = nullptr;
if (vkWindow->sourceModels.contains(name)) {
model = vkWindow->sourceModels[name];
} else {
@ -102,6 +102,7 @@ void MDLPart::addModel(physis_MDL mdl,
vkWindow->sourceModels[name] = model;
}
Q_ASSERT(model != nullptr);
vkWindow->models.push_back(DrawObjectInstance{name, model, position});
Q_EMIT modelChanged();
@ -432,4 +433,15 @@ RenderManager *MDLPart::manager() const
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"

View file

@ -65,7 +65,9 @@ public Q_SLOTS:
/// Clears all stored MDLs.
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,
bool skinned,
glm::vec3 position,
@ -75,6 +77,8 @@ public Q_SLOTS:
uint16_t fromBodyId = 101,
uint16_t toBodyId = 101);
void addExistingModel(const QString &name, glm::vec3 position);
void removeModel(const physis_MDL &mdl);
/// Sets the skeleton any skinned MDLs should bind to.