Skip to content

Commit 76b68d0

Browse files
authored
Code cleanup around models and textures (#382)
* D_800C1020.field_588 => hasGlobalPlm * map0_s01: remove overlaping externs * D_800E2570 => g_ModelsCommon * material_8 refcount * s_Material_8 => s_Texture * name some Tex functions * func_8005B3BC => Mat_TimFileNameGet * Tex_Init1
1 parent 679306a commit 76b68d0

7 files changed

Lines changed: 131 additions & 129 deletions

File tree

configs/maps/sym.map0_s01.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,4 @@ g_EventThing_KitchenKnife = 0x800E24A0;
226226
g_EventThing_Flashlight = 0x800E24D0;
227227
g_EventThing_Map = 0x800E2500;
228228
g_EventThing_PocketRadio = 0x800E2530;
229+
g_ModelsCommon = 0x800E2570; // size:0xA8

configs/sym.bodyprog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,3 +2688,5 @@ g_MapOverlayHeader = 0x800C957C; // type:MapOverlayHead
26882688
D_800FE5F8 = 0x800FE5F8; // ignore:True - Fixes fake missmatch in `Demo_Update`.
26892689
hack_D_800FE5FC_fix = 0x800FE5FC; // ignore:true - Part of temp memory block at 800FDE00, has to be unsymbolized for C to match.
26902690
Lm_ModelFind = 0x80056CB4; // type:func
2691+
Tex_RefCountReset = 0x8005B370; // type:func
2692+
Lm_MaterialRefCountDec = 0x80056BF8; // type:func

include/bodyprog/bodyprog.h

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,13 @@ typedef struct _Material_8
582582
s_FsImageDesc imageDesc_0;
583583
u_Filename textureName_8;
584584
u32 queueIdx_10;
585-
s8 field_14;
586-
} s_Material_8;
585+
s8 refCount_14;
586+
} s_Texture;
587587

588588
typedef struct _Material
589589
{
590-
u_Filename materialName_0;
591-
s_Material_8* field_8;
590+
u_Filename name_0;
591+
s_Texture* tex_8;
592592
u8 field_C;
593593
u8 unk_D[1];
594594
u8 field_E;
@@ -1173,17 +1173,17 @@ STATIC_ASSERT_SIZEOF(s_IpdColumn, 32);
11731173

11741174
typedef struct
11751175
{
1176-
s32 count_0;
1177-
s_Material_8* entries_4[10];
1176+
s32 count_0;
1177+
s_Texture* entries_4[10];
11781178
} s_800C1450_0;
11791179

11801180
// Related to textures.
11811181
typedef struct
11821182
{
11831183
s_800C1450_0 field_0;
11841184
s_800C1450_0 field_2C;
1185-
s_Material_8 field_58[8];
1186-
s_Material_8 field_118[2];
1185+
s_Texture field_58[8];
1186+
s_Texture field_118[2];
11871187
} s_800C1450;
11881188
STATIC_ASSERT_SIZEOF(s_800C1450, 328);
11891189

@@ -1207,7 +1207,10 @@ typedef struct
12071207
s32 field_57C;
12081208
s32 field_580; // File chunk coord X.
12091209
s32 field_584; // File chunk coord Z.
1210-
s32 field_588;
1210+
/* Might mean something else, it depends on the flags_6 in MapType
1211+
* but the only maps that have the required flag set are maps with global plm
1212+
*/
1213+
s32 hasGlobalPlm;
12111214
} s_800C1020;
12121215
STATIC_ASSERT_SIZEOF(s_800C1020, 1420);
12131216

@@ -2684,7 +2687,7 @@ void func_800420C0();
26842687

26852688
void func_800420FC();
26862689

2687-
s_Material_8* func_80042178(char* arg0);
2690+
s_Texture* func_80042178(char* arg0);
26882691

26892692
void func_800421D8(char* mapTag, s32 plmIdx, s32 arg2, s32 arg3, s32 arg4, s32 arg5);
26902693

