From 904e12970d3bdb5013da95315153117af1e9fef2 Mon Sep 17 00:00:00 2001 From: flyngmt <266733517+flyngmt@users.noreply.github.com> Date: Thu, 8 Oct 2026 16:59:18 +0300 Subject: [PATCH 1/3] Split d_skyNP --- config/RUUE01_00/config.yml | 1 + config/RUUE01_00/d_skyNP/splits.txt | 13 +++++++++++++ config/RUUE01_00/d_skyNP/symbols.txt | 3 ++- configure.py | 9 +++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/config/RUUE01_00/config.yml b/config/RUUE01_00/config.yml index 38ae6a0..68b4f79 100644 --- a/config/RUUE01_00/config.yml +++ b/config/RUUE01_00/config.yml @@ -631,6 +631,7 @@ modules: name: d_skyNP symbols: config/RUUE01_00/d_skyNP/symbols.txt splits: config/RUUE01_00/d_skyNP/splits.txt + force_active: [__global_destructor_chain] # the module runtime's chain: the REL's first 4 bytes of .bss - object: files/rels/d_sky_auroraNP.rel hash: 8ac2dd16d6f0a4a6d9239411fdb20cb24f9f61ad name: d_sky_auroraNP diff --git a/config/RUUE01_00/d_skyNP/splits.txt b/config/RUUE01_00/d_skyNP/splits.txt index 531cd64..6e7e2fe 100644 --- a/config/RUUE01_00/d_skyNP/splits.txt +++ b/config/RUUE01_00/d_skyNP/splits.txt @@ -5,3 +5,16 @@ Sections: .rodata type:rodata align:8 .data type:data align:8 .bss type:bss align:8 + +d_skyNP/global_destructor_chain.c: + .bss start:0x00000000 end:0x00000004 + +d_skyNP/rel_init.cpp: + .text start:0x00000000 end:0x0000005C + +d_skyNP/d_sky.cpp: + .text start:0x0000005C end:0x00001AB8 + .ctors start:0x00000000 end:0x00000004 + .rodata start:0x00000000 end:0x000000AC + .data start:0x00000000 end:0x000001B8 + .bss start:0x00000008 end:0x0000001C diff --git a/config/RUUE01_00/d_skyNP/symbols.txt b/config/RUUE01_00/d_skyNP/symbols.txt index 3418795..e406750 100644 --- a/config/RUUE01_00/d_skyNP/symbols.txt +++ b/config/RUUE01_00/d_skyNP/symbols.txt @@ -14,7 +14,7 @@ fn_120_FAC = .text:0x00000FAC; // type:function size:0x10C fn_120_10B8 = .text:0x000010B8; // type:function size:0x70 fn_120_1128 = .text:0x00001128; // type:function size:0x48 fn_120_1170 = .text:0x00001170; // type:function size:0x718 -fn_120_1888 = .text:0x00001888; // type:function size:0xA0 +__sinit_\d_sky_cpp = .text:0x00001888; // type:function size:0xA0 scope:local fn_120_1928 = .text:0x00001928; // type:function size:0x58 fn_120_1980 = .text:0x00001980; // type:function size:0x4 fn_120_1984 = .text:0x00001984; // type:function size:0x4 @@ -60,4 +60,5 @@ lbl_120_data_18C = .data:0x0000018C; // type:object size:0xC lbl_120_data_198 = .data:0x00000198; // type:object size:0x8 lbl_120_data_1A0 = .data:0x000001A0; // type:object size:0xF data:string lbl_120_data_1B0 = .data:0x000001B0; // type:object size:0x8 +__global_destructor_chain = .bss:0x00000000; // type:object size:0x4 scope:global lbl_120_bss_8 = .bss:0x00000008; // type:object size:0x14 data:byte diff --git a/configure.py b/configure.py index 470a463..fa04c62 100755 --- a/configure.py +++ b/configure.py @@ -1107,6 +1107,15 @@ def MatchingFor(*versions): Object(Matching, "d_fish_fieldNP/d_fish_field.cpp", extra_cflags=["-sym on"]), ], ), + Rel( + "d_skyNP", + [ + Object(Matching, "d_skyNP/rel_init.cpp", source="runtime/rel_init.cpp"), + Object(Matching, "d_skyNP/global_destructor_chain.c", source="runtime/global_destructor_chain.c", + cflags=[*cflags_runtime, "-sdata 0", "-sdata2 0"]), + Object(NonMatching, "d_skyNP/d_sky.cpp", extra_cflags=["-sym on"]), + ], + ), ] From 85d97ae2485d3772808bd1c3c34b6456527260da Mon Sep 17 00:00:00 2001 From: flyngmt <266733517+flyngmt@users.noreply.github.com> Date: Thu, 8 Oct 2026 17:13:00 +0300 Subject: [PATCH 2/3] Map d_skyNP symbols --- config/RUUE01_00/d_skyNP/symbols.txt | 68 +++++++++++++++------------- include/game/game/d_sky.hpp | 8 ++-- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/config/RUUE01_00/d_skyNP/symbols.txt b/config/RUUE01_00/d_skyNP/symbols.txt index e406750..97ebeb3 100644 --- a/config/RUUE01_00/d_skyNP/symbols.txt +++ b/config/RUUE01_00/d_skyNP/symbols.txt @@ -1,34 +1,34 @@ _prolog = .text:0x00000000; // type:function size:0x2C scope:global _epilog = .text:0x0000002C; // type:function size:0x2C scope:global _unresolved = .text:0x00000058; // type:function size:0x4 scope:global -fn_120_5C = .text:0x0000005C; // type:function size:0x30 -fn_120_8C = .text:0x0000008C; // type:function size:0x2E4 -fn_120_370 = .text:0x00000370; // type:function size:0x14C -fn_120_4BC = .text:0x000004BC; // type:function size:0x32C -fn_120_7E8 = .text:0x000007E8; // type:function size:0x80 -fn_120_868 = .text:0x00000868; // type:function size:0x610 -fn_120_E78 = .text:0x00000E78; // type:function size:0x110 -fn_120_F88 = .text:0x00000F88; // type:function size:0x20 +dSky_c_classInit__Fv = .text:0x0000005C; // type:function size:0x30 +__ct__6dSky_cFv = .text:0x0000008C; // type:function size:0x2E4 +__dt__6dSky_cFv = .text:0x00000370; // type:function size:0x14C +create__6dSky_cFv = .text:0x000004BC; // type:function size:0x32C +execute__6dSky_cFv = .text:0x000007E8; // type:function size:0x80 +draw__6dSky_cFv = .text:0x00000868; // type:function size:0x610 +doDelete__6dSky_cFv = .text:0x00000E78; // type:function size:0x110 +setFireworksBrightness__6dSky_cFf = .text:0x00000F88; // type:function size:0x20 fn_120_FA8 = .text:0x00000FA8; // type:function size:0x4 fn_120_FAC = .text:0x00000FAC; // type:function size:0x10C fn_120_10B8 = .text:0x000010B8; // type:function size:0x70 fn_120_1128 = .text:0x00001128; // type:function size:0x48 fn_120_1170 = .text:0x00001170; // type:function size:0x718 __sinit_\d_sky_cpp = .text:0x00001888; // type:function size:0xA0 scope:local -fn_120_1928 = .text:0x00001928; // type:function size:0x58 -fn_120_1980 = .text:0x00001980; // type:function size:0x4 -fn_120_1984 = .text:0x00001984; // type:function size:0x4 -fn_120_1988 = .text:0x00001988; // type:function size:0x8 -fn_120_1990 = .text:0x00001990; // type:function size:0x1C -fn_120_19AC = .text:0x000019AC; // type:function size:0x40 -fn_120_19EC = .text:0x000019EC; // type:function size:0x5C -fn_120_1A48 = .text:0x00001A48; // type:function size:0x48 -fn_120_1A90 = .text:0x00001A90; // type:function size:0xC -fn_120_1A9C = .text:0x00001A9C; // type:function size:0x8 -fn_120_1AA4 = .text:0x00001AA4; // type:function size:0x4 -fn_120_1AA8 = .text:0x00001AA8; // type:function size:0x4 -fn_120_1AAC = .text:0x00001AAC; // type:function size:0x4 -fn_120_1AB0 = .text:0x00001AB0; // type:function size:0x8 +__dt__Q23m3d6proc_cFv = .text:0x00001928; // type:function size:0x58 scope:weak +drawXlu__Q23m3d6proc_cFv = .text:0x00001980; // type:function size:0x4 scope:weak +drawOpa__Q23m3d6proc_cFv = .text:0x00001984; // type:function size:0x4 scope:weak +getType__Q23m3d6proc_cCFv = .text:0x00001988; // type:function size:0x8 scope:weak +fn_120_1990 = .text:0x00001990; // type:function size:0x1C scope:weak +fn_120_19AC = .text:0x000019AC; // type:function size:0x40 scope:weak +__dt__Q24dDvd11brresBank_cFv = .text:0x000019EC; // type:function size:0x5C scope:weak +onLoaded__Q24dDvd11brresBank_cFv = .text:0x00001A48; // type:function size:0x48 scope:weak +fn_120_1A90 = .text:0x00001A90; // type:function size:0xC scope:weak +createHeap__6dSky_cFv = .text:0x00001A9C; // type:function size:0x8 scope:weak +deleteReady__6dSky_cFv = .text:0x00001AA4; // type:function size:0x4 scope:weak +postDraw__6dSky_cFQ27fBase_c12MAIN_STATE_e = .text:0x00001AA8; // type:function size:0x4 scope:weak +postExecute__6dSky_cFQ27fBase_c12MAIN_STATE_e = .text:0x00001AAC; // type:function size:0x4 scope:weak +preCreate__6dSky_cFv = .text:0x00001AB0; // type:function size:0x8 scope:weak _ctors = .ctors:0x00000000; // type:label scope:global _dtors = .dtors:0x00000000; // type:label scope:global lbl_120_rodata_0 = .rodata:0x00000000; // type:object size:0x4 align:4 data:float @@ -37,28 +37,32 @@ lbl_120_rodata_14 = .rodata:0x00000014; // type:object size:0x14 align:4 data:fl lbl_120_rodata_28 = .rodata:0x00000028; // type:object size:0x10 align:8 data:double lbl_120_rodata_38 = .rodata:0x00000038; // type:object size:0xC align:4 data:float lbl_120_rodata_44 = .rodata:0x00000044; // type:object size:0x68 align:4 data:float -lbl_120_data_0 = .data:0x00000000; // type:object size:0x48 +g_profile_SKY = .data:0x00000000; // type:object size:0x8 +lbl_120_data_8 = .data:0x00000008; // type:object size:0x14 data:string +lbl_120_data_1C = .data:0x0000001C; // type:object size:0x12 data:string +lbl_120_data_30 = .data:0x00000030; // type:object size:0x13 data:string lbl_120_data_48 = .data:0x00000048; // type:object size:0x8 data:string lbl_120_data_50 = .data:0x00000050; // type:object size:0x6 data:string -lbl_120_data_58 = .data:0x00000058; // type:object size:0x50 +__vt__6dSky_c = .data:0x00000058; // type:object size:0x50 lbl_120_data_A8 = .data:0x000000A8; // type:object size:0x7 data:string lbl_120_data_B0 = .data:0x000000B0; // type:object size:0x10 -lbl_120_data_C0 = .data:0x000000C0; // type:object size:0x8 -lbl_120_data_C8 = .data:0x000000C8; // type:object size:0x14 +__RTTI__6dSky_c = .data:0x000000C0; // type:object size:0x8 +__vt__Q24dDvd11brresBank_c = .data:0x000000C8; // type:object size:0x14 lbl_120_data_DC = .data:0x000000DC; // type:object size:0x12 data:string lbl_120_data_F0 = .data:0x000000F0; // type:object size:0x18 -lbl_120_data_108 = .data:0x00000108; // type:object size:0x8 +__RTTI__Q24dDvd11brresBank_c = .data:0x00000108; // type:object size:0x8 lbl_120_data_110 = .data:0x00000110; // type:object size:0xD data:string lbl_120_data_120 = .data:0x00000120; // type:object size:0x10 -lbl_120_data_130 = .data:0x00000130; // type:object size:0x8 +__RTTI__Q24dDvd6bank_c = .data:0x00000130; // type:object size:0x8 lbl_120_data_138 = .data:0x00000138; // type:object size:0xF data:string -lbl_120_data_148 = .data:0x00000148; // type:object size:0x8 +__RTTI__Q24dDvd8loader_c = .data:0x00000148; // type:object size:0x8 lbl_120_data_150 = .data:0x00000150; // type:object size:0x8 data:string -lbl_120_data_158 = .data:0x00000158; // type:object size:0x28 +__RTTI__7fBase_c = .data:0x00000158; // type:object size:0x8 +__vt__Q23m3d6proc_c = .data:0x00000160; // type:object size:0x20 lbl_120_data_180 = .data:0x00000180; // type:object size:0xC data:string lbl_120_data_18C = .data:0x0000018C; // type:object size:0xC -lbl_120_data_198 = .data:0x00000198; // type:object size:0x8 +__RTTI__Q23m3d6proc_c = .data:0x00000198; // type:object size:0x8 lbl_120_data_1A0 = .data:0x000001A0; // type:object size:0xF data:string -lbl_120_data_1B0 = .data:0x000001B0; // type:object size:0x8 +__RTTI__Q23m3d9scnLeaf_c = .data:0x000001B0; // type:object size:0x8 __global_destructor_chain = .bss:0x00000000; // type:object size:0x4 scope:global lbl_120_bss_8 = .bss:0x00000008; // type:object size:0x14 data:byte diff --git a/include/game/game/d_sky.hpp b/include/game/game/d_sky.hpp index ccd4d41..977bf12 100644 --- a/include/game/game/d_sky.hpp +++ b/include/game/game/d_sky.hpp @@ -1,15 +1,15 @@ #pragma once -// The sky actor (RTTI dSky_c). Its code is in the d_skyNP REL, which is not split yet. +// The sky actor (RTTI dSky_c, profile 0xAA). Source: src/d_skyNP/d_sky.cpp (not decompiled yet). -#include +#include #include -class dSky_c : public dBase_c { +class dSky_c : public fBase_c { public: virtual void setFireworksBrightness(f32 brightness); // vtable 0x4C - u8 _pad[0x568 - sizeof(dBase_c)]; + u8 _pad[0x568 - sizeof(fBase_c)]; /* 0x568 */ nw4r::math::VEC3 mPos; }; From 2aaafbec6d6cb46c675c0729f36bf143c76d9420 Mon Sep 17 00:00:00 2001 From: flyngmt <266733517+flyngmt@users.noreply.github.com> Date: Thu, 8 Oct 2026 19:36:06 +0300 Subject: [PATCH 3/3] Link d_sky --- config/RUUE01_00/d_skyNP/symbols.txt | 19 +- config/RUUE01_00/symbols.txt | 28 +-- configure.py | 2 +- include/game/game/d_camera.hpp | 14 ++ include/game/game/d_sky.hpp | 56 ++++- include/game/game/d_star.hpp | 2 + include/game/game/d_star_draw.hpp | 50 ++++ include/game/mLib/m_3d.hpp | 5 +- include/game/mLib/m_angle.hpp | 3 + include/game/mLib/m_mtx.hpp | 9 +- src/d_fish_fieldNP/d_fish_field.cpp | 3 +- src/d_skyNP/d_sky.cpp | 355 +++++++++++++++++++++++++++ src/dol/game/d_dsn.cpp | 3 +- src/dol/game/d_rec_bank.cpp | 3 +- 14 files changed, 512 insertions(+), 40 deletions(-) create mode 100644 include/game/game/d_camera.hpp create mode 100644 include/game/game/d_star_draw.hpp create mode 100644 src/d_skyNP/d_sky.cpp diff --git a/config/RUUE01_00/d_skyNP/symbols.txt b/config/RUUE01_00/d_skyNP/symbols.txt index 97ebeb3..c2e061c 100644 --- a/config/RUUE01_00/d_skyNP/symbols.txt +++ b/config/RUUE01_00/d_skyNP/symbols.txt @@ -8,22 +8,21 @@ create__6dSky_cFv = .text:0x000004BC; // type:function size:0x32C execute__6dSky_cFv = .text:0x000007E8; // type:function size:0x80 draw__6dSky_cFv = .text:0x00000868; // type:function size:0x610 doDelete__6dSky_cFv = .text:0x00000E78; // type:function size:0x110 -setFireworksBrightness__6dSky_cFf = .text:0x00000F88; // type:function size:0x20 -fn_120_FA8 = .text:0x00000FA8; // type:function size:0x4 -fn_120_FAC = .text:0x00000FAC; // type:function size:0x10C -fn_120_10B8 = .text:0x000010B8; // type:function size:0x70 -fn_120_1128 = .text:0x00001128; // type:function size:0x48 -fn_120_1170 = .text:0x00001170; // type:function size:0x718 +setFireworksBrightness__6dSky_cFf = .text:0x00000F88; // type:function size:0x24 +getMoonAge__FPC7dTime_c = .text:0x00000FAC; // type:function size:0x10C +getOffsetY__Fv = .text:0x000010B8; // type:function size:0x70 +getOffsetZ__Fv = .text:0x00001128; // type:function size:0x48 +calc__6dSky_cFv = .text:0x00001170; // type:function size:0x718 __sinit_\d_sky_cpp = .text:0x00001888; // type:function size:0xA0 scope:local __dt__Q23m3d6proc_cFv = .text:0x00001928; // type:function size:0x58 scope:weak drawXlu__Q23m3d6proc_cFv = .text:0x00001980; // type:function size:0x4 scope:weak drawOpa__Q23m3d6proc_cFv = .text:0x00001984; // type:function size:0x4 scope:weak getType__Q23m3d6proc_cCFv = .text:0x00001988; // type:function size:0x8 scope:weak -fn_120_1990 = .text:0x00001990; // type:function size:0x1C scope:weak -fn_120_19AC = .text:0x000019AC; // type:function size:0x40 scope:weak +__ct__Q211dStarDraw_c6star_cFv = .text:0x00001990; // type:function size:0x1C scope:weak +__dt__Q211dStarDraw_c6star_cFv = .text:0x000019AC; // type:function size:0x40 scope:weak __dt__Q24dDvd11brresBank_cFv = .text:0x000019EC; // type:function size:0x5C scope:weak onLoaded__Q24dDvd11brresBank_cFv = .text:0x00001A48; // type:function size:0x48 scope:weak -fn_120_1A90 = .text:0x00001A90; // type:function size:0xC scope:weak +getViewCenter__Fv_PQ34nw4r4math4VEC3 = .text:0x00001A90; // type:function size:0xC scope:weak createHeap__6dSky_cFv = .text:0x00001A9C; // type:function size:0x8 scope:weak deleteReady__6dSky_cFv = .text:0x00001AA4; // type:function size:0x4 scope:weak postDraw__6dSky_cFQ27fBase_c12MAIN_STATE_e = .text:0x00001AA8; // type:function size:0x4 scope:weak @@ -65,4 +64,4 @@ __RTTI__Q23m3d6proc_c = .data:0x00000198; // type:object size:0x8 lbl_120_data_1A0 = .data:0x000001A0; // type:object size:0xF data:string __RTTI__Q23m3d9scnLeaf_c = .data:0x000001B0; // type:object size:0x8 __global_destructor_chain = .bss:0x00000000; // type:object size:0x4 scope:global -lbl_120_bss_8 = .bss:0x00000008; // type:object size:0x14 data:byte +sUnusedColors = .bss:0x00000008; // type:object size:0x14 scope:local data:byte diff --git a/config/RUUE01_00/symbols.txt b/config/RUUE01_00/symbols.txt index 6766e5d..997c6fa 100644 --- a/config/RUUE01_00/symbols.txt +++ b/config/RUUE01_00/symbols.txt @@ -15303,7 +15303,7 @@ fn_80233490 = .text:0x80233490; // type:function size:0x7C fn_8023350C = .text:0x8023350C; // type:function size:0x68 fn_80233574 = .text:0x80233574; // type:function size:0x70 GetResMdl__Q34nw4r3g3d7ResFileCFPCc = .text:0x802335E4; // type:function size:0x6C -fn_80233650 = .text:0x80233650; // type:function size:0x98 +GetResMdl__Q34nw4r3g3d7ResFileCFi = .text:0x80233650; // type:function size:0x98 fn_802336E8 = .text:0x802336E8; // type:function size:0x98 fn_80233780 = .text:0x80233780; // type:function size:0x6C fn_802337EC = .text:0x802337EC; // type:function size:0x6C @@ -15333,7 +15333,7 @@ fn_80234368 = .text:0x80234368; // type:function size:0x98 fn_80234400 = .text:0x80234400; // type:function size:0x98 fn_80234498 = .text:0x80234498; // type:function size:0x6C fn_80234504 = .text:0x80234504; // type:function size:0x6C -fn_80234570 = .text:0x80234570; // type:function size:0x98 +GetResAnmTexSrt__Q34nw4r3g3d7ResFileCFi = .text:0x80234570; // type:function size:0x98 fn_80234608 = .text:0x80234608; // type:function size:0x98 fn_802346A0 = .text:0x802346A0; // type:function size:0x6C fn_8023470C = .text:0x8023470C; // type:function size:0x98 @@ -15369,11 +15369,11 @@ fn_80235638 = .text:0x80235638; // type:function size:0x54 fn_8023568C = .text:0x8023568C; // type:function size:0x34 fn_802356C0 = .text:0x802356C0; // type:function size:0x54 fn_80235714 = .text:0x80235714; // type:function size:0x54 -fn_80235768 = .text:0x80235768; // type:function size:0x44 +GetResMat__Q34nw4r3g3d6ResMdlCFPCc = .text:0x80235768; // type:function size:0x44 fn_802357AC = .text:0x802357AC; // type:function size:0x50 -fn_802357FC = .text:0x802357FC; // type:function size:0x54 +GetResMat__Q34nw4r3g3d6ResMdlCFi = .text:0x802357FC; // type:function size:0x54 fn_80235850 = .text:0x80235850; // type:function size:0x54 -fn_802358A4 = .text:0x802358A4; // type:function size:0x34 +GetResMatNumEntries__Q34nw4r3g3d6ResMdlCFv = .text:0x802358A4; // type:function size:0x34 fn_802358D8 = .text:0x802358D8; // type:function size:0x44 fn_8023591C = .text:0x8023591C; // type:function size:0x54 fn_80235970 = .text:0x80235970; // type:function size:0x54 @@ -15422,8 +15422,8 @@ fn_80237414 = .text:0x80237414; // type:function size:0x34 fn_80237448 = .text:0x80237448; // type:function size:0x44 fn_8023748C = .text:0x8023748C; // type:function size:0x88 fn_80237514 = .text:0x80237514; // type:function size:0xD4 -fn_802375E8 = .text:0x802375E8; // type:function size:0x7C -fn_80237664 = .text:0x80237664; // type:function size:0x50 +SetEffectMtx__Q34nw4r3g3d9ResTexSrtFUlPCQ34nw4r4math5MTX34 = .text:0x802375E8; // type:function size:0x7C +GetEffectMtx__Q34nw4r3g3d9ResTexSrtCFUlPQ34nw4r4math5MTX34 = .text:0x80237664; // type:function size:0x50 fn_802376B4 = .text:0x802376B4; // type:function size:0x88 fn_8023773C = .text:0x8023773C; // type:function size:0x5C fn_80237798 = .text:0x80237798; // type:function size:0x34 @@ -17658,7 +17658,7 @@ setAnm__Q33m3d11anmTexSrt_c7child_cFRQ23m3d6bmdl_cQ34nw4r3g3d12ResAnmTexSrtQ23m3 fn_802B2B04 = .text:0x802B2B04; // type:function size:0x48 setFrmCtrlDefault__Q33m3d11anmTexSrt_c7child_cFRQ34nw4r3g3d12ResAnmTexSrtQ23m3d10playMode_e = .text:0x802B2B4C; // type:function size:0x68 heapCost__Q23m3d11anmTexSrt_cFQ34nw4r3g3d6ResMdlQ34nw4r3g3d12ResAnmTexSrtlb = .text:0x802B2BB4; // type:function size:0xE0 -fn_802B2C94 = .text:0x802B2C94; // type:function size:0x244 +create__Q23m3d11anmTexSrt_cFQ34nw4r3g3d6ResMdlQ34nw4r3g3d12ResAnmTexSrtP12mAllocator_cPUll = .text:0x802B2C94; // type:function size:0x244 __dt__Q23m3d11anmTexSrt_cFv = .text:0x802B2ED8; // type:function size:0x6C remove__Q23m3d11anmTexSrt_cFv = .text:0x802B2F44; // type:function size:0xEC setAnm__Q23m3d11anmTexSrt_cFRQ23m3d6bmdl_cQ34nw4r3g3d12ResAnmTexSrtlQ23m3d10playMode_e = .text:0x802B3030; // type:function size:0x140 @@ -17666,7 +17666,7 @@ fn_802B3170 = .text:0x802B3170; // type:function size:0x74 play__Q23m3d11anmTexSrt_cFv = .text:0x802B31E4; // type:function size:0xAC play__Q23m3d11anmTexSrt_cFl = .text:0x802B3290; // type:function size:0x60 fn_802B32F0 = .text:0x802B32F0; // type:function size:0x10 -fn_802B3300 = .text:0x802B3300; // type:function size:0x10 +setFrame__Q23m3d11anmTexSrt_cFfl = .text:0x802B3300; // type:function size:0x10 fn_802B3310 = .text:0x802B3310; // type:function size:0x10 fn_802B3320 = .text:0x802B3320; // type:function size:0x10 fn_802B3330 = .text:0x802B3330; // type:function size:0x10 @@ -24389,7 +24389,7 @@ __mod2u = .text:0x8044EAC4; // type:function size:0xE4 scope:global fn_8044EBA8 = .text:0x8044EBA8; // type:function size:0x10C fn_8044ECB4 = .text:0x8044ECB4; // type:function size:0x24 fn_8044ECD8 = .text:0x8044ECD8; // type:function size:0x24 -fn_8044ECFC = .text:0x8044ECFC; // type:function size:0xB4 +__cvt_sll_flt = .text:0x8044ECFC; // type:function size:0xB4 fn_8044EDB0 = .text:0x8044EDB0; // type:function size:0xA8 __init_cpp_exceptions = .text:0x8044EE58; // type:function size:0x3C scope:global __fini_cpp_exceptions = .text:0x8044EE94; // type:function size:0x34 scope:global @@ -24535,7 +24535,7 @@ fn_8045F844 = .text:0x8045F844; // type:function size:0x88 fn_8045F8CC = .text:0x8045F8CC; // type:function size:0x16C fn_8045FA38 = .text:0x8045FA38; // type:function size:0xFC fn_8045FB34 = .text:0x8045FB34; // type:function size:0xD8 -fn_8045FC0C = .text:0x8045FC0C; // type:function size:0x78 +tan = .text:0x8045FC0C; // type:function size:0x78 fn_8045FC84 = .text:0x8045FC84; // type:function size:0x4 fn_8045FC88 = .text:0x8045FC88; // type:function size:0x4 fn_8045FC8C = .text:0x8045FC8C; // type:function size:0x4 @@ -29368,7 +29368,7 @@ lbl_804F0C64 = .data:0x804F0C64; // type:object size:0xE data:string lbl_804F0C78 = .data:0x804F0C78; // type:object size:0x12C0 lbl_804F1F38 = .data:0x804F1F38; // type:object size:0x5A0 lbl_804F24D8 = .data:0x804F24D8; // type:object size:0x1098 data:2byte -lbl_804F3570 = .data:0x804F3570; // type:object size:0x20 +__vt__11dStarDraw_c = .data:0x804F3570; // type:object size:0x20 lbl_804F3590 = .data:0x804F3590; // type:object size:0xC data:string lbl_804F359C = .data:0x804F359C; // type:object size:0x14 lbl_804F35B0 = .data:0x804F35B0; // type:object size:0xC data:string @@ -31250,7 +31250,7 @@ lbl_80523C90 = .data:0x80523C90; // type:object size:0x30 lbl_80523CC0 = .data:0x80523CC0; // type:object size:0x16 data:string lbl_80523CD8 = .data:0x80523CD8; // type:object size:0x18 g_banmHeapName = .data:0x80523CF0; // type:object size:0x30 -lbl_80523D20 = .data:0x80523D20; // type:object size:0x18 +__vt__Q23m3d11anmTexSrt_c = .data:0x80523D20; // type:object size:0x18 lbl_80523D38 = .data:0x80523D38; // type:object size:0x11 data:string lbl_80523D4C = .data:0x80523D4C; // type:object size:0xC lbl_80523D58 = .data:0x80523D58; // type:object size:0x18 @@ -41120,7 +41120,7 @@ lbl_80752940 = .sdata2:0x80752940; // type:object size:0x4 align:4 data:float lbl_80752948 = .sdata2:0x80752948; // type:object size:0x8 align:8 data:double lbl_80752950 = .sdata2:0x80752950; // type:object size:0x4 lbl_80752954 = .sdata2:0x80752954; // type:object size:0x3 data:string -lbl_80752958 = .sdata2:0x80752958; // type:object size:0x4 align:4 data:float +AngleToDegreeCoefficient__4mAng = .sdata2:0x80752958; // type:object size:0x4 align:4 data:float lbl_8075295C = .sdata2:0x8075295C; // type:object size:0x4 align:4 data:float DegreeToAngleCoefficient__4mAng = .sdata2:0x80752960; // type:object size:0x4 align:4 data:float lbl_80752964 = .sdata2:0x80752964; // type:object size:0x4 align:4 data:float diff --git a/configure.py b/configure.py index fa04c62..56aa30c 100755 --- a/configure.py +++ b/configure.py @@ -1113,7 +1113,7 @@ def MatchingFor(*versions): Object(Matching, "d_skyNP/rel_init.cpp", source="runtime/rel_init.cpp"), Object(Matching, "d_skyNP/global_destructor_chain.c", source="runtime/global_destructor_chain.c", cflags=[*cflags_runtime, "-sdata 0", "-sdata2 0"]), - Object(NonMatching, "d_skyNP/d_sky.cpp", extra_cflags=["-sym on"]), + Object(Matching, "d_skyNP/d_sky.cpp", extra_cflags=["-sym on"]), ], ), ] diff --git a/include/game/game/d_camera.hpp b/include/game/game/d_camera.hpp new file mode 100644 index 0000000..41d6e6e --- /dev/null +++ b/include/game/game/d_camera.hpp @@ -0,0 +1,14 @@ +#pragma once + +// The game camera; not decompiled yet. Only what the sky uses. + +#include + +extern "C" { +extern nw4r::math::VEC3 lbl_80623FEC; // 80623FEC: the camera's target (the view center) +} + +template +T *getViewCenter() { + return &lbl_80623FEC; +} diff --git a/include/game/game/d_sky.hpp b/include/game/game/d_sky.hpp index 977bf12..1fa6760 100644 --- a/include/game/game/d_sky.hpp +++ b/include/game/game/d_sky.hpp @@ -1,16 +1,62 @@ #pragma once -// The sky actor (RTTI dSky_c, profile 0xAA). Source: src/d_skyNP/d_sky.cpp (not decompiled yet). +// The sky actor (RTTI dSky_c, profile 0xAA): the sky, cloud and moon models, the star field and the +// shooting stars. Source: src/d_skyNP/d_sky.cpp. Names other than the classes' are inferred. +#include #include +#include +#include +#include +#include +#include +#include #include class dSky_c : public fBase_c { public: - virtual void setFireworksBrightness(f32 brightness); // vtable 0x4C + dSky_c(); // 0x8C + virtual ~dSky_c(); // 0x370 - u8 _pad[0x568 - sizeof(fBase_c)]; - /* 0x568 */ nw4r::math::VEC3 mPos; -}; + virtual int create(); // 0x4BC + virtual int preCreate() { return SUCCEEDED; } // 0x1AB0 (weak) + virtual int doDelete(); // 0xE78 + virtual int execute(); // 0x7E8 + virtual void postExecute(MAIN_STATE_e state) {} // 0x1AAC (weak) + virtual int draw(); // 0x868 + virtual void postDraw(MAIN_STATE_e state) {} // 0x1AA8 (weak) + virtual void deleteReady() {} // 0x1AA4 (weak) + virtual bool createHeap() { return true; } // 0x1A9C (weak) + virtual void setFireworksBrightness(f32 brightness); // 0xF88: vtable 0x4C + + void calc(); // 0x1170 + + /* 0x000 fBase_c (vtable at 0x060) */ + /* 0x064 */ m3d::smdl_c mMdlCloud; + /* 0x070 */ m3d::smdl_c mMdlSky; + /* 0x07C */ m3d::smdl_c mMdlMoon; + /* 0x088 */ mAllocator_c mAllocator; + /* 0x0A4 */ dStarDraw_c mStarDraw; + /* 0x1E8 */ dStarMgr_c mStarMgr; + /* 0x2F0 */ m3d::anmTexSrt_c mAnmCloud; + /* 0x31C */ m3d::anmTexSrt_c mAnmMoon; + /* 0x348 */ dDvd::brresBank_c mResCloud; // /Sky/bg_cloud.brres + /* 0x3A0 */ dDvd::brresBank_c mResSky; // /Sky/bg_sky.brres + /* 0x3F8 */ dDvd::brresBank_c mResUnused; + /* 0x450 */ dDvd::brresBank_c mResMoon; // /Sky/bg_moon.brres + /* 0x4A8 */ mMtx_c mSkyMtx; + /* 0x4D8 */ mMtx_c mCloudMtx; + /* 0x508 */ mMtx_c mMoonMtx; + /* 0x538 */ mMtx_c mMtx538; + /* 0x568 */ mVec3_c mPos; + /* 0x574 */ mColor mSkyColor0; + /* 0x578 */ mColor mSkyColor1; + /* 0x57C */ u8 _57C[0x584 - 0x57C]; + /* 0x584 */ f32 mBrightness; // fireworks flashes dim the stars + /* 0x588 */ u8 _588[0x58C - 0x588]; + /* 0x58C */ bool mCreated; + /* 0x58D */ bool mSeasonActorCreated; + /* 0x58E */ bool mIsCity; +}; // size 0x590 extern dSky_c *lbl_8074E830; // 8074E830 (defined in d_play_util.cpp) diff --git a/include/game/game/d_star.hpp b/include/game/game/d_star.hpp index 0c7b9fe..43549e1 100644 --- a/include/game/game/d_star.hpp +++ b/include/game/game/d_star.hpp @@ -9,6 +9,8 @@ class dStar_c { public: + dStar_c() : mWait(0), mActive(false) {} + void start(int wait); // 80090D20 void execute(); // 80090D70 int countDown(); // 80090E10 diff --git a/include/game/game/d_star_draw.hpp b/include/game/game/d_star_draw.hpp new file mode 100644 index 0000000..afc2e07 --- /dev/null +++ b/include/game/game/d_star_draw.hpp @@ -0,0 +1,50 @@ +#pragma once + +// The night sky's star field (RTTI dStarDraw_c), part of the sky actor (dSky_c + 0xA4). Its code is +// in the DOL (dol/game/d_star_draw.cpp), not decompiled yet; only what d_sky uses is declared. + +#include +#include +#include + +class dStarDraw_c : public m3d::proc_c { +public: + struct star_c { + star_c() : m0(0.0f), m4(0), m8(0) {} + ~star_c() {} + + /* 0x0 */ f32 m0; + /* 0x4 */ int m4; + /* 0x8 */ u16 m8; + }; // size 0xC + // Fix this later + dStarDraw_c() + : m008(0), m0AC(0.0f), m0B0(0.0f), m128(0), m12C(0), m130(0), m134(-1), m138(-1), m13C(-1), + m140(0) {} + ~dStarDraw_c() {} + + virtual void drawXlu(); // 80164D14 (DOL; its vtable is emitted there) + + /* 0x008 */ int m008; + /* 0x00C */ u8 _00C[0x4A - 0xC]; + /* 0x04A */ u8 mAlpha; + /* 0x04C */ star_c mStars[8]; + /* 0x0AC */ f32 m0AC; + /* 0x0B0 */ f32 m0B0; + /* 0x0B4 */ mAllocator_c mAllocator; + /* 0x0D0 */ dDvd::brresBank_c mRes; + /* 0x128 */ int m128; + /* 0x12C */ u8 m12C; + /* 0x130 */ int m130; + /* 0x134 */ int m134; + /* 0x138 */ int m138; + /* 0x13C */ int m13C; + /* 0x140 */ u8 m140; +}; // size 0x144 + +// Not decompiled yet (C linkage keeps the target names). +extern "C" { +bool fn_801640DC(dStarDraw_c *draw, EGG::Heap *heap); // 801640DC: load and create +bool fn_8016418C(dStarDraw_c *draw); // 8016418C: unload +void fn_80164278(dStarDraw_c *draw, const nw4r::math::VEC3 *pos, const s16 &angle); // 80164278: calc +} diff --git a/include/game/mLib/m_3d.hpp b/include/game/mLib/m_3d.hpp index fb5cf41..6ab290f 100644 --- a/include/game/mLib/m_3d.hpp +++ b/include/game/mLib/m_3d.hpp @@ -202,10 +202,11 @@ namespace m3d { namespace m3d { class proc_c : public scnLeaf_c { public: + virtual ~proc_c() {} virtual scnLeaf_c::leafType_e getType() const { return scnLeaf_c::TYPE_PROC; }; - virtual void drawOpa(); - virtual void drawXlu(); + virtual void drawOpa() {} + virtual void drawXlu() {} bool create(mAllocator_c *allocator, size_t *size); }; diff --git a/include/game/mLib/m_angle.hpp b/include/game/mLib/m_angle.hpp index 4bf596e..17a01bd 100644 --- a/include/game/mLib/m_angle.hpp +++ b/include/game/mLib/m_angle.hpp @@ -57,6 +57,9 @@ struct mAng { /// @brief Computes the cosine of the angle. float cos() const { return nw4r::math::CosIdx(mAngle); } + /// @brief Converts the angle to degrees. + float degree() const { return mAngle * AngleToDegreeCoefficient; } + s16 mAngle; ///< The rotation. static float AngleToDegreeCoefficient; diff --git a/include/game/mLib/m_mtx.hpp b/include/game/mLib/m_mtx.hpp index 75585ac..5a8a68e 100644 --- a/include/game/mLib/m_mtx.hpp +++ b/include/game/mLib/m_mtx.hpp @@ -24,10 +24,9 @@ class mMtx_c : public nw4r::math::MTX34 { operator const Mtx*() const { return &mtx; } mMtx_c &operator=(const mMtx_c &other) { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 4; j++) { - m[i][j] = other.m[i][j]; - } + for (int i = 0; i < 12; i++) { + f32 v = other.a[i]; + a[i] = v; } return *this; } @@ -53,7 +52,7 @@ class mMtx_c : public nw4r::math::MTX34 { return mVec3_c(x, y, z); } - static mMtx_c createTrans(const mVec3_c &v) { return createTrans(v.x, v.y, v.z); } + static mMtx_c createTrans(const mVec3_c &v) { mMtx_c mtx; mtx.trans(v); return mtx; } static mMtx_c createTrans(float x, float y, float z) { mMtx_c mtx; PSMTXTrans(mtx, x, y, z); return mtx; } static mMtx_c createScale(const mVec3_c &v) { mMtx_c mtx; PSMTXScale(mtx, v.x, v.y, v.z); return mtx; } static mMtx_c createScale(float x, float y, float z) { mMtx_c mtx; PSMTXScale(mtx, x, y, z); return mtx; } diff --git a/src/d_fish_fieldNP/d_fish_field.cpp b/src/d_fish_fieldNP/d_fish_field.cpp index 55c6e47..a21283d 100644 --- a/src/d_fish_fieldNP/d_fish_field.cpp +++ b/src/d_fish_fieldNP/d_fish_field.cpp @@ -1,5 +1,6 @@ // dFishField_c: the fish in the town (REL d_fish_fieldNP). See include/game/game/d_fish_field.hpp. #include +#include #include #include #include @@ -57,7 +58,7 @@ void fn_111_6770(u16 item, const mVec3_c *pos, const mVec3_c *scale, const mAng3 extern const f32 lbl_8075041C; extern const f32 lbl_80750420; -extern EGG::Heap *lbl_8074E440; +extern EGG::ExpHeap *lbl_8074E440; extern nw4r::math::VEC3 lbl_80623FEC; // the camera's target (the view center) void *dFishField_c_classInit(); diff --git a/src/d_skyNP/d_sky.cpp b/src/d_skyNP/d_sky.cpp new file mode 100644 index 0000000..fb0bd93 --- /dev/null +++ b/src/d_skyNP/d_sky.cpp @@ -0,0 +1,355 @@ +// REL .text 0x5C..0x1AB8, .ctors 0x0..0x4, .rodata 0x0..0xAC, .data 0x0..0x1B8, .bss 0x8..0x1C. +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// The game camera; only what the sky uses. +struct dSkyCamera_c { + /* 0x000 */ u8 _000[0x16C]; + /* 0x16C */ mMtx_c mViewMtx; + /* 0x19C */ u8 _19C[0x1CC - 0x19C]; + /* 0x1CC */ s16 mPitch; + /* 0x1CE */ s16 mYaw; +}; + +// Not decompiled yet (C linkage keeps the target names). +extern "C" { +extern dSkyCamera_c *lbl_8074E9B0; // 8074E9B0: the camera +extern EGG::ExpHeap *lbl_8074E440; // 8074E440 + +void fn_80197414(mColor *color, int idx); // 80197414: a sky color for the time of day +u8 fn_801977BC(); // 801977BC: the star color's alpha +u32 fn_801660B0(const dTime_c *time); // 801660B0 +} + +void *dSky_c_classInit(); +f32 getMoonAge(const dTime_c *now); +f32 getOffsetY(); +f32 getOffsetZ(); + +fProf::fBaseProfile_c g_profile_SKY = {&dSky_c_classInit, 0xAA, 5}; + +// Added to the moon's tint. +static const GXColor sMoonAdd = {0x10, 0x10, 0x0C, 0xFF}; + +// Unused: only __sinit touches it. Five zero-initialized 4-byte members, of which bytes 0x2..0x11 +// are then set; the layout of the original type is unknown. +struct dSkyColor_c { + dSkyColor_c() : r(0), g(0), b(0), a(0) {} + + u8 r, g, b, a; +}; +struct dSkyUnused_c { + dSkyUnused_c() { + m0.b = 0xE5; + m0.a = 0xE7; + m1.r = 0xFF; + m1.g = 0xC0; + m1.b = 0x76; + m1.a = 0x62; + m2.r = 0x20; + m2.g = 0x00; + m2.b = 0x29; + m2.a = 0x2B; + m3.r = 0xFF; + m3.g = 0x00; + m3.b = 0x00; + m3.a = 0x10; + m4.r = 0x20; + m4.g = 0x00; + } + + dSkyColor_c m0, m1, m2, m3, m4; +}; +static dSkyUnused_c sUnusedColors; + +// 0x5C +void *dSky_c_classInit() { + return new dSky_c(); +} + +// 0x8C +dSky_c::dSky_c() : mBrightness(0.0f), mCreated(false), mSeasonActorCreated(false) {} + +// 0x370 +dSky_c::~dSky_c() {} + +// 0x4BC +int dSky_c::create() { + mIsCity = isCityScene(getCurrentScene()); + if (!mIsCity && !isSceneAttr(getCurrentScene(), 0x10) && !mSeasonActorCreated) { + if (isWinterSeasonType()) { + dBase_c::createBase(0xAB, this, 0, 0); + } else if (!isLateSeason()) { + dBase_c::createBase(0xAC, this, 0, 0); + } + mSeasonActorCreated = true; + } + + BOOL ok = TRUE; + EGG::Heap *heap = lbl_8074E440; + if (!mResCloud.load("/Sky/bg_cloud.brres", heap, 0)) { + ok = FALSE; + } + if (!mResSky.load("/Sky/bg_sky.brres", heap, 0)) { + ok = FALSE; + } + if (!mResMoon.load("/Sky/bg_moon.brres", heap, 0)) { + ok = FALSE; + } + if (!fn_801640DC(&mStarDraw, heap)) { + ok = FALSE; + } + if (!ok) { + return ok; + } + + mAllocator.attach(heap, 0x20); + mMdlCloud.create(nw4r::g3d::ResFile(mResCloud.getData()).GetResMdl(0), &mAllocator, 0, 1, NULL); + mMdlSky.create(nw4r::g3d::ResFile(mResSky.getData()).GetResMdl(0), &mAllocator, 0, 1, NULL); + mMdlMoon.create(nw4r::g3d::ResFile(mResMoon.getData()).GetResMdl(0), &mAllocator, 0, 1, NULL); + + if (mIsCity || isSceneAttr(getCurrentScene(), 0x110)) { + mStarDraw.m128 = 1; + } else { + mStarDraw.m128 = 0; + } + + mAnmCloud.create(nw4r::g3d::ResFile(mResCloud.getData()).GetResMdl(0), + nw4r::g3d::ResFile(mResCloud.getData()).GetResAnmTexSrt(0), &mAllocator, NULL, 1); + mMdlCloud.setAnm(mAnmCloud); + mAnmMoon.create(nw4r::g3d::ResFile(mResMoon.getData()).GetResMdl(0), + nw4r::g3d::ResFile(mResMoon.getData()).GetResAnmTexSrt(0), &mAllocator, NULL, 1); + mMdlMoon.setAnm(mAnmMoon); + + mStarMgr.init(); + mCreated = true; + lbl_8074E830 = this; + return ok; +} + +// 0x7E8 +int dSky_c::execute() { + mAnmCloud.play(); + mAnmMoon.setFrame(getMoonAge(dTime_c::getCurrent()), 0); + sLib::addCalc2(&mBrightness, 0.0f, 0.05f, 0.1f); + calc(); + return SUCCEEDED; +} + +static inline u8 addClamp(u8 value, int add) { + int sum = value + add; + return sum >= 0xFF ? 0xFF : sum; +} + +// 0x868 +int dSky_c::draw() { + nw4r::g3d::ResMat cloudMat = nw4r::g3d::ResFile(mResCloud.getData()).GetResMdl(0).GetResMat("m_cloud"); + nw4r::g3d::ResMat skyMat = nw4r::g3d::ResFile(mResSky.getData()).GetResMdl(0).GetResMat("m_sky"); + + mColor cloudColor0; + mColor cloudColor1; + fn_80197414(&mSkyColor0, 4); + fn_80197414(&mSkyColor1, 5); + fn_80197414(&cloudColor0, 6); + fn_80197414(&cloudColor1, 7); + cloudColor0.a = fn_801977BC(); + + u8 alpha; + if (dTime_c::getCurrent()->hour < 4 || dTime_c::getCurrent()->hour > 19) { + alpha = 0xFF; + } else if (dTime_c::getCurrent()->hour == 4 || dTime_c::getCurrent()->hour == 5) { + f32 rate = dTime_c::getCurrent()->min * (1.0f / 120.0f); + rate += (dTime_c::getCurrent()->hour - 4) * 0.5f; + rate = 1.0f - rate; + alpha = 255.0f * rate; + } else if (dTime_c::getCurrent()->hour == 18 || dTime_c::getCurrent()->hour == 19) { + f32 rate = dTime_c::getCurrent()->min * (1.0f / 120.0f); + rate += (dTime_c::getCurrent()->hour - 18) * 0.5f; + alpha = 255.0f * rate; + } else { + alpha = 0; + } + mStarDraw.mAlpha = alpha * (1.0f - mBrightness); + + cloudMat.GetResMatTevColor().GXSetTevKColor(GX_KCOLOR1, cloudColor0); + cloudMat.GetResMatTevColor().GXSetTevKColor(GX_KCOLOR2, cloudColor1); + cloudMat.GetResMatTevColor().DCStore(false); + skyMat.GetResMatTevColor().GXSetTevKColor(GX_KCOLOR1, mSkyColor0); + skyMat.GetResMatTevColor().GXSetTevKColor(GX_KCOLOR2, mSkyColor1); + skyMat.GetResMatTevColor().DCStore(false); + + mMdlSky.setPriorityDraw(2, 3); + mMdlSky.entry(); + if (mStarDraw.mAlpha != 0) { + mStarDraw.setPriorityDraw(2, 3); + mStarDraw.entry(); + } + + if (!isSceneAttr(getCurrentScene(), 0x110) && !isSceneAttr(getCurrentScene(), 0x4000)) { + nw4r::g3d::ResMat moonMat = nw4r::g3d::ResFile(mResMoon.getData()).GetResMdl(0).GetResMat(0); + mColor moonColor; + moonColor.lerp(mSkyColor0, mSkyColor1, 0.125f); + moonColor.r = addClamp(moonColor.r, sMoonAdd.r); + moonColor.g = addClamp(moonColor.g, sMoonAdd.g); + moonColor.b = addClamp(moonColor.b, sMoonAdd.b); + moonColor.a = addClamp(moonColor.a, sMoonAdd.a); + moonMat.GetResMatTevColor().GXSetTevKColor(GX_KCOLOR1, moonColor); + moonMat.GetResMatTevColor().DCStore(false); + mMdlMoon.setPriorityDraw(2, 4); + mMdlMoon.entry(); + } + + mMdlCloud.setPriorityDraw(2, 6); + mMdlCloud.entry(); + return SUCCEEDED; +} + +// 0xE78 +int dSky_c::doDelete() { + BOOL ok = TRUE; + if (mCreated) { + mMdlCloud.remove(); + mAnmCloud.remove(); + mMdlSky.remove(); + mMdlMoon.remove(); + mCreated = false; + } + if (!mResCloud.unload(FALSE)) { + ok = FALSE; + } + if (!mResSky.unload(FALSE)) { + ok = FALSE; + } + if (!mResMoon.unload(FALSE)) { + ok = FALSE; + } + if (!fn_8016418C(&mStarDraw)) { + ok = FALSE; + } + if (!ok) { + return ok; + } + lbl_8074E830 = NULL; + return ok; +} + +// 0xF88 +void dSky_c::setFireworksBrightness(f32 brightness) { + if (brightness > mBrightness) { + sLib::addCalc2(&mBrightness, brightness, 0.5f, 0.5f); + } +} + +// 0xFAC: the moon's age in days (0..28) for the animation frame. Days start at noon. +f32 getMoonAge(const dTime_c *now) { + dTime_c base; + base.init(); + dTime_c time = *now; + time.add(0, -12, 0, 0); + int days = dTime_c::diffDays(&time, &base, FALSE); + return (((days * 100 + 2420) % 2953) * 28) / 2953.0f; +} + +// 0x10B8 +f32 getOffsetY() { + if (isSceneAttr(getCurrentScene(), 0x110)) { + return 256.0f; + } + if (isSceneAttr(getCurrentScene(), 0x4000)) { + return 248.0f; + } + return 0.0f; +} + +// 0x1128 +f32 getOffsetZ() { + if (isSceneAttr(getCurrentScene(), 0x4000)) { + return -42.0f; + } + return 0.0f; +} + +// 0x1170 +void dSky_c::calc() { + mMtx_c view; + view = lbl_8074E9B0->mViewMtx; + mSkyMtx = view; + mCloudMtx = view; + mMoonMtx = view; + + f32 skyMinY = -145.0f; + f32 cityY; + f32 starMinY = -380.0f; + f32 starMaxY = -110.0f; + if (mIsCity) { + cityY = 220.0f; + } else { + cityY = 110.0f; + } + f32 pitch = mAng(lbl_8074E9B0->mPitch).degree(); + f32 rate = nw4r::math::TanDeg(pitch) - nw4r::math::TanDeg(-52.0f); + rate /= nw4r::math::TanDeg(-22.0f) - nw4r::math::TanDeg(-52.0f); + f32 inv = 1.0f - rate; + + mVec3_c skyPos(0.0f, cityY * inv + skyMinY * rate, -1300.0f); + mVec3_c cloudPos(0.0f, 32.0f, 0.0f); + skyPos.y += getOffsetY(); + cloudPos += skyPos; + mPos.set(lbl_8074E9B0->mYaw * 0.05f, starMaxY * inv + starMinY * rate, -1300.0f); + mPos.y += getOffsetY(); + mPos.z += getOffsetZ(); + + mSkyMtx.concat(mMtx_c::createTrans(skyPos)); + mSkyMtx.concat(mMtx_c::createScale(1.0f, 1.0f, 1.0f)); + mMtx538.trans(skyPos); + mCloudMtx.concat(mMtx_c::createTrans(cloudPos)); + mCloudMtx.concat(mMtx_c::createScale(0.9375f, 0.8f, 1.0f)); + mMdlCloud.setLocalMtx(&mCloudMtx); + mMdlCloud.calc(false); + + nw4r::g3d::ResMdl cloudMdl = nw4r::g3d::ResFile(mResCloud.getData()).GetResMdl(0); + f32 scroll = 0.0f; + if (lbl_8074E9B0 != NULL) { + scroll = 0.0016f * getViewCenter()->x; + scroll += -0.0002f * lbl_8074E9B0->mYaw; + scroll = fmod(scroll, 4.0); + } + for (u32 i = 0; i < cloudMdl.GetResMatNumEntries(); i++) { + nw4r::g3d::ResTexSrt texSrt = cloudMdl.GetResMat("m_cloud").GetResTexSrt(); + for (u32 j = 0; j < 3; j++) { + nw4r::math::MTX34 srt; + texSrt.GetEffectMtx(j, &srt); + srt._03 = scroll; + texSrt.SetEffectMtx(j, &srt); + } + } + mMdlSky.setLocalMtx(&mSkyMtx); + + dTime_c now = *dTime_c::getCurrent(); + dTime_c moonset = now; + moonset.add(0, -12, 0, 0); + moonset.set(moonset.year, moonset.month, moonset.mday, 23, 30, 0); + f32 secs = OS_TICKS_TO_SEC(dTime_c::diffTicks(&now, &moonset, FALSE)); + f32 angle = 20.0f * (secs / 16200.0f); + mVec3_c moonPos(0.0f, -330.0f, 0.0f); + moonPos += mPos; + mMoonMtx.concat(mMtx_c::createTrans(moonPos)); + mMoonMtx.ZrotM(mAng(angle * mAng::DegreeToAngleCoefficient)); + if (mIsCity) { + mMoonMtx.concat(mMtx_c::createTrans(0.0f, 752.0f, 0.0f)); + } else { + mMoonMtx.concat(mMtx_c::createTrans(0.0f, 875.0f, 0.0f)); + } + mMdlMoon.setLocalMtx(&mMoonMtx); + + fn_80164278(&mStarDraw, &mPos, fn_801660B0(&now) >> 16); + mStarMgr.execute(); +} diff --git a/src/dol/game/d_dsn.cpp b/src/dol/game/d_dsn.cpp index 17d4c24..ce5242e 100644 --- a/src/dol/game/d_dsn.cpp +++ b/src/dol/game/d_dsn.cpp @@ -1,6 +1,7 @@ // Original designs (patterns). .text 8010F124..8010FB6C. // First pass: every function is written for equivalence. #include +#include #include #include #include @@ -17,7 +18,7 @@ void fn_8016AE68(dScript::Word_c *word, u16 index, const char *group); // load a // Downloaded item blocks (Ghidra: DLC_Item). } -extern EGG::Heap *lbl_8074E440; +extern EGG::ExpHeap *lbl_8074E440; // 8010F124 dDesign_c::dDesign_c() { diff --git a/src/dol/game/d_rec_bank.cpp b/src/dol/game/d_rec_bank.cpp index 8c671c4..a3d8219 100644 --- a/src/dol/game/d_rec_bank.cpp +++ b/src/dol/game/d_rec_bank.cpp @@ -1,11 +1,12 @@ // dRecBank::bankTbl_c: a pool of same-sized frame heaps (see include/game/game/d_rec_bank.hpp). // .text 8010655C..801068AC. #include +#include #include #include // The heap the entry array comes from (not identified yet; also used by d_dsn). -extern EGG::Heap *lbl_8074E440; +extern EGG::ExpHeap *lbl_8074E440; namespace dRecBank {