summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_msw.cpp
blob: 76d20fe304a0c871d1d664b5e2bfd1ea0bd9a5fc (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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
//
// Generated by dtk
// Translation Unit: d_a_msw.cpp
//

#include "d/dolzel_rel.h" // IWYU pragma: keep
#include "d/actor/d_a_msw.h"
#include "res/Object/Msw.h"
#include "d/d_bg_s_movebg_actor.h"
#include "m_Do/m_Do_ext.h"
#include "d/d_com_inf_game.h"
#include "d/d_s_play.h"

/* 00000078-000002D4       .text ride_call_back__FP4dBgWP10fopAc_ac_cP10fopAc_ac_c */
void ride_call_back(dBgW* bgw, fopAc_ac_c* i_ac, fopAc_ac_c* i_pt) {
    msw_class* pActor = static_cast<msw_class*>(i_ac);

    cMtx_YrotS(*calc_mtx, -i_ac->current.angle.y);

    cXyz tmp = i_pt->current.pos - i_ac->current.pos;
    cXyz pos1;
    MtxPosition(&tmp, &pos1);
    cXyz pos2;
    tmp = i_pt->old.pos - i_ac->current.pos;
    MtxPosition(&tmp, &pos2);

    s16 z = pos1.z * ((REG0_F(0) + 20.0f) / i_ac->scale.z);
    s16 x = -pos1.x * ((REG0_F(0) + 20.0f) / i_ac->scale.x);

    cLib_addCalcAngleS2(&i_ac->current.angle.x, z, 10, 0x800);
    cLib_addCalcAngleS2(&i_ac->current.angle.z, x, 10, 0x800);

    f32 dist = (REG0_F(4) + 50.0f) * std::fabsf(pos1.z - pos2.z);
    if (pActor->m2BC.x < dist) {
        pActor->m2BC.x = dist;
    }

    dist = (REG0_F(4) + 50.0f) * std::fabsf(pos1.x - pos2.x);
    if (pActor->m2BC.z < dist) {
        pActor->m2BC.z = dist;
    }

    dist = (REG0_F(8) + 5.0f) * std::fabsf(pos1.x - pos2.x);
    if (dist > 10.0f && pActor->m2B0.x < dist) {
        cLib_addCalc2(&pActor->m2B0.x, dist, 1.0f, REG0_F(7) + 1.2f);
    }

    dist = (REG0_F(8) + 5.0f) * std::fabsf(pos1.z - pos2.z);
    if (dist > 10.0f && pActor->m2B0.z < dist) {
        cLib_addCalc2(&pActor->m2B0.z, dist, 1.0f, REG0_F(7) + 1.2f);
    }

}

/* 00000310-00000540       .text chain_Draw__FP9msw_class */
void chain_Draw(msw_class* i_this) {
    s16 angle1;
    s32 angle2;

    for (int i = 0; i < 4; i++) {
        cXyz tmp = i_this->m310[i] - i_this->m2E0[i];
        angle1 = -cM_atan2s(tmp.y, tmp.z);

        // TODO: std::sqrtf(float)
        angle2 = cM_atan2s(tmp.x, std::sqrtf(tmp.y * tmp.y + tmp.z * tmp.z));

        MtxTrans(i_this->m2E0[i].x, i_this->m2E0[i].y, i_this->m2E0[i].z, false);

        s16 var_r4;
        s32 var_r20;

        if (i_this->m83C[i] != 0) {
            var_r20 = i_this->m83C[i] * cM_ssin(i_this->m298 * 18000) * (REG6_F(6) + 100.0f);
            var_r4 = i_this->m298 * 3000;
        } else {
            var_r4 = 0;
            var_r20 = 0;
        }

        cMtx_YrotM(*calc_mtx, var_r4);
        cMtx_XrotM(*calc_mtx, angle1 + var_r20);
        cMtx_YrotM(*calc_mtx, angle2);

        i_this->mpChainModels[i]->setBaseTRMtx(*calc_mtx);
        g_env_light.setLightTevColorType(i_this->mpChainModels[i], &i_this->tevStr);
        mDoExt_modelUpdateDL(i_this->mpChainModels[i]);
    }
}

/* 00000540-000005E8       .text daMsw_Draw__FP9msw_class */
static BOOL daMsw_Draw(msw_class* i_this) {
    g_env_light.settingTevStruct(TEV_TYPE_BG0, &i_this->current.pos, &i_this->tevStr);
    g_env_light.setLightTevColorType(i_this->mpModel, &i_this->tevStr);

    mDoExt_modelUpdateDL(i_this->mpModel);

    dComIfGd_setListBG();
    chain_Draw(i_this);
    dComIfGd_setList();

    return TRUE;
}

/* 000005E8-0000080C       .text msw_move__FP9msw_class */
void msw_move(msw_class* i_this) {
    i_this->m298 += 1;

#if VERSION > VERSION_DEMO
    // Branchless comparison
    // Probably something #ifdef'd out for debug
    switch (i_this->m29A) {
        case 0:
            break;
    }
#endif

    cLib_addCalcAngleS2(&i_this->current.angle.x, 0, 10, 0x200);
    cLib_addCalcAngleS2(&i_this->current.angle.z, 0, 10, 0x200);

    i_this->m2C8.x = i_this->m2BC.x * cM_ssin(i_this->m298 * 1500);
    i_this->m2C8.z = i_this->m2BC.z * cM_ssin(i_this->m298 * 1300);

    cLib_addCalc2(&i_this->m2BC.x, REG0_F(9), 1.0f, REG0_F(3) + 20.0f);
    cLib_addCalc2(&i_this->m2BC.z, REG0_F(9), 1.0f, REG0_F(3) + 20.0f);

    i_this->m2A4.x = i_this->m2B0.x * cM_ssin(i_this->m298 * 750);
    i_this->m2A4.z = i_this->m2B0.z * cM_ssin(i_this->m298 * 900);

    cLib_addCalc0(&i_this->m2B0.x, 1.0f, REG0_F(6) + 0.25f);
    cLib_addCalc0(&i_this->m2B0.z, 1.0f, REG0_F(6) + 0.25f);

    i_this->shape_angle = i_this->current.angle + i_this->m2C8;
    i_this->current.pos = i_this->home.pos + i_this->m2A4;
}

/* 0000080C-00000AD4       .text daMsw_Execute__FP9msw_class */
static BOOL daMsw_Execute(msw_class* i_this) {
    /* Nonmatching - retail-only regalloc */
    fopAc_ac_c* actor = i_this;
    fopAc_ac_c* player = dComIfGp_getPlayer(0);

    msw_move(i_this);

    MtxTrans(actor->current.pos.x, actor->current.pos.y, actor->current.pos.z, false);
    cMtx_YrotM(*calc_mtx, actor->shape_angle.y);
    cMtx_XrotM(*calc_mtx, actor->shape_angle.x);
    cMtx_ZrotM(*calc_mtx, actor->shape_angle.z);
    MtxScale(actor->scale.x, 1.0f, actor->scale.z, true);
    i_this->mpModel->setBaseTRMtx(*calc_mtx);
    MtxPush();

    for (int chainIdx = 0; chainIdx < 4; chainIdx++) {
        static f32 xd[4] = { 1.0f,  1.0f, -1.0f, -1.0f };
        static f32 zd[4] = { 1.0f, -1.0f,  1.0f, -1.0f };
        cXyz src;
        src.x = (200.0f + REG0_F(10)) * xd[chainIdx];
        src.y = 0.0f;
        src.z = (200.0f + REG0_F(10)) * zd[chainIdx];
        MtxPosition(&src, &i_this->m2E0[chainIdx]);

        if (i_this->m844 != 0) {
            i_this->m844--;
            i_this->m310[chainIdx] = i_this->m2E0[chainIdx];
            i_this->m310[chainIdx].y = i_this->m2E0[chainIdx].y + 1000.0f;
        }

        if (i_this->m83C[chainIdx] != 0) {
            i_this->m83C[chainIdx]--;
        }

        if (i_this->mChainCyls[chainIdx].ChkTgHit() && i_this->m83C[chainIdx] < 10) {
            i_this->m83C[chainIdx] = REG6_S(3) + 15;

            mDoAud_seStart(JA_SE_LK_HIT_SBRIDGE_CHAIN, &i_this->m2E0[chainIdx], 0, dComIfGp_getReverb(fopAcM_GetRoomNo(actor)));

            cXyz scale;
            scale.x = scale.y = scale.z = 2.0f;
            dComIfGp_particle_set(dPa_name::ID_AK_JN_NG, i_this->mChainCyls[chainIdx].GetTgHitPosP(), &player->shape_angle, &scale);
        }
        i_this->mChainCyls[chainIdx].SetC(i_this->m2E0[chainIdx]);

        dComIfG_Ccsp()->Set(&i_this->mChainCyls[chainIdx]);
    }

    MtxPull();
    MTXCopy(*calc_mtx, i_this->mMtx);
    i_this->mpBgW->Move();

    return TRUE;
}

/* 00000AD4-00000B38       .text daMsw_IsDelete__FP9msw_class */
static BOOL daMsw_IsDelete(msw_class* i_this) {
    for (int i = 0; i < 4; i++) {
        mDoAud_seDeleteObject(&i_this->m2E0[i]);
    }

    return TRUE;
}

/* 00000B38-00000B88       .text daMsw_Delete__FP9msw_class */
static BOOL daMsw_Delete(msw_class* i_this) {
    dComIfG_resDeleteDemo(&i_this->mPhs, "Msw");
    dComIfG_Bgsp()->Release(i_this->mpBgW);

    return TRUE;
}

/* 00000B88-00000D3C       .text daMsw_CreateInit__FP10fopAc_ac_c */
BOOL daMsw_CreateInit(fopAc_ac_c* i_this) {
    msw_class* pActor = static_cast<msw_class*>(i_this);

    J3DModelData* modelData = static_cast<J3DModelData*>(dComIfG_getObjectRes("Msw", dRes_INDEX_MSW_BDL_MSWNG_e));
    pActor->mpModel = mDoExt_J3DModel__create(modelData, 0, 0x11020203);

    if (pActor->mpModel == NULL) {
        return FALSE;
    }

    modelData = static_cast<J3DModelData*>(dComIfG_getObjectRes("Msw", dRes_INDEX_MSW_BDL_OBM_CHAIN1_e));
    JUT_ASSERT(DEMO_SELECT(519, 523), modelData != NULL);

    for (int chainIdx = 0; chainIdx < 4; chainIdx++) {
        pActor->mpChainModels[chainIdx] = mDoExt_J3DModel__create(modelData, 0, 0x11020203);
        if (pActor->mpChainModels[chainIdx] == NULL) {
            return FALSE;
        }
    }

    pActor->mpBgW = new dBgW();

    if (pActor->mpBgW == NULL) {
        return FALSE;
    }

    cBgD_t* pBgd = static_cast<cBgD_t*>(dComIfG_getObjectRes("Msw", dRes_INDEX_MSW_DZB_MSWING_e));

    BOOL error = pActor->mpBgW->Set(pBgd, cBgW::MOVE_BG_e, &pActor->mMtx);
    if (error == TRUE) {
        return FALSE;
    }

    pActor->mpBgW->SetCrrFunc(dBgS_MoveBGProc_Typical);
    pActor->mpBgW->SetRideCallback(ride_call_back);

    return TRUE;
}

/* 00000D3C-00000FE0       .text daMsw_Create__FP10fopAc_ac_c */
static cPhs_State daMsw_Create(fopAc_ac_c* i_this) {
    static dCcD_SrcCyl himo_cyl_src = {
        // dCcD_SrcGObjInf
        {
            /* Flags             */ 0,
            /* SrcObjAt  Type    */ 0,
            /* SrcObjAt  Atp     */ 0,
            /* SrcObjAt  SPrm    */ 0,
            /* SrcObjTg  Type    */ ~(AT_TYPE_WATER | AT_TYPE_UNK20000 | AT_TYPE_WIND | AT_TYPE_UNK400000 | AT_TYPE_LIGHT),
            /* SrcObjTg  SPrm    */ cCcD_TgSPrm_Set_e | cCcD_TgSPrm_IsEnemy_e,
            /* SrcObjCo  SPrm    */ cCcD_CoSPrm_Set_e | cCcD_CoSPrm_IsPlayer_e | cCcD_CoSPrm_VsGrpAll_e,
            /* SrcGObjAt Se      */ 0,
            /* SrcGObjAt HitMark */ 0,
            /* SrcGObjAt Spl     */ 0,
            /* SrcGObjAt Mtrl    */ 0,
            /* SrcGObjAt SPrm    */ 0,
            /* SrcGObjTg Se      */ 0,
            /* SrcGObjTg HitMark */ 0,
            /* SrcGObjTg Spl     */ 0,
            /* SrcGObjTg Mtrl    */ 0,
            /* SrcGObjTg SPrm    */ dCcG_TgSPrm_Shield_e,
            /* SrcGObjCo SPrm    */ 0,
        },
        // cM3dGCylS
        {{
            /* Center */ {0.0f, 0.0f, 0.0f},
            /* Radius */ 10.0f,
            /* Height */ 1000.0f,
        }},
    };

    fopAcM_ct(i_this, msw_class);
    msw_class* a_this = static_cast<msw_class*>(i_this);

    cPhs_State phase_state = dComIfG_resLoad(&a_this->mPhs, "Msw");

    if (phase_state == cPhs_COMPLEATE_e) {
        a_this->m2A0 = (fopAcM_GetParam(a_this) >> 0) & 0xFF;

        if (a_this->m2A0 == 0xFF) {
            a_this->m2A0 = 0;
        }

        if (!fopAcM_entrySolidHeap(a_this, daMsw_CreateInit, 0x10040)) {
            return cPhs_ERROR_e;
        }

        if (a_this->mpModel == NULL) {
            return cPhs_ERROR_e;
        }

        if (dComIfG_Bgsp()->Regist(a_this->mpBgW, a_this)) {
            return cPhs_ERROR_e;
        }

        switch (a_this->m2A0) {
        case 1:
            a_this->scale.x = 1.5f;
            a_this->scale.z = 1.5f;
            break;
        case 2:
            a_this->scale.x = 2.0f;
            a_this->scale.z = 2.0f;
            break;
        case 3:
            a_this->scale.x = 3.0f;
            a_this->scale.z = 3.0f;
            break;
        default:
            a_this->scale.z = 1.0f;
            a_this->scale.x = 1.0f;
            break;
        }

        a_this->scale.y = 1.0f;
        fopAcM_SetMtx(a_this, a_this->mpModel->getBaseTRMtx());
        fopAcM_SetMin(a_this, a_this->scale.x * -200.0f, -5000.0f, a_this->scale.z * -200.0f);
        fopAcM_SetMax(a_this, a_this->scale.x * 200.0f, 5000.0f, a_this->scale.z * 200.0f);

        a_this->mStts.Init(0xFF, 0xFF, a_this);

        for (int chainIdx = 0; chainIdx < 4; chainIdx++) {
            a_this->mChainCyls[chainIdx].Set(himo_cyl_src);
            a_this->mChainCyls[chainIdx].SetStts(&a_this->mStts);
        }

        a_this->m844 = 10;
        daMsw_Execute(a_this);
    }

    return phase_state;
}

static actor_method_class l_daMsw_Method = {
    (process_method_func)daMsw_Create,
    (process_method_func)daMsw_Delete,
    (process_method_func)daMsw_Execute,
    (process_method_func)daMsw_IsDelete,
    (process_method_func)daMsw_Draw,
};

actor_process_profile_definition g_profile_MSW = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 0x0003,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_MSW_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(msw_class),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_MSW_e,
    /* Actor SubMtd */ &l_daMsw_Method,
    /* Status       */ fopAcStts_CULL_e | fopAcStts_UNK40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};