@@ -3110,16 +3113,15 @@ void func_8005A900(s_MeshHeader* meshHeader, s32 offset, s_GteScratchData* scrat
31103113

31113114
u8 func_8005AA08(s_MeshHeader* meshHeader, s32 arg1, s_GteScratchData2* scratchData);
31123115

3113-
/** Related to enviroment textures. */
3114-
void func_8005B1A0(s_Material_8* material_8, char* texName, u8 tPage0, u8 tPage1, s32 u, s32 v, s16 clutX, s16 clutY);
3116+
void Tex_Init1(s_Texture* tex_8, char* texName, u8 tPage0, u8 tPage1, s32 u, s32 v, s16 clutX, s16 clutY);
31153117

3116-
void func_8005B370(s_Material_8* material_8);
3118+
void Tex_RefCountReset(s_Texture* tex_8);
31173119

3118-
void func_8005B378(s_Material_8* material_8, char* arg1);
3120+
void func_8005B378(s_Texture* tex_8, char* arg1);
31193121

3120-
void func_8005B3A4(s_Material_8* material_8);
3122+
void Tex_Init0(s_Texture* tex_8);
31213123

3122-
void func_8005B3BC(char* filename, s_Material* material);
3124+
void Mat_TimFileNameGet(char* filename, s_Material* material);
31233125

31243126
void func_8005B424(VECTOR3* vec0, VECTOR3* vec1);
31253127

@@ -3146,7 +3148,7 @@ void func_80056954(s_LmHeader* lmHeader);
31463148

31473149
void func_80056A88(s_ModelHeader* modelHeader, s32 arg1, s_Material* mat, s32 flags);
31483150

3149-
void func_80056BF8(s_LmHeader* lmHeader);
3151+
void Lm_MaterialRefCountDec(s_LmHeader* lmHeader);
31503152

31513153
s32 LmHeader_ModelCountGet(s_LmHeader* lmHeader);
31523154

@@ -3175,7 +3177,7 @@ void func_80057658(s_MeshHeader* meshHeader, s32 offset, s_GteScratchData* scrat
31753177

31763178
void func_80057A3C(s_MeshHeader* meshHeader, s32 offset, s_GteScratchData* scratchData, SVECTOR3* lightVec);
31773179

3178-
s_Material_8* func_8005B1FC(s_Material* mat, s_800C1450_0* arg1, void* fsBuffer9, void* arg3, s32 arg4);
3180+
s_Texture* Tex_Get(s_Material* mat, s_800C1450_0* arg1, void* fsBuffer9, void* arg3, s32 arg4);
31793181

31803182
void func_8005B55C(GsCOORDINATE2* coord);
31813183

@@ -3496,9 +3498,9 @@ void GameFs_MapItemsModelLoad(u32 mapId);
34963498
void func_8005B46C(s_800C1450_0* arg0);
34973499

34983500
/** Crucial for map loading. */
3499-
void func_8005B474(s_800C1450_0* arg0, s_Material_8* material_8, s32 idx);
3501+
void func_8005B474(s_800C1450_0* arg0, s_Texture* tex_8, s32 idx);
35003502

3501-
s_Material_8* func_8005B4BC(char* str, s_800C1450_0* arg1);
3503+
s_Texture* func_8005B4BC(char* str, s_800C1450_0* arg1);
35023504

35033505
/** Sets the debug string position. */
35043506
void func_8005BF0C(s16 unused, s16 x, s16 y);

include/maps/map0/map0_s01.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ extern s_EventThing g_EventThing_PocketRadio; // 0x800E2530
5959

6060
extern s16 D_800E2560;
6161

62-
extern s_800BCE18_2BEC_0 D_800E258C;
63-
64-
/** Size might be 6. Possibly related to NPCs. */
65-
extern s_800BCE18_2BEC_0 D_800E2570[];
62+
extern s_800BCE18_2BEC_0 g_ModelsCommon[];
6663

6764
extern u16 g_SoundCmds[];
6865

src/bodyprog/bodyprog_80040A64.c

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ void func_80041C24(s_LmHeader* lmHeader, s32 arg1, s32 arg2) // 0x80041C24
535535
D_800C1020.field_150 = arg1;
536536
D_800C1020.field_154 = arg2;
537537
D_800C1020.ipdTableSize_158 = 0;
538-
D_800C1020.field_588 = 1;
538+
D_800C1020.hasGlobalPlm = 1;
539539

540540
func_80041D10(D_800C1020.ipdTable_15C, 4);
541541
func_80041D48();
@@ -585,15 +585,15 @@ void func_80041D48() // 0x80041D48
585585
y = 21;
586586
}
587587

588-
func_8005B1A0(&D_800C1020.field_430.field_58[i], 0, 0, y, 0, 0, x, j);
588+
Tex_Init1(&D_800C1020.field_430.field_58[i], 0, 0, y, 0, 0, x, j);
589589
}
590590

