From 04a4a969955cbeb0b6f0d0daddb6feb132d02259 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 12 Jul 2022 22:56:52 +1000 Subject: [PATCH] Decompile bgPopulateVtxBatchType --- src/game/bg.c | 509 ++++++++++++++----------------------- src/game/dlights.c | 4 +- src/game/explosions.c | 2 +- src/game/room.c | 2 +- src/game/shards.c | 16 +- src/game/smoke.c | 2 +- src/game/wallhit.c | 4 +- src/include/constants.h | 2 +- src/include/game/bg.h | 18 +- src/include/game/dlights.h | 4 +- src/include/game/room.h | 2 +- src/include/types.h | 24 +- 12 files changed, 235 insertions(+), 354 deletions(-) diff --git a/src/game/bg.c b/src/game/bg.c index f878d48f9..13505786c 100644 --- a/src/game/bg.c +++ b/src/game/bg.c @@ -73,6 +73,9 @@ #define BGRESULT_TRUE 0 #define BGRESULT_FALSE 1 +#define VTXBATCHTYPE_OPA 0x01 +#define VTXBATCHTYPE_XLU 0x02 + struct var800a4640 var800a4640; u8 *g_BgPrimaryData; u32 var800a4920; @@ -244,7 +247,7 @@ void roomSetOnscreen(s32 roomnum, s32 draworder, struct screenbox *box) if (g_Rooms[roomnum].loaded240 == 0 && var8007fc10 > 0) { var8007fc10--; - roomLoad(roomnum); + bgLoadRoom(roomnum); } else if (g_Rooms[roomnum].loaded240 == 0) { var8007fc10--; } @@ -2292,7 +2295,7 @@ glabel var7f1b75c4 /* f159f18: 27bd03d8 */ addiu $sp,$sp,0x3d8 ); -Gfx *bg0f159f1c(Gfx *gdl, s32 roomnum, struct roomgfxdata18 *arg2, bool recurse, s16 arg4[3]) +Gfx *bgRenderRoomXrayPass(Gfx *gdl, s32 roomnum, struct roomgfxdata18 *arg2, bool recurse, s16 arg4[3]) { struct player *player = g_Vars.currentplayer; @@ -2305,7 +2308,7 @@ Gfx *bg0f159f1c(Gfx *gdl, s32 roomnum, struct roomgfxdata18 *arg2, bool recurse, gdl = func0f1598b4(gdl, arg2->gdl, arg2->vertices, arg4); if (recurse) { - gdl = bg0f159f1c(gdl, roomnum, arg2->next, true, arg4); + gdl = bgRenderRoomXrayPass(gdl, roomnum, arg2->next, true, arg4); } break; case 1: @@ -2328,15 +2331,15 @@ Gfx *bg0f159f1c(Gfx *gdl, s32 roomnum, struct roomgfxdata18 *arg2, bool recurse, sum = sp34.f[0] * sp28.f[0] + sp34.f[1] * sp28.f[1] + sp34.f[2] * sp28.f[2]; if (sum < 0.0f) { - gdl = bg0f159f1c(gdl, roomnum, child1, false, arg4); - gdl = bg0f159f1c(gdl, roomnum, child2, false, arg4); + gdl = bgRenderRoomXrayPass(gdl, roomnum, child1, false, arg4); + gdl = bgRenderRoomXrayPass(gdl, roomnum, child2, false, arg4); } else { - gdl = bg0f159f1c(gdl, roomnum, child2, false, arg4); - gdl = bg0f159f1c(gdl, roomnum, child1, false, arg4); + gdl = bgRenderRoomXrayPass(gdl, roomnum, child2, false, arg4); + gdl = bgRenderRoomXrayPass(gdl, roomnum, child1, false, arg4); } if (recurse) { - gdl = bg0f159f1c(gdl, roomnum, arg2->next, true, arg4); + gdl = bgRenderRoomXrayPass(gdl, roomnum, arg2->next, true, arg4); } } break; @@ -2362,7 +2365,7 @@ Gfx *bgRenderRoomInXray(Gfx *gdl, s32 roomnum) if (g_Rooms[roomnum].loaded240 == 0) { if (var8007fc10 > 0) { var8007fc10--; - roomLoad(roomnum); + bgLoadRoom(roomnum); } } @@ -2384,9 +2387,9 @@ Gfx *bgRenderRoomInXray(Gfx *gdl, s32 roomnum) sp40[1] = sp54.f[1]; sp40[2] = sp54.f[2]; - gdl = room0f166d7c(gdl, roomnum); - gdl = bg0f159f1c(gdl, roomnum, g_Rooms[roomnum].gfxdata->unk08, true, sp40); - gdl = bg0f159f1c(gdl, roomnum, g_Rooms[roomnum].gfxdata->unk0c, true, sp40); + gdl = roomPushMtx(gdl, roomnum); + gdl = bgRenderRoomXrayPass(gdl, roomnum, g_Rooms[roomnum].gfxdata->unk08, true, sp40); + gdl = bgRenderRoomXrayPass(gdl, roomnum, g_Rooms[roomnum].gfxdata->unk0c, true, sp40); g_Rooms[roomnum].loaded240 = 1; @@ -2600,7 +2603,7 @@ Gfx *bgRenderScene(Gfx *gdl) if (roomnum != -1) { if (!g_Rooms[roomnum].loaded240) { - roomLoad(roomnum); + bgLoadRoom(roomnum); } gdl = bgRenderRoomOpaque(gdl, roomnum); @@ -3054,7 +3057,7 @@ glabel bgRenderScene /* f155194: 872c0002 */ lh $t4,0x2($t9) /* f155198: 55800004 */ bnezl $t4,.NB0f1551ac /* f15519c: 02202025 */ or $a0,$s1,$zero -/* f1551a0: 0fc560fc */ jal roomLoad +/* f1551a0: 0fc560fc */ jal bgLoadRoom /* f1551a4: 02402025 */ or $a0,$s2,$zero /* f1551a8: 02202025 */ or $a0,$s1,$zero .NB0f1551ac: @@ -7786,7 +7789,7 @@ void bgTick(void) Gfx *bgRender(Gfx *gdl) { - gdl = func0f001300(gdl); + gdl = lightsSetDefault(gdl); gSPSegment(gdl++, 0x0f, g_BgPrimaryData); @@ -8269,25 +8272,25 @@ Gfx *func0f15da00(struct roomgfxdata18 *arg0, Gfx *arg1, Gfx *arg2) return arg2; } -Gfx *room0f15dab4(s32 roomnum, Gfx *arg1, u32 arg2) +Gfx *room0f15dab4(s32 roomnum, Gfx *gdl, u32 types) { struct roomgfxdata18 *thing1 = g_Rooms[roomnum].gfxdata->unk08; struct roomgfxdata18 *thing2 = g_Rooms[roomnum].gfxdata->unk0c; Gfx *sp1c = NULL; Gfx *sp18 = NULL; - if ((arg2 & 1) && thing1) { - sp1c = func0f15da00(thing1, arg1, NULL); + if ((types & VTXBATCHTYPE_OPA) && thing1) { + sp1c = func0f15da00(thing1, gdl, NULL); - if (arg2 == 1) { + if (types == VTXBATCHTYPE_OPA) { return sp1c; } } - if ((arg2 & 2) && thing2) { - sp18 = func0f15da00(thing2, arg1, NULL); + if ((types & VTXBATCHTYPE_XLU) && thing2) { + sp18 = func0f15da00(thing2, gdl, NULL); - if (arg2 == 2) { + if (types == VTXBATCHTYPE_XLU) { return sp18; } } @@ -8330,7 +8333,7 @@ struct gfxvtx *room0f15dbb4(s32 roomnum, Gfx *gdl) #if VERSION >= VERSION_NTSC_1_0 GLOBAL_ASM( -glabel roomLoad +glabel bgLoadRoom /* f15dc58: 27bdfd08 */ addiu $sp,$sp,-760 /* f15dc5c: afbf0034 */ sw $ra,0x34($sp) /* f15dc60: afb40030 */ sw $s4,0x30($sp) @@ -8858,7 +8861,7 @@ glabel roomLoad /* f15e3f0: 0fc595ca */ jal gfxReplaceGbiCommandsRecursively /* f15e3f4: 8d64000c */ lw $a0,0xc($t3) .L0f15e3f8: -/* f15e3f8: 0fc57be7 */ jal room0f15ef9c +/* f15e3f8: 0fc57be7 */ jal bgFindRoomVtxBatches /* f15e3fc: 8fa402f8 */ lw $a0,0x2f8($sp) /* f15e400: 3c0c800a */ lui $t4,%hi(g_Rooms) /* f15e404: 8d8c4928 */ lw $t4,%lo(g_Rooms)($t4) @@ -8894,7 +8897,7 @@ glabel roomLoad ); #else GLOBAL_ASM( -glabel roomLoad +glabel bgLoadRoom /* f1583f0: 27bdfd08 */ addiu $sp,$sp,-760 /* f1583f4: afa402f8 */ sw $a0,0x2f8($sp) /* f1583f8: afbf002c */ sw $ra,0x2c($sp) @@ -9447,7 +9450,7 @@ glabel roomLoad /* f158be8: 0fc57fca */ jal gfxReplaceGbiCommandsRecursively /* f158bec: 8f04000c */ lw $a0,0xc($t8) .NB0f158bf0: -/* f158bf0: 0fc565e7 */ jal room0f15ef9c +/* f158bf0: 0fc565e7 */ jal bgFindRoomVtxBatches /* f158bf4: 8fa402f8 */ lw $a0,0x2f8($sp) /* f158bf8: 3c0f800b */ lui $t7,0x800b /* f158bfc: 8def90a8 */ lw $t7,-0x6f58($t7) @@ -9494,7 +9497,7 @@ const char var7f1b1a60nb[] = "bg.c"; // Mismatch: The below stores len * 4 into s1 which causes further codegen // differences. -//void roomLoad(s32 roomnum) +//void bgLoadRoom(s32 roomnum) //{ // s32 size; // 2f4 // s32 inflatedlen; // 2f0 @@ -9618,17 +9621,17 @@ const char var7f1b1a60nb[] = "bg.c"; // } // // g_Rooms[roomnum].gfxdata->numvertices = ((u32)g_Rooms[roomnum].gfxdata->colours - (u32)g_Rooms[roomnum].gfxdata->vertices) / sizeof(struct gfxvtx); -// g_Rooms[roomnum].gfxdata->numcolours = ((u32)room0f15dab4(roomnum, 0, 3) - (u32)g_Rooms[roomnum].gfxdata->colours) / sizeof(u32); +// g_Rooms[roomnum].gfxdata->numcolours = ((u32)room0f15dab4(roomnum, 0, VTXBATCHTYPE_OPA | VTXBATCHTYPE_XLU) - (u32)g_Rooms[roomnum].gfxdata->colours) / sizeof(u32); // // len = 0; -// v0 = room0f15dab4(roomnum, NULL, 3); +// v0 = room0f15dab4(roomnum, NULL, VTXBATCHTYPE_OPA | VTXBATCHTYPE_XLU); // // while (v0) { // sp208[len] = v0; // sp140[len] = room0f15dbb4(roomnum, v0); // len++; // -// v0 = room0f15dab4(roomnum, v0, 3); +// v0 = room0f15dab4(roomnum, v0, VTXBATCHTYPE_OPA | VTXBATCHTYPE_XLU); // } // // sp208[len] = (s32)allocation + inflatedlen; @@ -9700,7 +9703,7 @@ const char var7f1b1a60nb[] = "bg.c"; // gfxReplaceGbiCommandsRecursively(g_Rooms[roomnum].gfxdata->unk0c, 7); // } // -// room0f15ef9c(roomnum); +// bgFindRoomVtxBatches(roomnum); // // g_Rooms[roomnum].flags |= ROOMFLAG_DIRTY; // g_Rooms[roomnum].flags |= ROOMFLAG_0200; @@ -9739,15 +9742,14 @@ const char var7f1b7584[] = " Failed 1 - Crossed portal %d"; const char var7f1b75a4[] = " Passed"; const char var7f1b75ac[] = "edist"; - -void roomUnload(s32 roomnum) +void bgUnloadRoom(s32 roomnum) { u32 size; - if (g_Rooms[roomnum].unk44) { - size = ((g_Rooms[roomnum].unk40 << 5) + 0xf) & ~0xf; - memaFree(g_Rooms[roomnum].unk44, size); - g_Rooms[roomnum].unk44 = NULL; + if (g_Rooms[roomnum].vtxbatches) { + size = ((g_Rooms[roomnum].numvtxbatches) * sizeof(struct vtxbatch) + 0xf) & ~0xf; + memaFree(g_Rooms[roomnum].vtxbatches, size); + g_Rooms[roomnum].vtxbatches = NULL; } if (g_Rooms[roomnum].gfxdatalen > 0) { @@ -9765,7 +9767,7 @@ void bgUnloadAllRooms(void) for (i = 1; i < g_Vars.roomcount; i++) { if (g_Rooms[i].loaded240) { - roomUnload(i); + bgUnloadRoom(i); } } } @@ -9800,7 +9802,7 @@ void bgGarbageCollectRooms(s32 bytesneeded, bool desparate) } if (oldestroom != 0) { - roomUnload(oldestroom); + bgUnloadRoom(oldestroom); memaDefrag(); } @@ -9816,7 +9818,7 @@ void bgGarbageCollectRooms(s32 bytesneeded, bool desparate) if (g_Rooms[i].loaded240) #endif { - roomUnload(i); + bgUnloadRoom(i); memaDefrag(); if (memaGetLongestFree() >= bytesneeded) { @@ -9858,7 +9860,7 @@ void bgTickRooms(void) } if (numunloaded < 2 && g_Rooms[i].loaded240 == g_BgUnloadDelay240_2) { - roomUnload(i); + bgUnloadRoom(i); #if VERSION >= VERSION_NTSC_1_0 memaDefrag(); #endif @@ -9868,7 +9870,7 @@ void bgTickRooms(void) } } -Gfx *room0f15e85c(Gfx *gdl, s32 roomnum, struct roomgfxdata18 *arg2, bool arg3) +Gfx *bgRenderRoomPass(Gfx *gdl, s32 roomnum, struct roomgfxdata18 *arg2, bool arg3) { u32 v0; @@ -9900,7 +9902,7 @@ Gfx *room0f15e85c(Gfx *gdl, s32 roomnum, struct roomgfxdata18 *arg2, bool arg3) gSPDisplayList(gdl++, OS_PHYSICAL_TO_K0(arg2->gdl)); if (arg3) { - gdl = room0f15e85c(gdl, roomnum, arg2->next, true); + gdl = bgRenderRoomPass(gdl, roomnum, arg2->next, true); } break; case 1: @@ -9927,15 +9929,15 @@ Gfx *room0f15e85c(Gfx *gdl, s32 roomnum, struct roomgfxdata18 *arg2, bool arg3) sum = sp40[0] * sp34[0] + sp40[1] * sp34[1] + sp40[2] * sp34[2]; if (sum < 0.0f) { - gdl = room0f15e85c(gdl, roomnum, sp58, false); - gdl = room0f15e85c(gdl, roomnum, sp54, false); + gdl = bgRenderRoomPass(gdl, roomnum, sp58, false); + gdl = bgRenderRoomPass(gdl, roomnum, sp54, false); } else { - gdl = room0f15e85c(gdl, roomnum, sp54, false); - gdl = room0f15e85c(gdl, roomnum, sp58, false); + gdl = bgRenderRoomPass(gdl, roomnum, sp54, false); + gdl = bgRenderRoomPass(gdl, roomnum, sp58, false); } if (arg3) { - gdl = room0f15e85c(gdl, roomnum, arg2->next, true); + gdl = bgRenderRoomPass(gdl, roomnum, arg2->next, true); } } break; @@ -9953,10 +9955,11 @@ Gfx *bgRenderRoomOpaque(Gfx *gdl, s32 roomnum) return gdl; } - gdl = room0f166d7c(gdl, roomnum); - gdl = func0f001138(gdl, roomnum); - gdl = room0f15e85c(gdl, roomnum, g_Rooms[roomnum].gfxdata->unk08, true); - gdl = func0f001300(gdl); + gdl = roomPushMtx(gdl, roomnum); + + gdl = lightsSetForRoom(gdl, roomnum); + gdl = bgRenderRoomPass(gdl, roomnum, g_Rooms[roomnum].gfxdata->unk08, true); + gdl = lightsSetDefault(gdl); g_Rooms[roomnum].loaded240 = 1; @@ -9984,282 +9987,160 @@ Gfx *bgRenderRoomXlu(Gfx *gdl, s32 roomnum) if (g_Rooms[roomnum].gfxdata); if (g_Rooms[roomnum].gfxdata); - gdl = room0f166d7c(gdl, roomnum); - gdl = room0f15e85c(gdl, roomnum, g_Rooms[roomnum].gfxdata->unk0c, 1); + gdl = roomPushMtx(gdl, roomnum); + gdl = bgRenderRoomPass(gdl, roomnum, g_Rooms[roomnum].gfxdata->unk0c, true); g_Rooms[roomnum].loaded240 = 1; } else { - roomLoad(roomnum); + bgLoadRoom(roomnum); } return gdl; } -GLOBAL_ASM( -glabel func0f15ecd8 -.late_rodata -glabel var7f1b75d4 -.word 0x46fffe00 -.text -/* f15ecd8: 27bdffe0 */ addiu $sp,$sp,-32 -/* f15ecdc: afb5001c */ sw $s5,0x1c($sp) -/* f15ece0: afb40018 */ sw $s4,0x18($sp) -/* f15ece4: afb30014 */ sw $s3,0x14($sp) -/* f15ece8: afb20010 */ sw $s2,0x10($sp) -/* f15ecec: afb1000c */ sw $s1,0xc($sp) -/* f15ecf0: afb00008 */ sw $s0,0x8($sp) -/* f15ecf4: 80ce0000 */ lb $t6,0x0($a2) -/* f15ecf8: 2412ffb8 */ addiu $s2,$zero,-72 -/* f15ecfc: 00808025 */ or $s0,$a0,$zero -/* f15ed00: 124e009d */ beq $s2,$t6,.L0f15ef78 -/* f15ed04: 00001025 */ or $v0,$zero,$zero -/* f15ed08: 3c013f80 */ lui $at,0x3f80 -/* f15ed0c: 44819000 */ mtc1 $at,$f18 -/* f15ed10: 3c01c700 */ lui $at,0xc700 -/* f15ed14: 44818000 */ mtc1 $at,$f16 -/* f15ed18: 3c017f1b */ lui $at,%hi(var7f1b75d4) -/* f15ed1c: 3c15800a */ lui $s5,%hi(g_BgRooms) -/* f15ed20: 3c1400ff */ lui $s4,0xff -/* f15ed24: 3694ffff */ ori $s4,$s4,0xffff -/* f15ed28: 26b54cc4 */ addiu $s5,$s5,%lo(g_BgRooms) -/* f15ed2c: c42e75d4 */ lwc1 $f14,%lo(var7f1b75d4)($at) -/* f15ed30: 00c01825 */ or $v1,$a2,$zero -/* f15ed34: 80c40000 */ lb $a0,0x0($a2) -/* f15ed38: 24130004 */ addiu $s3,$zero,0x4 -/* f15ed3c: 8fac0030 */ lw $t4,0x30($sp) -/* f15ed40: 8fa80034 */ lw $t0,0x34($sp) -.L0f15ed44: -/* f15ed44: 16640087 */ bne $s3,$a0,.L0f15ef64 -/* f15ed48: 00077940 */ sll $t7,$a3,0x5 -/* f15ed4c: 00af2021 */ addu $a0,$a1,$t7 -/* f15ed50: 00108880 */ sll $s1,$s0,0x2 -/* f15ed54: 02308821 */ addu $s1,$s1,$s0 -/* f15ed58: 0007c140 */ sll $t8,$a3,0x5 -/* f15ed5c: ac860004 */ sw $a2,0x4($a0) -/* f15ed60: a4820000 */ sh $v0,0x0($a0) -/* f15ed64: a4880002 */ sh $t0,0x2($a0) -/* f15ed68: 00b85021 */ addu $t2,$a1,$t8 -/* f15ed6c: 00118880 */ sll $s1,$s1,0x2 -/* f15ed70: 00004825 */ or $t1,$zero,$zero -.L0f15ed74: -/* f15ed74: 25290001 */ addiu $t1,$t1,0x1 -/* f15ed78: 29210003 */ slti $at,$t1,0x3 -/* f15ed7c: 254a0004 */ addiu $t2,$t2,0x4 -/* f15ed80: e54e0004 */ swc1 $f14,0x4($t2) -/* f15ed84: 1420fffb */ bnez $at,.L0f15ed74 -/* f15ed88: e5500010 */ swc1 $f16,0x10($t2) -/* f15ed8c: 906a0001 */ lbu $t2,0x1($v1) -/* f15ed90: 8c6f0004 */ lw $t7,0x4($v1) -/* f15ed94: 00004825 */ or $t1,$zero,$zero -/* f15ed98: 000ac902 */ srl $t9,$t2,0x4 -/* f15ed9c: 332e000f */ andi $t6,$t9,0xf -/* f15eda0: 25ca0001 */ addiu $t2,$t6,0x1 -/* f15eda4: 01f4c024 */ and $t8,$t7,$s4 -/* f15eda8: 19400031 */ blez $t2,.L0f15ee70 -/* f15edac: 030c5821 */ addu $t3,$t8,$t4 -/* f15edb0: 01606825 */ or $t5,$t3,$zero -.L0f15edb4: -/* f15edb4: 85b90000 */ lh $t9,0x0($t5) -/* f15edb8: c48a0008 */ lwc1 $f10,0x8($a0) -/* f15edbc: 85ae0002 */ lh $t6,0x2($t5) -/* f15edc0: 44992000 */ mtc1 $t9,$f4 -/* f15edc4: 85af0004 */ lh $t7,0x4($t5) -/* f15edc8: 448e3000 */ mtc1 $t6,$f6 -/* f15edcc: 46802020 */ cvt.s.w $f0,$f4 -/* f15edd0: 448f4000 */ mtc1 $t7,$f8 -/* f15edd4: 25290001 */ addiu $t1,$t1,0x1 -/* f15edd8: 468030a0 */ cvt.s.w $f2,$f6 -/* f15eddc: 460a003c */ c.lt.s $f0,$f10 -/* f15ede0: 46804320 */ cvt.s.w $f12,$f8 -/* f15ede4: 45020003 */ bc1fl .L0f15edf4 -/* f15ede8: c484000c */ lwc1 $f4,0xc($a0) -/* f15edec: e4800008 */ swc1 $f0,0x8($a0) -/* f15edf0: c484000c */ lwc1 $f4,0xc($a0) -.L0f15edf4: -/* f15edf4: 4604103c */ c.lt.s $f2,$f4 -/* f15edf8: 00000000 */ nop -/* f15edfc: 45020003 */ bc1fl .L0f15ee0c -/* f15ee00: c4860010 */ lwc1 $f6,0x10($a0) -/* f15ee04: e482000c */ swc1 $f2,0xc($a0) -/* f15ee08: c4860010 */ lwc1 $f6,0x10($a0) -.L0f15ee0c: -/* f15ee0c: 4606603c */ c.lt.s $f12,$f6 -/* f15ee10: 00000000 */ nop -/* f15ee14: 45020003 */ bc1fl .L0f15ee24 -/* f15ee18: c4880014 */ lwc1 $f8,0x14($a0) -/* f15ee1c: e48c0010 */ swc1 $f12,0x10($a0) -/* f15ee20: c4880014 */ lwc1 $f8,0x14($a0) -.L0f15ee24: -/* f15ee24: 4600403c */ c.lt.s $f8,$f0 -/* f15ee28: 00000000 */ nop -/* f15ee2c: 45020003 */ bc1fl .L0f15ee3c -/* f15ee30: c48a0018 */ lwc1 $f10,0x18($a0) -/* f15ee34: e4800014 */ swc1 $f0,0x14($a0) -/* f15ee38: c48a0018 */ lwc1 $f10,0x18($a0) -.L0f15ee3c: -/* f15ee3c: 4602503c */ c.lt.s $f10,$f2 -/* f15ee40: 00000000 */ nop -/* f15ee44: 45020003 */ bc1fl .L0f15ee54 -/* f15ee48: c484001c */ lwc1 $f4,0x1c($a0) -/* f15ee4c: e4820018 */ swc1 $f2,0x18($a0) -/* f15ee50: c484001c */ lwc1 $f4,0x1c($a0) -.L0f15ee54: -/* f15ee54: 460c203c */ c.lt.s $f4,$f12 -/* f15ee58: 00000000 */ nop -/* f15ee5c: 45000002 */ bc1f .L0f15ee68 -/* f15ee60: 00000000 */ nop -/* f15ee64: e48c001c */ swc1 $f12,0x1c($a0) -.L0f15ee68: -/* f15ee68: 152affd2 */ bne $t1,$t2,.L0f15edb4 -/* f15ee6c: 25ad000c */ addiu $t5,$t5,0xc -.L0f15ee70: -/* f15ee70: c4800014 */ lwc1 $f0,0x14($a0) -/* f15ee74: c4860008 */ lwc1 $f6,0x8($a0) -/* f15ee78: 46003032 */ c.eq.s $f6,$f0 -/* f15ee7c: 00000000 */ nop -/* f15ee80: 45020004 */ bc1fl .L0f15ee94 -/* f15ee84: c4800018 */ lwc1 $f0,0x18($a0) -/* f15ee88: 46120200 */ add.s $f8,$f0,$f18 -/* f15ee8c: e4880014 */ swc1 $f8,0x14($a0) -/* f15ee90: c4800018 */ lwc1 $f0,0x18($a0) -.L0f15ee94: -/* f15ee94: c48a000c */ lwc1 $f10,0xc($a0) -/* f15ee98: 46005032 */ c.eq.s $f10,$f0 -/* f15ee9c: 00000000 */ nop -/* f15eea0: 45020004 */ bc1fl .L0f15eeb4 -/* f15eea4: c4800010 */ lwc1 $f0,0x10($a0) -/* f15eea8: 46120100 */ add.s $f4,$f0,$f18 -/* f15eeac: e4840018 */ swc1 $f4,0x18($a0) -/* f15eeb0: c4800010 */ lwc1 $f0,0x10($a0) -.L0f15eeb4: -/* f15eeb4: c482001c */ lwc1 $f2,0x1c($a0) -/* f15eeb8: 46020032 */ c.eq.s $f0,$f2 -/* f15eebc: 00000000 */ nop -/* f15eec0: 45020005 */ bc1fl .L0f15eed8 -/* f15eec4: 8eb80000 */ lw $t8,0x0($s5) -/* f15eec8: 46121180 */ add.s $f6,$f2,$f18 -/* f15eecc: c4800010 */ lwc1 $f0,0x10($a0) -/* f15eed0: e486001c */ swc1 $f6,0x1c($a0) -/* f15eed4: 8eb80000 */ lw $t8,0x0($s5) -.L0f15eed8: -/* f15eed8: c4880008 */ lwc1 $f8,0x8($a0) -/* f15eedc: c486000c */ lwc1 $f6,0xc($a0) -/* f15eee0: 0311c821 */ addu $t9,$t8,$s1 -/* f15eee4: c72a0004 */ lwc1 $f10,0x4($t9) -/* f15eee8: 24e70001 */ addiu $a3,$a3,0x1 -/* f15eeec: 460a4100 */ add.s $f4,$f8,$f10 -/* f15eef0: e4840008 */ swc1 $f4,0x8($a0) -/* f15eef4: 8eae0000 */ lw $t6,0x0($s5) -/* f15eef8: 01d17821 */ addu $t7,$t6,$s1 -/* f15eefc: c5e80008 */ lwc1 $f8,0x8($t7) -/* f15ef00: 46083280 */ add.s $f10,$f6,$f8 -/* f15ef04: c4880014 */ lwc1 $f8,0x14($a0) -/* f15ef08: e48a000c */ swc1 $f10,0xc($a0) -/* f15ef0c: 8eb80000 */ lw $t8,0x0($s5) -/* f15ef10: 0311c821 */ addu $t9,$t8,$s1 -/* f15ef14: c724000c */ lwc1 $f4,0xc($t9) -/* f15ef18: 46040180 */ add.s $f6,$f0,$f4 -/* f15ef1c: e4860010 */ swc1 $f6,0x10($a0) -/* f15ef20: 8eae0000 */ lw $t6,0x0($s5) -/* f15ef24: c4860018 */ lwc1 $f6,0x18($a0) -/* f15ef28: 01d17821 */ addu $t7,$t6,$s1 -/* f15ef2c: c5ea0004 */ lwc1 $f10,0x4($t7) -/* f15ef30: 460a4100 */ add.s $f4,$f8,$f10 -/* f15ef34: e4840014 */ swc1 $f4,0x14($a0) -/* f15ef38: 8eb80000 */ lw $t8,0x0($s5) -/* f15ef3c: c484001c */ lwc1 $f4,0x1c($a0) -/* f15ef40: 0311c821 */ addu $t9,$t8,$s1 -/* f15ef44: c7280008 */ lwc1 $f8,0x8($t9) -/* f15ef48: 46083280 */ add.s $f10,$f6,$f8 -/* f15ef4c: e48a0018 */ swc1 $f10,0x18($a0) -/* f15ef50: 8eae0000 */ lw $t6,0x0($s5) -/* f15ef54: 01d17821 */ addu $t7,$t6,$s1 -/* f15ef58: c5e6000c */ lwc1 $f6,0xc($t7) -/* f15ef5c: 46062200 */ add.s $f8,$f4,$f6 -/* f15ef60: e488001c */ swc1 $f8,0x1c($a0) -.L0f15ef64: -/* f15ef64: 80640008 */ lb $a0,0x8($v1) -/* f15ef68: 24420001 */ addiu $v0,$v0,0x1 -/* f15ef6c: 24630008 */ addiu $v1,$v1,0x8 -/* f15ef70: 1644ff74 */ bne $s2,$a0,.L0f15ed44 -/* f15ef74: 00000000 */ nop -.L0f15ef78: -/* f15ef78: 8fb00008 */ lw $s0,0x8($sp) -/* f15ef7c: 8fb1000c */ lw $s1,0xc($sp) -/* f15ef80: 8fb20010 */ lw $s2,0x10($sp) -/* f15ef84: 8fb30014 */ lw $s3,0x14($sp) -/* f15ef88: 8fb40018 */ lw $s4,0x18($sp) -/* f15ef8c: 8fb5001c */ lw $s5,0x1c($sp) -/* f15ef90: 27bd0020 */ addiu $sp,$sp,0x20 -/* f15ef94: 03e00008 */ jr $ra -/* f15ef98: 00e01025 */ or $v0,$a3,$zero -); - -void room0f15ef9c(s32 roomnum) +s32 bgPopulateVtxBatchType(s32 roomnum, struct vtxbatch *batches, Gfx *gdl, s32 batchindex, struct gfxvtx *vertices, s32 type) { s32 i; - s32 s3 = 0; - s32 s2; - Gfx *gdl; - void *allocation; + s32 j; + s32 numvertices; + struct gfxvtx *batchvertices; - if (g_Rooms[roomnum].unk44 == NULL) { - gdl = room0f15dab4(roomnum, NULL, 1); + for (i = 0; gdl[i].dma.cmd != G_ENDDL; i++) { + if (gdl[i].dma.cmd == G_VTX) { + batches[batchindex].gdl = gdl; + batches[batchindex].gbicmdindex = i; + batches[batchindex].type = type; + + for (j = 0; j < 3; j++) { + batches[batchindex].bbmin.f[j] = 32767.0f; + batches[batchindex].bbmax.f[j] = -32768.0f; + } + + numvertices = (((u32)gdl[i].bytes[1] >> 4) & 0xf) + 1; + batchvertices = (struct gfxvtx *)((u32)vertices + (gdl[i].words.w1 & 0xffffff)); + + for (j = 0; j < numvertices; j++) { + f32 x = batchvertices[j].x; + f32 y = batchvertices[j].y; + f32 z = batchvertices[j].z; + + if (x < batches[batchindex].bbmin.x) { + batches[batchindex].bbmin.x = x; + } + + if (y < batches[batchindex].bbmin.y) { + batches[batchindex].bbmin.y = y; + } + + if (z < batches[batchindex].bbmin.z) { + batches[batchindex].bbmin.z = z; + } + + if (x > batches[batchindex].bbmax.x) { + batches[batchindex].bbmax.x = x; + } + + if (y > batches[batchindex].bbmax.y) { + batches[batchindex].bbmax.y = y; + } + + if (z > batches[batchindex].bbmax.z) { + batches[batchindex].bbmax.z = z; + } + } + + if (batches[batchindex].bbmin.x == batches[batchindex].bbmax.x) { + batches[batchindex].bbmax.x++; + } + + if (batches[batchindex].bbmin.y == batches[batchindex].bbmax.y) { + batches[batchindex].bbmax.y++; + } + + if (batches[batchindex].bbmin.z == batches[batchindex].bbmax.z) { + batches[batchindex].bbmax.z++; + } + + batches[batchindex].bbmin.x += g_BgRooms[roomnum].pos.x; + batches[batchindex].bbmin.y += g_BgRooms[roomnum].pos.y; + batches[batchindex].bbmin.z += g_BgRooms[roomnum].pos.z; + + batches[batchindex].bbmax.x += g_BgRooms[roomnum].pos.x; + batches[batchindex].bbmax.y += g_BgRooms[roomnum].pos.y; + batches[batchindex].bbmax.z += g_BgRooms[roomnum].pos.z; + + batchindex++; + } + } + + return batchindex; +} + +void bgFindRoomVtxBatches(s32 roomnum) +{ + s32 i; + s32 batchindex = 0; + s32 xlucount; + Gfx *gdl; + struct vtxbatch *batches; + + if (g_Rooms[roomnum].vtxbatches == NULL) { + gdl = room0f15dab4(roomnum, NULL, VTXBATCHTYPE_OPA); if (gdl != NULL) { while (gdl) { for (i = 0; gdl[i].dma.cmd != G_ENDDL; i++) { // if gDPSetVerticeArray - if (gdl[i].dma.cmd == 0x04) { - s3++; + if (gdl[i].dma.cmd == G_VTX) { + batchindex++; } } - gdl = room0f15dab4(roomnum, gdl, 1); + gdl = room0f15dab4(roomnum, gdl, VTXBATCHTYPE_OPA); } - s2 = 0; + xlucount = 0; - gdl = room0f15dab4(roomnum, NULL, 2); + gdl = room0f15dab4(roomnum, NULL, VTXBATCHTYPE_XLU); while (gdl) { for (i = 0; gdl[i].dma.cmd != G_ENDDL; i++) { // if gDPSetVerticeArray - if (gdl[i].dma.cmd == 0x04) { - s2++; + if (gdl[i].dma.cmd == G_VTX) { + xlucount++; } } - gdl = room0f15dab4(roomnum, gdl, 2); + gdl = room0f15dab4(roomnum, gdl, VTXBATCHTYPE_XLU); } - s3 += s2; + batchindex += xlucount; - allocation = memaAlloc((s3 * 0x20 + 0xf) & ~0xf); + batches = memaAlloc((batchindex * sizeof(struct vtxbatch) + 0xf) & ~0xf); - if (allocation != NULL) { - gdl = room0f15dab4(roomnum, NULL, 1); - s3 = 0; + if (batches != NULL) { + gdl = room0f15dab4(roomnum, NULL, VTXBATCHTYPE_OPA); + batchindex = 0; - g_Rooms[roomnum].unk44 = allocation; + g_Rooms[roomnum].vtxbatches = batches; while (gdl) { - struct gfxvtx *vtx = room0f15dbb4(roomnum, gdl); - s3 = func0f15ecd8(roomnum, allocation, gdl, s3, vtx, 1); - gdl = room0f15dab4(roomnum, gdl, 1); + struct gfxvtx *vertices = room0f15dbb4(roomnum, gdl); + batchindex = bgPopulateVtxBatchType(roomnum, batches, gdl, batchindex, vertices, VTXBATCHTYPE_OPA); + gdl = room0f15dab4(roomnum, gdl, VTXBATCHTYPE_OPA); } - if (s2) { - gdl = room0f15dab4(roomnum, NULL, 2); + if (xlucount) { + gdl = room0f15dab4(roomnum, NULL, VTXBATCHTYPE_XLU); while (gdl) { - struct gfxvtx *vtx = room0f15dbb4(roomnum, gdl); - s3 = func0f15ecd8(roomnum, allocation, gdl, s3, vtx, 2); - gdl = room0f15dab4(roomnum, gdl, 2); + struct gfxvtx *vertices = room0f15dbb4(roomnum, gdl); + batchindex = bgPopulateVtxBatchType(roomnum, batches, gdl, batchindex, vertices, VTXBATCHTYPE_XLU); + gdl = room0f15dab4(roomnum, gdl, VTXBATCHTYPE_XLU); } } - g_Rooms[roomnum].unk40 = (s16)s3; + g_Rooms[roomnum].numvtxbatches = (s16)batchindex; } } } @@ -12482,7 +12363,7 @@ glabel var7f1b75dc /* f1612e0: 01a01025 */ or $v0,$t5,$zero ); -s32 bg0f1612e4(struct coord *arg0, struct coord *arg1, struct coord *arg2, struct coord *arg3, struct coord *arg4, struct coord *arg5) +s32 bg0f1612e4(struct coord *bbmin, struct coord *bbmax, struct coord *arg2, struct coord *arg3, struct coord *arg4, struct coord *arg5) { s32 i; u8 bail = true; @@ -12492,13 +12373,13 @@ s32 bg0f1612e4(struct coord *arg0, struct coord *arg1, struct coord *arg2, struc f32 sp2c[3]; for (i = 0; i < 3; i++) { - if (arg2->f[i] < arg0->f[i]) { + if (arg2->f[i] < bbmin->f[i]) { sp48[i] = 1; - sp38[i] = arg0->f[i]; + sp38[i] = bbmin->f[i]; bail = false; - } else if (arg1->f[i] < arg2->f[i]) { + } else if (bbmax->f[i] < arg2->f[i]) { sp48[i] = 0; - sp38[i] = arg1->f[i]; + sp38[i] = bbmax->f[i]; bail = false; } else { sp48[i] = 2; @@ -12534,7 +12415,7 @@ s32 bg0f1612e4(struct coord *arg0, struct coord *arg1, struct coord *arg2, struc if (bestindex != i) { arg5->f[i] = arg2->f[i] + sp2c[bestindex] * arg3->f[i]; - if (arg5->f[i] < arg0->f[i] || arg5->f[i] > arg1->f[i]) { + if (arg5->f[i] < bbmin->f[i] || arg5->f[i] > bbmax->f[i]) { return 0; } } else { @@ -12551,7 +12432,7 @@ bool func0f161520(struct coord *arg0, struct coord *arg1, s32 roomnum, struct hi s32 count; f32 f20; s32 a0; - s32 spd4; + s32 numbatches; s32 j; f32 f0; f32 spc8; @@ -12560,9 +12441,9 @@ bool func0f161520(struct coord *arg0, struct coord *arg1, s32 roomnum, struct hi struct coord spac; struct coord spa0; struct coord sp94; - struct room44 *sp90; + struct vtxbatch *batch; struct hitthing sp60; - s32 tmp00; + s32 tmpindex; count = 0; @@ -12586,16 +12467,16 @@ bool func0f161520(struct coord *arg0, struct coord *arg1, s32 roomnum, struct hi return false; } - sp90 = g_Rooms[roomnum].unk44; + batch = g_Rooms[roomnum].vtxbatches; - if (sp90 == NULL) { + if (batch == NULL) { return false; } - spd4 = g_Rooms[roomnum].unk40; + numbatches = g_Rooms[roomnum].numvtxbatches; - for (i = 0; i < spd4; sp90++, i++) { - j = bg0f1612e4(&sp90->unk08, &sp90->unk14, &spb8, &spa0, &sp94, &hitthing->unk00); + for (i = 0; i < numbatches; batch++, i++) { + j = bg0f1612e4(&batch->bbmin, &batch->bbmax, &spb8, &spa0, &sp94, &hitthing->unk00); if (j == 0) { continue; @@ -12621,23 +12502,23 @@ bool func0f161520(struct coord *arg0, struct coord *arg1, s32 roomnum, struct hi f2 = var800a6538[j].unk04; if (f2 > f20) { - tmp00 = var800a6538[j].unk00; - var800a6538[j].unk00 = a0; - a0 = tmp00; + tmpindex = var800a6538[j].vtxbatchindex; + var800a6538[j].vtxbatchindex = a0; + a0 = tmpindex; var800a6538[j].unk04 = f20; f20 = f2; } } - var800a6538[j].unk00 = a0; + var800a6538[j].vtxbatchindex = a0; var800a6538[j].unk04 = f20; count++; } else { count = 0; for (j = 0; j < ARRAYCOUNT(var800a6538); j++) { - if (func0f160a38(&spb8, &spac, &spa0, &g_Rooms[roomnum].unk44[var800a6538[j].unk00], roomnum, hitthing)) { + if (func0f160a38(&spb8, &spac, &spa0, &g_Rooms[roomnum].vtxbatches[var800a6538[j].vtxbatchindex], roomnum, hitthing)) { f0 = spb8.x - hitthing->unk00.x; f2 = f0 * f0; @@ -12648,11 +12529,11 @@ bool func0f161520(struct coord *arg0, struct coord *arg1, s32 roomnum, struct hi f2 += f0 * f0; if (count == 0) { - var800a6538[0].unk00 = var800a6538[j].unk00; + var800a6538[0].vtxbatchindex = var800a6538[j].vtxbatchindex; var800a6538[0].unk04 = f2; count = 1; } else if (f2 < var800a6538[0].unk04) { - var800a6538[0].unk00 = var800a6538[j].unk00; + var800a6538[0].vtxbatchindex = var800a6538[j].vtxbatchindex; var800a6538[0].unk04 = f2; count = 1; } @@ -12663,16 +12544,16 @@ bool func0f161520(struct coord *arg0, struct coord *arg1, s32 roomnum, struct hi if (f20 < var800a6538[0].unk04) { var800a6538[1].unk04 = var800a6538[0].unk04; var800a6538[0].unk04 = f20; - var800a6538[1].unk00 = var800a6538[0].unk00; - var800a6538[0].unk00 = i; + var800a6538[1].vtxbatchindex = var800a6538[0].vtxbatchindex; + var800a6538[0].vtxbatchindex = i; } else { - var800a6538[1].unk00 = i; + var800a6538[1].vtxbatchindex = i; var800a6538[1].unk04 = f20; } count = 2; } else { - var800a6538[0].unk00 = i; + var800a6538[0].vtxbatchindex = i; var800a6538[0].unk04 = f20; count = 1; } @@ -12683,10 +12564,10 @@ bool func0f161520(struct coord *arg0, struct coord *arg1, s32 roomnum, struct hi return false; } - sp90 = g_Rooms[roomnum].unk44; + batch = g_Rooms[roomnum].vtxbatches; for (i = 0; i < count; i++) { - if (func0f160a38(&spb8, &spac, &spa0, &sp90[var800a6538[i].unk00], roomnum, hitthing)) { + if (func0f160a38(&spb8, &spac, &spa0, &batch[var800a6538[i].vtxbatchindex], roomnum, hitthing)) { i++; if (i < count) { @@ -12701,7 +12582,7 @@ bool func0f161520(struct coord *arg0, struct coord *arg1, s32 roomnum, struct hi for (; i < count; i++) { if (var800a6538[i].unk04 <= spc8) { - if (func0f160a38(&spb8, &spac, &spa0, &sp90[var800a6538[i].unk00], roomnum, &sp60)) { + if (func0f160a38(&spb8, &spac, &spa0, &batch[var800a6538[i].vtxbatchindex], roomnum, &sp60)) { f0 = spb8.f[0] - sp60.unk00.f[0]; f20 = f0 * f0; @@ -14419,7 +14300,7 @@ Gfx *func0f164150(Gfx *gdl) } if (bestroomnum != 0) { - roomLoad(bestroomnum); + bgLoadRoom(bestroomnum); var8007fc28 = 64; } } diff --git a/src/game/dlights.c b/src/game/dlights.c index 639d75f8f..f91c831be 100644 --- a/src/game/dlights.c +++ b/src/game/dlights.c @@ -314,7 +314,7 @@ void roomSetDefaults(struct room *room) room->unk68 = 0; } -Gfx *func0f001138(Gfx *gdl, s16 roomnum) +Gfx *lightsSetForRoom(Gfx *gdl, s16 roomnum) { Lights1 *lights = gfxAllocate(sizeof(Lights1)); @@ -346,7 +346,7 @@ Gfx *func0f001138(Gfx *gdl, s16 roomnum) return gdl; } -Gfx *func0f001300(Gfx *gdl) +Gfx *lightsSetDefault(Gfx *gdl) { gSPSetLights1(gdl++, var80061460); diff --git a/src/game/explosions.c b/src/game/explosions.c index e50d3759b..eee34fdaf 100644 --- a/src/game/explosions.c +++ b/src/game/explosions.c @@ -1300,7 +1300,7 @@ Gfx *explosionRender(struct prop *prop, Gfx *gdl, bool xlupass) gSPClearGeometryMode(gdl++, G_CULL_BOTH | G_FOG); gSPMatrix(gdl++, osVirtualToPhysical(camGetOrthogonalMtxL()), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); - gdl = room0f166d7c(gdl, roomnum); + gdl = roomPushMtx(gdl, roomnum); gSPDisplayList(gdl++, g_TexGdl2); diff --git a/src/game/room.c b/src/game/room.c index f75433fb2..63166ab33 100644 --- a/src/game/room.c +++ b/src/game/room.c @@ -118,7 +118,7 @@ s32 room0f166c20(s32 roomnum) return index; } -Gfx *room0f166d7c(Gfx *gdl, s32 roomnum) +Gfx *roomPushMtx(Gfx *gdl, s32 roomnum) { s32 index = room0f166c20(roomnum); diff --git a/src/game/shards.c b/src/game/shards.c index 8a9955665..6b3f0c270 100644 --- a/src/game/shards.c +++ b/src/game/shards.c @@ -304,7 +304,7 @@ Gfx *shardsRenderWood(Gfx *gdl) gDPSetColorArray(gdl++, osVirtualToPhysical(colours), 3); } else { if (g_Shards[i].room != prevroom) { - gdl = func0f001138(gdl, g_Shards[i].room); + gdl = lightsSetForRoom(gdl, g_Shards[i].room); prevroom = g_Shards[i].room; } @@ -319,7 +319,7 @@ Gfx *shardsRenderWood(Gfx *gdl) } if (prevroom == 0) { - gdl = func0f001300(gdl); + gdl = lightsSetDefault(gdl); } gSPClearGeometryMode(gdl++, G_LIGHTING | G_TEXTURE_GEN); @@ -706,7 +706,7 @@ glabel shardsRenderWood /* f14c4cc: 85c50000 */ lh $a1,0x0($t6) /* f14c4d0: 51a50009 */ beql $t5,$a1,.NB0f14c4f8 /* f14c4d4: 3c080708 */ lui $t0,0x708 -/* f14c4d8: 0fc0044e */ jal func0f001138 +/* f14c4d8: 0fc0044e */ jal lightsSetForRoom /* f14c4dc: 02602025 */ or $a0,$s3,$zero /* f14c4e0: 8e4f0000 */ lw $t7,0x0($s2) /* f14c4e4: 00409825 */ or $s3,$v0,$zero @@ -754,7 +754,7 @@ glabel shardsRenderWood /* f14c57c: 87af0126 */ lh $t7,0x126($sp) /* f14c580: 55e00005 */ bnezl $t7,.NB0f14c598 /* f14c584: 02601025 */ or $v0,$s3,$zero -/* f14c588: 0fc004c0 */ jal func0f001300 +/* f14c588: 0fc004c0 */ jal lightsSetDefault /* f14c58c: 02602025 */ or $a0,$s3,$zero /* f14c590: 00409825 */ or $s3,$v0,$zero /* f14c594: 02601025 */ or $v0,$s3,$zero @@ -898,7 +898,7 @@ Gfx *shardsRenderGlass(Gfx *gdl) gDPSetColorArray(gdl++, osVirtualToPhysical(colours), 3); } else { if (g_Shards[i].room != prevroom) { - gdl = func0f001138(gdl, g_Shards[i].room); + gdl = lightsSetForRoom(gdl, g_Shards[i].room); prevroom = g_Shards[i].room; } @@ -913,7 +913,7 @@ Gfx *shardsRenderGlass(Gfx *gdl) } if (prevroom == 0) { - gdl = func0f001300(gdl); + gdl = lightsSetDefault(gdl); } gSPClearGeometryMode(gdl++, G_LIGHTING | G_TEXTURE_GEN); @@ -1346,7 +1346,7 @@ glabel shardsRenderGlass /* f14cc54: 85250000 */ lh $a1,0x0($t1) /* f14cc58: 51450009 */ beql $t2,$a1,.NB0f14cc80 /* f14cc5c: 8fb00138 */ lw $s0,0x138($sp) -/* f14cc60: 0fc0044e */ jal func0f001138 +/* f14cc60: 0fc0044e */ jal lightsSetForRoom /* f14cc64: 8fa40138 */ lw $a0,0x138($sp) /* f14cc68: 8e4b0000 */ lw $t3,0x0($s2) /* f14cc6c: afa20138 */ sw $v0,0x138($sp) @@ -1397,7 +1397,7 @@ glabel shardsRenderGlass /* f14cd10: 87a80136 */ lh $t0,0x136($sp) /* f14cd14: 55000005 */ bnezl $t0,.NB0f14cd2c /* f14cd18: 8fb90138 */ lw $t9,0x138($sp) -/* f14cd1c: 0fc004c0 */ jal func0f001300 +/* f14cd1c: 0fc004c0 */ jal lightsSetDefault /* f14cd20: 8fa40138 */ lw $a0,0x138($sp) /* f14cd24: afa20138 */ sw $v0,0x138($sp) /* f14cd28: 8fb90138 */ lw $t9,0x138($sp) diff --git a/src/game/smoke.c b/src/game/smoke.c index eb90355e0..3c273b736 100644 --- a/src/game/smoke.c +++ b/src/game/smoke.c @@ -655,7 +655,7 @@ Gfx *smokeRender(struct prop *prop, Gfx *gdl, bool xlupass) gSPClearGeometryMode(gdl++, G_CULL_BOTH | G_FOG); gSPMatrix(gdl++, osVirtualToPhysical(camGetOrthogonalMtxL()), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); - gdl = room0f166d7c(gdl, roomnum); + gdl = roomPushMtx(gdl, roomnum); if (near) { gSPMatrix(gdl++, osVirtualToPhysical(&var800a3448), G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW); diff --git a/src/game/wallhit.c b/src/game/wallhit.c index eb13ab4b6..e061f786a 100644 --- a/src/game/wallhit.c +++ b/src/game/wallhit.c @@ -1839,7 +1839,7 @@ Gfx *wallhitRenderOpaBgHits(s32 roomnum, Gfx *gdl) prevtexturenum = -1; prev6b = -1; - gdl = room0f166d7c(gdl, roomnum); + gdl = roomPushMtx(gdl, roomnum); wallhit = g_Rooms[roomnum].opawallhits; @@ -1901,7 +1901,7 @@ Gfx *wallhitRenderXluBgHits(s32 roomnum, Gfx *gdl) prevtexturenum = -1; prev6b = -1; - gdl = room0f166d7c(gdl, roomnum); + gdl = roomPushMtx(gdl, roomnum); wallhit = g_Rooms[roomnum].xluwallhits; diff --git a/src/include/constants.h b/src/include/constants.h index 247a6ae7a..73e30e2e2 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -3436,7 +3436,7 @@ #define RACE_ROBOT 4 #define RENDERPASS_OPA_PREBG 0 -#define RENDERPASS_XLU 1 +#define RENDERPASS_XLU 1 #define RENDERPASS_OPA_POSTBG 2 #define ROOMFLAG_DISABLEDBYSCRIPT 0x0001 diff --git a/src/include/game/bg.h b/src/include/game/bg.h index 3f626aa65..cceff91c5 100644 --- a/src/include/game/bg.h +++ b/src/include/game/bg.h @@ -13,7 +13,7 @@ u32 func0f158400(void); u32 func0f158884(void); u32 func0f158d9c(void); Gfx *func0f1598b4(Gfx *gdl, Gfx *gdl2, struct gfxvtx *vertices, s16 arg3[3]); -Gfx *bg0f159f1c(Gfx *gdl, s32 roomnum, struct roomgfxdata18 *arg2, bool recurse, s16 arg4[3]); +Gfx *bgRenderRoomXrayPass(Gfx *gdl, s32 roomnum, struct roomgfxdata18 *arg2, bool recurse, s16 arg4[3]); Gfx *bgRenderRoomInXray(Gfx *gdl, s32 roomnum); Gfx *bgRenderSceneInXray(Gfx *gdl); Gfx *bgRenderScene(Gfx *gdl); @@ -52,24 +52,24 @@ bool roomIsOnPlayerStandby(s32 room, u32 aibotindex); s32 portalFindNumByVertices(struct portalvertices *pvertices); u32 bgInflate(u8 *src, u8 *dst, u32 len); Gfx *func0f15da00(struct roomgfxdata18 *arg0, Gfx *arg1, Gfx *arg2); -Gfx *room0f15dab4(s32 roomnum, Gfx *arg1, u32 arg2); +Gfx *room0f15dab4(s32 roomnum, Gfx *gdl, u32 types); struct gfxvtx *room0f15dbb4(s32 roomnum, Gfx *gdl); -void roomLoad(s32 roomnum); -void roomUnload(s32 room); +void bgLoadRoom(s32 roomnum); +void bgUnloadRoom(s32 room); void bgUnloadAllRooms(void); void bgGarbageCollectRooms(s32 bytesneeded, bool desparate); void bgTickRooms(void); -Gfx *room0f15e85c(Gfx *gdl, s32 roomnum, struct roomgfxdata18 *arg2, bool arg3); +Gfx *bgRenderRoomPass(Gfx *gdl, s32 roomnum, struct roomgfxdata18 *arg2, bool arg3); Gfx *bgRenderRoomOpaque(Gfx *gdl, s32 roomnum); Gfx *bgRenderRoomXlu(Gfx *gdl, s32 roomnum); -s32 func0f15ecd8(s32 roomnum, void *allocation, Gfx *gdl, s32 arg3, struct gfxvtx *vtx, s32 arg5); -void room0f15ef9c(s32 roomnum); +s32 bgPopulateVtxBatchType(s32 roomnum, struct vtxbatch *batches, Gfx *gdl, s32 batchindex, struct gfxvtx *vertices, s32 arg5); +void bgFindRoomVtxBatches(s32 roomnum); bool func0f15f20c(struct coord *arg0, struct coord *arg1, s32 *arg2, s32 *arg3); bool bg0f15f2b0(struct coord *arg0, struct coord *arg1, struct coord *arg2, struct coord *arg3); bool func0f15f560(struct coord *arg0, struct coord *arg1, struct coord *arg2, Gfx *arg3, void *arg4, struct gfxvtx *vertices, struct hitthing *hitthing); bool func0f15ffdc(struct model *model, struct coord *arg1, struct coord *arg2, struct coord *arg3, Gfx *arg4, Gfx *arg5, struct gfxvtx *vertices, f32 *arg7, void *arg8); -bool func0f160a38(struct coord *arg0, struct coord *arg1, struct coord *arg2, struct room44 *arg3, s32 roomnum, struct hitthing *hitthing); -s32 bg0f1612e4(struct coord *arg0, struct coord *arg1, struct coord *arg2, struct coord *arg3, struct coord *arg4, struct coord *arg5); +bool func0f160a38(struct coord *arg0, struct coord *arg1, struct coord *arg2, struct vtxbatch *batches, s32 roomnum, struct hitthing *hitthing); +s32 bg0f1612e4(struct coord *bbmin, struct coord *bbmax, struct coord *arg2, struct coord *arg3, struct coord *arg4, struct coord *arg5); bool func0f161520(struct coord *arg0, struct coord *arg1, s32 roomnum, struct hitthing *hitthing); bool roomIsLoaded(s32 room); bool roomContainsCoord(struct coord *pos, s16 roomnum); diff --git a/src/include/game/dlights.h b/src/include/game/dlights.h index 4bc9dae86..9e06a2500 100644 --- a/src/include/game/dlights.h +++ b/src/include/game/dlights.h @@ -19,8 +19,8 @@ bool lightIsVulnerable(s32 roomnum, s32 lightnum); bool lightIsOn(s32 roomnum, s32 lightnum); void roomSetUnk52(s32 roomnum, s32 value); void roomSetDefaults(struct room *room); -Gfx *func0f001138(Gfx *gdl, s16 roomnum); -Gfx *func0f001300(Gfx *gdl); +Gfx *lightsSetForRoom(Gfx *gdl, s16 roomnum); +Gfx *lightsSetDefault(Gfx *gdl); void roomInitLights(s32 roomnum); bool lightsHandleHit(struct coord *gunpos, struct coord *hitpos, s32 roomnum); void roomSetLightsFaulty(s32 roomnum, s32 chance); diff --git a/src/include/game/room.h b/src/include/game/room.h index 5c2c506fa..ae2c9c3dc 100644 --- a/src/include/game/room.h +++ b/src/include/game/room.h @@ -15,7 +15,7 @@ void room0f16696c(s32 index); s32 room0f1669fc(void); void room0f166a6c(Mtxf *matrix, s32 roomnum); s32 room0f166c20(s32 roomnum); -Gfx *room0f166d7c(Gfx *gdl, s32 roomnum); +Gfx *roomPushMtx(Gfx *gdl, s32 roomnum); struct coord *roomGetPos(s32 room); void room0f166df0(s32 room, struct coord *globaldrawworldoffset); diff --git a/src/include/types.h b/src/include/types.h index 595a8bb5b..c289ca888 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -3555,20 +3555,20 @@ struct roomgfxdata18 { struct roomgfxdata { /*0x00*/ struct gfxvtx *vertices; /*0x04*/ u32 *colours; - /*0x08*/ struct roomgfxdata18 *unk08; - /*0x0c*/ struct roomgfxdata18 *unk0c; - /*0x10*/ s16 unk10; - /*0x10*/ s16 unk12; + /*0x08*/ struct roomgfxdata18 *unk08; // opa + /*0x0c*/ struct roomgfxdata18 *unk0c; // xlu + /*0x10*/ s32 unk10; /*0x14*/ s16 numvertices; /*0x16*/ s16 numcolours; /*0x18*/ struct roomgfxdata18 unk18[1]; }; -struct room44 { - /*0x00*/ u32 unk00; - /*0x04*/ u32 unk04; - /*0x08*/ struct coord unk08; - /*0x14*/ struct coord unk14; +struct vtxbatch { + /*0x00*/ s16 gbicmdindex; + /*0x02*/ s16 type; + /*0x04*/ Gfx *gdl; + /*0x08*/ struct coord bbmin; + /*0x14*/ struct coord bbmax; }; struct room { @@ -3589,8 +3589,8 @@ struct room { /*0x24*/ f32 bbmax[3]; /*0x30*/ struct coord centre; /*0x3c*/ f32 radius; // from volume centre to the corner in 3D - /*0x40*/ s32 unk40; - /*0x44*/ struct room44 *unk44; + /*0x40*/ s32 numvtxbatches; + /*0x44*/ struct vtxbatch *vtxbatches; /*0x48*/ u8 unk48; /*0x49*/ u8 unk49; /*0x4a*/ u8 unk4a; @@ -6346,7 +6346,7 @@ struct portalthing2 { }; struct var800a6538 { - s32 unk00; + s32 vtxbatchindex; f32 unk04; };