sm64coopdx/data/dynos_mgr_movtexqc.cpp
PeachyPeach ac03a9c0da
Fix DynOS generation bug with duplicates (#1220)
When generating multiple actors, if two or more data nodes share the same name, the generated actors can reference the wrong nodes in their display lists/geo layouts.
This results in:
- The wrong nodes compiled into binary files
- Intermediate layouts generated as actors since nothing is referencing them anymore, treating them as root geo layouts

The simplest fix was to first check for the model identifier (renamed to `mDataIdentifier`, since it's no longer related to models) when looking for nodes, to ensure it picks the right node, even if multiple nodes share the same name.
2026-05-18 07:50:20 +10:00

77 lines
2.1 KiB
C++

#include "dynos.cpp.h"
extern "C" {
#include "game/area.h"
}
struct RegisteredMovtexQC {
DataNode<MovtexQC>* dataNode;
s16 level;
s16 area;
s16 type;
};
static std::vector<RegisteredMovtexQC> &DynosRegisteredMovtexQCs() {
static std::vector<RegisteredMovtexQC> sDynosRegisteredMovtexQCs;
return sDynosRegisteredMovtexQCs;
}
void DynOS_MovtexQC_Register(const char* name, s16 level, s16 area, s16 type) {
auto& _DynosRegisteredMovtexQCs = DynosRegisteredMovtexQCs();
// check for duplicates
for (auto& registered : _DynosRegisteredMovtexQCs) {
if (registered.level == level && registered.area == area && registered.type == type) { return; }
}
// find it in the levels
for (auto& lvlPair : DynOS_Lvl_GetArray()) {
auto node = lvlPair.second->mMovtexQCs.Find(name);
if (node) {
// add it
_DynosRegisteredMovtexQCs.push_back({
.dataNode = node,
.level = level,
.area = area,
.type = type
});
return;
}
}
}
DataNode<MovtexQC>* DynOS_MovtexQC_GetFromId(u32 id) {
auto& _DynosRegisteredMovtexQCs = DynosRegisteredMovtexQCs();
// find the datanode
s16 type = (id & 0xF);
for (auto& registered : _DynosRegisteredMovtexQCs) {
if (registered.level == gCurrLevelNum && registered.area == gCurrAreaIndex && registered.type == type) {
return registered.dataNode;
}
}
return NULL;
}
DataNode<MovtexQC>* DynOS_MovtexQC_GetFromIndex(s32 index) {
GfxData* gfxData = DynOS_Lvl_GetActiveGfx();
if (gfxData == NULL) {
return NULL;
}
auto &mMovtexQCs = gfxData->mMovtexQCs;
// Sanity check the index we passed.
if (index < 0 || index >= mMovtexQCs.Count()) {
return NULL;
}
return mMovtexQCs[index];
}
void DynOS_MovtexQC_ModShutdown() {
auto& _DynosRegisteredMovtexQCs = DynosRegisteredMovtexQCs();
for (auto &registered : _DynosRegisteredMovtexQCs) {
Delete(registered.dataNode);
}
_DynosRegisteredMovtexQCs.clear();
}