move models to higher priority pools if needed
Some checks failed
Build coop / build-macos-arm (push) Has been cancelled
Build coop / build-ubuntu (push) Has been cancelled
Build coop / build-windows (push) Has been cancelled
Build coop / build-macos-intel (push) Has been cancelled

sometimes, a model may be loaded by the level, but then a mod loads it for the session, which causes issues so we move the model to the right pool.
This commit is contained in:
Isaac0-dev 2025-04-04 14:16:12 +10:00
parent f6d6de7fc8
commit 1bfe9d509c
2 changed files with 34 additions and 34 deletions

View file

@ -65,40 +65,40 @@ void DynOS_Model_Dump() {
static struct GraphNode* DynOS_Model_LoadCommonInternal(u32* aId, enum ModelPool aModelPool, void* aAsset, u8 aLayer, struct GraphNode* aGraphNode, bool aDeDuplicate, enum ModelLoadType mlt) { static struct GraphNode* DynOS_Model_LoadCommonInternal(u32* aId, enum ModelPool aModelPool, void* aAsset, u8 aLayer, struct GraphNode* aGraphNode, bool aDeDuplicate, enum ModelLoadType mlt) {
// sanity check pool // sanity check pool
if (aModelPool >= MODEL_POOL_MAX) { return NULL; } if (aModelPool < 0 || aModelPool >= MODEL_POOL_MAX) { return NULL; }
// allocate pool // allocate pool
if (!sModelPools[aModelPool]) { if (!sModelPools[aModelPool]) {
sModelPools[aModelPool] = dynamic_pool_init(); sModelPools[aModelPool] = dynamic_pool_init();
} }
// check perm map // check maps, permanent pool is always checked
auto& permMap = sAssetMap[MODEL_POOL_PERMANENT]; for (int i = 0; i < MODEL_POOL_MAX; ++i) {
if (aDeDuplicate && permMap.count(aAsset)) { auto& map = sAssetMap[i];
auto& found = permMap[aAsset]; if (aDeDuplicate && map.count(aAsset)) {
if (*aId && *aId == found.id) { auto& found = map[aAsset];
return found.graphNode;
} // if the expected pool has a higher priority,
if (*aId == 0) { // we need to move the asset to the new pool
if (i > aModelPool) {
found.modelPool = aModelPool;
sAssetMap[aModelPool][aAsset] = found;
map.erase(aAsset);
}
if (i != MODEL_POOL_PERMANENT && *aId && *aId != found.id) {
sOverwriteMap[*aId] = found.id;
}
*aId = found.id; *aId = found.id;
return found.graphNode; return found.graphNode;
} }
if (i < aModelPool) { i = aModelPool; } // to force check permanent pool, and then skip to the expected pool
} }
// check map
auto& map = sAssetMap[aModelPool];
if (aDeDuplicate && map.count(aAsset)) {
auto& found = map[aAsset];
if (*aId && *aId != found.id) {
sOverwriteMap[*aId] = found.id;
}
*aId = found.id;
return found.graphNode;
}
sCurrModelDuplicates = new std::vector<void*>();
// load geo // load geo
auto& map = sAssetMap[aModelPool];
sCurrModelDuplicates = new std::vector<void*>();
struct GraphNode* node = NULL; struct GraphNode* node = NULL;
switch (mlt) { switch (mlt) {
case MLT_GEO: case MLT_GEO:

View file

@ -534,7 +534,7 @@ s16 obj_turn_toward_object(struct Object *obj, struct Object *target, s16 angleI
void obj_set_parent_relative_pos(struct Object *obj, s16 relX, s16 relY, s16 relZ) { void obj_set_parent_relative_pos(struct Object *obj, s16 relX, s16 relY, s16 relZ) {
if (obj == NULL) { return; } if (obj == NULL) { return; }
obj->oParentRelativePosX = relX; obj->oParentRelativePosX = relX;
obj->oParentRelativePosY = relY; obj->oParentRelativePosY = relY;
obj->oParentRelativePosZ = relZ; obj->oParentRelativePosZ = relZ;
@ -542,7 +542,7 @@ void obj_set_parent_relative_pos(struct Object *obj, s16 relX, s16 relY, s16 rel
void obj_set_pos(struct Object *obj, s16 x, s16 y, s16 z) { void obj_set_pos(struct Object *obj, s16 x, s16 y, s16 z) {
if (obj == NULL) { return; } if (obj == NULL) { return; }
obj->oPosX = x; obj->oPosX = x;
obj->oPosY = y; obj->oPosY = y;
obj->oPosZ = z; obj->oPosZ = z;
@ -550,7 +550,7 @@ void obj_set_pos(struct Object *obj, s16 x, s16 y, s16 z) {
void obj_set_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) { void obj_set_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) {
if (obj == NULL) { return; } if (obj == NULL) { return; }
obj->oFaceAnglePitch = pitch; obj->oFaceAnglePitch = pitch;
obj->oFaceAngleYaw = yaw; obj->oFaceAngleYaw = yaw;
obj->oFaceAngleRoll = roll; obj->oFaceAngleRoll = roll;
@ -562,7 +562,7 @@ void obj_set_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) {
void obj_set_move_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) { void obj_set_move_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) {
if (obj == NULL) { return; } if (obj == NULL) { return; }
obj->oMoveAnglePitch = pitch; obj->oMoveAnglePitch = pitch;
obj->oMoveAngleYaw = yaw; obj->oMoveAngleYaw = yaw;
obj->oMoveAngleRoll = roll; obj->oMoveAngleRoll = roll;
@ -570,7 +570,7 @@ void obj_set_move_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) {
void obj_set_face_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) { void obj_set_face_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) {
if (obj == NULL) { return; } if (obj == NULL) { return; }
obj->oFaceAnglePitch = pitch; obj->oFaceAnglePitch = pitch;
obj->oFaceAngleYaw = yaw; obj->oFaceAngleYaw = yaw;
obj->oFaceAngleRoll = roll; obj->oFaceAngleRoll = roll;
@ -578,7 +578,7 @@ void obj_set_face_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) {
void obj_set_gfx_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) { void obj_set_gfx_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) {
if (obj == NULL) { return; } if (obj == NULL) { return; }
obj->header.gfx.angle[0] = pitch; obj->header.gfx.angle[0] = pitch;
obj->header.gfx.angle[1] = yaw; obj->header.gfx.angle[1] = yaw;
obj->header.gfx.angle[2] = roll; obj->header.gfx.angle[2] = roll;
@ -586,7 +586,7 @@ void obj_set_gfx_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) {
void obj_set_gfx_pos(struct Object *obj, f32 x, f32 y, f32 z) { void obj_set_gfx_pos(struct Object *obj, f32 x, f32 y, f32 z) {
if (obj == NULL) { return; } if (obj == NULL) { return; }
obj->header.gfx.pos[0] = x; obj->header.gfx.pos[0] = x;
obj->header.gfx.pos[1] = y; obj->header.gfx.pos[1] = y;
obj->header.gfx.pos[2] = z; obj->header.gfx.pos[2] = z;
@ -594,7 +594,7 @@ void obj_set_gfx_pos(struct Object *obj, f32 x, f32 y, f32 z) {
void obj_set_gfx_scale(struct Object *obj, f32 x, f32 y, f32 z) { void obj_set_gfx_scale(struct Object *obj, f32 x, f32 y, f32 z) {
if (obj == NULL) { return; } if (obj == NULL) { return; }
obj->header.gfx.scale[0] = x; obj->header.gfx.scale[0] = x;
obj->header.gfx.scale[1] = y; obj->header.gfx.scale[1] = y;
obj->header.gfx.scale[2] = z; obj->header.gfx.scale[2] = z;
@ -1970,14 +1970,14 @@ void cur_obj_set_billboard_if_vanilla_cam(void) {
void obj_set_hitbox_radius_and_height(struct Object *o, f32 radius, f32 height) { void obj_set_hitbox_radius_and_height(struct Object *o, f32 radius, f32 height) {
if (o == NULL) { return; } if (o == NULL) { return; }
o->hitboxRadius = radius; o->hitboxRadius = radius;
o->hitboxHeight = height; o->hitboxHeight = height;
} }
void obj_set_hurtbox_radius_and_height(struct Object *o, f32 radius, f32 height) { void obj_set_hurtbox_radius_and_height(struct Object *o, f32 radius, f32 height) {
if (o == NULL) { return; } if (o == NULL) { return; }
o->hurtboxRadius = radius; o->hurtboxRadius = radius;
o->hurtboxHeight = height; o->hurtboxHeight = height;
} }
@ -2548,7 +2548,7 @@ void cur_obj_spawn_particles(struct SpawnParticlesInfo *info) {
if (gPrevFrameObjectCount > (OBJECT_POOL_CAPACITY * 150 / 240) && numParticles > 10) { if (gPrevFrameObjectCount > (OBJECT_POOL_CAPACITY * 150 / 240) && numParticles > 10) {
numParticles = 10; numParticles = 10;
} }
// We're close to running out of object slots, so don't spawn particles at // We're close to running out of object slots, so don't spawn particles at
// all // all
@ -2745,7 +2745,7 @@ s32 cur_obj_progress_direction_table(void) {
if (tableLength < 0 || index < 0 || tableLength >= 150 || index >= tableLength) { if (tableLength < 0 || index < 0 || tableLength >= 150 || index >= tableLength) {
ret = table[0]; ret = table[0];
o->oToxBoxMovementStep = 0; o->oToxBoxMovementStep = 0;
LOG_ERROR("Exceeded direction table! tableLength %d, index %d\n", tableLength, index); LOG_ERROR("Exceeded direction table! tableLength %d, index %d", tableLength, index);
} else if (table[index] != -1) { } else if (table[index] != -1) {
ret = table[index]; ret = table[index];
o->oToxBoxMovementStep++; o->oToxBoxMovementStep++;