From 4e2faca54b1ca03ac59d53c5be3cadd758573b48 Mon Sep 17 00:00:00 2001 From: Daniel Hajjar <33489389+DanTGL@users.noreply.github.com> Date: Wed, 17 Jul 2024 16:07:28 +0200 Subject: [PATCH] d_a_obj_timer (#669) * Started work on d_a_obj_timer * daObjTimer::Act_c::_create matching * d_a_obj_timer work * daObjTimer::Act_c::mode_count matching * d_a_obj_timer matching * Fix build --- configure.py | 2 +- include/d/actor/d_a_obj_timer.h | 32 +++++++++--- src/d/actor/d_a_obj_timer.cpp | 89 ++++++++++++++++++++++++++------- 3 files changed, 96 insertions(+), 27 deletions(-) diff --git a/configure.py b/configure.py index 0c44d457d..1abf74b65 100644 --- a/configure.py +++ b/configure.py @@ -1335,7 +1335,7 @@ config.libs = [ ActorRel(NonMatching, "d_a_obj_table"), ActorRel(NonMatching, "d_a_obj_tenmado"), ActorRel(NonMatching, "d_a_obj_tide"), - ActorRel(NonMatching, "d_a_obj_timer"), + ActorRel(Matching, "d_a_obj_timer"), ActorRel(NonMatching, "d_a_obj_toripost", extra_cflags=['-pragma "nosyminline on"']), ActorRel(NonMatching, "d_a_obj_tousekiki"), ActorRel(NonMatching, "d_a_obj_warpt"), diff --git a/include/d/actor/d_a_obj_timer.h b/include/d/actor/d_a_obj_timer.h index 01a52c6ba..67ec9ba21 100644 --- a/include/d/actor/d_a_obj_timer.h +++ b/include/d/actor/d_a_obj_timer.h @@ -1,25 +1,43 @@ #ifndef D_A_OBJ_TIMER_H #define D_A_OBJ_TIMER_H +#include "d/d_a_obj.h" #include "f_op/f_op_actor.h" namespace daObjTimer { class Act_c : public fopAc_ac_c { public: - void prm_get_swSave() const {} - void prm_get_time() const {} + typedef void (Act_c::*ModeFunc)(); + + enum Mode_e { + Mode_WAIT_e, + Mode_COUNT_e, + }; + + enum Prm_e { + PRM_TIME_W = 0x08, + PRM_TIME_S = 0x00, + + PRM_SWSAVE_W = 0x08, + PRM_SWSAVE_S = 0x10, + }; + + s32 prm_get_swSave() const { return daObj::PrmAbstract(this, PRM_SWSAVE_W, PRM_SWSAVE_S); } + s32 prm_get_time() const { return daObj::PrmAbstract(this, PRM_TIME_W, PRM_TIME_S); } void stopTimer() {} - + s32 _create(); - BOOL _delete(); + bool _delete(); void mode_wait_init(); void mode_wait(); void mode_count_init(); void mode_count(); - BOOL _execute(); - + bool _execute(); + public: - /* Place member variables here */ + /* 0x290 */ Mode_e mMode; + /* 0x294 */ s32 m294; + /* 0x298 */ bool m298; }; }; diff --git a/src/d/actor/d_a_obj_timer.cpp b/src/d/actor/d_a_obj_timer.cpp index b401226bb..c96f0f7b1 100644 --- a/src/d/actor/d_a_obj_timer.cpp +++ b/src/d/actor/d_a_obj_timer.cpp @@ -5,67 +5,118 @@ #include "d/actor/d_a_obj_timer.h" #include "d/d_procname.h" +#include "d/d_com_inf_game.h" + +// Needed for the .data section to match. +static f32 dummy1[3] = {1.0f, 1.0f, 1.0f}; +static f32 dummy2[3] = {1.0f, 1.0f, 1.0f}; +static u8 dummy3[4] = {0x02, 0x00, 0x02, 0x01}; +static f64 dummy4[2] = {3.0, 0.5}; /* 00000078-00000114 .text _create__Q210daObjTimer5Act_cFv */ s32 daObjTimer::Act_c::_create() { - /* Nonmatching */ + fopAcM_SetupActor(this, daObjTimer::Act_c); + + fopAcM_offDraw(this); + + if (fopAcM_isSwitch(this, prm_get_swSave())) { + mode_count_init(); + } else { + mode_wait_init(); + } + + return cPhs_COMPLEATE_e; } /* 00000114-0000011C .text _delete__Q210daObjTimer5Act_cFv */ -BOOL daObjTimer::Act_c::_delete() { - /* Nonmatching */ +bool daObjTimer::Act_c::_delete() { + return true; } /* 0000011C-0000012C .text mode_wait_init__Q210daObjTimer5Act_cFv */ void daObjTimer::Act_c::mode_wait_init() { - /* Nonmatching */ + m294 = 0; + mMode = Mode_WAIT_e; } /* 0000012C-00000188 .text mode_wait__Q210daObjTimer5Act_cFv */ void daObjTimer::Act_c::mode_wait() { - /* Nonmatching */ + if (fopAcM_isSwitch(this, prm_get_swSave())) { + mode_count_init(); + } } /* 00000188-000001CC .text mode_count_init__Q210daObjTimer5Act_cFv */ void daObjTimer::Act_c::mode_count_init() { - /* Nonmatching */ + m294 = 15 * prm_get_time(); + mMode = Mode_COUNT_e; } /* 000001CC-00000304 .text mode_count__Q210daObjTimer5Act_cFv */ void daObjTimer::Act_c::mode_count() { - /* Nonmatching */ + if (m298) return; + + m294 -= 1; + if (m294 % 30 == 0) { + s32 time = m294 / 30; + if (time <= 20) { + u32 soundId; + if (time > 10) { + soundId = JA_SE_SYS_EV_TIMER_20; + } else if (time > 5) { + soundId = JA_SE_SYS_EV_TIMER_10; + } else if (time > 0) { + soundId = JA_SE_SYS_EV_TIMER_5; + } else { + soundId = JA_SE_SYS_EV_TIMER_0; + } + + mDoAud_seStart(soundId); + } + } + + if (m294 <= 0 || !fopAcM_isSwitch(this, prm_get_swSave())) { + fopAcM_offSwitch(this, prm_get_swSave()); + mode_wait_init(); + } } /* 00000304-00000394 .text _execute__Q210daObjTimer5Act_cFv */ -BOOL daObjTimer::Act_c::_execute() { - /* Nonmatching */ +bool daObjTimer::Act_c::_execute() { + static ModeFunc mode_proc[] = { + &mode_wait, + &mode_count, + }; + (this->*mode_proc[mMode])(); + + return true; } namespace daObjTimer { namespace { /* 00000394-000003B4 .text Mthd_Create__Q210daObjTimer27@unnamed@d_a_obj_timer_cpp@FPv */ -void Mthd_Create(void*) { - /* Nonmatching */ +s32 Mthd_Create(void* i_this) { + return static_cast(i_this)->_create(); } /* 000003B4-000003D8 .text Mthd_Delete__Q210daObjTimer27@unnamed@d_a_obj_timer_cpp@FPv */ -void Mthd_Delete(void*) { - /* Nonmatching */ +BOOL Mthd_Delete(void* i_this) { + return static_cast(i_this)->_delete(); } /* 000003D8-000003FC .text Mthd_Execute__Q210daObjTimer27@unnamed@d_a_obj_timer_cpp@FPv */ -void Mthd_Execute(void*) { - /* Nonmatching */ +BOOL Mthd_Execute(void* i_this) { + return static_cast(i_this)->_execute(); } /* 000003FC-00000404 .text Mthd_Draw__Q210daObjTimer27@unnamed@d_a_obj_timer_cpp@FPv */ -void Mthd_Draw(void*) { - /* Nonmatching */ +BOOL Mthd_Draw(void*) { + return TRUE; } /* 00000404-0000040C .text Mthd_IsDelete__Q210daObjTimer27@unnamed@d_a_obj_timer_cpp@FPv */ -void Mthd_IsDelete(void*) { - /* Nonmatching */ +BOOL Mthd_IsDelete(void*) { + return TRUE; } static actor_method_class Mthd_Table = {