summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_branch.cpp
blob: 80fd17ae3bf4063563b30eb74972b30865b3b61f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/**
 * d_a_branch.cpp
 * Object - Forest of Fairies - Tree branch (Tetra)
 */

#include "d/dolzel_rel.h" // IWYU pragma: keep
#include "d/actor/d_a_branch.h"
#include "res/Object/Kwood_00.h"
#include "JSystem/JUtility/JUTAssert.h"
#include "f_op/f_op_actor_mng.h"
#include "m_Do/m_Do_mtx.h"
#include "d/d_kankyo.h"
#include "JSystem/J3DGraphBase/J3DMaterial.h"

static u16 anim_table[] = {
    dRes_ID_KWOOD_00_BCK_SWING02_e, dRes_ID_KWOOD_00_BAS_SWING02_e,
    dRes_ID_KWOOD_00_BCK_SWING_e,   dRes_ID_KWOOD_00_BAS_SWING_e,
    dRes_ID_KWOOD_00_BCK_BREAK_e,   dRes_ID_KWOOD_00_BAS_BREAK_e,
};

char daBranch_c::m_arcname[] = "Kwood_00";

/* 00000078-00000128       .text set_mtx__10daBranch_cFv */
void daBranch_c::set_mtx() {
    J3DModel* pMdl;

    for (int i = 0; i < (s32)ARRAY_SIZE(mModel); i ++) {
        pMdl = mModel[i];

        if (pMdl) {
            pMdl->setBaseScale(scale);

            mDoMtx_stack_c::transS(current.pos);
            mDoMtx_stack_c::XYZrotM(current.angle);
            
            pMdl->setBaseTRMtx(mDoMtx_stack_c::get());
        }
    }
}

/* 00000128-000001E4       .text set_anim__10daBranch_cFiii */
void daBranch_c::set_anim(int i_animIdx, int i_bckId, int i_basId) {
    if (i_bckId > 0 && i_basId > 0) {
        mAnims[i_animIdx]->setAnm(
            static_cast<J3DAnmTransform*>(dComIfG_getObjectIDRes(m_arcname, i_bckId)),
            -1, 0.0f, 1.0f, 0.0f, -1.0f,
            dComIfG_getObjectIDRes(m_arcname, i_basId)
        );
    }
}

/* 000001E4-00000228       .text demoPlay__10daBranch_cFP14mDoExt_McaMorf */
void daBranch_c::demoPlay(mDoExt_McaMorf* morf) {
    dDemo_setDemoData(
        this,
        dDemo_actor_c::ENABLE_ANM_e,
        morf, m_arcname,
        ARRAY_SIZE(anim_table) / 2,
        anim_table
    );
}

/* 00000228-00000248       .text solidHeapCB__10daBranch_cFP10fopAc_ac_c */
BOOL daBranch_c::solidHeapCB(fopAc_ac_c* i_this) {
    daBranch_c* branch = static_cast<daBranch_c*>(i_this);
    return branch->CreateHeap();
}

/* 00000248-0000049C       .text CreateHeap__10daBranch_cFv */
BOOL daBranch_c::CreateHeap() {
    int bmd[] = { dRes_ID_KWOOD_00_BMD_WS_e, dRes_ID_KWOOD_00_BMD_WB_e };
    int bck[] = { dRes_ID_KWOOD_00_BCK_SWING02_e, dRes_ID_KWOOD_00_BCK_BREAK_e };
    int bas[] = { dRes_ID_KWOOD_00_BAS_SWING02_e, dRes_ID_KWOOD_00_BAS_BREAK_e };

    BOOL status = TRUE;

    for (int i = 0; i < (s32)ARRAY_SIZE(mAnims); i++) {
#if VERSION > VERSION_DEMO
        J3DModelData* modelData = static_cast<J3DModelData*>(dComIfG_getObjectIDRes(m_arcname, bmd[i]));
        J3DAnmTransformKey* bckData = static_cast<J3DAnmTransformKey*>(dComIfG_getObjectIDRes(m_arcname, bck[i]));

        JUT_ASSERT(0x1CC, modelData != NULL);
        // Bug: They probably meant to assert that bckData isn't null, but accidentally used the array of bck file IDs.
        JUT_ASSERT(0x1CD, bck != NULL);
#endif

        mAnims[i] = new mDoExt_McaMorf(
            static_cast<J3DModelData*>(dComIfG_getObjectIDRes(m_arcname, bmd[i])),
            NULL, NULL,
            static_cast<J3DAnmTransformKey*>(dComIfG_getObjectIDRes(m_arcname, bck[i])),
            -1, 1.0f, 0, -1, 1, NULL,
            0, 0x11020203
        );

#if VERSION == VERSION_DEMO
        set_anim(i, bck[i], bas[i]);
        mAnims[i]->setFrame(0.0f);
#endif

#if VERSION > VERSION_DEMO
        if (!mAnims[i]) {
            status = FALSE;
            break;
        }
#endif

        mModel[i] = mAnims[i]->getModel();
        if (!mModel[i]) {
            status = FALSE;
            break;
        }

#if VERSION > VERSION_DEMO
        mAnims[i]->setFrame(0.0f);
        set_anim(i, bck[i], bas[i]);
#endif
    }

    return status;
}