591591
func_8005B46C(&D_800C1020.field_430.field_0);
592592
func_8005B474(&D_800C1020.field_430.field_0, D_800C1020.field_430.field_58, 8);
593593

594594
for (i = 0, y = 26, j = 0; i < 2; i++, x += 16)
595595
{
596-
func_8005B1A0(&D_800C1020.field_430.field_118[i], 0, 0, y, (i & 0x1) * 32, 0, x, j);
596+
Tex_Init1(&D_800C1020.field_430.field_118[i], 0, 0, y, (i & 0x1) * 32, 0, x, j);
597597
if (i & 0x1)
598598
{
599599
y++;
@@ -629,7 +629,7 @@ void Map_PlaceIpdAtGridPos(s16 ipdFileIdx, s32 x, s32 z) // 0x80041ED0
629629
ipd = ptr->ipdHeader_0;
630630
if (ipd->isLoaded_1)
631631
{
632-
func_80056BF8(ipd->lmHeader_4);
632+
Lm_MaterialRefCountDec(ipd->lmHeader_4);
633633
}
634634
}
635635

@@ -644,28 +644,28 @@ void func_80041FF0() // 0x80041FF0
644644

645645
void func_8004201C() // 0x8004201C
646646
{
647-
s_Material_8* material_8;
647+
s_Texture* tex_8;
648648

649-
material_8 = &D_800C1020.field_430.field_58[0];
650-
while (material_8 < (&D_800C1020.field_430.field_58[8]))
649+
tex_8 = &D_800C1020.field_430.field_58[0];
650+
while (tex_8 < (&D_800C1020.field_430.field_58[8]))
651651
{
652-
if (material_8->field_14 == 0)
652+
if (tex_8->refCount_14 == 0)
653653
{
654-
func_8005B3A4(material_8);
654+
Tex_Init0(tex_8);
655655
}
656656

657-
material_8++;
657+
tex_8++;
658658
}
659659

660-
material_8 = &D_800C1020.field_430.field_118[0];
661-
while (material_8 < (&D_800C1020.field_430.field_118[2]))
660+
tex_8 = &D_800C1020.field_430.field_118[0];
661+
while (tex_8 < (&D_800C1020.field_430.field_118[2]))
662662
{
663-
if (material_8->field_14 == 0)
663+
if (tex_8->refCount_14 == 0)
664664
{
665-
func_8005B3A4(material_8);
665+
Tex_Init0(tex_8);
666666
}
667667

668-
material_8++;
668+
tex_8++;
669669
}
670670
}
671671

@@ -685,34 +685,34 @@ void func_800420FC() // 0x800420FC
685685
if (Fs_QueueEntryLoadStatusGet(ptr->queueIdx_8) >= FsQueueEntryLoadStatus_Loaded &&
686686
ptr->lmHeader_0->isLoaded_2)
687687
{
688-
func_80056BF8(D_800C1020.field_138.lmHeader_0);
688+
Lm_MaterialRefCountDec(D_800C1020.field_138.lmHeader_0);
689689
}
690690

691691
func_80041CB4(&D_800C1020.field_138, D_800C1020.field_138.lmHeader_0);
692692
}
693693

