From 2999309f13ade6c8c451a48dac20085e39727d82 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Sun, 23 Oct 2022 16:44:06 +0300 Subject: [PATCH] Add CScriptVisorFlare and CVisorFlare --- asm/MetroidPrime/CVisorFlare.s | 30 +- asm/MetroidPrime/Enemies/CDrone.s | 6 +- asm/MetroidPrime/ScriptLoader.s | 20 +- .../ScriptObjects/CScriptVisorFlare.s | 26 +- configure.py | 4 +- include/Kyoto/Graphics/CGraphics.hpp | 1 + include/MetaRender/IRenderer.hpp | 20 ++ include/MetroidPrime/CStateManager.hpp | 7 + include/MetroidPrime/CVisorFlare.hpp | 69 +++++ .../ScriptObjects/CScriptVisorFlare.hpp | 26 ++ src/MetroidPrime/CVisorFlare.cpp | 264 ++++++++++++++++++ .../ScriptObjects/CScriptVisorFlare.cpp | 41 +++ 12 files changed, 471 insertions(+), 43 deletions(-) create mode 100644 include/MetroidPrime/CVisorFlare.hpp create mode 100644 include/MetroidPrime/ScriptObjects/CScriptVisorFlare.hpp create mode 100644 src/MetroidPrime/CVisorFlare.cpp create mode 100644 src/MetroidPrime/ScriptObjects/CScriptVisorFlare.cpp diff --git a/asm/MetroidPrime/CVisorFlare.s b/asm/MetroidPrime/CVisorFlare.s index 8a1a3c05..f72963cd 100644 --- a/asm/MetroidPrime/CVisorFlare.s +++ b/asm/MetroidPrime/CVisorFlare.s @@ -35,8 +35,8 @@ lbl_805A7F64: .section .text, "ax" -.global sub_802075fc -sub_802075fc: +.global ResetTevSwapMode__11CVisorFlareCFRC13CStateManager +ResetTevSwapMode__11CVisorFlareCFRC13CStateManager: /* 802075FC 0020455C 94 21 FF F0 */ stwu r1, -0x10(r1) /* 80207600 00204560 7C 08 02 A6 */ mflr r0 /* 80207604 00204564 90 01 00 14 */ stw r0, 0x14(r1) @@ -53,8 +53,8 @@ lbl_80207624: /* 8020762C 0020458C 38 21 00 10 */ addi r1, r1, 0x10 /* 80207630 00204590 4E 80 00 20 */ blr -.global sub_80207634 -sub_80207634: +.global SetupRenderState__11CVisorFlareCFRC13CStateManager +SetupRenderState__11CVisorFlareCFRC13CStateManager: /* 80207634 00204594 94 21 FF F0 */ stwu r1, -0x10(r1) /* 80207638 00204598 7C 08 02 A6 */ mflr r0 /* 8020763C 0020459C 90 01 00 14 */ stw r0, 0x14(r1) @@ -188,8 +188,8 @@ lbl_80207810: /* 8020781C 0020477C 38 21 00 10 */ addi r1, r1, 0x10 /* 80207820 00204780 4E 80 00 20 */ blr -.global sub_80207824 -sub_80207824: +.global DrawStreamed__11CVisorFlareCFRC6CColorff +DrawStreamed__11CVisorFlareCFRC6CColorff: /* 80207824 00204784 94 21 FF A0 */ stwu r1, -0x60(r1) /* 80207828 00204788 7C 08 02 A6 */ mflr r0 /* 8020782C 0020478C 90 01 00 64 */ stw r0, 0x64(r1) @@ -273,8 +273,8 @@ sub_80207824: /* 80207964 002048C4 38 21 00 60 */ addi r1, r1, 0x60 /* 80207968 002048C8 4E 80 00 20 */ blr -.global sub_8020796c -sub_8020796c: +.global DrawDirect__11CVisorFlareCFRC6CColorff +DrawDirect__11CVisorFlareCFRC6CColorff: /* 8020796C 002048CC 94 21 FF D0 */ stwu r1, -0x30(r1) /* 80207970 002048D0 7C 08 02 A6 */ mflr r0 /* 80207974 002048D4 90 01 00 34 */ stw r0, 0x34(r1) @@ -519,7 +519,7 @@ lbl_80207D04: /* 80207D0C 00204C6C 7F E4 FB 78 */ mr r4, r31 /* 80207D10 00204C70 7C 00 00 34 */ cntlzw r0, r0 /* 80207D14 00204C74 54 1A D9 7E */ srwi r26, r0, 5 -/* 80207D18 00204C78 4B FF F9 1D */ bl sub_80207634 +/* 80207D18 00204C78 4B FF F9 1D */ bl SetupRenderState__11CVisorFlareCFRC13CStateManager /* 80207D1C 00204C7C C0 02 B0 E8 */ lfs f0, lbl_805ACE08@sda21(r2) /* 80207D20 00204C80 3C 60 80 5A */ lis r3, sUpVector__9CVector3f@ha /* 80207D24 00204C84 C3 C2 B0 EC */ lfs f30, lbl_805ACE0C@sda21(r2) @@ -626,14 +626,14 @@ lbl_80207E98: /* 80207EA8 00204E08 90 61 00 0C */ stw r3, 0xc(r1) /* 80207EAC 00204E0C 7F C3 F3 78 */ mr r3, r30 /* 80207EB0 00204E10 38 81 00 0C */ addi r4, r1, 0xc -/* 80207EB4 00204E14 4B FF FA B9 */ bl sub_8020796c +/* 80207EB4 00204E14 4B FF FA B9 */ bl DrawDirect__11CVisorFlareCFRC6CColorff /* 80207EB8 00204E18 48 00 00 18 */ b lbl_80207ED0 lbl_80207EBC: /* 80207EBC 00204E1C FC 20 B8 90 */ fmr f1, f23 /* 80207EC0 00204E20 90 61 00 08 */ stw r3, 8(r1) /* 80207EC4 00204E24 7F C3 F3 78 */ mr r3, r30 /* 80207EC8 00204E28 38 81 00 08 */ addi r4, r1, 8 -/* 80207ECC 00204E2C 4B FF F9 59 */ bl sub_80207824 +/* 80207ECC 00204E2C 4B FF F9 59 */ bl DrawStreamed__11CVisorFlareCFRC6CColorff lbl_80207ED0: /* 80207ED0 00204E30 38 61 00 58 */ addi r3, r1, 0x58 /* 80207ED4 00204E34 38 80 00 00 */ li r4, 0 @@ -647,7 +647,7 @@ lbl_80207EE4: /* 80207EEC 00204E4C 41 80 FE 54 */ blt lbl_80207D40 /* 80207EF0 00204E50 7F C3 F3 78 */ mr r3, r30 /* 80207EF4 00204E54 7F E4 FB 78 */ mr r4, r31 -/* 80207EF8 00204E58 4B FF F7 05 */ bl sub_802075fc +/* 80207EF8 00204E58 4B FF F7 05 */ bl ResetTevSwapMode__11CVisorFlareCFRC13CStateManager lbl_80207EFC: /* 80207EFC 00204E5C E3 E1 02 08 */ psq_l f31, 520(r1), 0, qr0 /* 80207F00 00204E60 CB E1 02 00 */ lfd f31, 0x200(r1) @@ -914,8 +914,8 @@ lbl_802082AC: /* 802082D0 00205230 38 21 09 20 */ addi r1, r1, 0x920 /* 802082D4 00205234 4E 80 00 20 */ blr -.global "__ct__11CVisorFlareFQ211CVisorFlare10EBlendModebfffRCQ24rstl60vector" -"__ct__11CVisorFlareFQ211CVisorFlare10EBlendModebfffRCQ24rstl60vector": +.global "__ct__11CVisorFlareFQ211CVisorFlare10EBlendModebfffUiUiRCQ24rstl60vector" +"__ct__11CVisorFlareFQ211CVisorFlare10EBlendModebfffUiUiRCQ24rstl60vector": /* 802082D8 00205238 94 21 FF C0 */ stwu r1, -0x40(r1) /* 802082DC 0020523C 7C 08 02 A6 */ mflr r0 /* 802082E0 00205240 90 01 00 44 */ stw r0, 0x44(r1) @@ -937,7 +937,7 @@ lbl_802082AC: /* 80208320 00205280 7C FF 3B 78 */ mr r31, r7 /* 80208324 00205284 7D 04 43 78 */ mr r4, r8 /* 80208328 00205288 38 7C 00 04 */ addi r3, r28, 4 -/* 8020832C 0020528C 4B EC 61 41 */ bl sub_800ce46c +/* 8020832C 0020528C 4B EC 61 41 */ bl "__ct__Q24rstl60vectorFRCQ24rstl60vector" /* 80208330 00205290 9B BC 00 14 */ stb r29, 0x14(r28) /* 80208334 00205294 C0 2D 93 90 */ lfs f1, lbl_805A7F50@sda21(r13) /* 80208338 00205298 C0 01 00 08 */ lfs f0, 8(r1) diff --git a/asm/MetroidPrime/Enemies/CDrone.s b/asm/MetroidPrime/Enemies/CDrone.s index 94dec56f..c3e66fdc 100644 --- a/asm/MetroidPrime/Enemies/CDrone.s +++ b/asm/MetroidPrime/Enemies/CDrone.s @@ -708,7 +708,7 @@ lbl_8015F0C0: lbl_8015F0E8: /* 8015F0E8 0015C048 38 7E 05 7C */ addi r3, r30, 0x57c /* 8015F0EC 0015C04C 38 80 FF FF */ li r4, -1 -/* 8015F0F0 0015C050 4B F6 E6 C9 */ bl sub_800cd7b8 +/* 8015F0F0 0015C050 4B F6 E6 C9 */ bl "__dt__Q24rstl60vectorFv" /* 8015F0F4 0015C054 34 1E 05 6C */ addic. r0, r30, 0x56c /* 8015F0F8 0015C058 41 82 00 18 */ beq lbl_8015F110 /* 8015F0FC 0015C05C 34 1E 05 6C */ addic. r0, r30, 0x56c @@ -8481,7 +8481,7 @@ sub_801660a4: /* 80166210 00163170 90 01 00 10 */ stw r0, 0x10(r1) /* 80166214 00163174 39 20 00 00 */ li r9, 0 /* 80166218 00163178 39 40 00 01 */ li r10, 1 -/* 8016621C 0016317C 48 07 05 11 */ bl "__ct__17CScriptVisorFlareF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobRC9CVector3fQ211CVisorFlare10EBlendModebfffRCQ24rstl60vector" +/* 8016621C 0016317C 48 07 05 11 */ bl "__ct__17CScriptVisorFlareF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobRC9CVector3fQ211CVisorFlare10EBlendModebfffUiUiRCQ24rstl60vector" /* 80166220 00163180 7C 7F 1B 78 */ mr r31, r3 lbl_80166224: /* 80166224 00163184 7F 40 07 75 */ extsb. r0, r26 @@ -8990,7 +8990,7 @@ lbl_8016689C: /* 80166954 001638B4 B0 1E 05 78 */ sth r0, 0x578(r30) /* 80166958 001638B8 A0 0D A3 8C */ lhz r0, kInvalidUniqueId@sda21(r13) /* 8016695C 001638BC B0 1E 05 7A */ sth r0, 0x57a(r30) -/* 80166960 001638C0 4B F6 7B 0D */ bl sub_800ce46c +/* 80166960 001638C0 4B F6 7B 0D */ bl "__ct__Q24rstl60vectorFRCQ24rstl60vector" /* 80166964 001638C4 38 00 00 02 */ li r0, 2 /* 80166968 001638C8 3C 60 80 5A */ lis r3, sZeroVector__9CVector3f@ha /* 8016696C 001638CC 90 1E 05 8C */ stw r0, 0x58c(r30) diff --git a/asm/MetroidPrime/ScriptLoader.s b/asm/MetroidPrime/ScriptLoader.s index 25bf4bec..e0742403 100644 --- a/asm/MetroidPrime/ScriptLoader.s +++ b/asm/MetroidPrime/ScriptLoader.s @@ -9191,12 +9191,12 @@ lbl_800CD61C: /* 800CD684 000CA5E4 38 A1 00 3C */ addi r5, r1, 0x3c /* 800CD688 000CA5E8 90 01 00 10 */ stw r0, 0x10(r1) /* 800CD68C 000CA5EC 39 01 00 30 */ addi r8, r1, 0x30 -/* 800CD690 000CA5F0 48 10 90 9D */ bl "__ct__17CScriptVisorFlareF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobRC9CVector3fQ211CVisorFlare10EBlendModebfffRCQ24rstl60vector" +/* 800CD690 000CA5F0 48 10 90 9D */ bl "__ct__17CScriptVisorFlareF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobRC9CVector3fQ211CVisorFlare10EBlendModebfffUiUiRCQ24rstl60vector" /* 800CD694 000CA5F4 7C 7B 1B 78 */ mr r27, r3 lbl_800CD698: /* 800CD698 000CA5F8 38 61 00 20 */ addi r3, r1, 0x20 /* 800CD69C 000CA5FC 38 80 FF FF */ li r4, -1 -/* 800CD6A0 000CA600 48 00 01 19 */ bl sub_800cd7b8 +/* 800CD6A0 000CA600 48 00 01 19 */ bl "__dt__Q24rstl60vectorFv" /* 800CD6A4 000CA604 88 01 00 D8 */ lbz r0, 0xd8(r1) /* 800CD6A8 000CA608 28 00 00 00 */ cmplwi r0, 0 /* 800CD6AC 000CA60C 41 82 00 1C */ beq lbl_800CD6C8 @@ -9273,8 +9273,8 @@ lbl_800CD78C: /* 800CD7B0 000CA710 38 21 01 90 */ addi r1, r1, 0x190 /* 800CD7B4 000CA714 4E 80 00 20 */ blr -.global sub_800cd7b8 -sub_800cd7b8: +.global "__dt__Q24rstl60vectorFv" +"__dt__Q24rstl60vectorFv": /* 800CD7B8 000CA718 94 21 FF D0 */ stwu r1, -0x30(r1) /* 800CD7BC 000CA71C 7C 08 02 A6 */ mflr r0 /* 800CD7C0 000CA720 90 01 00 34 */ stw r0, 0x34(r1) @@ -9783,7 +9783,7 @@ lbl_800CDEE4: /* 800CDEFC 000CAE5C 41 82 01 08 */ beq lbl_800CE004 /* 800CDF00 000CAE60 38 61 00 98 */ addi r3, r1, 0x98 /* 800CDF04 000CAE64 38 80 FF FF */ li r4, -1 -/* 800CDF08 000CAE68 4B FF F8 B1 */ bl sub_800cd7b8 +/* 800CDF08 000CAE68 4B FF F8 B1 */ bl "__dt__Q24rstl60vectorFv" /* 800CDF0C 000CAE6C 88 01 01 6C */ lbz r0, 0x16c(r1) /* 800CDF10 000CAE70 28 00 00 00 */ cmplwi r0, 0 /* 800CDF14 000CAE74 41 82 00 1C */ beq lbl_800CDF30 @@ -9942,7 +9942,7 @@ lbl_800CE004: /* 800CE160 000CB0C0 41 82 01 40 */ beq lbl_800CE2A0 /* 800CE164 000CB0C4 38 61 00 88 */ addi r3, r1, 0x88 /* 800CE168 000CB0C8 38 81 00 98 */ addi r4, r1, 0x98 -/* 800CE16C 000CB0CC 48 00 03 01 */ bl sub_800ce46c +/* 800CE16C 000CB0CC 48 00 03 01 */ bl "__ct__Q24rstl60vectorFRCQ24rstl60vector" /* 800CE170 000CB0D0 80 E1 04 70 */ lwz r7, 0x470(r1) /* 800CE174 000CB0D4 38 A0 00 01 */ li r5, 1 /* 800CE178 000CB0D8 80 C1 04 74 */ lwz r6, 0x474(r1) @@ -10030,11 +10030,11 @@ lbl_800CE2B4: /* 800CE2B8 000CB218 41 82 00 10 */ beq lbl_800CE2C8 /* 800CE2BC 000CB21C 38 61 00 88 */ addi r3, r1, 0x88 /* 800CE2C0 000CB220 38 80 FF FF */ li r4, -1 -/* 800CE2C4 000CB224 4B FF F4 F5 */ bl sub_800cd7b8 +/* 800CE2C4 000CB224 4B FF F4 F5 */ bl "__dt__Q24rstl60vectorFv" lbl_800CE2C8: /* 800CE2C8 000CB228 38 61 00 98 */ addi r3, r1, 0x98 /* 800CE2CC 000CB22C 38 80 FF FF */ li r4, -1 -/* 800CE2D0 000CB230 4B FF F4 E9 */ bl sub_800cd7b8 +/* 800CE2D0 000CB230 4B FF F4 E9 */ bl "__dt__Q24rstl60vectorFv" /* 800CE2D4 000CB234 88 01 01 6C */ lbz r0, 0x16c(r1) /* 800CE2D8 000CB238 28 00 00 00 */ cmplwi r0, 0 /* 800CE2DC 000CB23C 41 82 00 1C */ beq lbl_800CE2F8 @@ -10144,8 +10144,8 @@ lbl_800CE3C8: /* 800CE464 000CB3C4 38 21 06 30 */ addi r1, r1, 0x630 /* 800CE468 000CB3C8 4E 80 00 20 */ blr -.global sub_800ce46c -sub_800ce46c: +.global "__ct__Q24rstl60vectorFRCQ24rstl60vector" +"__ct__Q24rstl60vectorFRCQ24rstl60vector": /* 800CE46C 000CB3CC 94 21 FF E0 */ stwu r1, -0x20(r1) /* 800CE470 000CB3D0 7C 08 02 A6 */ mflr r0 /* 800CE474 000CB3D4 90 01 00 24 */ stw r0, 0x24(r1) diff --git a/asm/MetroidPrime/ScriptObjects/CScriptVisorFlare.s b/asm/MetroidPrime/ScriptObjects/CScriptVisorFlare.s index 8fde57f4..b2bf710c 100644 --- a/asm/MetroidPrime/ScriptObjects/CScriptVisorFlare.s +++ b/asm/MetroidPrime/ScriptObjects/CScriptVisorFlare.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803E5830 -lbl_803E5830: +.global __vt__17CScriptVisorFlare +__vt__17CScriptVisorFlare: # ROM: 0x3E2830 .4byte 0 .4byte 0 @@ -193,12 +193,12 @@ __dt__17CScriptVisorFlareFv: /* 801D6678 001D35D8 93 C1 00 08 */ stw r30, 8(r1) /* 801D667C 001D35DC 7C 7E 1B 79 */ or. r30, r3, r3 /* 801D6680 001D35E0 41 82 00 38 */ beq lbl_801D66B8 -/* 801D6684 001D35E4 3C 80 80 3E */ lis r4, lbl_803E5830@ha +/* 801D6684 001D35E4 3C 80 80 3E */ lis r4, __vt__17CScriptVisorFlare@ha /* 801D6688 001D35E8 38 7E 00 E8 */ addi r3, r30, 0xe8 -/* 801D668C 001D35EC 38 04 58 30 */ addi r0, r4, lbl_803E5830@l +/* 801D668C 001D35EC 38 04 58 30 */ addi r0, r4, __vt__17CScriptVisorFlare@l /* 801D6690 001D35F0 38 80 FF FF */ li r4, -1 /* 801D6694 001D35F4 90 1E 00 00 */ stw r0, 0(r30) -/* 801D6698 001D35F8 48 00 00 3D */ bl sub_801d66d4 +/* 801D6698 001D35F8 48 00 00 3D */ bl __dt__11CVisorFlareFv /* 801D669C 001D35FC 7F C3 F3 78 */ mr r3, r30 /* 801D66A0 001D3600 38 80 00 00 */ li r4, 0 /* 801D66A4 001D3604 4B E7 F0 4D */ bl __dt__6CActorFv @@ -215,8 +215,8 @@ lbl_801D66B8: /* 801D66CC 001D362C 38 21 00 10 */ addi r1, r1, 0x10 /* 801D66D0 001D3630 4E 80 00 20 */ blr -.global sub_801d66d4 -sub_801d66d4: +.global __dt__11CVisorFlareFv +__dt__11CVisorFlareFv: /* 801D66D4 001D3634 94 21 FF F0 */ stwu r1, -0x10(r1) /* 801D66D8 001D3638 7C 08 02 A6 */ mflr r0 /* 801D66DC 001D363C 90 01 00 14 */ stw r0, 0x14(r1) @@ -227,7 +227,7 @@ sub_801d66d4: /* 801D66F0 001D3650 41 82 00 20 */ beq lbl_801D6710 /* 801D66F4 001D3654 38 7E 00 04 */ addi r3, r30, 4 /* 801D66F8 001D3658 38 80 FF FF */ li r4, -1 -/* 801D66FC 001D365C 4B EF 70 BD */ bl sub_800cd7b8 +/* 801D66FC 001D365C 4B EF 70 BD */ bl "__dt__Q24rstl60vectorFv" /* 801D6700 001D3660 7F E0 07 35 */ extsh. r0, r31 /* 801D6704 001D3664 40 81 00 0C */ ble lbl_801D6710 /* 801D6708 001D3668 7F C3 F3 78 */ mr r3, r30 @@ -241,8 +241,8 @@ lbl_801D6710: /* 801D6724 001D3684 38 21 00 10 */ addi r1, r1, 0x10 /* 801D6728 001D3688 4E 80 00 20 */ blr -.global "__ct__17CScriptVisorFlareF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobRC9CVector3fQ211CVisorFlare10EBlendModebfffRCQ24rstl60vector" -"__ct__17CScriptVisorFlareF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobRC9CVector3fQ211CVisorFlare10EBlendModebfffRCQ24rstl60vector": +.global "__ct__17CScriptVisorFlareF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobRC9CVector3fQ211CVisorFlare10EBlendModebfffUiUiRCQ24rstl60vector" +"__ct__17CScriptVisorFlareF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobRC9CVector3fQ211CVisorFlare10EBlendModebfffUiUiRCQ24rstl60vector": /* 801D672C 001D368C 94 21 FE B0 */ stwu r1, -0x150(r1) /* 801D6730 001D3690 7C 08 02 A6 */ mflr r0 /* 801D6734 001D3694 90 01 01 54 */ stw r0, 0x154(r1) @@ -307,9 +307,9 @@ lbl_801D6710: /* 801D6820 001D3780 38 61 00 B8 */ addi r3, r1, 0xb8 /* 801D6824 001D3784 38 80 FF FF */ li r4, -1 /* 801D6828 001D3788 4B F4 02 25 */ bl __dt__10CModelDataFv -/* 801D682C 001D378C 3C 60 80 3E */ lis r3, lbl_803E5830@ha +/* 801D682C 001D378C 3C 60 80 3E */ lis r3, __vt__17CScriptVisorFlare@ha /* 801D6830 001D3790 FC 20 E8 90 */ fmr f1, f29 -/* 801D6834 001D3794 38 03 58 30 */ addi r0, r3, lbl_803E5830@l +/* 801D6834 001D3794 38 03 58 30 */ addi r0, r3, __vt__17CScriptVisorFlare@l /* 801D6838 001D3798 FC 40 F0 90 */ fmr f2, f30 /* 801D683C 001D379C FC 60 F8 90 */ fmr f3, f31 /* 801D6840 001D37A0 90 16 00 00 */ stw r0, 0(r22) @@ -319,7 +319,7 @@ lbl_801D6710: /* 801D6850 001D37B0 7F C7 F3 78 */ mr r7, r30 /* 801D6854 001D37B4 7F E8 FB 78 */ mr r8, r31 /* 801D6858 001D37B8 38 76 00 E8 */ addi r3, r22, 0xe8 -/* 801D685C 001D37BC 48 03 1A 7D */ bl "__ct__11CVisorFlareFQ211CVisorFlare10EBlendModebfffRCQ24rstl60vector" +/* 801D685C 001D37BC 48 03 1A 7D */ bl "__ct__11CVisorFlareFQ211CVisorFlare10EBlendModebfffUiUiRCQ24rstl60vector" /* 801D6860 001D37C0 38 00 00 01 */ li r0, 1 /* 801D6864 001D37C4 38 80 00 02 */ li r4, 2 /* 801D6868 001D37C8 98 16 01 1C */ stb r0, 0x11c(r22) diff --git a/configure.py b/configure.py index a487ceb9..ab813341 100755 --- a/configure.py +++ b/configure.py @@ -284,7 +284,7 @@ LIBS = [ "MetroidPrime/ScriptObjects/CFishCloud", ["MetroidPrime/CHealthInfo", True], "MetroidPrime/Player/CGameState", - "MetroidPrime/ScriptObjects/CScriptVisorFlare", + ["MetroidPrime/ScriptObjects/CScriptVisorFlare", False], "MetroidPrime/ScriptObjects/CScriptWorldTeleporter", "MetroidPrime/ScriptObjects/CScriptVisorGoo", "MetroidPrime/Enemies/CJellyZap", @@ -309,7 +309,7 @@ LIBS = [ "MetroidPrime/CMapUniverse", "MetroidPrime/Enemies/CThardusRockProjectile", "MetroidPrime/CInventoryScreen", - "MetroidPrime/CVisorFlare", + ["MetroidPrime/CVisorFlare", False], "MetroidPrime/Enemies/CFlaahgraPlants", "MetroidPrime/CWorldTransManager", ["MetroidPrime/ScriptObjects/CScriptMidi", False], diff --git a/include/Kyoto/Graphics/CGraphics.hpp b/include/Kyoto/Graphics/CGraphics.hpp index d70a0dcc..4d2f2e8b 100644 --- a/include/Kyoto/Graphics/CGraphics.hpp +++ b/include/Kyoto/Graphics/CGraphics.hpp @@ -120,6 +120,7 @@ public: static void StreamBegin(ERglPrimitive primitive); static void StreamColor(const CColor& color); static void StreamTexcoord(float u, float v); + static void StreamVertex(float, float, float); static void StreamVertex(const CVector3f& vtx); static void StreamEnd(); diff --git a/include/MetaRender/IRenderer.hpp b/include/MetaRender/IRenderer.hpp index d1ae816b..e3e07a81 100644 --- a/include/MetaRender/IRenderer.hpp +++ b/include/MetaRender/IRenderer.hpp @@ -31,6 +31,26 @@ public: virtual void PostRenderFogs(); virtual void SetModelMatrix(const CTransform4f& xf); virtual void AddParticleGen(const CParticleGen& gen); + virtual void AddParticleGen2(); + virtual void AddPlaneObject(); + virtual void AddDrawable(const void* obj, const CVector3f& pos, const CAABox& bounds, int mode, + IRenderer::EDrawableSorting sorting); + virtual void SetDrawableCallback(); + virtual void SetWorldViewpoint(); + virtual void SetPerspective1(); + virtual void SetPerspective2(); + virtual rstl::pair< CVector2f, CVector2f > SetViewportOrtho(bool centered, float znear, + float zfar); + virtual void SetClippingPlanes(); + virtual void SetViewport(); + virtual void SetDepthReadWrite(bool read, bool update); + virtual void SetBlendMode_AdditiveAlpha(); + virtual void SetBlendMode_AlphaBlended(); + virtual void SetBlendMode_NoColorWrite(); + virtual void SetBlendMode_ColorMultiply(); + virtual void SetBlendMode_InvertDst(); + virtual void SetBlendMode_InvertSrc(); + virtual void SetBlendMode_AdditiveDestColor(); }; namespace Renderer { diff --git a/include/MetroidPrime/CStateManager.hpp b/include/MetroidPrime/CStateManager.hpp index a8789778..dfe36221 100644 --- a/include/MetroidPrime/CStateManager.hpp +++ b/include/MetroidPrime/CStateManager.hpp @@ -97,6 +97,7 @@ public: kCFS_Max, }; + bool RenderLast(const TUniqueId&); void ResetEscapeSequenceTimer(float); void SendScriptMsg(TUniqueId uid, TEditorId target, EScriptObjectMessage msg, EScriptObjectState state); @@ -109,6 +110,9 @@ public: void AddObject(CEntity*); TUniqueId AllocateUniqueId(); + + void BuildNearList(TEntityList& nearList, const CVector3f& pos, const CVector3f& dir, float mag, const CMaterialFilter&, + const CActor*) const; void BuildNearList(TEntityList& nearList, const CAABox&, const CMaterialFilter&, const CActor*) const; bool RayCollideWorld(const CVector3f& start, const CVector3f& end, const TEntityList& nearList, @@ -169,6 +173,7 @@ public: float GetThermalColdScale1() const { return xf24_thermColdScale1; } float GetThermalColdScale2() const { return xf28_thermColdScale2; } + void SetThermalColdScale2(float s) { xf28_thermColdScale2 = s; } bool IsGeneratingObject() const { return xf94_26_generatingObject; } void SetIsGeneratingObject(bool gen) { xf94_26_generatingObject = gen; } @@ -198,6 +203,8 @@ public: bool GetWantsToEnterMessageScreen() const { return xf90_deferredTransition == kSMT_MessageScreen; } + + EThermalDrawFlag GetThermalDrawFlag() const { return xf34_thermalFlag; } void SetLastTriggerId(TUniqueId uid) { xf74_lastTrigger = uid; } TUniqueId GetLastTriggerId() const { return xf74_lastTrigger; } diff --git a/include/MetroidPrime/CVisorFlare.hpp b/include/MetroidPrime/CVisorFlare.hpp new file mode 100644 index 00000000..3b603392 --- /dev/null +++ b/include/MetroidPrime/CVisorFlare.hpp @@ -0,0 +1,69 @@ +#ifndef _CVISORFLARE +#define _CVISORFLARE + +#include "Kyoto/TToken.hpp" +#include "Kyoto/Graphics/CColor.hpp" + +#include "rstl/vector.hpp" +#include "rstl/optional_object.hpp" + +class CTexture; +class CStateManager; +class CVector3f; +class CActor; + +class CVisorFlare { +public: + enum EBlendMode { + kBM_Additive = 0, + kBM_Blend = 1, + }; + class CFlareDef { + mutable TToken x0_tex; + float x8_pos; + float xc_scale; + CColor x10_color; + + public: + // CFlareDef() = default; + // CFlareDef(const CFlareDef& other) + // : x0_tex(other.x0_tex) + // , x8_pos(other.x8_pos) + // , xc_scale(other.xc_scale) + // , x10_color(other.x10_color) + // {} + CFlareDef(const TToken& tex, float pos, float scale, uint color); + + TToken& GetTexture() const { return x0_tex; } + CColor GetColor() const { return x10_color; } + float GetPosition() const { return x8_pos; } + float GetScale() const { return xc_scale; } + }; + +private: + EBlendMode x0_blendMode; + rstl::vector x4_flareDefs; + bool x14_b1; + float x18_f1; + float x1c_f2; + float x20_f3; + float x24_; + float x28_; + int x2c_w1; + int x30_w2; + + void SetupRenderState(const CStateManager& mgr) const; + void ResetTevSwapMode(const CStateManager& mgr) const; + void DrawDirect(const CColor& color, float f1, float f2) const; + void DrawStreamed(const CColor& color, float f1, float f2) const; + +public: + CVisorFlare(EBlendMode blendMode, bool, float, float, float, uint, uint, const rstl::vector& flares); + ~CVisorFlare() {} + + void Update(float dt, const CVector3f& pos, const CActor* act, CStateManager& mgr); + void Render(const CVector3f& pos, const CStateManager& mgr) const; + static rstl::optional_object LoadFlareDef(CInputStream& in); +}; + +#endif // _CVISORFLARE diff --git a/include/MetroidPrime/ScriptObjects/CScriptVisorFlare.hpp b/include/MetroidPrime/ScriptObjects/CScriptVisorFlare.hpp new file mode 100644 index 00000000..20266552 --- /dev/null +++ b/include/MetroidPrime/ScriptObjects/CScriptVisorFlare.hpp @@ -0,0 +1,26 @@ +#ifndef _CSCRIPTVISORFLARE +#define _CSCRIPTVISORFLARE + +#include "MetroidPrime/CActor.hpp" + +#include "MetroidPrime/CVisorFlare.hpp" + +class CScriptVisorFlare : public CActor { + CVisorFlare xe8_flare; + bool x11c_notInRenderLast; + +public: + CScriptVisorFlare(TUniqueId uid, const rstl::string& name, const CEntityInfo& info, bool active, + const CVector3f& pos, CVisorFlare::EBlendMode blendMode, bool, float, float, float, uint, uint, + const rstl::vector& flares); + ~CScriptVisorFlare(); + + void Accept(IVisitor& visitor) override; + void Think(float, CStateManager& stateMgr) override; + void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override; + void PreRender(CStateManager&, const CFrustumPlanes&) override; + void AddToRenderer(const CFrustumPlanes&, const CStateManager&) const override; + void Render(const CStateManager&) const override; +}; + +#endif // _CSCRIPTVISORFLARE diff --git a/src/MetroidPrime/CVisorFlare.cpp b/src/MetroidPrime/CVisorFlare.cpp new file mode 100644 index 00000000..5a8cb9e6 --- /dev/null +++ b/src/MetroidPrime/CVisorFlare.cpp @@ -0,0 +1,264 @@ +#include "MetroidPrime/CVisorFlare.hpp" + +#include "MetroidPrime/CStateManager.hpp" +#include "MetroidPrime/Cameras/CCameraManager.hpp" +#include "MetroidPrime/Cameras/CGameCamera.hpp" +#include "MetroidPrime/Player/CPlayer.hpp" +#include "MetroidPrime/Player/CPlayerState.hpp" + +#include "Collision/CRayCastResult.hpp" + +#include "MetaRender/CCubeRenderer.hpp" + +#include "Kyoto/Graphics/CGX.hpp" +#include "Kyoto/Graphics/CGraphics.hpp" +#include "Kyoto/Graphics/CTexture.hpp" +#include "Kyoto/Math/CloseEnough.hpp" +#include "Kyoto/Streams/CInputStream.hpp" + +#include "dolphin/gx.h" + +#include "math.h" +#include "rstl/math.hpp" + +CVisorFlare::CFlareDef::CFlareDef(const TToken< CTexture >& tex, float pos, float scale, uint color) +: x0_tex(tex), x8_pos(pos), xc_scale(scale), x10_color(color) { + x0_tex.Lock(); +} + +rstl::optional_object< CVisorFlare::CFlareDef > CVisorFlare::LoadFlareDef(CInputStream& in) { + uint propCount = in.ReadLong(); + if (propCount != 4) + return rstl::optional_object_null(); + + CAssetId txtrId = in.Get< CAssetId >(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + CColor color = in.Get< CColor >(); + if (txtrId == kInvalidAssetId) + return rstl::optional_object_null(); + + TToken< CTexture > tex = gpSimplePool->GetObj(SObjectTag('TXTR', txtrId)); + + return CFlareDef(tex, f1, f2, color.GetColor_u32()); +} + +CVisorFlare::CVisorFlare(EBlendMode blendMode, bool b1, float f1, float f2, float f3, uint w1, + uint w2, const rstl::vector< CFlareDef >& flares) +: x0_blendMode(blendMode) +, x4_flareDefs(flares) +, x14_b1(b1) +, x18_f1(rstl::max_val(1.0E-4f, f1)) +, x1c_f2(f2) +, x20_f3(f3) +, x24_(0.f) +, x28_(0.f) +, x2c_w1(w1) +, x30_w2(w2) {} + +void CVisorFlare::Update(float dt, const CVector3f& pos, const CActor* act, CStateManager& mgr) { + const CPlayerState::EPlayerVisor visor = mgr.GetPlayerState()->GetCurrentVisor(); + + if ((visor == CPlayerState::kPV_Combat || (x2c_w1 != 1 && visor == CPlayerState::kPV_Thermal)) && + mgr.GetPlayer()->GetMorphballTransitionState() == CPlayer::kMS_Unmorphed) { + + CVector3f camPos = mgr.GetCameraManager()->GetCurrentCamera(mgr)->GetTranslation(); + CVector3f camDiff = pos - camPos; + const float mag = camDiff.Magnitude(); + camDiff = camDiff * (1.f / mag); + + bool rayCastIsValid; + + { + const CMaterialFilter& nearMaterialList = + CMaterialFilter::MakeInclude(CMaterialList(kMT_Occluder)); + TEntityList nearVec; + mgr.BuildNearList(nearVec, camPos, camDiff, mag, nearMaterialList, act); + + const CMaterialFilter& rayMaterialList = CMaterialFilter::MakeIncludeExclude( + CMaterialList(kMT_Solid), CMaterialList(kMT_SeeThrough)); + TUniqueId id(kInvalidUniqueId); + rayCastIsValid = + mgr.RayWorldIntersection(id, camPos, camDiff, mag, rayMaterialList, nearVec).IsValid(); + } + + if (!rayCastIsValid) { + x28_ -= dt; + } else { + x28_ += dt; + } + x28_ = rstl::max_val(x18_f1, rstl::min_val(x28_, 0.f)); + + const CGameCamera* curCam = mgr.GetCameraManager()->GetCurrentCamera(mgr); + const CVector3f cameraForward = curCam->GetTransform().GetForward(); + x24_ = 1.f - (x28_ / x18_f1); + + const CVector3f dir = (pos - curCam->GetTranslation()).AsNormalized(); + float dot = CVector3f::Dot(dir, cameraForward); + x24_ *= rstl::max_val(0.f, 1.f - (x1c_f2 * 4.f * (1.f - dot))); + + if (x2c_w1 == 2) { + mgr.SetThermalColdScale2(mgr.GetThermalColdScale2() + x24_); + } + } +} + +void CVisorFlare::Render(const CVector3f& inPos, const CStateManager& mgr) const { + if (close_enough(x28_, x18_f1, 1.0E-5f) || + mgr.GetPlayer()->GetMorphballTransitionState() != CPlayer::kMS_Unmorphed) { + return; + } + + switch (mgr.GetPlayerState()->GetActiveVisor(mgr)) { + case CPlayerState::kPV_Combat: + if (x30_w2 != 0) + return; + break; + case CPlayerState::kPV_Thermal: + if (x2c_w1 != 0) + return; + break; + default: + return; + } + + CGraphics::DisableAllLights(); + gpRender->SetDepthReadWrite(false, false); + const CGameCamera* cam = mgr.GetCameraManager()->GetCurrentCamera(mgr); + CVector3f camPos = cam->GetTranslation(); + CVector3f inPosCopy(inPos); + + CTransform4f viewMatrix = CGraphics::GetViewMatrix(); + const CVector3f invPos = viewMatrix.GetInverse() * inPosCopy; + const CVector3f invPos2 = viewMatrix * CVector3f(-invPos.GetX(), invPos.GetY(), -invPos.GetZ()); + CVector3f camFront = cam->GetTransform().GetForward(); + if (!close_enough(x24_, 0.f, 1.0E-5f)) { + float acos = 0.f; + if (!close_enough(x20_f3, 0.f, 1.0E-5f)) { + CVector3f camDist(CVector3f(inPosCopy.GetX() - camPos.GetX(), inPosCopy.GetY() - camPos.GetY(), 0.f).AsNormalized()); + CVector3f camDir(CVector3f(camFront.GetX(), camFront.GetY(), 0.f).AsNormalized()); + acos = CMath::ArcCosineR(CVector3f::Dot(camDist, camDir)); + if (camDist.GetX() * camDir.GetY() - camDir.GetX() * camDist.GetY() < 0.f) { + acos = -acos; + } + acos = x20_f3 * acos; + } + SetupRenderState(mgr); + for (rstl::vector< CFlareDef >::const_iterator item = x4_flareDefs.begin(); + item != x4_flareDefs.end(); ++item) { + + const float itemPos = item->GetPosition(); + const CVector3f origin = inPosCopy * (1.f - itemPos) + invPos2 * itemPos; + CTransform4f modelMatrix(CTransform4f::LookAt(origin, camPos)); + gpRender->SetModelMatrix(modelMatrix); + float scale = 0.5f * x24_ * item->GetScale(); + if (x14_b1) { + CVector3f dist = origin - camPos; + if (dist.CanBeNormalized()) { + scale *= dist.Magnitude(); + } + } + if (item->GetTexture().IsLoaded()) { + item->GetTexture()->Load(GX_TEXMAP0, CTexture::kCM_Repeat); + float f1; + if (close_enough(acos, 0.f)) { + f1 = 0.f; + } else { + f1 = scale * sinf(acos); + scale *= cosf(acos); + } + if (mgr.GetThermalDrawFlag() == kTD_Hot) { + DrawDirect(item->GetColor(), f1, scale); + } else { + DrawStreamed(item->GetColor(), f1, scale); + } + } + } + ResetTevSwapMode(mgr); + } +} + +void CVisorFlare::DrawDirect(const CColor& color, float f1, float f2) const { + // Giant TODO + // CColor kcolor = color; + // kcolor.a() *= x24_; // TODO i think this is wrong + GXColor gxColor; + CGX::SetTevKColor(GX_KCOLOR0, gxColor); + CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4); + // GXPosition3f32(f1 - f2, 0.f, f2 + f1); + // GXTexCoord2f32(0.f, 1.f); + // GXPosition3f32(f2 + f1, 0.f, f2 - f1); + // GXTexCoord2f32(1.f, 1.f); + // GXPosition3f32(-(f2 - f1), 0.f, -(f2 - f1)); + // GXTexCoord2f32(0.f, 0.f); + // GXPosition3f32(-f1 + f2, 0.f, -f2 - f1); + // GXTexCoord2f32(1.f, 0.f); + CGX::End(); +} + +void CVisorFlare::DrawStreamed(const CColor& color, float f1, float f2) const { + CGraphics::StreamBegin(kP_TriangleStrip); + float a = color.GetAlpha(); // TODO: incorrect + CGraphics::StreamColor(CColor(color, a * x24_)); + CGraphics::StreamTexcoord(0.f, 1.f); + CGraphics::StreamVertex(f1 - f2, 0.f, f2 + f1); + CGraphics::StreamTexcoord(1.f, 1.f); + CGraphics::StreamVertex(f1 + f2, 0.f, f2 - f1); + CGraphics::StreamTexcoord(0.f, 0.f); + CGraphics::StreamVertex(-(f1 + f2), 0.f, -(f2 - f1)); + CGraphics::StreamTexcoord(1.f, 0.f); + CGraphics::StreamVertex(-f1 + f2, 0.f, -f2 - f1); + CGraphics::StreamEnd(); +} + +void CVisorFlare::SetupRenderState(const CStateManager& mgr) const { + if (mgr.GetThermalDrawFlag() == kTD_Hot) { + CGX::SetBlendMode(GX_BM_BLEND, GX_BL_ONE, GX_BL_ONE, GX_LO_CLEAR); + CGX::SetStandardTevColorAlphaOp(GX_TEVSTAGE0); + CGX::SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + CGX::SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_OR, GX_ALWAYS, 0); + GXSetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP0, GX_TEV_SWAP1); + CGX::SetTevKColorSel(GX_TEVSTAGE0, GX_TEV_KCSEL_K0_A); + CGX::SetTevKAlphaSel(GX_TEVSTAGE0, GX_TEV_KASEL_K0_A); + CGX::SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_TEXC, GX_CC_KONST, GX_CC_ZERO); + CGX::SetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_TEXA, GX_CA_KONST, GX_CA_ZERO); + CGX::SetNumTexGens(1); + CGX::SetNumChans(0); + CGX::SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY, false, GX_PTIDENTITY); + switch (x0_blendMode) { + case kBM_Additive: + CGX::SetNumTevStages(1); + break; + case kBM_Blend: + CGX::SetStandardTevColorAlphaOp(GX_TEVSTAGE1); + CGX::SetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + CGX::SetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_TEXA, GX_CC_CPREV, GX_CC_ZERO); + CGX::SetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_TEXA, GX_CA_APREV, GX_CA_ZERO); + CGX::SetNumTevStages(2); + break; + } + static const GXVtxDescList vtxDescList[3] = { + {GX_VA_POS, GX_DIRECT}, + {GX_VA_TEX0, GX_DIRECT}, + {GX_VA_NULL, GX_NONE}, + }; + CGX::SetVtxDescv(vtxDescList); + } else { + switch (x0_blendMode) { + case kBM_Additive: + gpRender->SetBlendMode_AdditiveAlpha(); + break; + case kBM_Blend: + gpRender->SetBlendMode_AlphaBlended(); + break; + } + CGraphics::SetTevOp(kTS_Stage0, CGraphics::kEnvModulate); + CGraphics::SetTevOp(kTS_Stage1, CGraphics::kEnvPassthru); + } +} + +void CVisorFlare::ResetTevSwapMode(const CStateManager& mgr) const { + if (mgr.GetThermalDrawFlag() == kTD_Hot) { + GXSetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP0, GX_TEV_SWAP0); + } +} diff --git a/src/MetroidPrime/ScriptObjects/CScriptVisorFlare.cpp b/src/MetroidPrime/ScriptObjects/CScriptVisorFlare.cpp new file mode 100644 index 00000000..c426376a --- /dev/null +++ b/src/MetroidPrime/ScriptObjects/CScriptVisorFlare.cpp @@ -0,0 +1,41 @@ +#include "MetroidPrime/ScriptObjects/CScriptVisorFlare.hpp" + +#include "MetroidPrime/CActorParameters.hpp" +#include "MetroidPrime/CStateManager.hpp" +#include "MetroidPrime/Player/CPlayer.hpp" + +CScriptVisorFlare::CScriptVisorFlare(TUniqueId uid, const rstl::string& name, const CEntityInfo& info, bool active, + const CVector3f& pos, CVisorFlare::EBlendMode blendMode, bool b1, float f1, + float f2, float f3, uint w1, uint w2, const rstl::vector& flares) +: CActor(uid, active, name, info, CTransform4f::Translate(pos), CModelData::CModelDataNull(), + CMaterialList(kMT_NoStepLogic), CActorParameters::None(), kInvalidUniqueId) +, xe8_flare(blendMode, b1, f1, f2, f3, w1, w2, flares) +, x11c_notInRenderLast(true) { + xe6_27_thermalVisorFlags = kTF_Hot; +} + +CScriptVisorFlare::~CScriptVisorFlare() {} + +void CScriptVisorFlare::Accept(IVisitor& visitor) { visitor.Visit(*this); } + +void CScriptVisorFlare::Think(float dt, CStateManager& stateMgr) { + if (GetActive()) { + xe8_flare.Update(dt, GetTranslation(), this, stateMgr); + } +} + +void CScriptVisorFlare::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) { + CActor::AcceptScriptMsg(msg, objId, stateMgr); +} + +void CScriptVisorFlare::PreRender(CStateManager& stateMgr, const CFrustumPlanes&) { + x11c_notInRenderLast = !stateMgr.RenderLast(GetUniqueId()); +} + +void CScriptVisorFlare::AddToRenderer(const CFrustumPlanes&, const CStateManager& stateMgr) const { + if (x11c_notInRenderLast) { + EnsureRendered(stateMgr, stateMgr.GetPlayer()->GetTranslation(), GetSortingBounds(stateMgr)); + } +} + +void CScriptVisorFlare::Render(const CStateManager& stateMgr) const { xe8_flare.Render(GetTranslation(), stateMgr); }