inline BOOL daBranch_c::draw() {
    int activeIdx = 0;
    if (m02B8 == 5) {
        activeIdx = 1;
    }

    g_env_light.settingTevStruct(TEV_TYPE_BG0, &current.pos, &tevStr);
    g_env_light.setLightTevColorType(mModel[activeIdx], &tevStr);

    mAnims[activeIdx]->updateDL();

    return TRUE;
}

/* 0000049C-00000524       .text daBranch_Draw__FP10daBranch_c */
static BOOL daBranch_Draw(daBranch_c* i_this) {
    daBranch_c* branch = static_cast<daBranch_c*>(i_this);
    return branch->draw();
}

inline BOOL daBranch_c::execute() {
    u8 demoId = demoActorID;

    if (demoId == 0) {
        if (m02B8 == 5) {
            if (mAnims[1]) {
                mAnims[1]->play(0, 0, 0);
            }
        }
        else if (m02B8 == 6 && mAnims[0]) {
            mAnims[0]->play(0, 0, 0);
        }
    }
    else {
        dDemo_actor_c* demoActor = dComIfGp_demo_getActor(demoId);

        if (demoActor) {
            m02B8 = demoActor->getShapeId();

            if (m02B8 == 6) {
                demoPlay(mAnims[0]);
            }
            else if (m02B8 == 5) {
                demoPlay(mAnims[1]);
            }
        }
    }

    set_mtx();

    return TRUE;
}

/* 00000524-0000060C       .text daBranch_Execute__FP10daBranch_c */
static BOOL daBranch_Execute(daBranch_c* i_this) {
    daBranch_c* branch = static_cast<daBranch_c*>(i_this);
    return branch->execute();
}

/* 0000060C-00000614       .text daBranch_IsDelete__FP10daBranch_c */
static BOOL daBranch_IsDelete(daBranch_c* i_this) {
    return TRUE;
}

/* 00000614-00000694       .text daBranch_Delete__FP10daBranch_c */
static BOOL daBranch_Delete(daBranch_c* i_this) {
    i_this->~daBranch_c();
    return TRUE;
}

inline cPhs_State daBranch_c::create() {
    fopAcM_ct_Retail(this, daBranch_c);

    cPhs_State phase_state = dComIfG_resLoad(&mPhase, daBranch_c::m_arcname);
    if (phase_state == cPhs_COMPLEATE_e) {
        fopAcM_ct_Demo(this, daBranch_c);

        if (!fopAcM_entrySolidHeap(this, daBranch_c::solidHeapCB, 0x4000)) {
            for (int i = 0; i < (s32)ARRAY_SIZE(mAnims); i++) {
                mAnims[i] = NULL;
            }

            phase_state = cPhs_ERROR_e;
        }
        else {
            fopAcM_SetMtx(this, mModel[0]->getBaseTRMtx());
            fopAcM_setCullSizeBox(this, 0.0f, 0.0f, -50.0f, 300.0f, 100.0f, 50.0f);
            
            m02B8 = 6;
            m02BC = 0;
            m02BD = 0;

            set_mtx();

            for (int i = 0; i < (s32)ARRAY_SIZE(mModel); i++) {
                J3DModelData* modelData = mModel[i]->getModelData();

                for (u16 j = 0; j < modelData->getMaterialNum(); j++) {
                    J3DMaterial* mat = modelData->getMaterialNodePointer(j);
                    if (mat) {
                        mat->getFog()->setType(2);
                    }
                }
            }
        }
    }

    return phase_state;
}

/* 00000694-0000080C       .text daBranch_Create__FP10fopAc_ac_c */
static cPhs_State daBranch_Create(fopAc_ac_c* i_this) {
    daBranch_c* branch = static_cast<daBranch_c*>(i_this);
    return branch->create();
}

static actor_method_class l_daBranch_Method = {
    (process_method_func)daBranch_Create,
    (process_method_func)daBranch_Delete,
    (process_method_func)daBranch_Execute,
    (process_method_func)daBranch_IsDelete,
    (process_method_func)daBranch_Draw,
};

actor_process_profile_definition g_profile_BRANCH = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 0x0007,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_BRANCH_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daBranch_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_BRANCH_e,
    /* Actor SubMtd */ &l_daBranch_Method,
#if VERSION == VERSION_DEMO
    /* Status       */ fopAcStts_CULL_e | fopAcStts_UNK4000_e | fopAcStts_UNK40000_e,
#else
    /* Status       */ fopAcStts_UNK4000_e | fopAcStts_UNK40000_e,
#endif
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};