summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_lv9SwShutter.cpp
blob: 0a034ea6bd3ccbb51b415e2c77c5859736d86d03 (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
/**
 * @file d_a_obj_lv9SwShutter.cpp
 * 
*/

#include "d/dolzel_rel.h" // IWYU pragma: keep

#include "d/actor/d_a_obj_lv9SwShutter.h"

class daLv9SwShutter_HIO_c : public mDoHIO_entry_c {
public:
    daLv9SwShutter_HIO_c();
    virtual ~daLv9SwShutter_HIO_c() {}

    void genMessage(JORMContext*);

    /* 0x04 */ f32 open_speed;
    /* 0x08 */ f32 close_speed;
    /* 0x0C */ f32 close_accel;
    /* 0x10 */ u8 vibration;
};

daLv9SwShutter_HIO_c::daLv9SwShutter_HIO_c() {
    open_speed = 6.0f;
    close_speed = 30.0f;
    close_accel = 15.0f;
    vibration = 3;
}

static daLv9SwShutter_HIO_c l_HIO;

void daLv9SwShutter_c::setBaseMtx() {
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::ZXYrotM(shape_angle.x, shape_angle.y, shape_angle.z);
    mDoMtx_stack_c::transM(0.0f, field_0x5b0, 0.0f);
    mpModel->setBaseScale(scale);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
}

int daLv9SwShutter_c::CreateHeap() {
    J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes("L9SwShut", 4);
    JUT_ASSERT(167, modelData != NULL);

    mpModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000084);
    if (mpModel == NULL) {
        return 0;
    }

    return 1;
}

int daLv9SwShutter_c::create() {
    fopAcM_ct(this, daLv9SwShutter_c);

    int phase_state = dComIfG_resLoad(&mPhase, "L9SwShut");
    if (phase_state == cPhs_COMPLEATE_e) {
        if (MoveBGCreate("L9SwShut", 7, dBgS_MoveBGProc_TypicalRotY, 0x1300, NULL) == cPhs_ERROR_e) {
            return cPhs_ERROR_e;
        }

        fopAcM_SetMtx(this, mpModel->getBaseTRMtx());
        fopAcM_setCullSizeBox2(this, mpModel->getModelData());

        mSwbit = getSw();
        field_0x5b0 = 0.0f;

        mIsSwitch = fopAcM_isSwitch(this, mSwbit);
        if (mIsSwitch) {
            field_0x5b0 = 600.0f;
        }

        init_modeWait();
        setBaseMtx();

        #if DEBUG
        l_HIO.entryHIO("スイッチシャッター(Lv9)");
        #endif
    }

    return phase_state;
}

int daLv9SwShutter_c::Execute(Mtx** param_0) {
    moveShutter();
    *param_0 = &mpModel->getBaseTRMtx();
    setBaseMtx();
    return 1;
}

void daLv9SwShutter_c::moveShutter() {
    static void (daLv9SwShutter_c::*mode_proc[])() = {
        &daLv9SwShutter_c::modeWait,
        &daLv9SwShutter_c::modeOpen,
        &daLv9SwShutter_c::modeClose,
    };

    u8 prev_switch = mIsSwitch;
    mIsSwitch = fopAcM_isSwitch(this, mSwbit);
    if (mIsSwitch != prev_switch) {
        if (mIsSwitch) {
            init_modeOpen();
        } else {
            init_modeClose();
        }
    }

    (this->*mode_proc[mMode])();
}

void daLv9SwShutter_c::init_modeWait() {
    mMode = 0;
}

void daLv9SwShutter_c::modeWait() {}

void daLv9SwShutter_c::init_modeOpen() {
    mMode = 1;
}

void daLv9SwShutter_c::modeOpen() {
    f32 temp_f31 = cLib_addCalc(&field_0x5b0, 600.0f, 0.1f, l_HIO.open_speed, 5.0f);
    mDoMtx_stack_c::ZXYrotS(shape_angle.x, shape_angle.y, shape_angle.z);
    cXyz sp8(0.0f, field_0x5b0, 0.0f);
    mDoMtx_stack_c::multVec(&sp8, &sp8);
    sp8 += current.pos;

    mDoAud_seStartLevel(Z2SE_OBJ_GATE_LV9_OP, &sp8, 0, dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
    if (0.0f == temp_f31) {
        mDoAud_seStart(Z2SE_OBJ_GATE_LV9_STOP, &sp8, 0, dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
        init_modeWait();
    }
}

void daLv9SwShutter_c::init_modeClose() {
    fopAcM_SetSpeedF(this, 0.0f);
    mMode = 2;
}

void daLv9SwShutter_c::modeClose() {
    cLib_chaseF(&speedF, l_HIO.close_speed, l_HIO.close_accel);

    f32 temp_f31 = cLib_addCalc(&field_0x5b0, 0.0f, 1.0f, fopAcM_GetSpeedF(this), 5.0f);
    mDoMtx_stack_c::ZXYrotS(shape_angle.x, shape_angle.y, shape_angle.z);
    cXyz sp8(0.0f, field_0x5b0, 0.0f);
    mDoMtx_stack_c::multVec(&sp8, &sp8);
    sp8 += current.pos;

    mDoAud_seStartLevel(Z2SE_OBJ_GATE_LV9_OP, &sp8, 0, dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
    if (0.0f == temp_f31) {
        mDoAud_seStart(Z2SE_OBJ_GATE_LV9_STOP, &sp8, 0, dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
        init_modeWait();
    }
}

int daLv9SwShutter_c::Draw() {
    g_env_light.settingTevStruct(16, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpModel, &tevStr);
    dComIfGd_setListBG();
    mDoExt_modelUpdateDL(mpModel);
    dComIfGd_setList();
    return 1;
}

int daLv9SwShutter_c::Delete() {
    dComIfG_resDelete(&mPhase, "L9SwShut");
    #if DEBUG
    l_HIO.removeHIO();
    #endif
    return 1;
}

static int daLv9SwShutter_Draw(daLv9SwShutter_c* i_this) {
    return i_this->MoveBGDraw();
}

static int daLv9SwShutter_Execute(daLv9SwShutter_c* i_this) {
    return i_this->MoveBGExecute();
}

static int daLv9SwShutter_Delete(daLv9SwShutter_c* i_this) {
    return i_this->MoveBGDelete();
}

static int daLv9SwShutter_Create(fopAc_ac_c* i_this) {
    return ((daLv9SwShutter_c*)i_this)->create();
}

static actor_method_class l_daLv9SwShutter_Method = {
    (process_method_func)daLv9SwShutter_Create,
    (process_method_func)daLv9SwShutter_Delete,
    (process_method_func)daLv9SwShutter_Execute,
    NULL,
    (process_method_func)daLv9SwShutter_Draw,
};

actor_process_profile_definition g_profile_Obj_Lv9SwShutter = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 3,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_Lv9SwShutter_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daLv9SwShutter_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_Lv9SwShutter_e,
    /* Actor SubMtd */ &l_daLv9SwShutter_Method,
    /* Status       */ fopAcStts_UNK_0x40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};