diff --git a/src/game/body.c b/src/game/body.c index 366a74a75..196766623 100644 --- a/src/game/body.c +++ b/src/game/body.c @@ -247,9 +247,9 @@ struct model *body0f02ce8c(s32 bodynum, s32 headnum, struct modelfiledata *bodyf } if (model) { - if (model->unk02 < bodyfiledata->rwdatalen); + if (model->rwdatalen < bodyfiledata->rwdatalen); } else { - model = modelInstantiateWithAnim(bodyfiledata); + model = modelmgrInstantiateModelWithAnim(bodyfiledata); } if (model) { @@ -259,7 +259,7 @@ struct model *body0f02ce8c(s32 bodynum, s32 headnum, struct modelfiledata *bodyf if (headfiledata && !g_HeadsAndBodies[bodynum].unk00_01) { bodyfiledata->rwdatalen -= headfiledata->rwdatalen; - func0f0b32a0(model, node, headfiledata); + modelmgr0f0b32a0(model, node, headfiledata); if ((s16)*(s32 *)&headfiledata->skel == SKEL_HEAD) { struct modelnode *node2; diff --git a/src/game/bondgun.c b/src/game/bondgun.c index 2b6d738c4..fa9e50596 100644 --- a/src/game/bondgun.c +++ b/src/game/bondgun.c @@ -12482,7 +12482,7 @@ void bgunCreateFiredProjectile(s32 handnum) } if (weapon->base.model) { - modelFree(weapon->base.model); + modelmgrFreeModel(weapon->base.model); } weapon->base.prop = NULL; diff --git a/src/game/chr.c b/src/game/chr.c index 5f8ec77fc..88d4f0ff9 100644 --- a/src/game/chr.c +++ b/src/game/chr.c @@ -566,7 +566,7 @@ bool chr0f01f264(struct chrdata *chr, struct coord *pos, s16 *rooms, f32 arg3) } #endif - return result == true; + return result == CDRESULT_NOCOLLISION; } bool chr0f01f378(struct model *model, struct coord *arg1, struct coord *arg2, f32 *mangroundptr) @@ -1453,7 +1453,7 @@ void chrRemove(struct prop *prop, bool delete) child = next; } - modelFree(model); + modelmgrFreeModel(model); chr->model = NULL; if (delete) { diff --git a/src/game/chraction.c b/src/game/chraction.c index 864eb9fce..015df37f9 100644 --- a/src/game/chraction.c +++ b/src/game/chraction.c @@ -23265,7 +23265,7 @@ struct prop *chrSpawnAtCoord(s32 bodynum, s32 headnum, struct coord *pos, s16 *r return prop; } - modelFree(model); + modelmgrFreeModel(model); } } } diff --git a/src/game/chraicommands.c b/src/game/chraicommands.c index f95be91ba..9b5c1cf7b 100644 --- a/src/game/chraicommands.c +++ b/src/game/chraicommands.c @@ -4959,7 +4959,7 @@ bool aiObjectDoAnimation(void) struct anim *anim = obj->model->anim; if (obj->model->anim == NULL) { - obj->model->anim = func0f0b32e4(); + obj->model->anim = modelmgrInstantiateAnim(); } if (obj->model->anim) { diff --git a/src/game/game_00b820.c b/src/game/game_00b820.c index 5fb53b2d9..b03452350 100644 --- a/src/game/game_00b820.c +++ b/src/game/game_00b820.c @@ -158,7 +158,7 @@ void stageLoadAllAilistModels(void) break; case AICMD_EQUIPWEAPON: setupLoadModeldef(cmd[3] | (cmd[2] << 8)); - if (weaponLoadProjectileModels(cmd[4])); + if (modelmgrLoadProjectileModeldefs(cmd[4])); break; case AICMD_EQUIPHAT: setupLoadModeldef(cmd[3] | (cmd[2] << 8)); diff --git a/src/game/game_0b28d0.c b/src/game/game_0b28d0.c index 5abf00273..b90a59acd 100644 --- a/src/game/game_0b28d0.c +++ b/src/game/game_0b28d0.c @@ -7,88 +7,88 @@ #include "data.h" #include "types.h" -struct model *var8009dd00; -struct anim *var8009dd04; -s32 var8009dd08; -s32 var8009dd0c; -struct var8009dd10 *var8009dd10[3]; +struct model *g_ModelSlots; +struct anim *g_AnimSlots; +s32 g_ModelNumObjs; +s32 g_ModelNumChrs; +struct modelrwdatabinding *g_ModelRwdataBindings[3]; -s32 var800705a0 = 0; -s32 var800705a4 = 0; -bool var800705a8 = false; -s32 var800705ac = 0; -s32 var800705b0 = 0; -s32 var800705b4 = 0; -s32 var800705b8 = 0; -s32 var800705bc = 0; +s32 g_MaxModels = 0; +s32 g_MaxAnims = 0; +bool g_ModelIsLvResetting = false; +s32 g_ModelMostType1 = 0; +s32 g_ModelMostType2 = 0; +s32 g_ModelMostType3 = 0; +s32 g_ModelMostModels = 0; +s32 g_ModelMostAnims = 0; -#define NUMTHINGS1() (IS4MB() ? 0 : 35) -#define NUMTHINGS2() (IS4MB() ? 24 : 25) -#define NUMTHINGS3() (IS4MB() ? 0 : 20) +#define NUMTYPE1() (IS4MB() ? 0 : 35) +#define NUMTYPE2() (IS4MB() ? 24 : 25) +#define NUMTYPE3() (IS4MB() ? 0 : 20) -bool func0f0b28d0(struct model *model, struct modelfiledata *modeldef) +bool modelmgrCanSlotFitRwdata(struct model *modelslot, struct modelfiledata *modeldef) { return modeldef->rwdatalen <= 0 - || (model->rwdatas != NULL && model->unk02 >= modeldef->rwdatalen); + || (modelslot->rwdatas != NULL && modelslot->rwdatalen >= modeldef->rwdatalen); } -void func0f0b2904(void) +void modelmgrPrintCounts(void) { s32 i; - s32 count1 = 0; - s32 count2 = 0; - s32 count3 = 0; - s32 count4 = 0; - s32 count5 = 0; + s32 numtype1 = 0; + s32 numtype2 = 0; + s32 numtype3 = 0; + s32 nummodels = 0; + s32 numanims = 0; - for (i = 0; i < NUMTHINGS1(); i++) { - if (var8009dd10[0][i].model) { - count1++; + for (i = 0; i < NUMTYPE1(); i++) { + if (g_ModelRwdataBindings[0][i].model) { + numtype1++; } } - for (i = 0; i < NUMTHINGS2(); i++) { - if (var8009dd10[1][i].model) { - count2++; + for (i = 0; i < NUMTYPE2(); i++) { + if (g_ModelRwdataBindings[1][i].model) { + numtype2++; } } - for (i = 0; i < NUMTHINGS3(); i++) { - if (var8009dd10[2][i].model) { - count3++; + for (i = 0; i < NUMTYPE3(); i++) { + if (g_ModelRwdataBindings[2][i].model) { + numtype3++; } } - for (i = 0; i < var800705a0; i++) { - if (var8009dd00[i].filedata) { - count4++; + for (i = 0; i < g_MaxModels; i++) { + if (g_ModelSlots[i].filedata) { + nummodels++; } } - for (i = 0; i < var800705a4; i++) { - if (var8009dd04[i].animnum != -1) { - count5++; + for (i = 0; i < g_MaxAnims; i++) { + if (g_AnimSlots[i].animnum != -1) { + numanims++; } } - if (count1 > var800705ac) { - var800705ac = count1; + if (numtype1 > g_ModelMostType1) { + g_ModelMostType1 = numtype1; } - if (count2 > var800705b0) { - var800705b0 = count2; + if (numtype2 > g_ModelMostType2) { + g_ModelMostType2 = numtype2; } - if (count3 > var800705b4) { - var800705b4 = count3; + if (numtype3 > g_ModelMostType3) { + g_ModelMostType3 = numtype3; } - if (count4 > var800705b8) { - var800705b8 = count4; + if (nummodels > g_ModelMostModels) { + g_ModelMostModels = nummodels; } - if (count5 > var800705bc) { - var800705bc = count5; + if (numanims > g_ModelMostAnims) { + g_ModelMostAnims = numanims; } osSyncPrintf("MOT : Type 1 = %d/%d (%d)"); @@ -102,32 +102,33 @@ void func0f0b2904(void) if (IS4MB()); } -struct model *modelInstantiate(struct modelfiledata *modeldef, bool withanim) +struct model *modelmgrInstantiateModel(struct modelfiledata *modeldef, bool withanim) { - struct model *model; - union modelrwdata **rwdatas; - s16 sp36; + struct model *model = NULL; + union modelrwdata **rwdatas = NULL; + s16 datalen = -1; s32 i; - model = NULL; - rwdatas = NULL; - sp36 = -1; - - if (!var800705a8) { - for (i = 0; i < var800705a0; i++) { - if (var8009dd00[i].filedata == NULL && func0f0b28d0(&var8009dd00[i], modeldef)) { - model = &var8009dd00[i]; - rwdatas = var8009dd00[i].rwdatas; - sp36 = var8009dd00[i].unk02; + if (!g_ModelIsLvResetting) { + // If it's being allocated mid-gameplay, look through all slots + // and find any slot that's big enough. + for (i = 0; i < g_MaxModels; i++) { + if (g_ModelSlots[i].filedata == NULL && modelmgrCanSlotFitRwdata(&g_ModelSlots[i], modeldef)) { + model = &g_ModelSlots[i]; + rwdatas = g_ModelSlots[i].rwdatas; + datalen = g_ModelSlots[i].rwdatalen; break; } } } if (model == NULL) { - for (i = 0; i < var800705a0; i++) { - if (var8009dd00[i].filedata == NULL) { - model = &var8009dd00[i]; + // This is lv reset, or gameplay when a suitable slot can't be found + + // Find any spare slot or allocate a new one + for (i = 0; i < g_MaxModels; i++) { + if (g_ModelSlots[i].filedata == NULL) { + model = &g_ModelSlots[i]; break; } } @@ -137,60 +138,67 @@ struct model *modelInstantiate(struct modelfiledata *modeldef, bool withanim) model = mempAlloc(ALIGN16(sizeof(struct model)), MEMPOOL_STAGE); } - if (var800705a8) { + if (g_ModelIsLvResetting) { if (modeldef->rwdatalen > 0) { - sp36 = modeldef->rwdatalen; - rwdatas = mempAlloc(ALIGN16(sp36 * 4), MEMPOOL_STAGE); + datalen = modeldef->rwdatalen; + rwdatas = mempAlloc(ALIGN16(datalen * 4), MEMPOOL_STAGE); } } else { + // At this point, it's during gameplay. A model instance slot has + // been found or allocated, but rwdata needs to be allocated. if (modeldef->rwdatalen < 256) { bool done = false; u32 stack; + // 4 words (0x10 bytes) or less -> try type 1 if (modeldef->rwdatalen <= 4) { - for (i = 0; i < NUMTHINGS1(); i++) { - if (var8009dd10[0][i].model == NULL) { + for (i = 0; i < NUMTYPE1(); i++) { + if (g_ModelRwdataBindings[0][i].model == NULL) { osSyncPrintf("MotInst: Using cache entry type 1 %d (0x%08x) - Bytes=%d\n"); - rwdatas = var8009dd10[0][i].rwdata; - var8009dd10[0][i].model = model; + rwdatas = g_ModelRwdataBindings[0][i].rwdata; + g_ModelRwdataBindings[0][i].model = model; done = true; break; } } } + // 52 words (0xd0 bytes) or less -> try type 2 if (!done && modeldef->rwdatalen <= 52) { - for (i = 0; i < NUMTHINGS2(); i++) { - if (var8009dd10[1][i].model == NULL) { + for (i = 0; i < NUMTYPE2(); i++) { + if (g_ModelRwdataBindings[1][i].model == NULL) { osSyncPrintf("MotInst: Using cache entry type 2 %d (0x%08x) - Bytes=%d\n"); if (IS4MB()); - rwdatas = var8009dd10[1][i].rwdata; - var8009dd10[1][i].model = model; + rwdatas = g_ModelRwdataBindings[1][i].rwdata; + g_ModelRwdataBindings[1][i].model = model; done = true; break; } } } + // 256 words (0x400 bytes) or less -> try type 3 + // First looking for unused slots with an existing rwdata allocation if (!done && modeldef->rwdatalen <= 256) { - for (i = 0; i < NUMTHINGS3(); i++) { - if (var8009dd10[2][i].model == NULL && var8009dd10[2][i].rwdata != NULL) { + for (i = 0; i < NUMTYPE3(); i++) { + if (g_ModelRwdataBindings[2][i].model == NULL && g_ModelRwdataBindings[2][i].rwdata != NULL) { osSyncPrintf("MotInst: Using cache entry type 3 %d (0x%08x) - Bytes=%d\n"); if (IS4MB()); - rwdatas = var8009dd10[2][i].rwdata; - var8009dd10[2][i].model = model; + rwdatas = g_ModelRwdataBindings[2][i].rwdata; + g_ModelRwdataBindings[2][i].model = model; done = true; break; } } } + // Type 3 again, but looking for null rwdata allocations if (!done && modeldef->rwdatalen <= 256) { - for (i = 0; i < NUMTHINGS3(); i++) { - if (var8009dd10[2][i].model == NULL && var8009dd10[2][i].rwdata == NULL) { - var8009dd10[2][i].rwdata = mempAlloc(0x400, MEMPOOL_STAGE); - rwdatas = var8009dd10[2][i].rwdata; - var8009dd10[2][i].model = model; + for (i = 0; i < NUMTYPE3(); i++) { + if (g_ModelRwdataBindings[2][i].model == NULL && g_ModelRwdataBindings[2][i].rwdata == NULL) { + g_ModelRwdataBindings[2][i].rwdata = mempAlloc(256 * 4, MEMPOOL_STAGE); + rwdatas = g_ModelRwdataBindings[2][i].rwdata; + g_ModelRwdataBindings[2][i].model = model; break; } } @@ -200,29 +208,29 @@ struct model *modelInstantiate(struct modelfiledata *modeldef, bool withanim) } if (withanim) { - sp36 = 256; + datalen = 256; } else { - sp36 = IS4MB() ? 52 : 256; + datalen = IS4MB() ? 52 : 256; } - if (sp36 < modeldef->rwdatalen) { - sp36 = modeldef->rwdatalen; + if (datalen < modeldef->rwdatalen) { + datalen = modeldef->rwdatalen; } if (rwdatas == NULL) { - rwdatas = mempAlloc(ALIGN16(sp36 * 4), MEMPOOL_STAGE); + rwdatas = mempAlloc(ALIGN16(datalen * 4), MEMPOOL_STAGE); } } } if (model) { if (withanim) { - model->anim = func0f0b32e4(); + model->anim = modelmgrInstantiateAnim(); if (model->anim) { animInit(model->anim); } else { - modelFree(model); + modelmgrFreeModel(model); model = NULL; } } else { @@ -232,7 +240,7 @@ struct model *modelInstantiate(struct modelfiledata *modeldef, bool withanim) if (model) { modelInit(model, modeldef, rwdatas, false); - model->unk02 = sp36; + model->rwdatalen = datalen; } osSyncPrintf("***************************************\n"); @@ -241,22 +249,22 @@ struct model *modelInstantiate(struct modelfiledata *modeldef, bool withanim) return model; } -struct model *modelInstantiateWithoutAnim(struct modelfiledata *modelfiledata) +struct model *modelmgrInstantiateModelWithoutAnim(struct modelfiledata *modelfiledata) { - return modelInstantiate(modelfiledata, false); + return modelmgrInstantiateModel(modelfiledata, false); } -void modelFree(struct model *model) +void modelmgrFreeModel(struct model *model) { bool done = false; s32 i; - for (i = 0; i < NUMTHINGS1(); i++) { - if (var8009dd10[0][i].model == model) { - var8009dd10[0][i].model = NULL; + for (i = 0; i < NUMTYPE1(); i++) { + if (g_ModelRwdataBindings[0][i].model == model) { + g_ModelRwdataBindings[0][i].model = NULL; model->rwdatas = NULL; - model->unk02 = -1; + model->rwdatalen = -1; done = true; break; @@ -264,14 +272,14 @@ void modelFree(struct model *model) } if (!done) { - for (i = 0; i < NUMTHINGS2(); i++) { - if (var8009dd10[1][i].model == model) { + for (i = 0; i < NUMTYPE2(); i++) { + if (g_ModelRwdataBindings[1][i].model == model) { osSyncPrintf("\nMotInst: Freeing type 2 cache entry %d (0x%08x)\n\n"); - var8009dd10[1][i].model = NULL; + g_ModelRwdataBindings[1][i].model = NULL; model->rwdatas = NULL; - model->unk02 = -1; + model->rwdatalen = -1; done = true; break; @@ -280,13 +288,13 @@ void modelFree(struct model *model) } if (!done) { - for (i = 0; i < NUMTHINGS3(); i++) { - if (var8009dd10[2][i].model == model) { + for (i = 0; i < NUMTYPE3(); i++) { + if (g_ModelRwdataBindings[2][i].model == model) { osSyncPrintf("\nMotInst: Freeing type 3 cache entry %d (0x%08x)\n\n"); - var8009dd10[2][i].model = NULL; + g_ModelRwdataBindings[2][i].model = NULL; model->rwdatas = NULL; - model->unk02 = -1; + model->rwdatalen = -1; done = true; break; @@ -299,32 +307,32 @@ void modelFree(struct model *model) } if (model->anim) { - animTurnOff(model->anim); + modelmgrFreeAnim(model->anim); model->anim = NULL; } model->filedata = NULL; } -struct model *modelInstantiateWithAnim(struct modelfiledata *modelfiledata) +struct model *modelmgrInstantiateModelWithAnim(struct modelfiledata *modelfiledata) { - return modelInstantiate(modelfiledata, true); + return modelmgrInstantiateModel(modelfiledata, true); } -void func0f0b32a0(struct model *model, struct modelnode *node, struct modelfiledata *headmodeldef) +void modelmgr0f0b32a0(struct model *model, struct modelnode *node, struct modelfiledata *headmodeldef) { model00023108(model, model->filedata, node, headmodeldef); modelInitRwData(model, headmodeldef->rootnode); } -struct anim *func0f0b32e4(void) +struct anim *modelmgrInstantiateAnim(void) { s32 i; struct anim *anim = NULL; - for (i = 0; i < var800705a4; i++) { - if (var8009dd04[i].animnum == -1) { - anim = &var8009dd04[i]; + for (i = 0; i < g_MaxAnims; i++) { + if (g_AnimSlots[i].animnum == -1) { + anim = &g_AnimSlots[i]; break; } } @@ -332,7 +340,7 @@ struct anim *func0f0b32e4(void) return anim; } -void animTurnOff(struct anim *anim) +void modelmgrFreeAnim(struct anim *anim) { anim->animnum = -1; } diff --git a/src/game/gunfx.c b/src/game/gunfx.c index db74c6f3b..8dd92087d 100644 --- a/src/game/gunfx.c +++ b/src/game/gunfx.c @@ -2782,8 +2782,8 @@ glabel var7f1acd8c /* f0af9fc: 3c017f1b */ lui $at,%hi(var7f1acd8c) /* f0afa00: c43acd8c */ lwc1 $f26,%lo(var7f1acd8c)($at) .L0f0afa04: -/* f0afa04: 3c08800a */ lui $t0,%hi(var8009dd00) -/* f0afa08: 2508dd00 */ addiu $t0,$t0,%lo(var8009dd00) +/* f0afa04: 3c08800a */ lui $t0,%hi(g_ModelSlots) +/* f0afa08: 2508dd00 */ addiu $t0,$t0,%lo(g_ModelSlots) /* f0afa0c: 26100048 */ addiu $s0,$s0,72 /* f0afa10: 5608fe89 */ bnel $s0,$t0,.L0f0af438 /* f0afa14: 8e0d0000 */ lw $t5,0x0($s0) @@ -3515,8 +3515,8 @@ glabel var7f1acd90 /* f0b0200: add80000 */ sw $t8,0x0($t6) /* f0b0204: add90004 */ sw $t9,0x4($t6) .L0f0b0208: -/* f0b0208: 3c08800a */ lui $t0,%hi(var8009dd00) -/* f0b020c: 2508dd00 */ addiu $t0,$t0,%lo(var8009dd00) +/* f0b0208: 3c08800a */ lui $t0,%hi(g_ModelSlots) +/* f0b020c: 2508dd00 */ addiu $t0,$t0,%lo(g_ModelSlots) /* f0b0210: 26100048 */ addiu $s0,$s0,72 /* f0b0214: 5608fec9 */ bnel $s0,$t0,.L0f0afd3c /* f0b0218: 8e090000 */ lw $t1,0x0($s0) diff --git a/src/game/lv.c b/src/game/lv.c index 2b8a496c5..120bda57e 100644 --- a/src/game/lv.c +++ b/src/game/lv.c @@ -288,7 +288,7 @@ void lvReset(s32 stagenum) g_MiscAudioHandle = NULL; musicReset(); - func0f011124(true); + modelmgrSetLvResetting(true); surfaceReset(); texReset(); textReset(); @@ -357,7 +357,7 @@ void lvReset(s32 stagenum) animsReset(); objectivesReset(); vtxstoreReset(); - func0f011110(); + modelmgrReset(); propsndReset(); setupLoadFiles(stagenum); scenarioReset(); @@ -451,7 +451,7 @@ void lvReset(s32 stagenum) pheadReset(); } - func0f011124(false); + modelmgrSetLvResetting(false); var80084018 = 1; schedResetArtifacts(); lvSetPaused(0); @@ -2304,7 +2304,7 @@ void lvTick(void) sndTick(); pakExecuteDebugOperations(); lightingTick(); - func0f0b2904(); + modelmgrPrintCounts(); boltbeamsTick(); amTick(); menuTick(); diff --git a/src/game/menu.c b/src/game/menu.c index 9fb1511f2..0ce76091e 100644 --- a/src/game/menu.c +++ b/src/game/menu.c @@ -1831,7 +1831,7 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) modelInit(&thing->bodymodel, thing->bodymodeldef, &thing->unk110, true); animInit(&thing->bodyanim); - thing->bodymodel.unk02 = 256; + thing->bodymodel.rwdatalen = 256; thing->bodymodel.anim = &thing->bodyanim; body0f02ce8c(bodynum, headnum, thing->bodymodeldef, thing->headmodeldef, totalfilelen * 0, &thing->bodymodel, false, 1); @@ -1850,7 +1850,7 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) modelInit(&thing->bodymodel, thing->bodymodeldef, &thing->unk110, true); animInit(&thing->bodyanim); - thing->bodymodel.unk02 = 256; + thing->bodymodel.rwdatalen = 256; thing->bodymodel.anim = &thing->bodyanim; } diff --git a/src/game/player.c b/src/game/player.c index 1d9ddfb88..beebd9f4f 100644 --- a/src/game/player.c +++ b/src/game/player.c @@ -1412,7 +1412,7 @@ void playerTickChrBody(void) modelInit(model, bodyfiledata, rwdatas, false); animInit(model->anim); - model->unk02 = 256; + model->rwdatalen = 256; func0f172f54(&sp100); diff --git a/src/game/playerreset.c b/src/game/playerreset.c index 8b62cf59a..dba7a22ff 100644 --- a/src/game/playerreset.c +++ b/src/game/playerreset.c @@ -24,439 +24,139 @@ #include "data.h" #include "types.h" -#define NUMTHINGS1() (IS4MB() ? 0 : 35) -#define NUMTHINGS2() (IS4MB() ? 24 : 25) -#define NUMTHINGS3() (IS4MB() ? 0 : 20) -#define NUMTHINGS4() (IS4MB() ? 40 : 60) +#define NUMTYPE1() (IS4MB() ? 0 : 35) +#define NUMTYPE2() (IS4MB() ? 24 : 25) +#define NUMTYPE3() (IS4MB() ? 0 : 20) +#define NUMSPARE() (IS4MB() ? 40 : 60) -void func0f011110(void) +void modelmgrReset(void) { - var800705a4 = 0; - var800705a0 = 0; + g_MaxAnims = 0; + g_MaxModels = 0; } -void func0f011124(bool value) +void modelmgrSetLvResetting(bool value) { - var800705a8 = value; + g_ModelIsLvResetting = value; } -GLOBAL_ASM( -glabel func0f011130 -/* f011130: 3c01800a */ lui $at,%hi(var8009dd08) -/* f011134: ac24dd08 */ sw $a0,%lo(var8009dd08)($at) -/* f011138: 3c0a8009 */ lui $t2,%hi(g_Is4Mb) -/* f01113c: 3c01800a */ lui $at,%hi(var8009dd0c) -/* f011140: 254a0af0 */ addiu $t2,$t2,%lo(g_Is4Mb) -/* f011144: ac25dd0c */ sw $a1,%lo(var8009dd0c)($at) -/* f011148: 91480000 */ lbu $t0,0x0($t2) -/* f01114c: 27bdffc0 */ addiu $sp,$sp,-64 -/* f011150: 24090001 */ addiu $t1,$zero,0x1 -/* f011154: 15280003 */ bne $t1,$t0,.L0f011164 -/* f011158: afbf0014 */ sw $ra,0x14($sp) -/* f01115c: 10000002 */ b .L0f011168 -/* f011160: 24020028 */ addiu $v0,$zero,0x28 -.L0f011164: -/* f011164: 2402003c */ addiu $v0,$zero,0x3c -.L0f011168: -/* f011168: 00827021 */ addu $t6,$a0,$v0 -/* f01116c: 01c57821 */ addu $t7,$t6,$a1 -/* f011170: 25f80014 */ addiu $t8,$t7,0x14 -/* f011174: 3c018007 */ lui $at,%hi(var800705a0) -/* f011178: ac3805a0 */ sw $t8,%lo(var800705a0)($at) -/* f01117c: 3c018007 */ lui $at,%hi(var800705a4) -/* f011180: 24b90014 */ addiu $t9,$a1,0x14 -/* f011184: 15280003 */ bne $t1,$t0,.L0f011194 -/* f011188: ac3905a4 */ sw $t9,%lo(var800705a4)($at) -/* f01118c: 10000002 */ b .L0f011198 -/* f011190: 24030018 */ addiu $v1,$zero,0x18 -.L0f011194: -/* f011194: 24030019 */ addiu $v1,$zero,0x19 -.L0f011198: -/* f011198: 15280003 */ bne $t1,$t0,.L0f0111a8 -/* f01119c: 3c07800a */ lui $a3,%hi(var8009dd10) -/* f0111a0: 10000002 */ b .L0f0111ac -/* f0111a4: 00001025 */ or $v0,$zero,$zero -.L0f0111a8: -/* f0111a8: 24020023 */ addiu $v0,$zero,0x23 -.L0f0111ac: -/* f0111ac: 15280003 */ bne $t1,$t0,.L0f0111bc -/* f0111b0: 24e7dd10 */ addiu $a3,$a3,%lo(var8009dd10) -/* f0111b4: 10000002 */ b .L0f0111c0 -/* f0111b8: 00003025 */ or $a2,$zero,$zero -.L0f0111bc: -/* f0111bc: 24060014 */ addiu $a2,$zero,0x14 -.L0f0111c0: -/* f0111c0: 00c27021 */ addu $t6,$a2,$v0 -/* f0111c4: 01c35821 */ addu $t3,$t6,$v1 -/* f0111c8: 000b78c0 */ sll $t7,$t3,0x3 -/* f0111cc: 15280003 */ bne $t1,$t0,.L0f0111dc -/* f0111d0: 01e05825 */ or $t3,$t7,$zero -/* f0111d4: 10000002 */ b .L0f0111e0 -/* f0111d8: 00003025 */ or $a2,$zero,$zero -.L0f0111dc: -/* f0111dc: 24060023 */ addiu $a2,$zero,0x23 -.L0f0111e0: -/* f0111e0: 15280003 */ bne $t1,$t0,.L0f0111f0 -/* f0111e4: 00061900 */ sll $v1,$a2,0x4 -/* f0111e8: 10000002 */ b .L0f0111f4 -/* f0111ec: 24060018 */ addiu $a2,$zero,0x18 -.L0f0111f0: -/* f0111f0: 24060019 */ addiu $a2,$zero,0x19 -.L0f0111f4: -/* f0111f4: 00061080 */ sll $v0,$a2,0x2 -/* f0111f8: 00461023 */ subu $v0,$v0,$a2 -/* f0111fc: 00021080 */ sll $v0,$v0,0x2 -/* f011200: 00461021 */ addu $v0,$v0,$a2 -/* f011204: 15280003 */ bne $t1,$t0,.L0f011214 -/* f011208: 00021100 */ sll $v0,$v0,0x4 -/* f01120c: 10000001 */ b .L0f011214 -/* f011210: 00000000 */ nop -.L0f011214: -/* f011214: 3c0d8007 */ lui $t5,%hi(var800705a4) -/* f011218: 25ad05a4 */ addiu $t5,$t5,%lo(var800705a4) -/* f01121c: 8da80000 */ lw $t0,0x0($t5) -/* f011220: 3c0c8007 */ lui $t4,%hi(var800705a0) -/* f011224: 258c05a0 */ addiu $t4,$t4,%lo(var800705a0) -/* f011228: 8d9f0000 */ lw $ra,0x0($t4) -/* f01122c: 000878c0 */ sll $t7,$t0,0x3 -/* f011230: 01e87821 */ addu $t7,$t7,$t0 -/* f011234: 000f7880 */ sll $t7,$t7,0x2 -/* f011238: 001fc0c0 */ sll $t8,$ra,0x3 -/* f01123c: 01e87823 */ subu $t7,$t7,$t0 -/* f011240: 031fc021 */ addu $t8,$t8,$ra -/* f011244: 0018c080 */ sll $t8,$t8,0x2 -/* f011248: 000f7880 */ sll $t7,$t7,0x2 -/* f01124c: 271f000f */ addiu $ra,$t8,0xf -/* f011250: 25e8000f */ addiu $t0,$t7,0xf -/* f011254: 37f9000f */ ori $t9,$ra,0xf -/* f011258: 3518000f */ ori $t8,$t0,0xf -/* f01125c: 01637021 */ addu $t6,$t3,$v1 -/* f011260: 3b3f000f */ xori $ra,$t9,0xf -/* f011264: 3b08000f */ xori $t0,$t8,0xf -/* f011268: 01c27821 */ addu $t7,$t6,$v0 -/* f01126c: 01ffc021 */ addu $t8,$t7,$ra -/* f011270: 03082021 */ addu $a0,$t8,$t0 -/* f011274: 2484000f */ addiu $a0,$a0,0xf -/* f011278: 3499000f */ ori $t9,$a0,0xf -/* f01127c: afbf0020 */ sw $ra,0x20($sp) -/* f011280: ace00000 */ sw $zero,0x0($a3) -/* f011284: ace00004 */ sw $zero,0x4($a3) -/* f011288: ace00008 */ sw $zero,0x8($a3) -/* f01128c: 3b24000f */ xori $a0,$t9,0xf -/* f011290: afa8001c */ sw $t0,0x1c($sp) -/* f011294: 0c0048f2 */ jal mempAlloc -/* f011298: 24050004 */ addiu $a1,$zero,0x4 -/* f01129c: 3c0a8009 */ lui $t2,%hi(g_Is4Mb) -/* f0112a0: 254a0af0 */ addiu $t2,$t2,%lo(g_Is4Mb) -/* f0112a4: 91480000 */ lbu $t0,0x0($t2) -/* f0112a8: 3c07800a */ lui $a3,%hi(var8009dd10) -/* f0112ac: 24090001 */ addiu $t1,$zero,0x1 -/* f0112b0: 3c0c8007 */ lui $t4,%hi(var800705a0) -/* f0112b4: 3c0d8007 */ lui $t5,%hi(var800705a4) -/* f0112b8: 25ad05a4 */ addiu $t5,$t5,%lo(var800705a4) -/* f0112bc: 258c05a0 */ addiu $t4,$t4,%lo(var800705a0) -/* f0112c0: 24e7dd10 */ addiu $a3,$a3,%lo(var8009dd10) -/* f0112c4: 8fbf0020 */ lw $ra,0x20($sp) -/* f0112c8: 15280003 */ bne $t1,$t0,.L0f0112d8 -/* f0112cc: 00402025 */ or $a0,$v0,$zero -/* f0112d0: 10000002 */ b .L0f0112dc -/* f0112d4: 00003025 */ or $a2,$zero,$zero -.L0f0112d8: -/* f0112d8: 24060023 */ addiu $a2,$zero,0x23 -.L0f0112dc: -/* f0112dc: 10c00009 */ beqz $a2,.L0f011304 -/* f0112e0: 3c05800a */ lui $a1,%hi(var8009dd00) -/* f0112e4: 3c01800a */ lui $at,%hi(var8009dd10) -/* f0112e8: 15280003 */ bne $t1,$t0,.L0f0112f8 -/* f0112ec: ac22dd10 */ sw $v0,%lo(var8009dd10)($at) -/* f0112f0: 10000002 */ b .L0f0112fc -/* f0112f4: 00003025 */ or $a2,$zero,$zero -.L0f0112f8: -/* f0112f8: 24060023 */ addiu $a2,$zero,0x23 -.L0f0112fc: -/* f0112fc: 000678c0 */ sll $t7,$a2,0x3 -/* f011300: 004f2021 */ addu $a0,$v0,$t7 -.L0f011304: -/* f011304: 15280003 */ bne $t1,$t0,.L0f011314 -/* f011308: 24a5dd00 */ addiu $a1,$a1,%lo(var8009dd00) -/* f01130c: 10000002 */ b .L0f011318 -/* f011310: 24060018 */ addiu $a2,$zero,0x18 -.L0f011314: -/* f011314: 24060019 */ addiu $a2,$zero,0x19 -.L0f011318: -/* f011318: 10c00008 */ beqz $a2,.L0f01133c -/* f01131c: 3c0b800a */ lui $t3,%hi(var8009dd04) -/* f011320: 15280003 */ bne $t1,$t0,.L0f011330 -/* f011324: ace40004 */ sw $a0,0x4($a3) -/* f011328: 10000002 */ b .L0f011334 -/* f01132c: 24060018 */ addiu $a2,$zero,0x18 -.L0f011330: -/* f011330: 24060019 */ addiu $a2,$zero,0x19 -.L0f011334: -/* f011334: 0006c0c0 */ sll $t8,$a2,0x3 -/* f011338: 00982021 */ addu $a0,$a0,$t8 -.L0f01133c: -/* f01133c: 15280003 */ bne $t1,$t0,.L0f01134c -/* f011340: 256bdd04 */ addiu $t3,$t3,%lo(var8009dd04) -/* f011344: 10000002 */ b .L0f011350 -/* f011348: 00003025 */ or $a2,$zero,$zero -.L0f01134c: -/* f01134c: 24060014 */ addiu $a2,$zero,0x14 -.L0f011350: -/* f011350: 10c00008 */ beqz $a2,.L0f011374 -/* f011354: 00001825 */ or $v1,$zero,$zero -/* f011358: 15280003 */ bne $t1,$t0,.L0f011368 -/* f01135c: ace40008 */ sw $a0,0x8($a3) -/* f011360: 10000002 */ b .L0f01136c -/* f011364: 00003025 */ or $a2,$zero,$zero -.L0f011368: -/* f011368: 24060014 */ addiu $a2,$zero,0x14 -.L0f01136c: -/* f01136c: 0006c8c0 */ sll $t9,$a2,0x3 -/* f011370: 00992021 */ addu $a0,$a0,$t9 -.L0f011374: -/* f011374: aca40000 */ sw $a0,0x0($a1) -/* f011378: 8fae001c */ lw $t6,0x1c($sp) -/* f01137c: 009f2021 */ addu $a0,$a0,$ra -/* f011380: ad640000 */ sw $a0,0x0($t3) -/* f011384: 15280003 */ bne $t1,$t0,.L0f011394 -/* f011388: 008e2021 */ addu $a0,$a0,$t6 -/* f01138c: 10000002 */ b .L0f011398 -/* f011390: 00003025 */ or $a2,$zero,$zero -.L0f011394: -/* f011394: 24060023 */ addiu $a2,$zero,0x23 -.L0f011398: -/* f011398: 18c00014 */ blez $a2,.L0f0113ec -/* f01139c: 000310c0 */ sll $v0,$v1,0x3 -/* f0113a0: 8cef0000 */ lw $t7,0x0($a3) -.L0f0113a4: -/* f0113a4: 24630001 */ addiu $v1,$v1,0x1 -/* f0113a8: 24060023 */ addiu $a2,$zero,0x23 -/* f0113ac: 01e2c021 */ addu $t8,$t7,$v0 -/* f0113b0: af040004 */ sw $a0,0x4($t8) -/* f0113b4: 8cf90000 */ lw $t9,0x0($a3) -/* f0113b8: 24840010 */ addiu $a0,$a0,0x10 -/* f0113bc: 03227021 */ addu $t6,$t9,$v0 -/* f0113c0: adc00000 */ sw $zero,0x0($t6) -/* f0113c4: 91480000 */ lbu $t0,0x0($t2) -/* f0113c8: 24420008 */ addiu $v0,$v0,0x8 -/* f0113cc: 15280003 */ bne $t1,$t0,.L0f0113dc -/* f0113d0: 00000000 */ nop -/* f0113d4: 10000001 */ b .L0f0113dc -/* f0113d8: 00003025 */ or $a2,$zero,$zero -.L0f0113dc: -/* f0113dc: 0066082a */ slt $at,$v1,$a2 -/* f0113e0: 5420fff0 */ bnezl $at,.L0f0113a4 -/* f0113e4: 8cef0000 */ lw $t7,0x0($a3) -/* f0113e8: 00001825 */ or $v1,$zero,$zero -.L0f0113ec: -/* f0113ec: 15280003 */ bne $t1,$t0,.L0f0113fc -/* f0113f0: 24060019 */ addiu $a2,$zero,0x19 -/* f0113f4: 10000001 */ b .L0f0113fc -/* f0113f8: 24060018 */ addiu $a2,$zero,0x18 -.L0f0113fc: -/* f0113fc: 18c00014 */ blez $a2,.L0f011450 -/* f011400: 000310c0 */ sll $v0,$v1,0x3 -/* f011404: 8cef0004 */ lw $t7,0x4($a3) -.L0f011408: -/* f011408: 24630001 */ addiu $v1,$v1,0x1 -/* f01140c: 24060019 */ addiu $a2,$zero,0x19 -/* f011410: 01e2c021 */ addu $t8,$t7,$v0 -/* f011414: af040004 */ sw $a0,0x4($t8) -/* f011418: 8cf90004 */ lw $t9,0x4($a3) -/* f01141c: 248400d0 */ addiu $a0,$a0,0xd0 -/* f011420: 03227021 */ addu $t6,$t9,$v0 -/* f011424: adc00000 */ sw $zero,0x0($t6) -/* f011428: 91480000 */ lbu $t0,0x0($t2) -/* f01142c: 24420008 */ addiu $v0,$v0,0x8 -/* f011430: 15280003 */ bne $t1,$t0,.L0f011440 -/* f011434: 00000000 */ nop -/* f011438: 10000001 */ b .L0f011440 -/* f01143c: 24060018 */ addiu $a2,$zero,0x18 -.L0f011440: -/* f011440: 0066082a */ slt $at,$v1,$a2 -/* f011444: 5420fff0 */ bnezl $at,.L0f011408 -/* f011448: 8cef0004 */ lw $t7,0x4($a3) -/* f01144c: 00001825 */ or $v1,$zero,$zero -.L0f011450: -/* f011450: 15280003 */ bne $t1,$t0,.L0f011460 -/* f011454: 24060014 */ addiu $a2,$zero,0x14 -/* f011458: 10000001 */ b .L0f011460 -/* f01145c: 00003025 */ or $a2,$zero,$zero -.L0f011460: -/* f011460: 18c00013 */ blez $a2,.L0f0114b0 -/* f011464: 000310c0 */ sll $v0,$v1,0x3 -/* f011468: 8cef0008 */ lw $t7,0x8($a3) -.L0f01146c: -/* f01146c: 24630001 */ addiu $v1,$v1,0x1 -/* f011470: 24060014 */ addiu $a2,$zero,0x14 -/* f011474: 01e2c021 */ addu $t8,$t7,$v0 -/* f011478: af000004 */ sw $zero,0x4($t8) -/* f01147c: 8cf90008 */ lw $t9,0x8($a3) -/* f011480: 03227021 */ addu $t6,$t9,$v0 -/* f011484: adc00000 */ sw $zero,0x0($t6) -/* f011488: 914f0000 */ lbu $t7,0x0($t2) -/* f01148c: 24420008 */ addiu $v0,$v0,0x8 -/* f011490: 152f0003 */ bne $t1,$t7,.L0f0114a0 -/* f011494: 00000000 */ nop -/* f011498: 10000001 */ b .L0f0114a0 -/* f01149c: 00003025 */ or $a2,$zero,$zero -.L0f0114a0: -/* f0114a0: 0066082a */ slt $at,$v1,$a2 -/* f0114a4: 5420fff1 */ bnezl $at,.L0f01146c -/* f0114a8: 8cef0008 */ lw $t7,0x8($a3) -/* f0114ac: 00001825 */ or $v1,$zero,$zero -.L0f0114b0: -/* f0114b0: 8d980000 */ lw $t8,0x0($t4) -/* f0114b4: 00001025 */ or $v0,$zero,$zero -/* f0114b8: 2404ffff */ addiu $a0,$zero,-1 -/* f0114bc: 5b00000f */ blezl $t8,.L0f0114fc -/* f0114c0: 8dae0000 */ lw $t6,0x0($t5) -/* f0114c4: 8cb90000 */ lw $t9,0x0($a1) -.L0f0114c8: -/* f0114c8: 24630001 */ addiu $v1,$v1,0x1 -/* f0114cc: 03227021 */ addu $t6,$t9,$v0 -/* f0114d0: adc00008 */ sw $zero,0x8($t6) -/* f0114d4: 8caf0000 */ lw $t7,0x0($a1) -/* f0114d8: 01e2c021 */ addu $t8,$t7,$v0 -/* f0114dc: af000010 */ sw $zero,0x10($t8) -/* f0114e0: 8d990000 */ lw $t9,0x0($t4) -/* f0114e4: 24420024 */ addiu $v0,$v0,0x24 -/* f0114e8: 0079082a */ slt $at,$v1,$t9 -/* f0114ec: 5420fff6 */ bnezl $at,.L0f0114c8 -/* f0114f0: 8cb90000 */ lw $t9,0x0($a1) -/* f0114f4: 00001825 */ or $v1,$zero,$zero -/* f0114f8: 8dae0000 */ lw $t6,0x0($t5) -.L0f0114fc: -/* f0114fc: 00001025 */ or $v0,$zero,$zero -/* f011500: 19c0000a */ blez $t6,.L0f01152c -/* f011504: 00000000 */ nop -/* f011508: 8d6f0000 */ lw $t7,0x0($t3) -.L0f01150c: -/* f01150c: 24630001 */ addiu $v1,$v1,0x1 -/* f011510: 01e2c021 */ addu $t8,$t7,$v0 -/* f011514: a7040000 */ sh $a0,0x0($t8) -/* f011518: 8db90000 */ lw $t9,0x0($t5) -/* f01151c: 2442008c */ addiu $v0,$v0,0x8c -/* f011520: 0079082a */ slt $at,$v1,$t9 -/* f011524: 5420fff9 */ bnezl $at,.L0f01150c -/* f011528: 8d6f0000 */ lw $t7,0x0($t3) -.L0f01152c: -/* f01152c: 3c018007 */ lui $at,%hi(var800705ac) -/* f011530: ac2005ac */ sw $zero,%lo(var800705ac)($at) -/* f011534: 3c018007 */ lui $at,%hi(var800705b0) -/* f011538: ac2005b0 */ sw $zero,%lo(var800705b0)($at) -/* f01153c: 3c018007 */ lui $at,%hi(var800705b4) -/* f011540: ac2005b4 */ sw $zero,%lo(var800705b4)($at) -/* f011544: 8fbf0014 */ lw $ra,0x14($sp) -/* f011548: 3c018007 */ lui $at,%hi(var800705b8) -/* f01154c: ac2005b8 */ sw $zero,%lo(var800705b8)($at) -/* f011550: 3c018007 */ lui $at,%hi(var800705bc) -/* f011554: ac2005bc */ sw $zero,%lo(var800705bc)($at) -/* f011558: 03e00008 */ jr $ra -/* f01155c: 27bd0040 */ addiu $sp,$sp,0x40 -); +/** + * Allocate slots for model instances and animations. + * + * Each model instance can require rwdata: a block of bytes where it can save + * information specific to its own instance. + * + * The rwdata slots are split into 3 types. Types 1 and 2 use different slot + * sizes, while type 3 has no allocated slots at all. When models are + * instantiated they require a certain amount of rwdata, and are bound to type 1 + * if possible, otherwise type 2 if possible. If neither of those are possible + * then it allocates rwdata on the fly and puts it in type 3. + * + * The function allocates more than what is specified in the arguments. + * If the expansion pak is being used, 60 spare model slots are allocated + * (eg. for thrown weapons), and a further 20 model and 20 anim slots are + * allocated for animated objects. + */ +void modelmgrAllocateSlots(s32 numobjs, s32 numchrs) +{ + s32 rwdata2sizetotal; + s32 rwdata1sizetotal; + s32 rwdata3sizetotal; + s32 bindingssize; + u8 *ptr; + s32 i; + s32 totalsize; + s32 modelssize; + s32 animssize; + s32 rwdata1sizeeach = 0x10; + s32 rwdata2sizeeach = 0xd0; + s32 rwdata3sizeeach = 0; + s32 maxanimatedobjs = 20; + s32 numspare; -extern s32 var800705a0_2; -extern s32 var800705a4_2; + g_ModelNumObjs = numobjs; + g_ModelNumChrs = numchrs; -// Mismatch: Regalloc, although the _2 trick is certainly fake (they're the same -// variables as used earlier, but we need to force address recalculations) -//void func0f011130(s32 arg0, s32 numchrs) -//{ -// s32 v1; -// s32 v0; -// s32 a2; -// s32 tmp; -// u8 *ptr; -// s32 i; -// s32 totalsize; -// s32 modelssize; // 20 -// s32 animssize; // 1c -// s32 rwdatasize1 = 0x10; -// s32 rwdatasize2 = 0xd0; -// s32 rwdatasize3 = 0; -// -// var8009dd08 = arg0; -// var8009dd0c = numchrs; -// -// var800705a0 = arg0 + NUMTHINGS4() + numchrs + 20; -// var800705a4 = numchrs + 20; -// -// a2 = (NUMTHINGS1() + NUMTHINGS2() + NUMTHINGS3()) * sizeof(struct var8009dd10); -// v0 = NUMTHINGS1() * rwdatasize1; -// v1 = NUMTHINGS2() * rwdatasize2; -// tmp = NUMTHINGS3() * rwdatasize3; -// -// modelssize = ALIGN16(var800705a0_2 * sizeof(struct model)); -// animssize = ALIGN16(var800705a4_2 * sizeof(struct anim)); -// -// totalsize = ALIGN16(a2 + v0 + v1 + tmp + modelssize + animssize); -// -// var8009dd10[0] = NULL; -// var8009dd10[1] = NULL; -// var8009dd10[2] = NULL; -// -// ptr = mempAlloc(totalsize, MEMPOOL_STAGE); -// -// if (NUMTHINGS1()) { -// var8009dd10[0] = (struct var8009dd10 *)ptr; -// ptr += NUMTHINGS1() * 8; -// } -// -// if (NUMTHINGS2()) { -// var8009dd10[1] = (struct var8009dd10 *)ptr; -// ptr += NUMTHINGS2() * 8; -// } -// -// if (NUMTHINGS3()) { -// var8009dd10[2] = (struct var8009dd10 *)ptr; -// ptr += NUMTHINGS3() * 8; -// } -// -// var8009dd00 = (struct model *)ptr; -// ptr += modelssize; -// var8009dd04 = (struct anim *)ptr; -// ptr += animssize; -// -// for (i = 0; i < NUMTHINGS1(); i++) { -// var8009dd10[0][i].rwdata = ptr; -// var8009dd10[0][i].model = NULL; -// -// ptr += rwdatasize1; -// } -// -// for (i = 0; i < NUMTHINGS2(); i++) { -// var8009dd10[1][i].rwdata = ptr; -// var8009dd10[1][i].model = NULL; -// -// ptr += rwdatasize2; -// } -// -// for (i = 0; i < NUMTHINGS3(); i++) { -// var8009dd10[2][i].rwdata = NULL; -// var8009dd10[2][i].model = NULL; -// -// ptr += rwdatasize3; -// } -// -// for (i = 0; i < var800705a0_2; i++) { -// var8009dd00[i].filedata = NULL; -// var8009dd00[i].rwdatas = NULL; -// } -// -// for (i = 0; i < var800705a4_2; i++) { -// var8009dd04[i].animnum = -1; -// } -// -// var800705ac = 0; -// var800705b0 = 0; -// var800705b4 = 0; -// var800705b8 = 0; -// var800705bc = 0; -//} + numspare = NUMSPARE(); + g_MaxModels = numobjs + numspare + numchrs + maxanimatedobjs; + g_MaxAnims = numchrs + maxanimatedobjs; -bool weaponLoadProjectileModels(s32 weaponnum) + i = NUMTYPE2(); + bindingssize = (NUMTYPE1() + i + NUMTYPE3()) * sizeof(struct modelrwdatabinding); + + rwdata1sizetotal = NUMTYPE1() * rwdata1sizeeach; + rwdata2sizetotal = NUMTYPE2() * rwdata2sizeeach; + rwdata3sizetotal = NUMTYPE3() * rwdata3sizeeach; + + modelssize = ALIGN16(g_MaxModels * sizeof(struct model)); + animssize = ALIGN16(g_MaxAnims * sizeof(struct anim)); + + totalsize = ALIGN16(bindingssize + rwdata1sizetotal + rwdata2sizetotal + rwdata3sizetotal + modelssize + animssize); + + g_ModelRwdataBindings[0] = NULL; + g_ModelRwdataBindings[1] = NULL; + g_ModelRwdataBindings[2] = NULL; + + ptr = mempAlloc(totalsize, MEMPOOL_STAGE); + + if (NUMTYPE1()) { + g_ModelRwdataBindings[0] = (struct modelrwdatabinding *) ptr; + ptr += NUMTYPE1() * 8; + } + + if (NUMTYPE2()) { + g_ModelRwdataBindings[1] = (struct modelrwdatabinding *) ptr; + ptr += NUMTYPE2() * 8; + } + + if (NUMTYPE3()) { + g_ModelRwdataBindings[2] = (struct modelrwdatabinding *) ptr; + ptr += NUMTYPE3() * 8; + } + + g_ModelSlots = (struct model *) ptr; + ptr += modelssize; + g_AnimSlots = (struct anim *) ptr; + ptr += animssize; + + for (i = 0; i < NUMTYPE1(); i++) { + g_ModelRwdataBindings[0][i].rwdata = ptr; + g_ModelRwdataBindings[0][i].model = NULL; + + ptr += rwdata1sizeeach; + } + + for (i = 0; i < NUMTYPE2(); i++) { + g_ModelRwdataBindings[1][i].rwdata = ptr; + g_ModelRwdataBindings[1][i].model = NULL; + + ptr += rwdata2sizeeach; + } + + for (i = 0; i < NUMTYPE3(); i++) { + g_ModelRwdataBindings[2][i].rwdata = NULL; + g_ModelRwdataBindings[2][i].model = NULL; + + ptr += rwdata3sizeeach; + } + + for (i = 0; i < g_MaxModels; i++) { + g_ModelSlots[i].filedata = NULL; + g_ModelSlots[i].rwdatas = NULL; + } + + for (i = 0; i < g_MaxAnims; i++) { + g_AnimSlots[i].animnum = -1; + } + + g_ModelMostType1 = 0; + g_ModelMostType2 = 0; + g_ModelMostType3 = 0; + g_ModelMostModels = 0; + g_ModelMostAnims = 0; +} + +bool modelmgrLoadProjectileModeldefs(s32 weaponnum) { bool result = false; struct weapon *weapon = g_Weapons[weaponnum]; @@ -642,10 +342,10 @@ void playerReset(void) break; case INTROCMD_WEAPON: if (cmd->param3 == 0 && g_Vars.currentplayer != g_Vars.anti) { - weaponLoadProjectileModels(cmd->param1); + modelmgrLoadProjectileModeldefs(cmd->param1); if (cmd->param2 >= 0) { - weaponLoadProjectileModels(cmd->param2); + modelmgrLoadProjectileModeldefs(cmd->param2); invGiveDoubleWeapon(cmd->param1, cmd->param2); } else { invGiveSingleWeapon(cmd->param1); diff --git a/src/game/propobj.c b/src/game/propobj.c index 9b995fc8a..b56450285 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -2017,7 +2017,7 @@ struct prop *objInit(struct defaultobj *obj, struct modelfiledata *filedata, str } if (model == NULL) { - model = modelInstantiateWithoutAnim(filedata); + model = modelmgrInstantiateModelWithoutAnim(filedata); } if (prop && model) { @@ -2088,7 +2088,7 @@ struct prop *objInit(struct defaultobj *obj, struct modelfiledata *filedata, str } } else { if (model) { - modelFree(model); + modelmgrFreeModel(model); } if (prop) { @@ -2538,7 +2538,7 @@ void objFree(struct defaultobj *obj, bool freeprop, bool canregen) modelFreeVertices(1, obj->model); } - modelFree(obj->model); + modelmgrFreeModel(obj->model); if (freeprop) { propDelist(obj->prop); @@ -22415,7 +22415,7 @@ s32 objTickPlayer(struct prop *prop) if (g_Anims[model->anim->animnum].flags & 0x02) { if (g_Vars.tickmode != TICKMODE_CUTSCENE && modelGetCurAnimFrame(model) >= modelGetNumAnimFrames(model) - 1) { - animTurnOff(model->anim); + modelmgrFreeAnim(model->anim); model->anim = NULL; } else { // In cutscene @@ -22560,7 +22560,7 @@ s32 objTickPlayer(struct prop *prop) } if (modelGetCurAnimFrame(model) >= modelGetNumAnimFrames(model) - 1) { - animTurnOff(model->anim); + modelmgrFreeAnim(model->anim); model->anim = NULL; mtx00015be4(camGetProjectionMtxF(), model->matrices, &sp248); mtx4ToMtx3(&sp248, obj->realrot); @@ -31975,7 +31975,7 @@ struct prop *hatCreateForChr(struct chrdata *chr, s32 modelnum, u32 flags) setupLoadModeldef(modelnum); filedata = g_ModelStates[modelnum].filedata; prop = propAllocate(); - model = modelInstantiateWithoutAnim(filedata); + model = modelmgrInstantiateModelWithoutAnim(filedata); obj = hatCreate(prop == NULL, model == NULL, filedata); if (prop == NULL) { @@ -31983,7 +31983,7 @@ struct prop *hatCreateForChr(struct chrdata *chr, s32 modelnum, u32 flags) } if (model == NULL) { - model = modelInstantiateWithoutAnim(filedata); + model = modelmgrInstantiateModelWithoutAnim(filedata); } if (obj && prop && model) { @@ -32021,7 +32021,7 @@ struct prop *hatCreateForChr(struct chrdata *chr, s32 modelnum, u32 flags) prop = hatApplyToChr(obj, chr, filedata, prop, model); } else { if (model) { - modelFree(model); + modelmgrFreeModel(model); } if (prop) { @@ -32077,7 +32077,7 @@ struct weaponobj *weaponCreate(bool musthaveprop, bool musthavemodel, struct mod } if (usable) { - if (!musthavemodel || func0f0b28d0(g_WeaponSlots[i].base.model, filedata)) { + if (!musthavemodel || modelmgrCanSlotFitRwdata(g_WeaponSlots[i].base.model, filedata)) { if ((g_WeaponSlots[i].base.prop->flags & (PROPFLAG_ONTHISSCREENTHISTICK | PROPFLAG_ONANYSCREENTHISTICK | PROPFLAG_ONANYSCREENPREVTICK)) == 0 && sp40 < 0) { sp40 = i; } @@ -32166,7 +32166,7 @@ struct hatobj *hatCreate(bool musthaveprop, bool musthavemodel, struct modelfile } } else if ((g_HatSlots[i].base.hidden & OBJHFLAG_PROJECTILE) == 0 && g_HatSlots[i].base.prop->parent == NULL - && (!musthavemodel || func0f0b28d0(g_HatSlots[i].base.model, filedata))) { + && (!musthavemodel || modelmgrCanSlotFitRwdata(g_HatSlots[i].base.model, filedata))) { if ((g_HatSlots[i].base.prop->flags & (PROPFLAG_ONTHISSCREENTHISTICK | PROPFLAG_ONANYSCREENTHISTICK | PROPFLAG_ONANYSCREENPREVTICK)) == 0 && sp40 < 0) { sp40 = i; } @@ -32550,7 +32550,7 @@ struct prop *func0f08b108(struct weaponobj *weapon, struct chrdata *chr, struct prop = NULL; weapon->base.prop = NULL; - modelFree(weapon->base.model); + modelmgrFreeModel(weapon->base.model); weapon->base.model = NULL; } } else { @@ -32561,7 +32561,7 @@ struct prop *func0f08b108(struct weaponobj *weapon, struct chrdata *chr, struct } if (weapon->base.model) { - modelFree(weapon->base.model); + modelmgrFreeModel(weapon->base.model); weapon->base.model = NULL; } } @@ -32612,14 +32612,14 @@ struct autogunobj *laptopDeploy(s32 modelnum, struct gset *gset, struct chrdata } prop = propAllocate(); - model = modelInstantiateWithoutAnim(filedata); + model = modelmgrInstantiateModelWithoutAnim(filedata); if (prop == NULL) { prop = propAllocate(); } if (model == NULL) { - model = modelInstantiateWithoutAnim(filedata); + model = modelmgrInstantiateModelWithoutAnim(filedata); } if (laptop && prop && model) { @@ -32713,7 +32713,7 @@ struct autogunobj *laptopDeploy(s32 modelnum, struct gset *gset, struct chrdata laptop->base.flags3 |= OBJFLAG3_INTERACTABLE | OBJFLAG3_08000000; } else { if (model) { - modelFree(model); + modelmgrFreeModel(model); } if (prop) { @@ -32738,7 +32738,7 @@ struct weaponobj *weaponCreateProjectileFromGset(s32 modelnum, struct gset *gset modeldef = g_ModelStates[modelnum].filedata; prop = propAllocate(); - model = modelInstantiateWithoutAnim(modeldef); + model = modelmgrInstantiateModelWithoutAnim(modeldef); weapon = weaponCreate(prop == NULL, model == NULL, modeldef); @@ -32747,7 +32747,7 @@ struct weaponobj *weaponCreateProjectileFromGset(s32 modelnum, struct gset *gset } if (model == NULL) { - model = modelInstantiateWithoutAnim(modeldef); + model = modelmgrInstantiateModelWithoutAnim(modeldef); } if (weapon && prop && model) { @@ -32831,7 +32831,7 @@ struct weaponobj *weaponCreateProjectileFromGset(s32 modelnum, struct gset *gset weapon = NULL; if (model) { - modelFree(model); + modelmgrFreeModel(model); } if (prop) { @@ -32869,7 +32869,7 @@ struct prop *weaponCreateForChr(struct chrdata *chr, s32 modelnum, s32 weaponnum } prop = propAllocate(); - model = modelInstantiateWithoutAnim(filedata); + model = modelmgrInstantiateModelWithoutAnim(filedata); if (obj == NULL) { obj = weaponCreate(prop == NULL, model == NULL, filedata); @@ -32880,7 +32880,7 @@ struct prop *weaponCreateForChr(struct chrdata *chr, s32 modelnum, s32 weaponnum } if (model == NULL) { - model = modelInstantiateWithoutAnim(filedata); + model = modelmgrInstantiateModelWithoutAnim(filedata); } if (obj && prop && model) { @@ -32930,7 +32930,7 @@ struct prop *weaponCreateForChr(struct chrdata *chr, s32 modelnum, s32 weaponnum prop = func0f08b108(obj, chr, filedata, prop, model); } else { if (model) { - modelFree(model); + modelmgrFreeModel(model); } if (prop) { diff --git a/src/game/setup.c b/src/game/setup.c index 4f1f47733..6c4e74658 100644 --- a/src/game/setup.c +++ b/src/game/setup.c @@ -627,18 +627,18 @@ void setupPlaceWeapon(struct weaponobj *weapon, s32 cmdindex) #if VERSION >= VERSION_NTSC_1_0 weapon->base.flags &= ~OBJFLAG_DEACTIVATED; weapon->base.flags |= OBJFLAG_WEAPON_AICANNOTUSE; - weaponLoadProjectileModels(weapon->weaponnum); + modelmgrLoadProjectileModeldefs(weapon->weaponnum); func0f08b25c(weapon, chr); #else if (g_Vars.stagenum == STAGE_INVESTIGATION && lvGetDifficulty() == DIFF_PA && weapon->weaponnum == WEAPON_K7AVENGER) { - weaponLoadProjectileModels(weapon->weaponnum); + modelmgrLoadProjectileModeldefs(weapon->weaponnum); func0f08b25c(weapon, chr); } else if (g_Vars.stagenum == STAGE_ATTACKSHIP) { weapon->base.flags &= ~OBJFLAG_DEACTIVATED; weapon->base.flags |= OBJFLAG_WEAPON_AICANNOTUSE; - weaponLoadProjectileModels(weapon->weaponnum); + modelmgrLoadProjectileModeldefs(weapon->weaponnum); func0f08b25c(weapon, chr); } else { weapon->weaponnum = WEAPON_NONE; @@ -695,7 +695,7 @@ void setupPlaceWeapon(struct weaponobj *weapon, s32 cmdindex) } } - weaponLoadProjectileModels(weapon->weaponnum); + modelmgrLoadProjectileModeldefs(weapon->weaponnum); func0f08b25c(weapon, chr); } } @@ -750,7 +750,7 @@ void setupPlaceWeapon(struct weaponobj *weapon, s32 cmdindex) } if (weapon->weaponnum != WEAPON_NONE && giveweapon) { - weaponLoadProjectileModels(weapon->weaponnum); + modelmgrLoadProjectileModeldefs(weapon->weaponnum); setupCreateObject(&weapon->base, cmdindex); } } @@ -1292,7 +1292,7 @@ void setupLoadFiles(s32 stagenum) s32 j; struct ailist tmp; s32 numchrs = 0; - s32 total = 0; + s32 numobjs = 0; s32 extra; struct stagesetup *setup; u16 filenum; @@ -1388,49 +1388,51 @@ void setupLoadFiles(s32 stagenum) } } + // Count the number of chrs and objects so enough model slots can be allocated numchrs += setupCountCommandType(OBJTYPE_CHR); if (!g_Vars.normmplayerisrunning && g_MissionConfig.iscoop && g_Vars.numaibuddies > 0) { + // @bug? The Hotshot buddy has two guns, but only one is counted here. numchrs += g_Vars.numaibuddies; - total += g_Vars.numaibuddies; + numobjs += g_Vars.numaibuddies; // the buddy's weapon } - total += setupCountCommandType(OBJTYPE_WEAPON); - total += setupCountCommandType(OBJTYPE_KEY); - total += setupCountCommandType(OBJTYPE_HAT); - total += setupCountCommandType(OBJTYPE_DOOR); - total += setupCountCommandType(OBJTYPE_CCTV); - total += setupCountCommandType(OBJTYPE_AUTOGUN); - total += setupCountCommandType(OBJTYPE_HANGINGMONITORS); - total += setupCountCommandType(OBJTYPE_SINGLEMONITOR); - total += setupCountCommandType(OBJTYPE_MULTIMONITOR); - total += setupCountCommandType(OBJTYPE_SHIELD); - total += setupCountCommandType(OBJTYPE_BASIC); - total += setupCountCommandType(OBJTYPE_DEBRIS); - total += setupCountCommandType(OBJTYPE_GLASS); - total += setupCountCommandType(OBJTYPE_TINTEDGLASS); - total += setupCountCommandType(OBJTYPE_SAFE); - total += setupCountCommandType(OBJTYPE_29); - total += setupCountCommandType(OBJTYPE_GASBOTTLE); - total += setupCountCommandType(OBJTYPE_ALARM); - total += setupCountCommandType(OBJTYPE_AMMOCRATE); - total += setupCountCommandType(OBJTYPE_MULTIAMMOCRATE); - total += setupCountCommandType(OBJTYPE_TRUCK); - total += setupCountCommandType(OBJTYPE_TANK); - total += setupCountCommandType(OBJTYPE_LIFT); - total += setupCountCommandType(OBJTYPE_HOVERBIKE); - total += setupCountCommandType(OBJTYPE_HOVERPROP); - total += setupCountCommandType(OBJTYPE_FAN); - total += setupCountCommandType(OBJTYPE_HOVERCAR); - total += setupCountCommandType(OBJTYPE_CHOPPER); - total += setupCountCommandType(OBJTYPE_HELI); - total += setupCountCommandType(OBJTYPE_ESCASTEP); + numobjs += setupCountCommandType(OBJTYPE_WEAPON); + numobjs += setupCountCommandType(OBJTYPE_KEY); + numobjs += setupCountCommandType(OBJTYPE_HAT); + numobjs += setupCountCommandType(OBJTYPE_DOOR); + numobjs += setupCountCommandType(OBJTYPE_CCTV); + numobjs += setupCountCommandType(OBJTYPE_AUTOGUN); + numobjs += setupCountCommandType(OBJTYPE_HANGINGMONITORS); + numobjs += setupCountCommandType(OBJTYPE_SINGLEMONITOR); + numobjs += setupCountCommandType(OBJTYPE_MULTIMONITOR); + numobjs += setupCountCommandType(OBJTYPE_SHIELD); + numobjs += setupCountCommandType(OBJTYPE_BASIC); + numobjs += setupCountCommandType(OBJTYPE_DEBRIS); + numobjs += setupCountCommandType(OBJTYPE_GLASS); + numobjs += setupCountCommandType(OBJTYPE_TINTEDGLASS); + numobjs += setupCountCommandType(OBJTYPE_SAFE); + numobjs += setupCountCommandType(OBJTYPE_29); + numobjs += setupCountCommandType(OBJTYPE_GASBOTTLE); + numobjs += setupCountCommandType(OBJTYPE_ALARM); + numobjs += setupCountCommandType(OBJTYPE_AMMOCRATE); + numobjs += setupCountCommandType(OBJTYPE_MULTIAMMOCRATE); + numobjs += setupCountCommandType(OBJTYPE_TRUCK); + numobjs += setupCountCommandType(OBJTYPE_TANK); + numobjs += setupCountCommandType(OBJTYPE_LIFT); + numobjs += setupCountCommandType(OBJTYPE_HOVERBIKE); + numobjs += setupCountCommandType(OBJTYPE_HOVERPROP); + numobjs += setupCountCommandType(OBJTYPE_FAN); + numobjs += setupCountCommandType(OBJTYPE_HOVERCAR); + numobjs += setupCountCommandType(OBJTYPE_CHOPPER); + numobjs += setupCountCommandType(OBJTYPE_HELI); + numobjs += setupCountCommandType(OBJTYPE_ESCASTEP); if (g_Vars.normmplayerisrunning) { - total += scenarioNumProps(); + numobjs += scenarioNumProps(); } - func0f011130(total, numchrs); + modelmgrAllocateSlots(numobjs, numchrs); } else { // cover isn't set to NULL here... I guess it's not important g_StageSetup.waypoints = NULL; @@ -1441,7 +1443,7 @@ void setupLoadFiles(s32 stagenum) g_StageSetup.ailists = NULL; g_StageSetup.padfiledata = NULL; - func0f011130(0, 0); + modelmgrAllocateSlots(0, 0); } if (IS4MB()) { @@ -1452,7 +1454,7 @@ void setupLoadFiles(s32 stagenum) if (IS4MB()); - g_Vars.maxprops = total + numchrs + extra + 40; + g_Vars.maxprops = numobjs + numchrs + extra + 40; } void setupCreateProps(s32 stagenum) diff --git a/src/game/setuputils.c b/src/game/setuputils.c index d8f90f1e7..e2e36e7f9 100644 --- a/src/game/setuputils.c +++ b/src/game/setuputils.c @@ -322,7 +322,7 @@ struct defaultobj *setupFindObjForReuse(s32 wanttype, struct defaultobj **offscr && (obj->flags & OBJFLAG_00800000) == 0 #endif && obj->prop->parent == NULL - && (!musthavemodel || func0f0b28d0(obj->model, filedata))) { + && (!musthavemodel || modelmgrCanSlotFitRwdata(obj->model, filedata))) { if (offscreenobj == NULL && (obj->prop->flags & (PROPFLAG_ONTHISSCREENTHISTICK | PROPFLAG_ONANYSCREENTHISTICK | PROPFLAG_ONANYSCREENPREVTICK)) == 0) { offscreenobj = obj; } diff --git a/src/game/title.c b/src/game/title.c index 63ac265e1..3183033bc 100644 --- a/src/game/title.c +++ b/src/game/title.c @@ -560,7 +560,7 @@ void titleInitPdLogo(void) remaining = 0x47800 - size; modelCalculateRwDataLen(g_ModelStates[MODEL_NLOGO].filedata); - g_TitleModel = modelInstantiateWithAnim(g_ModelStates[MODEL_NLOGO].filedata); + g_TitleModel = modelmgrInstantiateModelWithAnim(g_ModelStates[MODEL_NLOGO].filedata); modelSetScale(g_TitleModel, 1); modelSetRootPosition(g_TitleModel, &coord); } @@ -573,7 +573,7 @@ void titleInitPdLogo(void) remaining -= size; modelCalculateRwDataLen(g_ModelStates[MODEL_NLOGO2].filedata); - g_TitleModelNLogo2 = modelInstantiateWithAnim(g_ModelStates[MODEL_NLOGO2].filedata); + g_TitleModelNLogo2 = modelmgrInstantiateModelWithAnim(g_ModelStates[MODEL_NLOGO2].filedata); modelSetScale(g_TitleModelNLogo2, 1); modelSetRootPosition(g_TitleModelNLogo2, &coord); } @@ -586,7 +586,7 @@ void titleInitPdLogo(void) remaining -= size; modelCalculateRwDataLen(g_ModelStates[MODEL_PDTWO].filedata); - g_TitleModelPdTwo = modelInstantiateWithoutAnim(g_ModelStates[MODEL_PDTWO].filedata); + g_TitleModelPdTwo = modelmgrInstantiateModelWithoutAnim(g_ModelStates[MODEL_PDTWO].filedata); modelSetScale(g_TitleModelPdTwo, 1); modelSetRootPosition(g_TitleModelPdTwo, &coord); } @@ -600,8 +600,8 @@ void titleInitPdLogo(void) remaining -= size; modelCalculateRwDataLen(g_ModelStates[MODEL_JPNLOGO].filedata); - g_TitleModelJpnLogo1 = modelInstantiateWithoutAnim(g_ModelStates[MODEL_JPNLOGO].filedata); - g_TitleModelJpnLogo2 = modelInstantiateWithoutAnim(g_ModelStates[MODEL_JPNLOGO].filedata); + g_TitleModelJpnLogo1 = modelmgrInstantiateModelWithoutAnim(g_ModelStates[MODEL_JPNLOGO].filedata); + g_TitleModelJpnLogo2 = modelmgrInstantiateModelWithoutAnim(g_ModelStates[MODEL_JPNLOGO].filedata); modelSetScale(g_TitleModelJpnLogo1, 1); modelSetScale(g_TitleModelJpnLogo2, 1); modelSetRootPosition(g_TitleModelJpnLogo1, &coord); @@ -613,7 +613,7 @@ void titleInitPdLogo(void) remaining -= size; modelCalculateRwDataLen(g_ModelStates[MODEL_JPNPD].filedata); - g_TitleModelJpnPd = modelInstantiateWithoutAnim(g_ModelStates[MODEL_JPNPD].filedata); + g_TitleModelJpnPd = modelmgrInstantiateModelWithoutAnim(g_ModelStates[MODEL_JPNPD].filedata); modelSetScale(g_TitleModelJpnPd, 1); modelSetRootPosition(g_TitleModelJpnPd, &coord); } @@ -627,7 +627,7 @@ void titleInitPdLogo(void) remaining -= size; modelCalculateRwDataLen(g_ModelStates[MODEL_PDTHREE].filedata); - g_TitleModelPdThree = modelInstantiateWithoutAnim(g_ModelStates[MODEL_PDTHREE].filedata); + g_TitleModelPdThree = modelmgrInstantiateModelWithoutAnim(g_ModelStates[MODEL_PDTHREE].filedata); modelSetScale(g_TitleModelPdThree, 1); modelSetRootPosition(g_TitleModelPdThree, &coord); } @@ -669,15 +669,15 @@ void titleInitPdLogo(void) void titleExitPdLogo(void) { - modelFree(g_TitleModel); - modelFree(g_TitleModelNLogo2); - modelFree(g_TitleModelPdTwo); - modelFree(g_TitleModelPdThree); + modelmgrFreeModel(g_TitleModel); + modelmgrFreeModel(g_TitleModelNLogo2); + modelmgrFreeModel(g_TitleModelPdTwo); + modelmgrFreeModel(g_TitleModelPdThree); #if VERSION == VERSION_JPN_FINAL - modelFree(g_TitleModelJpnLogo1); - modelFree(g_TitleModelJpnLogo2); - modelFree(g_TitleModelJpnPd); + modelmgrFreeModel(g_TitleModelJpnLogo1); + modelmgrFreeModel(g_TitleModelJpnLogo2); + modelmgrFreeModel(g_TitleModelJpnPd); #endif joy00014810(true); @@ -8071,7 +8071,7 @@ void titleInitNintendoLogo(void) g_ModelStates[MODEL_NINTENDOLOGO].filedata = modeldefLoad(g_ModelStates[MODEL_NINTENDOLOGO].fileid, nextaddr, 0x47800, 0); modelCalculateRwDataLen(g_ModelStates[MODEL_NINTENDOLOGO].filedata); - g_TitleModel = modelInstantiateWithoutAnim(g_ModelStates[MODEL_NINTENDOLOGO].filedata); + g_TitleModel = modelmgrInstantiateModelWithoutAnim(g_ModelStates[MODEL_NINTENDOLOGO].filedata); modelSetScale(g_TitleModel, 1); modelSetRootPosition(g_TitleModel, &coord); var800624f4 = 1; @@ -8081,7 +8081,7 @@ void titleInitNintendoLogo(void) void titleExitNintendoLogo(void) { - modelFree(g_TitleModel); + modelmgrFreeModel(g_TitleModel); joy00014810(true); } @@ -8230,7 +8230,7 @@ void titleInitRareLogo(void) g_ModelStates[MODEL_RARELOGO].filedata = modeldefLoad(g_ModelStates[MODEL_RARELOGO].fileid, nextaddr, 0x47800, 0); modelCalculateRwDataLen(g_ModelStates[MODEL_RARELOGO].filedata); - g_TitleModel = modelInstantiateWithoutAnim(g_ModelStates[MODEL_RARELOGO].filedata); + g_TitleModel = modelmgrInstantiateModelWithoutAnim(g_ModelStates[MODEL_RARELOGO].filedata); modelSetScale(g_TitleModel, 1); modelSetRootPosition(g_TitleModel, &coord); @@ -8247,7 +8247,7 @@ void titleInitRareLogo(void) void titleExitRareLogo(void) { - modelFree(g_TitleModel); + modelmgrFreeModel(g_TitleModel); joy00014810(true); } diff --git a/src/include/bss.h b/src/include/bss.h index 0f083c8a6..c1965af21 100644 --- a/src/include/bss.h +++ b/src/include/bss.h @@ -134,11 +134,11 @@ extern struct fireslot g_Fireslots[NUM_FIRESLOTS]; extern struct casing g_Casings[20]; extern struct boltbeam g_BoltBeams[8]; extern struct lasersight g_LaserSights[4]; -extern struct model *var8009dd00; -extern struct anim *var8009dd04; -extern s32 var8009dd08; -extern s32 var8009dd0c; -extern struct var8009dd10 *var8009dd10[3]; +extern struct model *g_ModelSlots; +extern struct anim *g_AnimSlots; +extern s32 g_ModelNumObjs; +extern s32 g_ModelNumChrs; +extern struct modelrwdatabinding *g_ModelRwdataBindings[3]; extern struct coord var8009dd20; extern f32 var8009dd2c; extern struct coord var8009dd30; diff --git a/src/include/data.h b/src/include/data.h index fe11846de..230a48973 100644 --- a/src/include/data.h +++ b/src/include/data.h @@ -246,14 +246,14 @@ extern struct inventory_class invclass_default; extern struct weapon *g_Weapons[]; extern u32 var800700ac; extern bool g_CasingsActive; -extern s32 var800705a0; -extern s32 var800705a4; -extern bool var800705a8; -extern s32 var800705ac; -extern s32 var800705b0; -extern s32 var800705b4; -extern s32 var800705b8; -extern s32 var800705bc; +extern s32 g_MaxModels; +extern s32 g_MaxAnims; +extern bool g_ModelIsLvResetting; +extern s32 g_ModelMostType1; +extern s32 g_ModelMostType2; +extern s32 g_ModelMostType3; +extern s32 g_ModelMostModels; +extern s32 g_ModelMostAnims; extern s32 g_ViRes; extern bool g_HiResEnabled; extern s32 var8007072c; diff --git a/src/include/game/game_0b28d0.h b/src/include/game/game_0b28d0.h index 392fc9d63..0cf8f0a92 100644 --- a/src/include/game/game_0b28d0.h +++ b/src/include/game/game_0b28d0.h @@ -4,14 +4,14 @@ #include "data.h" #include "types.h" -bool func0f0b28d0(struct model *model, struct modelfiledata *filedata); -void func0f0b2904(void); -struct model *modelInstantiate(struct modelfiledata *modelfiledata, bool arg1); -struct model *modelInstantiateWithoutAnim(struct modelfiledata *modelfiledata); -void modelFree(struct model *model); -struct model *modelInstantiateWithAnim(struct modelfiledata *modelfiledata); -void func0f0b32a0(struct model *model, struct modelnode *node, struct modelfiledata *headfiledata); -struct anim *func0f0b32e4(void); -void animTurnOff(struct anim *anim); +bool modelmgrCanSlotFitRwdata(struct model *modelslot, struct modelfiledata *filedata); +void modelmgrPrintCounts(void); +struct model *modelmgrInstantiateModel(struct modelfiledata *modelfiledata, bool arg1); +struct model *modelmgrInstantiateModelWithoutAnim(struct modelfiledata *modelfiledata); +void modelmgrFreeModel(struct model *model); +struct model *modelmgrInstantiateModelWithAnim(struct modelfiledata *modelfiledata); +void modelmgr0f0b32a0(struct model *model, struct modelnode *node, struct modelfiledata *headfiledata); +struct anim *modelmgrInstantiateAnim(void); +void modelmgrFreeAnim(struct anim *anim); #endif diff --git a/src/include/game/playerreset.h b/src/include/game/playerreset.h index e3e29fac5..bfa2ffb9f 100644 --- a/src/include/game/playerreset.h +++ b/src/include/game/playerreset.h @@ -4,10 +4,10 @@ #include "data.h" #include "types.h" -void func0f011110(void); -void func0f011124(bool value); -void func0f011130(s32 arg0, s32 numchrs); -bool weaponLoadProjectileModels(s32 weaponnum); +void modelmgrReset(void); +void modelmgrSetLvResetting(bool value); +void modelmgrAllocateSlots(s32 numobjs, s32 numchrs); +bool modelmgrLoadProjectileModeldefs(s32 weaponnum); void playerInitEyespy(void); void playerReset(void); diff --git a/src/include/types.h b/src/include/types.h index 720576181..8d296c78c 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -584,7 +584,7 @@ struct modelfiledata { struct model { /*0x00*/ u8 unk00; /*0x01*/ u8 unk01; - /*0x02*/ s16 unk02; + /*0x02*/ s16 rwdatalen; // in words /*0x04*/ union { struct chrdata *chr; @@ -6335,7 +6335,7 @@ struct hovtype { /*0x30*/ f32 unk30; }; -struct var8009dd10 { +struct modelrwdatabinding { struct model *model; void *rwdata; }; diff --git a/src/lib/model.c b/src/lib/model.c index 130e1648e..2bc7a5e0b 100644 --- a/src/lib/model.c +++ b/src/lib/model.c @@ -4105,7 +4105,7 @@ void modelInit(struct model *model, struct modelfiledata *filedata, union modelr model->unk00 = 0; model->filedata = filedata; model->rwdatas = rwdatas; - model->unk02 = -1; + model->rwdatalen = -1; model->scale = 1; model->attachedtomodel = NULL; model->attachedtonode = NULL;