summaryrefslogtreecommitdiff
path: root/src/actors/piranha_plant/render.inc.c
blob: 0de9d357fea28ec19aa5e277df032cc82f82c55a (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
#include <actors.h>
#include <main.h>
#include <libultra/gbi.h>
#include <assets/mario_raceway_data.h>
#include <assets/royal_raceway_data.h>

/**
 * @brief Renders the piranha plant actor.
 * Actor used in Mario Raceway and Royal Raceway.
 *
 * @param arg0
 * @param arg1
 * @param arg2
 */
void render_actor_piranha_plant(Camera* arg0, Mat4 arg1, struct PiranhaPlant* arg2) {
    UNUSED s32 pad;
    u8* addr;
    s16 temp_lo = arg0 - camera1;
    s16 animationFrame; // unconfirmed
    s16 temp = arg2->flags;
    f32 temp_f0;
    s32 maxObjectsReached;

    if (temp & 0x800) {
        return;
    }

    temp_f0 = is_within_render_distance(arg0->pos, arg2->pos, arg0->rot[1], 0, gCameraZoom[arg0 - camera1], 1000000.0f);

    if (CVarGetInteger("gNoCulling", 0) == 1) {
        temp_f0 = MAX(temp_f0, 0.0f);
    }

    if (temp_f0 < 0.0f) {

        switch (temp_lo) {
            case 0:
                arg2->visibilityStates[0] = -1;
                break;
            case 1:
                arg2->visibilityStates[1] = -1;
                break;
            case 2:
                arg2->visibilityStates[2] = -1;
                break;
            case 3:
                arg2->visibilityStates[3] = -1;
                break;
        }
        return;
    }
    arg1[3][0] = arg2->pos[0];
    arg1[3][1] = arg2->pos[1];
    arg1[3][2] = arg2->pos[2];
    maxObjectsReached = render_set_position(arg1, 0) == 0;
    if (maxObjectsReached) {
        return;
    }

    if (CVarGetInteger("gDisableLod", 1) == 1) {
        temp_f0 = 0.0f;
    }

    if (90000.0f < temp_f0) {

        switch (temp_lo) {
            case 0:
                arg2->visibilityStates[0] = 0;
                break;
            case 1:
                arg2->visibilityStates[1] = 0;
                break;
            case 2:
                arg2->visibilityStates[2] = 0;
                break;
            case 3:
                arg2->visibilityStates[3] = 0;
                break;
        }
        animationFrame = 0;

    } else {
        switch (temp_lo) {
            case 0:
                arg2->visibilityStates[0] = 1;
                break;
            case 1:
                arg2->visibilityStates[1] = 1;
                break;
            case 2:
                arg2->visibilityStates[2] = 1;
                break;
            case 3:
                arg2->visibilityStates[3] = 1;
                break;
        }

        switch (temp_lo) {
            case 0:
                animationFrame = arg2->timers[0];
                break;
            case 1:
                animationFrame = arg2->timers[1];
                break;
            case 2:
                animationFrame = arg2->timers[2];
                break;
            case 3:
                animationFrame = arg2->timers[3];
                break;
        }
    }
    animationFrame /= 6;

    if (animationFrame > 8) {
        animationFrame = 8;
    }
    addr = D_802BA058 + (animationFrame << 0xB);
    gDPLoadTextureBlock(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(addr), G_IM_FMT_CI, G_IM_SIZ_8b, 32, 64, 0,
                        G_TX_MIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD,
                        G_TX_NOLOD);

    if (IsMarioRaceway) {
        gSPDisplayList(gDisplayListHead++, &d_course_mario_raceway_dl_piranha_plant);
    } else {
        gSPDisplayList(gDisplayListHead++, &d_course_royal_raceway_dl_piranha_plant);
    }
}