From df896be1827fc817716b78263eb98577871cdd5c Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 26 Feb 2021 23:58:01 +1000 Subject: [PATCH] Decompile shardsRenderWood --- src/game/chr/chr.c | 4 +- src/game/explosions/explosions.c | 4 +- src/game/gfxmemory.c | 2 +- src/game/propobj.c | 4 +- src/game/shards/render.c | 625 +++++++------------------------ src/include/constants.h | 7 + src/include/game/gfxmemory.h | 2 +- src/include/lib/lib_16110.h | 2 +- src/include/types.h | 18 +- 9 files changed, 142 insertions(+), 526 deletions(-) diff --git a/src/game/chr/chr.c b/src/game/chr/chr.c index 9c9fc44b1..ec091578b 100644 --- a/src/game/chr/chr.c +++ b/src/game/chr/chr.c @@ -6591,9 +6591,7 @@ Gfx *chrRender(struct prop *prop, Gfx *gdl, bool withalpha) if (g_Vars.currentplayer->visionmode == VISIONMODE_XRAY) { f32 fadedist; - f32 chrdist = sqrtf((prop->pos.z - g_Vars.currentplayer->eraserpos.z) * (prop->pos.z - g_Vars.currentplayer->eraserpos.z) - + ((prop->pos.x - g_Vars.currentplayer->eraserpos.x) * (prop->pos.x - g_Vars.currentplayer->eraserpos.x) - + (prop->pos.y - g_Vars.currentplayer->eraserpos.y) * (prop->pos.y - g_Vars.currentplayer->eraserpos.y))); + f32 chrdist = sqrtf(ERASERSQDIST(prop->pos.f)); if (chrdist > g_Vars.currentplayer->eraserpropdist) { return gdl; diff --git a/src/game/explosions/explosions.c b/src/game/explosions/explosions.c index 440be6886..bddfeb226 100644 --- a/src/game/explosions/explosions.c +++ b/src/game/explosions/explosions.c @@ -2938,9 +2938,7 @@ Gfx *explosionRender(struct prop *prop, Gfx *gdl, bool withalpha) u32 alpha = 0x80; u32 red; u32 green; - f32 expdist = sqrtf((prop->pos.z - g_Vars.currentplayer->eraserpos.z) * (prop->pos.z - g_Vars.currentplayer->eraserpos.z) - + ((prop->pos.x - g_Vars.currentplayer->eraserpos.x) * (prop->pos.x - g_Vars.currentplayer->eraserpos.x) - + (prop->pos.y - g_Vars.currentplayer->eraserpos.y) * (prop->pos.y - g_Vars.currentplayer->eraserpos.y))); + f32 expdist = sqrtf(ERASERSQDIST(prop->pos.f)); if (g_Vars.currentplayer->eraserpropdist < expdist) { return gdl; diff --git a/src/game/gfxmemory.c b/src/game/gfxmemory.c index 476a8eedb..11534e124 100644 --- a/src/game/gfxmemory.c +++ b/src/game/gfxmemory.c @@ -146,7 +146,7 @@ void *gfxAllocate4Words(s32 count) return ptr; } -u32 *gfxAllocateColours(s32 count) +void *gfxAllocateColours(s32 count) { void *ptr = g_GfxMemPos; count = ALIGN16(count * sizeof(u32)); diff --git a/src/game/propobj.c b/src/game/propobj.c index 72733a9a4..d100051e1 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -31096,9 +31096,7 @@ glabel var7f1aa82c // } // } else if (g_Vars.currentplayer->visionmode == VISIONMODE_XRAY) { // fadedist; -// objdist = sqrtf((prop->pos.z - g_Vars.currentplayer->eraserpos.z) * (prop->pos.z - g_Vars.currentplayer->eraserpos.z) -// + ((prop->pos.x - g_Vars.currentplayer->eraserpos.x) * (prop->pos.x - g_Vars.currentplayer->eraserpos.x) -// + (prop->pos.y - g_Vars.currentplayer->eraserpos.y) * (prop->pos.y - g_Vars.currentplayer->eraserpos.y))); +// objdist = sqrtf(ERASERSQDIST(prop->pos.f)); // // if (objdist > g_Vars.currentplayer->eraserpropdist) { // return gdl; diff --git a/src/game/shards/render.c b/src/game/shards/render.c index 440afe353..b19f29fd1 100644 --- a/src/game/shards/render.c +++ b/src/game/shards/render.c @@ -4,6 +4,7 @@ #include "game/game_092610.h" #include "game/atan2f.h" #include "game/game_0b3350.h" +#include "game/gfxmemory.h" #include "game/file.h" #include "gvars/gvars.h" #include "lib/rng.h" @@ -12,513 +13,137 @@ #include "data.h" #include "types.h" -const u32 var7f1b7390[] = {0xc61c4000}; -const u32 var7f1b7394[] = {0x461c4000}; -const u32 var7f1b7398[] = {0xc61c4000}; -const u32 var7f1b739c[] = {0x461c4000}; +Gfx *shardsRenderWood(Gfx *gdl) +{ + if (g_ShardsActive) { + s16 prevroom = 0; + s32 i; + Mtxf shardmtx; + s32 j; -Gfx *shardsRenderWood(Gfx *gdl); + if (g_Vars.currentplayer->visionmode); -GLOBAL_ASM( -glabel shardsRenderWood -/* f151780: 27bdfed0 */ addiu $sp,$sp,-304 -/* f151784: 3c0e8008 */ lui $t6,%hi(g_ShardsActive) -/* f151788: 8dcefa84 */ lw $t6,%lo(g_ShardsActive)($t6) -/* f15178c: afb30054 */ sw $s3,0x54($sp) -/* f151790: 00809825 */ or $s3,$a0,$zero -/* f151794: afbf006c */ sw $ra,0x6c($sp) -/* f151798: afbe0068 */ sw $s8,0x68($sp) -/* f15179c: afb70064 */ sw $s7,0x64($sp) -/* f1517a0: afb60060 */ sw $s6,0x60($sp) -/* f1517a4: afb5005c */ sw $s5,0x5c($sp) -/* f1517a8: afb40058 */ sw $s4,0x58($sp) -/* f1517ac: afb20050 */ sw $s2,0x50($sp) -/* f1517b0: afb1004c */ sw $s1,0x4c($sp) -/* f1517b4: afb00048 */ sw $s0,0x48($sp) -/* f1517b8: f7be0040 */ sdc1 $f30,0x40($sp) -/* f1517bc: f7bc0038 */ sdc1 $f28,0x38($sp) -/* f1517c0: f7ba0030 */ sdc1 $f26,0x30($sp) -/* f1517c4: f7b80028 */ sdc1 $f24,0x28($sp) -/* f1517c8: f7b60020 */ sdc1 $f22,0x20($sp) -/* f1517cc: 11c001ad */ beqz $t6,.L0f151e84 -/* f1517d0: f7b40018 */ sdc1 $f20,0x18($sp) -/* f1517d4: a7a0012e */ sh $zero,0x12e($sp) -/* f1517d8: 24930008 */ addiu $s3,$a0,0x8 -/* f1517dc: 3c0fb600 */ lui $t7,0xb600 -/* f1517e0: 24183000 */ addiu $t8,$zero,0x3000 -/* f1517e4: ac980004 */ sw $t8,0x4($a0) -/* f1517e8: ac8f0000 */ sw $t7,0x0($a0) -/* f1517ec: 02601825 */ or $v1,$s3,$zero -/* f1517f0: 26730008 */ addiu $s3,$s3,0x8 -/* f1517f4: 3c19b700 */ lui $t9,0xb700 -/* f1517f8: ac790000 */ sw $t9,0x0($v1) -/* f1517fc: 24080204 */ addiu $t0,$zero,0x204 -/* f151800: 02602025 */ or $a0,$s3,$zero -/* f151804: ac680004 */ sw $t0,0x4($v1) -/* f151808: 26730008 */ addiu $s3,$s3,0x8 -/* f15180c: 3c09fcff */ lui $t1,0xfcff -/* f151810: 3c0afffe */ lui $t2,0xfffe -/* f151814: 354a793c */ ori $t2,$t2,0x793c -/* f151818: 3529ffff */ ori $t1,$t1,0xffff -/* f15181c: 02602825 */ or $a1,$s3,$zero -/* f151820: ac890000 */ sw $t1,0x0($a0) -/* f151824: ac8a0004 */ sw $t2,0x4($a0) -/* f151828: 26730008 */ addiu $s3,$s3,0x8 -/* f15182c: 3c0bba00 */ lui $t3,0xba00 -/* f151830: 356b0c02 */ ori $t3,$t3,0xc02 -/* f151834: 240c2000 */ addiu $t4,$zero,0x2000 -/* f151838: 02603025 */ or $a2,$s3,$zero -/* f15183c: acac0004 */ sw $t4,0x4($a1) -/* f151840: acab0000 */ sw $t3,0x0($a1) -/* f151844: 26730008 */ addiu $s3,$s3,0x8 -/* f151848: 3c0dba00 */ lui $t5,0xba00 -/* f15184c: 35ad1402 */ ori $t5,$t5,0x1402 -/* f151850: 3c0e0010 */ lui $t6,0x10 -/* f151854: 02601025 */ or $v0,$s3,$zero -/* f151858: acce0004 */ sw $t6,0x4($a2) -/* f15185c: accd0000 */ sw $t5,0x0($a2) -/* f151860: 3c0fba00 */ lui $t7,0xba00 -/* f151864: 35ef1001 */ ori $t7,$t7,0x1001 -/* f151868: 26730008 */ addiu $s3,$s3,0x8 -/* f15186c: 3c180001 */ lui $t8,0x1 -/* f151870: 3c190103 */ lui $t9,0x103 -/* f151874: 3c17800a */ lui $s7,%hi(g_Vars) -/* f151878: ac580004 */ sw $t8,0x4($v0) -/* f15187c: ac4f0000 */ sw $t7,0x0($v0) -/* f151880: 37390040 */ ori $t9,$t9,0x40 -/* f151884: 02608025 */ or $s0,$s3,$zero -/* f151888: 26f79fc0 */ addiu $s7,$s7,%lo(g_Vars) -/* f15188c: ae190000 */ sw $t9,0x0($s0) -/* f151890: 0fc2d402 */ jal currentPlayerGetUnk1758 -/* f151894: 26730008 */ addiu $s3,$s3,0x8 -/* f151898: 0c012d20 */ jal osVirtualToPhysical -/* f15189c: 00402025 */ or $a0,$v0,$zero -/* f1518a0: ae020004 */ sw $v0,0x4($s0) -/* f1518a4: 3c08800a */ lui $t0,%hi(g_MaxShards) -/* f1518a8: 8d0845c0 */ lw $t0,%lo(g_MaxShards)($t0) -/* f1518ac: 0000f025 */ or $s8,$zero,$zero -/* f1518b0: 0000a025 */ or $s4,$zero,$zero -/* f1518b4: 19000159 */ blez $t0,.L0f151e1c -/* f1518b8: 3c014316 */ lui $at,0x4316 -/* f1518bc: 4481f000 */ mtc1 $at,$f30 -/* f1518c0: 3c017f1b */ lui $at,%hi(var7f1b7390) -/* f1518c4: c43c7390 */ lwc1 $f28,%lo(var7f1b7390)($at) -/* f1518c8: 3c017f1b */ lui $at,%hi(var7f1b7394) -/* f1518cc: c43a7394 */ lwc1 $f26,%lo(var7f1b7394)($at) -/* f1518d0: 3c013f80 */ lui $at,0x3f80 -/* f1518d4: 3c158008 */ lui $s5,%hi(var8007fa80) -/* f1518d8: 3c12800a */ lui $s2,%hi(g_Shards) -/* f1518dc: 4481c000 */ mtc1 $at,$f24 -/* f1518e0: 265245c4 */ addiu $s2,$s2,%lo(g_Shards) -/* f1518e4: 26b5fa80 */ addiu $s5,$s5,%lo(var8007fa80) -/* f1518e8: c7b600bc */ lwc1 $f22,0xbc($sp) -/* f1518ec: 2416000c */ addiu $s6,$zero,0xc -/* f1518f0: 8e490000 */ lw $t1,0x0($s2) -.L0f1518f4: -/* f1518f4: 01341021 */ addu $v0,$t1,$s4 -/* f1518f8: 8c4a0004 */ lw $t2,0x4($v0) -/* f1518fc: 1940013f */ blez $t2,.L0f151dfc -/* f151900: 00000000 */ nop -/* f151904: 904b0068 */ lbu $t3,0x68($v0) -/* f151908: 24010002 */ addiu $at,$zero,0x2 -/* f15190c: 24100001 */ addiu $s0,$zero,0x1 -/* f151910: 1561013a */ bne $t3,$at,.L0f151dfc -/* f151914: 00000000 */ nop -/* f151918: 0fc59e66 */ jal gfxAllocateMatrix -/* f15191c: 4600c506 */ mov.s $f20,$f24 -/* f151920: 8ee30284 */ lw $v1,0x284($s7) -/* f151924: 24010001 */ addiu $at,$zero,0x1 -/* f151928: 00408825 */ or $s1,$v0,$zero -/* f15192c: 946c0010 */ lhu $t4,0x10($v1) -/* f151930: 15810025 */ bne $t4,$at,.L0f1519c8 -/* f151934: 00000000 */ nop -/* f151938: 8e4d0000 */ lw $t5,0x0($s2) -/* f15193c: c46a0018 */ lwc1 $f10,0x18($v1) -/* f151940: c4660020 */ lwc1 $f6,0x20($v1) -/* f151944: 01b41021 */ addu $v0,$t5,$s4 -/* f151948: c4480008 */ lwc1 $f8,0x8($v0) -/* f15194c: c4440010 */ lwc1 $f4,0x10($v0) -/* f151950: c450000c */ lwc1 $f16,0xc($v0) -/* f151954: 460a4081 */ sub.s $f2,$f8,$f10 -/* f151958: c472001c */ lwc1 $f18,0x1c($v1) -/* f15195c: 46062001 */ sub.s $f0,$f4,$f6 -/* f151960: 46021102 */ mul.s $f4,$f2,$f2 -/* f151964: 46128381 */ sub.s $f14,$f16,$f18 -/* f151968: 460e7182 */ mul.s $f6,$f14,$f14 -/* f15196c: 46062200 */ add.s $f8,$f4,$f6 -/* f151970: 46000282 */ mul.s $f10,$f0,$f0 -/* f151974: 0c012974 */ jal sqrtf -/* f151978: 46085300 */ add.s $f12,$f10,$f8 -/* f15197c: 8eee0284 */ lw $t6,0x284($s7) -/* f151980: c5c20024 */ lwc1 $f2,0x24($t6) -/* f151984: 4600103c */ c.lt.s $f2,$f0 -/* f151988: 461e1301 */ sub.s $f12,$f2,$f30 -/* f15198c: 45000002 */ bc1f .L0f151998 -/* f151990: 46020583 */ div.s $f22,$f0,$f2 -/* f151994: 00008025 */ or $s0,$zero,$zero -.L0f151998: -/* f151998: 4600603c */ c.lt.s $f12,$f0 -/* f15199c: 00000000 */ nop -/* f1519a0: 45020005 */ bc1fl .L0f1519b8 -/* f1519a4: 4616c03c */ c.lt.s $f24,$f22 -/* f1519a8: 460c0401 */ sub.s $f16,$f0,$f12 -/* f1519ac: 461e8483 */ div.s $f18,$f16,$f30 -/* f1519b0: 4612c501 */ sub.s $f20,$f24,$f18 -/* f1519b4: 4616c03c */ c.lt.s $f24,$f22 -.L0f1519b8: -/* f1519b8: 00000000 */ nop -/* f1519bc: 45000002 */ bc1f .L0f1519c8 -/* f1519c0: 00000000 */ nop -/* f1519c4: 4600c586 */ mov.s $f22,$f24 -.L0f1519c8: -/* f1519c8: 1200010c */ beqz $s0,.L0f151dfc -/* f1519cc: 00000000 */ nop -/* f1519d0: 8e4f0000 */ lw $t7,0x0($s2) -/* f1519d4: 27a600e8 */ addiu $a2,$sp,0xe8 -/* f1519d8: 01f41021 */ addu $v0,$t7,$s4 -/* f1519dc: 24440008 */ addiu $a0,$v0,0x8 -/* f1519e0: 0c0059a9 */ jal func000166a4 -/* f1519e4: 24450014 */ addiu $a1,$v0,0x14 -/* f1519e8: 8ee30284 */ lw $v1,0x284($s7) -/* f1519ec: c7a40118 */ lwc1 $f4,0x118($sp) -/* f1519f0: c7a8011c */ lwc1 $f8,0x11c($sp) -/* f1519f4: c4660038 */ lwc1 $f6,0x38($v1) -/* f1519f8: 46062281 */ sub.s $f10,$f4,$f6 -/* f1519fc: c7a40120 */ lwc1 $f4,0x120($sp) -/* f151a00: e7aa0118 */ swc1 $f10,0x118($sp) -/* f151a04: c470003c */ lwc1 $f16,0x3c($v1) -/* f151a08: 461a503c */ c.lt.s $f10,$f26 -/* f151a0c: 46104481 */ sub.s $f18,$f8,$f16 -/* f151a10: e7b2011c */ swc1 $f18,0x11c($sp) -/* f151a14: c4660040 */ lwc1 $f6,0x40($v1) -/* f151a18: 46062201 */ sub.s $f8,$f4,$f6 -/* f151a1c: 450000f7 */ bc1f .L0f151dfc -/* f151a20: e7a80120 */ swc1 $f8,0x120($sp) -/* f151a24: 460ae03c */ c.lt.s $f28,$f10 -/* f151a28: 00000000 */ nop -/* f151a2c: 450000f3 */ bc1f .L0f151dfc -/* f151a30: 00000000 */ nop -/* f151a34: 461a903c */ c.lt.s $f18,$f26 -/* f151a38: 00000000 */ nop -/* f151a3c: 450000ef */ bc1f .L0f151dfc -/* f151a40: 00000000 */ nop -/* f151a44: 4612e03c */ c.lt.s $f28,$f18 -/* f151a48: 00000000 */ nop -/* f151a4c: 450000eb */ bc1f .L0f151dfc -/* f151a50: 00000000 */ nop -/* f151a54: 461a403c */ c.lt.s $f8,$f26 -/* f151a58: 00000000 */ nop -/* f151a5c: 450000e7 */ bc1f .L0f151dfc -/* f151a60: 00000000 */ nop -/* f151a64: 4608e03c */ c.lt.s $f28,$f8 -/* f151a68: 27a400e8 */ addiu $a0,$sp,0xe8 -/* f151a6c: 450000e3 */ bc1f .L0f151dfc -/* f151a70: 00000000 */ nop -/* f151a74: 0c005815 */ jal func00016054 -/* f151a78: 02202825 */ or $a1,$s1,$zero -/* f151a7c: 3c180102 */ lui $t8,0x102 -/* f151a80: 37180040 */ ori $t8,$t8,0x40 -/* f151a84: 02608025 */ or $s0,$s3,$zero -/* f151a88: ae180000 */ sw $t8,0x0($s0) -/* f151a8c: 26730008 */ addiu $s3,$s3,0x8 -/* f151a90: 0c012d20 */ jal osVirtualToPhysical -/* f151a94: 02202025 */ or $a0,$s1,$zero -/* f151a98: ae020004 */ sw $v0,0x4($s0) -/* f151a9c: 8ef90284 */ lw $t9,0x284($s7) -/* f151aa0: 24010001 */ addiu $at,$zero,0x1 -/* f151aa4: 97280010 */ lhu $t0,0x10($t9) -/* f151aa8: 150100ad */ bne $t0,$at,.L0f151d60 -/* f151aac: 3c01437f */ lui $at,0x437f -/* f151ab0: 44818000 */ mtc1 $at,$f16 -/* f151ab4: 24100001 */ addiu $s0,$zero,0x1 -/* f151ab8: 3c014f00 */ lui $at,0x4f00 -/* f151abc: 4610b102 */ mul.s $f4,$f22,$f16 -/* f151ac0: 24040003 */ addiu $a0,$zero,0x3 -/* f151ac4: 4449f800 */ cfc1 $t1,$31 -/* f151ac8: 44d0f800 */ ctc1 $s0,$31 -/* f151acc: 00000000 */ nop -/* f151ad0: 460021a4 */ cvt.w.s $f6,$f4 -/* f151ad4: 4450f800 */ cfc1 $s0,$31 -/* f151ad8: 00000000 */ nop -/* f151adc: 32100078 */ andi $s0,$s0,0x78 -/* f151ae0: 52000013 */ beqzl $s0,.L0f151b30 -/* f151ae4: 44103000 */ mfc1 $s0,$f6 -/* f151ae8: 44813000 */ mtc1 $at,$f6 -/* f151aec: 24100001 */ addiu $s0,$zero,0x1 -/* f151af0: 46062181 */ sub.s $f6,$f4,$f6 -/* f151af4: 44d0f800 */ ctc1 $s0,$31 -/* f151af8: 00000000 */ nop -/* f151afc: 460031a4 */ cvt.w.s $f6,$f6 -/* f151b00: 4450f800 */ cfc1 $s0,$31 -/* f151b04: 00000000 */ nop -/* f151b08: 32100078 */ andi $s0,$s0,0x78 -/* f151b0c: 16000005 */ bnez $s0,.L0f151b24 -/* f151b10: 00000000 */ nop -/* f151b14: 44103000 */ mfc1 $s0,$f6 -/* f151b18: 3c018000 */ lui $at,0x8000 -/* f151b1c: 10000007 */ b .L0f151b3c -/* f151b20: 02018025 */ or $s0,$s0,$at -.L0f151b24: -/* f151b24: 10000005 */ b .L0f151b3c -/* f151b28: 2410ffff */ addiu $s0,$zero,-1 -/* f151b2c: 44103000 */ mfc1 $s0,$f6 -.L0f151b30: -/* f151b30: 00000000 */ nop -/* f151b34: 0600fffb */ bltz $s0,.L0f151b24 -/* f151b38: 00000000 */ nop -.L0f151b3c: -/* f151b3c: 44c9f800 */ ctc1 $t1,$31 -/* f151b40: 3c01437f */ lui $at,0x437f -/* f151b44: 44819000 */ mtc1 $at,$f18 -/* f151b48: 4616c281 */ sub.s $f10,$f24,$f22 -/* f151b4c: 24110001 */ addiu $s1,$zero,0x1 -/* f151b50: 3c014f00 */ lui $at,0x4f00 -/* f151b54: 46125202 */ mul.s $f8,$f10,$f18 -/* f151b58: 444af800 */ cfc1 $t2,$31 -/* f151b5c: 44d1f800 */ ctc1 $s1,$31 -/* f151b60: 00000000 */ nop -/* f151b64: 46004424 */ cvt.w.s $f16,$f8 -/* f151b68: 4451f800 */ cfc1 $s1,$31 -/* f151b6c: 00000000 */ nop -/* f151b70: 32310078 */ andi $s1,$s1,0x78 -/* f151b74: 52200013 */ beqzl $s1,.L0f151bc4 -/* f151b78: 44118000 */ mfc1 $s1,$f16 -/* f151b7c: 44818000 */ mtc1 $at,$f16 -/* f151b80: 24110001 */ addiu $s1,$zero,0x1 -/* f151b84: 46104401 */ sub.s $f16,$f8,$f16 -/* f151b88: 44d1f800 */ ctc1 $s1,$31 -/* f151b8c: 00000000 */ nop -/* f151b90: 46008424 */ cvt.w.s $f16,$f16 -/* f151b94: 4451f800 */ cfc1 $s1,$31 -/* f151b98: 00000000 */ nop -/* f151b9c: 32310078 */ andi $s1,$s1,0x78 -/* f151ba0: 16200005 */ bnez $s1,.L0f151bb8 -/* f151ba4: 00000000 */ nop -/* f151ba8: 44118000 */ mfc1 $s1,$f16 -/* f151bac: 3c018000 */ lui $at,0x8000 -/* f151bb0: 10000007 */ b .L0f151bd0 -/* f151bb4: 02218825 */ or $s1,$s1,$at -.L0f151bb8: -/* f151bb8: 10000005 */ b .L0f151bd0 -/* f151bbc: 2411ffff */ addiu $s1,$zero,-1 -/* f151bc0: 44118000 */ mfc1 $s1,$f16 -.L0f151bc4: -/* f151bc4: 00000000 */ nop -/* f151bc8: 0620fffb */ bltz $s1,.L0f151bb8 -/* f151bcc: 00000000 */ nop -.L0f151bd0: -/* f151bd0: 44caf800 */ ctc1 $t2,$31 -/* f151bd4: 0fc59e73 */ jal gfxAllocateColours -/* f151bd8: 00000000 */ nop -/* f151bdc: 8e4b0000 */ lw $t3,0x0($s2) -/* f151be0: 00403025 */ or $a2,$v0,$zero -/* f151be4: 01746021 */ addu $t4,$t3,$s4 -/* f151be8: 8d830004 */ lw $v1,0x4($t4) -/* f151bec: 3c0b0708 */ lui $t3,0x708 -/* f151bf0: 356b000c */ ori $t3,$t3,0xc -/* f151bf4: 28610064 */ slti $at,$v1,0x64 -/* f151bf8: 54200013 */ bnezl $at,.L0f151c48 -/* f151bfc: 3c013f00 */ lui $at,0x3f00 -/* f151c00: 44832000 */ mtc1 $v1,$f4 -/* f151c04: 3c014248 */ lui $at,0x4248 -/* f151c08: 44815000 */ mtc1 $at,$f10 -/* f151c0c: 468021a0 */ cvt.s.w $f6,$f4 -/* f151c10: 3c013f80 */ lui $at,0x3f80 -/* f151c14: 44819000 */ mtc1 $at,$f18 -/* f151c18: 3c013f80 */ lui $at,0x3f80 -/* f151c1c: 460a3003 */ div.s $f0,$f6,$f10 -/* f151c20: 4600903c */ c.lt.s $f18,$f0 -/* f151c24: 00000000 */ nop -/* f151c28: 45020004 */ bc1fl .L0f151c3c -/* f151c2c: 4600c201 */ sub.s $f8,$f24,$f0 -/* f151c30: 44810000 */ mtc1 $at,$f0 -/* f151c34: 00000000 */ nop -/* f151c38: 4600c201 */ sub.s $f8,$f24,$f0 -.L0f151c3c: -/* f151c3c: 46144502 */ mul.s $f20,$f8,$f20 -/* f151c40: 00000000 */ nop -/* f151c44: 3c013f00 */ lui $at,0x3f00 -.L0f151c48: -/* f151c48: 44818000 */ mtc1 $at,$f16 -/* f151c4c: 00002025 */ or $a0,$zero,$zero -/* f151c50: 00401825 */ or $v1,$v0,$zero -/* f151c54: 4610a502 */ mul.s $f20,$f20,$f16 -/* f151c58: 00000000 */ nop -.L0f151c5c: -/* f151c5c: a0700000 */ sb $s0,0x0($v1) -/* f151c60: a0710001 */ sb $s1,0x1($v1) -/* f151c64: a0600002 */ sb $zero,0x2($v1) -/* f151c68: 8eae0000 */ lw $t6,0x0($s5) -/* f151c6c: 8e4d0000 */ lw $t5,0x0($s2) -/* f151c70: 3c014f80 */ lui $at,0x4f80 -/* f151c74: 000e78c0 */ sll $t7,$t6,0x3 -/* f151c78: 01ee7823 */ subu $t7,$t7,$t6 -/* f151c7c: 000f7880 */ sll $t7,$t7,0x2 -/* f151c80: 01ee7823 */ subu $t7,$t7,$t6 -/* f151c84: 000f7880 */ sll $t7,$t7,0x2 -/* f151c88: 01afc021 */ addu $t8,$t5,$t7 -/* f151c8c: 0304c821 */ addu $t9,$t8,$a0 -/* f151c90: 9328005f */ lbu $t0,0x5f($t9) -/* f151c94: 24840004 */ addiu $a0,$a0,0x4 -/* f151c98: 44882000 */ mtc1 $t0,$f4 -/* f151c9c: 05010004 */ bgez $t0,.L0f151cb0 -/* f151ca0: 468021a0 */ cvt.s.w $f6,$f4 -/* f151ca4: 44815000 */ mtc1 $at,$f10 -/* f151ca8: 00000000 */ nop -/* f151cac: 460a3180 */ add.s $f6,$f6,$f10 -.L0f151cb0: -/* f151cb0: 46143482 */ mul.s $f18,$f6,$f20 -/* f151cb4: 240a0001 */ addiu $t2,$zero,0x1 -/* f151cb8: 3c014f00 */ lui $at,0x4f00 -/* f151cbc: 4449f800 */ cfc1 $t1,$31 -/* f151cc0: 44caf800 */ ctc1 $t2,$31 -/* f151cc4: 00000000 */ nop -/* f151cc8: 46009224 */ cvt.w.s $f8,$f18 -/* f151ccc: 444af800 */ cfc1 $t2,$31 -/* f151cd0: 00000000 */ nop -/* f151cd4: 314a0078 */ andi $t2,$t2,0x78 -/* f151cd8: 51400013 */ beqzl $t2,.L0f151d28 -/* f151cdc: 440a4000 */ mfc1 $t2,$f8 -/* f151ce0: 44814000 */ mtc1 $at,$f8 -/* f151ce4: 240a0001 */ addiu $t2,$zero,0x1 -/* f151ce8: 46089201 */ sub.s $f8,$f18,$f8 -/* f151cec: 44caf800 */ ctc1 $t2,$31 -/* f151cf0: 00000000 */ nop -/* f151cf4: 46004224 */ cvt.w.s $f8,$f8 -/* f151cf8: 444af800 */ cfc1 $t2,$31 -/* f151cfc: 00000000 */ nop -/* f151d00: 314a0078 */ andi $t2,$t2,0x78 -/* f151d04: 15400005 */ bnez $t2,.L0f151d1c -/* f151d08: 00000000 */ nop -/* f151d0c: 440a4000 */ mfc1 $t2,$f8 -/* f151d10: 3c018000 */ lui $at,0x8000 -/* f151d14: 10000007 */ b .L0f151d34 -/* f151d18: 01415025 */ or $t2,$t2,$at -.L0f151d1c: -/* f151d1c: 10000005 */ b .L0f151d34 -/* f151d20: 240affff */ addiu $t2,$zero,-1 -/* f151d24: 440a4000 */ mfc1 $t2,$f8 -.L0f151d28: -/* f151d28: 00000000 */ nop -/* f151d2c: 0540fffb */ bltz $t2,.L0f151d1c -/* f151d30: 00000000 */ nop -.L0f151d34: -/* f151d34: 44c9f800 */ ctc1 $t1,$31 -/* f151d38: 24630004 */ addiu $v1,$v1,0x4 -/* f151d3c: 1496ffc7 */ bne $a0,$s6,.L0f151c5c -/* f151d40: a06affff */ sb $t2,-0x1($v1) -/* f151d44: 02608025 */ or $s0,$s3,$zero -/* f151d48: ae0b0000 */ sw $t3,0x0($s0) -/* f151d4c: 26730008 */ addiu $s3,$s3,0x8 -/* f151d50: 0c012d20 */ jal osVirtualToPhysical -/* f151d54: 00c02025 */ or $a0,$a2,$zero -/* f151d58: 10000018 */ b .L0f151dbc -/* f151d5c: ae020004 */ sw $v0,0x4($s0) -.L0f151d60: -/* f151d60: 8e4c0000 */ lw $t4,0x0($s2) -/* f151d64: 87ad012e */ lh $t5,0x12e($sp) -/* f151d68: 01947021 */ addu $t6,$t4,$s4 -/* f151d6c: 85c50000 */ lh $a1,0x0($t6) -/* f151d70: 51a50009 */ beql $t5,$a1,.L0f151d98 -/* f151d74: 3c080708 */ lui $t0,0x708 -/* f151d78: 0fc0044e */ jal func0f001138 -/* f151d7c: 02602025 */ or $a0,$s3,$zero -/* f151d80: 8e4f0000 */ lw $t7,0x0($s2) -/* f151d84: 00409825 */ or $s3,$v0,$zero -/* f151d88: 01f4c021 */ addu $t8,$t7,$s4 -/* f151d8c: 87190000 */ lh $t9,0x0($t8) -/* f151d90: a7b9012e */ sh $t9,0x12e($sp) -/* f151d94: 3c080708 */ lui $t0,0x708 -.L0f151d98: -/* f151d98: 3508000c */ ori $t0,$t0,0xc -/* f151d9c: 02608025 */ or $s0,$s3,$zero -/* f151da0: ae080000 */ sw $t0,0x0($s0) -/* f151da4: 8e490000 */ lw $t1,0x0($s2) -/* f151da8: 26730008 */ addiu $s3,$s3,0x8 -/* f151dac: 01342021 */ addu $a0,$t1,$s4 -/* f151db0: 0c012d20 */ jal osVirtualToPhysical -/* f151db4: 2484005c */ addiu $a0,$a0,0x5c -/* f151db8: ae020004 */ sw $v0,0x4($s0) -.L0f151dbc: -/* f151dbc: 3c0a0420 */ lui $t2,0x420 -/* f151dc0: 354a0024 */ ori $t2,$t2,0x24 -/* f151dc4: 02608025 */ or $s0,$s3,$zero -/* f151dc8: ae0a0000 */ sw $t2,0x0($s0) -/* f151dcc: 8e4b0000 */ lw $t3,0x0($s2) -/* f151dd0: 26730008 */ addiu $s3,$s3,0x8 -/* f151dd4: 01742021 */ addu $a0,$t3,$s4 -/* f151dd8: 0c012d20 */ jal osVirtualToPhysical -/* f151ddc: 24840038 */ addiu $a0,$a0,0x38 -/* f151de0: 02601825 */ or $v1,$s3,$zero -/* f151de4: ae020004 */ sw $v0,0x4($s0) -/* f151de8: 3c0cbf00 */ lui $t4,0xbf00 -/* f151dec: 240e0a14 */ addiu $t6,$zero,0xa14 -/* f151df0: ac6e0004 */ sw $t6,0x4($v1) -/* f151df4: ac6c0000 */ sw $t4,0x0($v1) -/* f151df8: 26730008 */ addiu $s3,$s3,0x8 -.L0f151dfc: -/* f151dfc: 3c0d800a */ lui $t5,%hi(g_MaxShards) -/* f151e00: 8dad45c0 */ lw $t5,%lo(g_MaxShards)($t5) -/* f151e04: 27de0001 */ addiu $s8,$s8,0x1 -/* f151e08: 2694006c */ addiu $s4,$s4,0x6c -/* f151e0c: 03cd082a */ slt $at,$s8,$t5 -/* f151e10: 5420feb8 */ bnezl $at,.L0f1518f4 -/* f151e14: 8e490000 */ lw $t1,0x0($s2) -/* f151e18: e7b600bc */ swc1 $f22,0xbc($sp) -.L0f151e1c: -/* f151e1c: 87af012e */ lh $t7,0x12e($sp) -/* f151e20: 55e00005 */ bnezl $t7,.L0f151e38 -/* f151e24: 02601025 */ or $v0,$s3,$zero -/* f151e28: 0fc004c0 */ jal func0f001300 -/* f151e2c: 02602025 */ or $a0,$s3,$zero -/* f151e30: 00409825 */ or $s3,$v0,$zero -/* f151e34: 02601025 */ or $v0,$s3,$zero -.L0f151e38: -/* f151e38: 26730008 */ addiu $s3,$s3,0x8 -/* f151e3c: 3c18b600 */ lui $t8,0xb600 -/* f151e40: 3c190006 */ lui $t9,0x6 -/* f151e44: 3c080103 */ lui $t0,0x103 -/* f151e48: ac590004 */ sw $t9,0x4($v0) -/* f151e4c: ac580000 */ sw $t8,0x0($v0) -/* f151e50: 35080040 */ ori $t0,$t0,0x40 -/* f151e54: 02608025 */ or $s0,$s3,$zero -/* f151e58: ae080000 */ sw $t0,0x0($s0) -/* f151e5c: 0fc2d3fa */ jal currentPlayerGetUnk1750 -/* f151e60: 26730008 */ addiu $s3,$s3,0x8 -/* f151e64: 3c090102 */ lui $t1,0x102 -/* f151e68: ae020004 */ sw $v0,0x4($s0) -/* f151e6c: 35290040 */ ori $t1,$t1,0x40 -/* f151e70: 02608825 */ or $s1,$s3,$zero -/* f151e74: ae290000 */ sw $t1,0x0($s1) -/* f151e78: 0fc2d3ea */ jal currentPlayerGetUnk173c -/* f151e7c: 26730008 */ addiu $s3,$s3,0x8 -/* f151e80: ae220004 */ sw $v0,0x4($s1) -.L0f151e84: -/* f151e84: 8fbf006c */ lw $ra,0x6c($sp) -/* f151e88: 02601025 */ or $v0,$s3,$zero -/* f151e8c: 8fb30054 */ lw $s3,0x54($sp) -/* f151e90: d7b40018 */ ldc1 $f20,0x18($sp) -/* f151e94: d7b60020 */ ldc1 $f22,0x20($sp) -/* f151e98: d7b80028 */ ldc1 $f24,0x28($sp) -/* f151e9c: d7ba0030 */ ldc1 $f26,0x30($sp) -/* f151ea0: d7bc0038 */ ldc1 $f28,0x38($sp) -/* f151ea4: d7be0040 */ ldc1 $f30,0x40($sp) -/* f151ea8: 8fb00048 */ lw $s0,0x48($sp) -/* f151eac: 8fb1004c */ lw $s1,0x4c($sp) -/* f151eb0: 8fb20050 */ lw $s2,0x50($sp) -/* f151eb4: 8fb40058 */ lw $s4,0x58($sp) -/* f151eb8: 8fb5005c */ lw $s5,0x5c($sp) -/* f151ebc: 8fb60060 */ lw $s6,0x60($sp) -/* f151ec0: 8fb70064 */ lw $s7,0x64($sp) -/* f151ec4: 8fbe0068 */ lw $s8,0x68($sp) -/* f151ec8: 03e00008 */ jr $ra -/* f151ecc: 27bd0130 */ addiu $sp,$sp,0x130 -); + gSPClearGeometryMode(gdl++, G_CULL_BOTH); + gSPSetGeometryMode(gdl++, G_SHADE | G_SHADING_SMOOTH); + gDPSetCombineMode(gdl++, G_CC_SHADE, G_CC_SHADE); + gDPSetTextureFilter(gdl++, G_TF_BILERP); + gDPSetCycleType(gdl++, G_CYC_2CYCLE); + gDPSetTextureLOD(gdl++, G_TL_LOD); + gSPMatrix(gdl++, osVirtualToPhysical(currentPlayerGetUnk1758()), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); + + for (i = 0; i < g_MaxShards; i++) { + if (g_Shards[i].age60 > 0 && g_Shards[i].type == SHARDTYPE_WOOD) { + bool render = true; + f32 alphamult = 1.0f; + f32 xraydist; + Mtxf *mtx = gfxAllocateMatrix(); + u32 stack; + + if (g_Vars.currentplayer->visionmode == VISIONMODE_XRAY) { + xraydist = sqrtf(ERASERSQDIST(g_Shards[i].pos.f)); + + if (g_Vars.currentplayer->eraserpropdist < xraydist) { + render = false; + } + + if (g_Vars.currentplayer->eraserpropdist - 150.0f < xraydist) { + alphamult = 1.0f - (xraydist - (g_Vars.currentplayer->eraserpropdist - 150.0f)) / 150.0f; + } + + xraydist = xraydist / g_Vars.currentplayer->eraserpropdist; + + if (xraydist > 1.0f) { + xraydist = 1.0f; + } + } + + if (render) { + /** + * The following function call is really just this: + * + * func000166a4(&g_Shards[i].pos, &g_Shards[i].rot, &shardmtx); + * + * ... but that causes a mismatch, so I'm using a hacky but + * matching alternative. This hack is @dangerous because it + * assumes the offsets of pos and rot in the shard struct. + */ + func000166a4( + (struct coord *)((u8 *)g_Shards + i * sizeof(struct shard) + 0x08), + (struct coord *)((u8 *)g_Shards + i * sizeof(struct shard) + 0x14), + &shardmtx); + + shardmtx.m[3][0] -= g_Vars.currentplayer->globaldrawworldoffset.x; + shardmtx.m[3][1] -= g_Vars.currentplayer->globaldrawworldoffset.y; + shardmtx.m[3][2] -= g_Vars.currentplayer->globaldrawworldoffset.z; + + if (shardmtx.m[3][0] < 10000 && shardmtx.m[3][0] > -10000 + && shardmtx.m[3][1] < 10000 && shardmtx.m[3][1] > -10000 + && shardmtx.m[3][2] < 10000 && shardmtx.m[3][2] > -10000) { + func00016054(&shardmtx, mtx); + + gSPMatrix(gdl++, osVirtualToPhysical(mtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + if (g_Vars.currentplayer->visionmode == VISIONMODE_XRAY) { + u8 (*colours)[4] = gfxAllocateColours(3); + + if (g_Shards[i].age60 >= 100) { + f32 frac = g_Shards[i].age60 / 50.0f; + + if (frac > 1) { + frac = 1; + } + + alphamult = (1.0f - frac) * alphamult; + } + + alphamult *= 0.5f; + + for (j = 0; j < 3; j++) { + colours[j][0] = xraydist * 255.0f; + colours[j][1] = (1.0f - xraydist) * 255.0f; + colours[j][2] = 0; + colours[j][3] = g_Shards[var8007fa80].colours[j][3] * alphamult; + } + + gDPSetColorArray(gdl++, osVirtualToPhysical(colours), 3); + } else { + if (g_Shards[i].room != prevroom) { + gdl = func0f001138(gdl, g_Shards[i].room); + prevroom = g_Shards[i].room; + } + + gDPSetColorArray(gdl++, osVirtualToPhysical(g_Shards[i].colours), 3); + } + + gDPSetVerticeArray(gdl++, osVirtualToPhysical(g_Shards[i].vertices), 3); + gSP1Triangle(gdl++, 0, 1, 2, 0); + } + } + } + } + + if (prevroom == 0) { + gdl = func0f001300(gdl); + } + + gSPClearGeometryMode(gdl++, G_LIGHTING | G_TEXTURE_GEN); + gSPMatrix(gdl++, currentPlayerGetUnk1750(), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); + gSPMatrix(gdl++, currentPlayerGetUnk173c(), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + } + + return gdl; +} Gfx *shardsRenderGlass(Gfx *gdl); GLOBAL_ASM( glabel shardsRenderGlass +.late_rodata +glabel var7f1b7398 +.word 0xc61c4000 +glabel var7f1b739c +.word 0x461c4000 +.text /* f151ed0: 27bdfec0 */ addiu $sp,$sp,-320 /* f151ed4: 3c0e8008 */ lui $t6,%hi(g_ShardsActive) /* f151ed8: 8dcefa84 */ lw $t6,%lo(g_ShardsActive)($t6) diff --git a/src/include/constants.h b/src/include/constants.h index b8c0d49c0..1b8017262 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -30,6 +30,11 @@ #define VOLUME(volume) (volume > 0x5000 ? 0x5000 : volume) #define EYESPYINACTIVE() (!g_Vars.currentplayer->eyespy || (g_Vars.currentplayer->eyespy && !g_Vars.currentplayer->eyespy->active)) +#define ERASERSQDIST(p) ( \ + (p[0] - g_Vars.currentplayer->eraserpos.f[0]) * (p[0] - g_Vars.currentplayer->eraserpos.f[0]) + \ + (p[1] - g_Vars.currentplayer->eraserpos.f[1]) * (p[1] - g_Vars.currentplayer->eraserpos.f[1]) + \ + (p[2] - g_Vars.currentplayer->eraserpos.f[2]) * (p[2] - g_Vars.currentplayer->eraserpos.f[2])) + // Macro to convert an ASCII character to N64 font code. // N64 font code uses 0x0f for space, 0x10-0x19 for 0-9 and 0x1a-0x33 for A-Z. #define N64CHAR(c) (c == ' ' ? 0x0f : (c >= 'A' && c <= 'Z' ? c - 0x27 : c - 0x20)) @@ -2955,6 +2960,8 @@ #define SCREENSPLIT_HORIZONTAL 0 #define SCREENSPLIT_VERTICAL 1 +#define SHARDTYPE_WOOD 2 + #define SHOTREGION_TOTAL 0 #define SHOTREGION_HEAD 1 #define SHOTREGION_BODY 2 diff --git a/src/include/game/gfxmemory.h b/src/include/game/gfxmemory.h index f9948dd40..f3bf8bc0d 100644 --- a/src/include/game/gfxmemory.h +++ b/src/include/game/gfxmemory.h @@ -9,7 +9,7 @@ Gfx *gfxGetMasterDisplayList(void); struct gfxvtx *gfxAllocateVertices(s32 count); void *gfxAllocateMatrix(void); void *gfxAllocate4Words(s32 count); -u32 *gfxAllocateColours(s32 count); +void *gfxAllocateColours(s32 count); void *gfxAllocate(u32 size); void gfxSwapBuffers(void); diff --git a/src/include/lib/lib_16110.h b/src/include/lib/lib_16110.h index ebb4470db..26f89b87c 100644 --- a/src/include/lib/lib_16110.h +++ b/src/include/lib/lib_16110.h @@ -15,7 +15,7 @@ void func00016374(f32 angle, Mtxf *matrix); void func00016400(f32 angle, Mtxf *matrix); void func0001648c(struct coord *coord, Mtxf *dest); u32 func000165d8(void); -u32 func000166a4(void); +void func000166a4(struct coord *pos, struct coord *rot, Mtxf *matrix); void func000166dc(struct coord *pos, Mtxf *matrix); u32 func00016710(void); void func00016748(f32 arg0); diff --git a/src/include/types.h b/src/include/types.h index 918d85ef6..23df0f55b 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -6666,25 +6666,15 @@ struct gfxvtx { }; struct shard { - /*0x00*/ u32 unk00; + /*0x00*/ s16 room; /*0x04*/ s32 age60; /*0x08*/ struct coord pos; /*0x14*/ struct coord rot; /*0x20*/ struct coord vel; /*0x2c*/ struct coord rotspeed; - /*0x38*/ u32 unk38; - /*0x3c*/ u32 unk3c; - /*0x40*/ u32 unk40; - /*0x44*/ u32 unk44; - /*0x48*/ u32 unk48; - /*0x4c*/ u32 unk4c; - /*0x50*/ u32 unk50; - /*0x54*/ u32 unk54; - /*0x58*/ u32 unk58; - /*0x5c*/ u32 unk5c; - /*0x60*/ u32 unk60; - /*0x64*/ u32 unk64; - /*0x68*/ u32 unk68; + /*0x38*/ struct gfxvtx vertices[3]; + /*0x5c*/ u8 colours[3][4]; + /*0x68*/ u8 type; }; struct audiochannel {