694-
s_Material_8* func_80042178(char* arg0) // 0x80042178
694+
s_Texture* func_80042178(char* arg0) // 0x80042178
695695
{
696-
s_Material_8* material_8;
696+
s_Texture* tex_8;
697697

698-
material_8 = func_8005B4BC(arg0, &D_800C1020.field_430.field_0);
699-
if (material_8 != NULL)
698+
tex_8 = func_8005B4BC(arg0, &D_800C1020.field_430.field_0);
699+
if (tex_8 != NULL)
700700
{
701-
return material_8;
701+
return tex_8;
702702
}
703703

704-
material_8 = func_8005B4BC(arg0, &D_800C1020.field_430.field_2C);
705-
if (material_8 != NULL)
704+
tex_8 = func_8005B4BC(arg0, &D_800C1020.field_430.field_2C);
705+
if (tex_8 != NULL)
706706
{
707-
return material_8;
707+
return tex_8;
708708
}
709709

710710
return NULL;
711711
}
712712

713713
void func_800421D8(char* mapTag, s32 plmIdx, s32 arg2, s32 arg3, s32 arg4, s32 arg5) // 0x800421D8
714714
{
715-
D_800C1020.field_588 = arg3;
715+
D_800C1020.hasGlobalPlm = arg3;
716716
D_800C1020.field_134 = arg5;
717717

718718
if (plmIdx != NO_VALUE)
@@ -722,7 +722,7 @@ void func_800421D8(char* mapTag, s32 plmIdx, s32 arg2, s32 arg3, s32 arg4, s32 a
722722
if (Fs_QueueEntryLoadStatusGet(D_800C1020.field_138.queueIdx_8) >= FsQueueEntryLoadStatus_Loaded &&
723723
D_800C1020.field_138.lmHeader_0->isLoaded_2)
724724
{
725-
func_80056BF8(D_800C1020.field_138.lmHeader_0);
725+
Lm_MaterialRefCountDec(D_800C1020.field_138.lmHeader_0);
726726
}
727727

728728
D_800C1020.field_138.fileIdx_4 = plmIdx;
@@ -763,7 +763,7 @@ void func_80042300(s_800C1020* arg0, s32 arg1) // 0x80042300
763763
ipd1 = temp_s0->ipdHeader_0;
764764
if (ipd1->isLoaded_1)
765765
{
766-
func_80056BF8(ipd1->lmHeader_4);
766+
Lm_MaterialRefCountDec(ipd1->lmHeader_4);
767767
}
768768
}
769769

@@ -983,7 +983,7 @@ s32 func_8004287C(s_800BCE18_2BEC_0* arg0, s_800BCE18_2BEC_0_10* arg1, s32 posX,
983983
continue;
984984
}
985985

986-
if (D_800C1020.field_588 == 0)
986+
if (D_800C1020.hasGlobalPlm == 0)
987987
{
988988
if (ptr1->field_8 == xIdx && ptr1->field_A == zIdx)
989989
{
@@ -1138,35 +1138,35 @@ s32 func_80042EBC(s_800C1020* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) // 0
11381138
arg0->field_580 = temp_v0;
11391139
arg0->field_584 = var_v1;
11401140

1141-
func_800431E4(arg0, arg1, arg2, arg3, arg4, arg0->field_588);
1141+
func_800431E4(arg0, arg1, arg2, arg3, arg4, arg0->hasGlobalPlm);
11421142
func_800433B8(arg0);
11431143

11441144
for (i = NO_VALUE; i < 2; i++)
11451145
{
11461146
for (j = NO_VALUE; j < 2; j++)
11471147
{
1148-
if (arg0->field_588 != 0 || (j == 0 && i == 0))
1148+
if (arg0->hasGlobalPlm != 0 || (j == 0 && i == 0))
11491149
{
11501150
temp_s3 = sp2C + i;
11511151
temp_s1 = sp28 + j;
11521152

11531153
temp_v0_2 = func_80043554(temp_s1, temp_s3);
11541154
if (temp_v0_2 != NO_VALUE &&
1155-
func_80042DE8(arg1, arg2, temp_s1, temp_s3, arg0->field_588) <= 0 &&
1155+
func_80042DE8(arg1, arg2, temp_s1, temp_s3, arg0->hasGlobalPlm) <= 0 &&
11561156
!func_80043578(&arg0->ipdTable_15C[0], temp_s1, temp_s3))
11571157
{
1158-
temp_v0_3 = func_800435E4(&arg0->ipdTable_15C[0], arg0->field_588);
1158+
temp_v0_3 = func_800435E4(&arg0->ipdTable_15C[0], arg0->hasGlobalPlm);
11591159

11601160
if (Fs_QueueEntryLoadStatusGet(temp_v0_3->queueEntryIdx_4) >= 2)
11611161
{
11621162
temp_v1 = temp_v0_3->destBuffer_0;
11631163
if (temp_v1->field_1 != 0)
11641164
{
1165-
func_80056BF8(temp_v1->field_4);
1165+
Lm_MaterialRefCountDec(temp_v1->field_4);
11661166
}
11671167
}
11681168

1169-
temp_v0_4 = func_800436D8(temp_v0_3, temp_v0_2, temp_s1, temp_s3, arg1, arg2, arg3, arg4, arg0->field_588);
1169+
temp_v0_4 = func_800436D8(temp_v0_3, temp_v0_2, temp_s1, temp_s3, arg1, arg2, arg3, arg4, arg0->hasGlobalPlm);
11701170
if (temp_v0_4 != NO_VALUE)
11711171
{
11721172
sp30 = temp_v0_4;
@@ -1231,7 +1231,7 @@ void func_800433B8(s_800C1020* arg0) // 0x800433B8
12311231
{
12321232
if (ptr->ipdHeader_0->isLoaded_1 && ptr->field_C > 0 && ptr->field_10 > 0)
12331233
{
1234-
func_80056BF8(ptr->ipdHeader_0->lmHeader_4);
1234+
Lm_MaterialRefCountDec(ptr->ipdHeader_0->lmHeader_4);
12351235
}
12361236
}
12371237
}
@@ -1442,7 +1442,7 @@ bool func_8004393C(s32 posX, s32 posZ) // 0x8004393C
14421442
fileChunkCoordX = FLOOR_TO_STEP(FP_METER_TO_GEO(posX), FP_METER_GEO(40.0f));
14431443
fileChunkCoordZ = FLOOR_TO_STEP(FP_METER_TO_GEO(posZ), FP_METER_GEO(40.0f));
14441444

1445-
if (D_800C1020.field_588 != 0)
1445+
if (D_800C1020.hasGlobalPlm != 0)
14461446
{
14471447
return func_80042E2C(FP_METER_TO_GEO(D_800C1020.field_578), FP_METER_TO_GEO(D_800C1020.field_57C), fileChunkCoordX, fileChunkCoordZ) <= FP_METER_GEO(4.5f);
14481448
}
@@ -1491,7 +1491,7 @@ bool func_80043B34(s_800C117C* arg0, s_800C1020* arg1)
14911491
return true;
14921492
}
14931493

1494-
return arg1->field_588 != 0;
1494+
return arg1->hasGlobalPlm != 0;
14951495
}
14961496

14971497
bool IpdHeader_IsTextureLoaded(s_IpdHeader* ipdHeader) // 0x80043B70
@@ -1572,7 +1572,7 @@ bool LmFilter_NameEndsWithH(s_Material* mat) // 0x80043D64
15721572
{
15731573
char* charCode;
15741574

1575-
for (charCode = &mat->materialName_0.str[7]; charCode >= &mat->materialName_0.str[0]; charCode--)
1575+
for (charCode = &mat->name_0.str[7]; charCode >= &mat->name_0.str[0]; charCode--)
15761576
{
15771577
if (*charCode == '\0')
15781578
{

0 commit comments

Comments
 (0)