DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
weaponeffect.cpp
1#include "weaponeffect.hpp"
2
3#include <libvu0.h>
4
5#include "frame.hpp"
6#include "mglib.hpp"
7#include "rect.hpp"
8#include "snd.hpp"
9
10void CWeaponEffect::InitSet(CFrame *frame, char *root_name, char *tip_name) {
11 tip = NULL;
12 root = NULL;
13
14 if (frame != NULL) {
15 root = frame->SearchFrame(root_name);
16 tip = frame->SearchFrame(tip_name);
17 }
18}
19
20void CWeaponEffect::Set(int hold, float fade, float fade_out) {
21 sceVu0FVECTOR centre = {0.0f, 0.0f, 0.0f, 1.0f};
22
23 if (root == NULL || tip == NULL) {
24 return;
25 }
26
27 this->hold = hold;
28 this->fade = fade;
29 strength = 255.0f;
30 timer = 0;
31 this->fade_out = fade_out;
32
33 root->GetWorldPosition(edge[cursor * 2], centre);
34 tip->GetWorldPosition(edge[cursor * 2 + 1], centre);
35 edge[cursor * 2 + 1][3] = 1.0f;
36 edge[cursor * 2][3] = 1.0f;
37 alpha[cursor] = 128.0f;
38 used[cursor] = 1;
39
40 cursor++;
41
43 cursor = 0;
44 }
45}
46
48 sceVu0FVECTOR centre = {0.0f, 0.0f, 0.0f, 1.0f};
49 int i;
50
51 if (root == NULL || tip == NULL) {
52 return;
53 }
54
55 // The trail is laid down at full strength while the swing is held, and
56 // weakens once it is over.
57 if (timer < hold) {
58 timer = timer + 1;
59 } else {
61
62 if (strength <= 0.0f) {
63 strength = 0.0f;
64 }
65 }
66
67 if (!(strength <= 0.0f)) {
68 cursor++;
69
71 cursor = 0;
72 }
73
74 root->GetWorldPosition(edge[cursor * 2], centre);
75 tip->GetWorldPosition(edge[cursor * 2 + 1], centre);
76 edge[cursor * 2 + 1][3] = 1.0f;
77 edge[cursor * 2][3] = 1.0f;
79 used[cursor] = 1;
80 }
81
82 for (i = 0; i < WEAPON_EFFECT_STEP_MAX; i++) {
83 if (used[i] != 0) {
84 alpha[i] -= fade;
85
86 if (alpha[i] <= 0.0f) {
87 used[i] = 0;
88 }
89 }
90 }
91}
92
94 int near_root[4];
95 int near_tip[4];
96 int far_root[4];
97 int far_tip[4];
98 sceGsAlpha alpha_reg;
99 sceGsZbuf zbuf;
100 int prev;
101 int i;
102
103 if (root == NULL || tip == NULL) {
104 return;
105 }
106
107 alpha_reg = mgAlpha;
108 alpha_reg.bits.a = 0;
109 alpha_reg.bits.b = 2;
110 alpha_reg.bits.c = 0;
111 alpha_reg.bits.d = 1;
112 MGSetGsALPHA(&alpha_reg);
113
114 zbuf = mgZBuffer;
115 zbuf.bits.zmsk = 1;
116 MGSetGsZBUF(&zbuf);
117
118 // Every piece of the ribbon spans one step and the one before it, so the
119 // first piece reaches back around to the last slot.
120 for (i = 0; i < WEAPON_EFFECT_STEP_MAX; i++) {
121 if (i == 0) {
122 prev = WEAPON_EFFECT_STEP_MAX - 1;
123 } else {
124 prev = i - 1;
125 }
126
127 if (used[i] != 0 && used[prev] != 0 && MGRotTransPers(near_root, edge[prev * 2], 0) != 0 && MGRotTransPers(near_tip, edge[prev * 2 + 1], 0) != 0 && MGRotTransPers(far_root, edge[i * 2], 0) != 0 && MGRotTransPers(far_tip, edge[i * 2 + 1], 0) != 0) {
128 colour[0].a = (u8) alpha[prev];
129 colour[1].a = (u8) alpha[prev];
130 colour[2].a = (u8) alpha[i];
131 colour[3].a = (u8) alpha[i];
132 set3DColSprite(Vif1Packet, near_root, far_root, near_tip, far_tip, &colour[0], &colour[2], &colour[1], &colour[3]);
133 }
134 }
135
136 MGSetGsALPHA(NULL);
137 MGSetGsZBUF(NULL);
138}
void InitSet(CFrame *frame, char *root_name, char *tip_name)
float alpha[WEAPON_EFFECT_STEP_MAX]
void Set(int hold, float fade, float fade_out)
sceVu0FVECTOR edge[WEAPON_EFFECT_STEP_MAX *2]
spRGBA colour[4]
s32 used[WEAPON_EFFECT_STEP_MAX]
u8 a
Definition rect.hpp:49
#define WEAPON_EFFECT_STEP_MAX