summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_mirror_sand.cpp
blob: d8b21299c612981b7f2fab4fb1b70e4be4ccac42 (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
/**
 * d_a_obj_mirror_sand.cpp
 * Mirror Chamber Sand Floor
 */

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

#include "d/actor/d_a_obj_mirror_sand.h"
#include "f_pc/f_pc_name.h"

static char* l_arcName = "MR-Sand";

int daObjMirrorSand_c::createHeap() {
    J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes(l_arcName, 8);
    mpModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000084);
    if (mpModel == NULL) {
        return 0;
    }

    J3DAnmTransform* bck = (J3DAnmTransform*)dComIfG_getObjectRes(l_arcName, 5);
    mpBck = new mDoExt_bckAnm();

    f32 speed;
    if (isSwitch()) {
        speed = 1.0f;
    } else {
        speed = 0.0f;
    }

    if (mpBck == NULL || !mpBck->init(bck, FALSE, J3DFrameCtrl::EMode_NONE, speed, 0, -1, false)) {
        return 0;
    }

    if (isSwitch()) {
        mpBck->setFrame(bck->getFrameMax());
    }

    int i = 0;  // probably fake match, needed to avoid saving mBgMtx to a register
    cBgD_t* dzb = (cBgD_t*)dComIfG_getObjectRes(l_arcName, 11);
    if (mBgw[0].Set(dzb, dBgW::MOVE_BG_e, (Mtx*)&mBgMtx[i])) {
        return 0;
    }

    cBgD_t* dzb2 = (cBgD_t*)dComIfG_getObjectRes(l_arcName, 12);
    if (mBgw[1].Set(dzb2, dBgW::MOVE_BG_e, &mBgMtx)) {
        return 0;
    }

    return 1;
}

static int createSolidHeap(fopAc_ac_c* i_this) {
    return static_cast<daObjMirrorSand_c*>(i_this)->createHeap();
}

void daObjMirrorSand_c::initBaseMtx() {
    fopAcM_SetMtx(this, mpModel->getBaseTRMtx());
    setBaseMtx();
}

void daObjMirrorSand_c::setBaseMtx() {
    mDoMtx_stack_c::transS(current.pos);
    mDoMtx_stack_c::ZXYrotM(shape_angle);

    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
    cMtx_copy(mDoMtx_stack_c::get(), mBgMtx);
    mpCurrentBgw->Move();
}

int daObjMirrorSand_c::draw() {
    g_env_light.settingTevStruct(0x10, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpModel, &tevStr);

    mpBck->entry(mpModel->getModelData());

    dComIfGd_setListBG();
    mDoExt_modelUpdateDL(mpModel);
    dComIfGd_setList();

    mpBck->remove(mpModel->getModelData());
    return 1;
}

static int daObjMirrorSand_Draw(daObjMirrorSand_c* i_this) {
    return i_this->draw();
}

int daObjMirrorSand_c::execute() {
    mpBck->play();

    if (mpCurrentBgw == &mBgw[0] && mpBck->getPlaySpeed() > 0.0f) {
        dComIfG_Bgsp().Release(&mBgw[0]);
        dComIfG_Bgsp().Regist(&mBgw[1], this);
        mpCurrentBgw = &mBgw[1];
        mpCurrentBgw->Move();
    }

    return 1;
}

static int daObjMirrorSand_Execute(daObjMirrorSand_c* i_this) {
    return i_this->execute();
}

static int daObjMirrorSand_IsDelete(daObjMirrorSand_c* i_this) {
    return 1;
}

daObjMirrorSand_c::~daObjMirrorSand_c() {
    if (mBgw[0].ChkUsed()) {
        dComIfG_Bgsp().Release(&mBgw[0]);
    }

    if (mBgw[1].ChkUsed()) {
        dComIfG_Bgsp().Release(&mBgw[1]);
    }

    dComIfG_resDelete(&mPhase, l_arcName);
}

static int daObjMirrorSand_Delete(daObjMirrorSand_c* i_this) {
    i_this->~daObjMirrorSand_c();
    return 1;
}

void daObjMirrorSand_c::create_init() {
    fopAcM_setCullSizeBox2(this, mpModel->getModelData());
    mpBck->setPlaySpeed(0.0f);

    mBgw[0].SetCrrFunc(NULL);
    mBgw[0].SetRoomId(fopAcM_GetRoomNo(this));
    mBgw[1].SetCrrFunc(NULL);
    mBgw[1].SetRoomId(fopAcM_GetRoomNo(this));

    dBgW* current_bgw;
    if (isSwitch()) {
        current_bgw = &mBgw[1];
    } else {
        current_bgw = &mBgw[0];
    }

    mpCurrentBgw = current_bgw;
    dComIfG_Bgsp().Regist(mpCurrentBgw, this);
    initBaseMtx();
}

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

    int phase = dComIfG_resLoad(&mPhase, l_arcName);
    if (phase == cPhs_COMPLEATE_e) {
        if (!fopAcM_entrySolidHeap(this, createSolidHeap, 0x1AD0)) {
            return cPhs_ERROR_e;
        }

        create_init();
    }

    return phase;
}

static int daObjMirrorSand_Create(fopAc_ac_c* i_this) {
    return static_cast<daObjMirrorSand_c*>(i_this)->create();
}

static actor_method_class l_daObjMirrorSand_Method = {
    (process_method_func)daObjMirrorSand_Create,  (process_method_func)daObjMirrorSand_Delete,
    (process_method_func)daObjMirrorSand_Execute, (process_method_func)daObjMirrorSand_IsDelete,
    (process_method_func)daObjMirrorSand_Draw,
};

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