summaryrefslogtreecommitdiff
path: root/src/actors/item_box/render.inc.c
blob: 1c3e24e621b845707078a32ffdecccf228146c42 (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
#include <actors.h>
#include <main.h>
#include <macros.h>
#include "port/interpolation/FrameInterpolation.h"

/**
 * @brief Renders the item box actor.
 *
 * @param camera
 * @param item_box
 */
void render_actor_item_box(Camera* camera, struct ItemBox* item_box) {
    UNUSED s32 pad[2];
    Vec3f someVec1;
    Vec3f someVec2;
    Vec3s someRot;
    f32 thing;
    UNUSED s32 pad2;
    Mat4 someMatrix1;
    Mat4 someMatrix2;
    UNUSED s32 pad3[4];
    f32 temp_f0;
    f32 temp_f0_2;
    f32 temp_f0_3;
    f32 temp_f12;
    f32 temp_f2;
    f32 temp_f2_2;
    f32 someMultiplier;

    size_t actorIdx = CM_FindActorIndex((struct Actor*)item_box);
    if (-1 == actorIdx) {
        printf("[render_actor_item_box] Could not find item box for FI, skipping!\n");
        return;
    }

    u32 uniqueIdentifier = TAG_ITEM_ADDR((actorIdx << 4) | (camera - cameras));

    temp_f0 = is_within_render_distance(camera->pos, item_box->pos, camera->rot[1], 0.0f, camera->fieldOfView,
                                        4000000.0f);
    if (CVarGetInteger("gNoCulling", 0) == 1) {
        temp_f0 = CLAMP(temp_f0, 0.0f, 600000.0f);
    }
    if (!(temp_f0 < 0.0f) && !(600000.0f < temp_f0)) {
        if ((item_box->state == 2) && (temp_f0 < 100000.0f)) {
            someRot[0] = 0;
            someRot[1] = item_box->rot[1];
            someRot[2] = 0;
            someVec2[0] = item_box->pos[0];
            someVec2[1] = item_box->resetDistance + 2.0f;
            someVec2[2] = item_box->pos[2];

            FrameInterpolation_RecordOpenChild("itembox", uniqueIdentifier);
            mtxf_pos_rotation_xyz(someMatrix1, someVec2, someRot);

            if (!render_set_position(someMatrix1, 0)) {
                FrameInterpolation_RecordCloseChild();
                return;
            }

            gSPDisplayList(gDisplayListHead++, D_0D002EE8);
            FrameInterpolation_RecordCloseChild();
            FrameInterpolation_RecordOpenChild("itembox2", uniqueIdentifier);


            someRot[1] = item_box->rot[1] * 2;
            someVec2[1] = item_box->pos[1];

            mtxf_pos_rotation_xyz(someMatrix1, someVec2, someRot);

            if (!render_set_position(someMatrix1, 0)) {
                FrameInterpolation_RecordCloseChild();
                return;
            }

            gSPDisplayList(gDisplayListHead++, itemBoxQuestionMarkModel);
            FrameInterpolation_RecordCloseChild();
        }
        if (item_box->state == 5) {
            FrameInterpolation_RecordOpenChild("itembox3", uniqueIdentifier);
            mtxf_pos_rotation_xyz(someMatrix1, item_box->pos, item_box->rot);

            if (!render_set_position(someMatrix1, 0)) {
                FrameInterpolation_RecordCloseChild();
                return;
            }

            gSPDisplayList(gDisplayListHead++, itemBoxQuestionMarkModel);
            FrameInterpolation_RecordCloseChild();
        }
        if (item_box->state != 3) {
            FrameInterpolation_RecordOpenChild("itembox4", uniqueIdentifier);
            mtxf_pos_rotation_xyz(someMatrix1, item_box->pos, item_box->rot);

            if (!render_set_position(someMatrix1, 0)) {
                FrameInterpolation_RecordCloseChild();
                return;
            }

            gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING);
            gDPSetCombineMode(gDisplayListHead++, G_CC_MODULATEIA, G_CC_MODULATEIA);

            /*
             * In the original game, the question mark texture would become corrupted. Thus, this code
             * makes it disappear to hide the issue. Since the texture no longer becomes corrupted, this
             * fix can be removed.
             */
#ifdef TARGET_N64
            if ((item_box->rot[1] < 0xAA1) && (item_box->rot[1] > 0)) {
                gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
            } else if ((item_box->rot[1] >= 0x6AA5) && (item_box->rot[1] < 0x754E)) {
                gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
            } else if ((item_box->rot[1] >= 0x38E1) && (item_box->rot[1] < 0x438A)) {
                gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
            } else if ((item_box->rot[1] >= 0xC711) && (item_box->rot[1] < 0xD1BA)) {
                gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
            } else {
#endif
            gDPSetBlendMask(gDisplayListHead++, 0xFF);
            gDPSetRenderMode(gDisplayListHead++, G_RM_ZB_CLD_SURF, G_RM_ZB_CLD_SURF2);
#ifdef TARGET_N64
            }
#endif
            gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH);
            gSPDisplayList(gDisplayListHead++, D_0D003090);
            FrameInterpolation_RecordCloseChild();
        } else {
            gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING);
            gSPClearGeometryMode(gDisplayListHead++, G_CULL_BACK);
            gDPSetBlendMask(gDisplayListHead++, 0xFF);
            thing = item_box->someTimer;

            FrameInterpolation_RecordOpenChild("itembox5", uniqueIdentifier);
            mtxf_pos_rotation_xyz(someMatrix1, item_box->pos, item_box->rot);
            if (thing < 10.0f) {
                someMultiplier = 1.0f;
            } else {
                someMultiplier = 1.0f - ((thing - 10.0f) * 0.1f);
            }
            mtxf_scale(someMatrix1, someMultiplier);
            if (item_box->someTimer & 1) {
                gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
            } else {
                gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_XLU_INTER, G_RM_NOOP2);
            }
            temp_f2 = 2.0f * thing;
            someVec1[0] = 0.0f;
            someVec1[1] = temp_f2;
            someVec1[2] = thing;
            add_translate_mat4_vec3f(someMatrix1, someMatrix2, someVec1);

            if (!render_set_position(someMatrix2, 0)) {
                FrameInterpolation_RecordCloseChild();
                return;
            }

            gSPDisplayList(gDisplayListHead++, D_0D003158);
            FrameInterpolation_RecordCloseChild();
            FrameInterpolation_RecordOpenChild("itembox6", uniqueIdentifier);

            temp_f2_2 = 0.8f * thing;
            temp_f12 = 0.5f * thing;
            someVec1[0] = temp_f2_2;
            someVec1[1] = 2.3f * thing;
            someVec1[2] = temp_f12;
            add_translate_mat4_vec3f(someMatrix1, someMatrix2, someVec1);

            if (!render_set_position(someMatrix2, 0)) {
                FrameInterpolation_RecordCloseChild();
                return;
            }

            gSPDisplayList(gDisplayListHead++, D_0D0031B8);
            FrameInterpolation_RecordCloseChild();
            FrameInterpolation_RecordOpenChild("itembox7", uniqueIdentifier);

            temp_f0_2 = -0.5f * thing;
            someVec1[0] = temp_f2_2;
            someVec1[1] = 1.2f * thing;
            someVec1[2] = temp_f0_2;

            add_translate_mat4_vec3f(someMatrix1, someMatrix2, someVec1);

            if (!render_set_position(someMatrix2, 0)) {
                FrameInterpolation_RecordCloseChild();
                return;
            }

            gSPDisplayList(gDisplayListHead++, D_0D003128);
            FrameInterpolation_RecordCloseChild();
            FrameInterpolation_RecordOpenChild("itembox8", uniqueIdentifier);


            if (!(item_box->someTimer & 1)) {
                gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
            } else {
                gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_XLU_INTER, G_RM_NOOP2);
            }
            someVec1[0] = 0.0f;
            someVec1[1] = 1.8f * thing;
            someVec1[2] = -1.0f * thing;

            add_translate_mat4_vec3f(someMatrix1, someMatrix2, someVec1);

            if (!render_set_position(someMatrix2, 0)) {
                FrameInterpolation_RecordCloseChild();
                return;
            }

            gSPDisplayList(gDisplayListHead++, D_0D0031E8);
            FrameInterpolation_RecordCloseChild();
            FrameInterpolation_RecordOpenChild("itembox9", uniqueIdentifier);

            temp_f0_3 = -0.8f * thing;
            someVec1[0] = temp_f0_3;
            someVec1[1] = 0.6f * thing;
            someVec1[2] = temp_f0_2;

            add_translate_mat4_vec3f(someMatrix1, someMatrix2, someVec1);

            if (!render_set_position(someMatrix2, 0)) {
                FrameInterpolation_RecordCloseChild();
                return;
            }

            gSPDisplayList(gDisplayListHead++, D_0D003188);
            FrameInterpolation_RecordCloseChild();
            FrameInterpolation_RecordOpenChild("itembox10", uniqueIdentifier);

            someVec1[0] = temp_f0_3;
            someVec1[1] = temp_f2;
            someVec1[2] = temp_f12;

            add_translate_mat4_vec3f(someMatrix1, someMatrix2, someVec1);

            if (!render_set_position(someMatrix2, 0)) {
                FrameInterpolation_RecordCloseChild();
                return;
            }

            gSPDisplayList(gDisplayListHead++, D_0D0030F8);
            FrameInterpolation_RecordCloseChild();

            gSPSetGeometryMode(gDisplayListHead++, G_CULL_BACK);
        }
        gSPTexture(gDisplayListHead++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON);
    }
}