DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
fireomni.cpp
1#include "fireomni.hpp"
2
3#include <cstdlib>
4
5#include "camera.hpp"
6#include "mglib.hpp"
7#include "rect.hpp"
8#include "runeffect.hpp"
9#include "snd.hpp"
10#include "texture.hpp"
11
12CFireOmni::CFireOmni() {
13 raster_phase = 0.0f;
14 flame_phase = 0.0f;
15 cell_phase = 15.0f;
16 flicker_width = 0.0f;
17 flicker_height = 0.0f;
18 // Starting the count somewhere in the cycle keeps two fires out of step.
19 flicker_count = (int) (4.0f * (float) rand() / 2.1474836e9f);
20 flicker_seed = 0;
21 unk_00 = 0;
22 glow = NULL;
23 core = NULL;
24 texture_set = 0;
25}
26
27void CFireOmni::FireStep() {
28 cell_phase -= 0.4f;
29
30 if (cell_phase <= 0.0f) {
31 cell_phase = 14.8f;
32 }
33
34 flame_phase += 1.0f;
35
36 if (!(flame_phase < 128.0f)) {
37 flame_phase = 0.0f;
38 }
39
40 flicker_seed = (int) (60000.0f * (float) rand() / 2.1474836e9f);
41}
42
43void CFireOmni::FireCreate() {
44 CTexture *texture = TexManager.GetTexture("d01e02", -1);
45
46 if (texture == NULL) {
47 return;
48 }
49
50 if (texture->bpp == 1) {
51 int cell = (int) cell_phase;
52 int column = cell % 4;
53 int row = cell / 4;
54 sceGsTex0 blend = *reinterpret_cast<sceGsTex0 *>(&TexManager.GetTexture("blender", -1)->tex0);
55 blendTextuer(Vif1Packet, blend.TBP0, blend.TBW, blend.PSM, TexManager.GetTexture("d01e03", -1), CRect_i_(0, 0, 128, 128), CRect_i_(0, (int) flame_phase, 128, 64), TexManager.GetTexture("d01e02", -1), CRect_i_(0, 0, 128, 128), CRect_i_(column * 64, row * 64, 64, 64));
56 } else {
57 sceGsTex0 blend = *reinterpret_cast<sceGsTex0 *>(&TexManager.GetTexture("blender", -1)->tex0);
58 blendTextuer(Vif1Packet, blend.TBP0, blend.TBW, blend.PSM, TexManager.GetTexture("d01e03", -1), CRect_i_(0, 0, 128, 128), CRect_i_(0, (int) flame_phase, 128, 64), TexManager.GetTexture("d01e02", -1), CRect_i_(0, 0, 128, 128), CRect_i_(0, (int) cell_phase * 64, 64, 64));
59 }
60}
61
62void CFireOmni::SetTexture(CTexture *core_texture, CTexture *glow_texture) {
63 this->core = core_texture;
64 this->glow = glow_texture;
65 this->texture_set = 1;
66}
67
68void CFireOmni::DrawFire(int unused0, int unused1, CCamera *camera, float *colour, float scale, int layers, float camera_offset) {
69 sceVu0FVECTOR camera_direction;
70 sceVu0FVECTOR camera_ref;
71 int near_top_left[4];
72 int near_bottom_right[4];
73 sceVu0FVECTOR world;
74 int top_left[4];
75 int bottom_right[4];
76 int top_right[4];
77 int bottom_left[4];
78 sceGsTest test;
79 sceGsZbuf zbuffer;
80 sceGsAlpha alpha;
81
82 if (texture_set == 0) {
83 if (core == NULL) {
84 core = TexManager.GetTexture("lightling", -1);
85 }
86
87 if (glow == NULL) {
88 glow = TexManager.GetTexture("blender", -1);
89 }
90 }
91
92 camera->GetPos(camera_direction);
93 camera->GetRef(camera_ref);
94 sceVu0SubVector(camera_direction, camera_direction, camera_ref);
95 sceVu0Normalize(camera_direction, camera_direction);
96 sceVu0ScaleVector(camera_direction, camera_direction, camera_offset);
97 spRGBA white = {0x80, 0x80, 0x80, 0x80};
98
99 if (layers & 1) {
100 sceVif1PkCnt(Vif1Packet, 0);
101 sceVif1PkOpenDirectCode(Vif1Packet, 0);
102 sceVif1PkOpenGifTag(Vif1Packet, *(u_long128 *) &GiftagAD);
103 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEX1_1, 0x61);
104 test = mgPixelTest;
105 test.bits.ate = 0;
106 test.bits.zte = 1;
107 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEST_1, *(u_long *) &test);
108 zbuffer = mgZBuffer;
109 zbuffer.bits.zmsk = 1;
110 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_ZBUF_1, *(u_long *) &zbuffer);
111 alpha = mgAlpha;
112 alpha.bits.a = 0;
113 alpha.bits.b = 2;
114 alpha.bits.c = 0;
115 alpha.bits.d = 1;
116 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_ALPHA_1, *(u_long *) &alpha);
117 sceVif1PkCloseGifTag(Vif1Packet);
118 sceVif1PkCloseDirectCode(Vif1Packet);
119
120 world[0] = pos[0];
121 world[1] = pos[1] + 4.6f;
122 world[2] = pos[2];
123 world[3] = 1.0f;
124
125 if (MGRotTransPers3DSprite(top_left, bottom_right, world, 18.0f * scale, 9.0f * scale, 1) == 1) {
126 set3DSpriteFog(Vif1Packet, core, CRect_i_(0, 0, 64, 64), top_left, bottom_right, &white);
127 set3DSpriteFog(Vif1Packet, glow, CRect_i_(2, 2, 124, 124), top_left, bottom_right, &white);
128 }
129 }
130
131 if (layers & 2) {
132 sceVif1PkCnt(Vif1Packet, 0);
133 sceVif1PkOpenDirectCode(Vif1Packet, 0);
134 sceVif1PkOpenGifTag(Vif1Packet, *(u_long128 *) &GiftagAD);
135 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEX1_1, 0x61);
136 test = mgPixelTest;
137 test.bits.ate = 0;
138 test.bits.zte = 1;
139 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEST_1, *(u_long *) &test);
140 zbuffer = mgZBuffer;
141 zbuffer.bits.zmsk = 1;
142 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_ZBUF_1, *(u_long *) &zbuffer);
143 alpha = mgAlpha;
144 alpha.bits.a = 0;
145 alpha.bits.b = 2;
146 alpha.bits.c = 0;
147 alpha.bits.d = 1;
148 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_ALPHA_1, *(u_long *) &alpha);
149 sceVif1PkCloseGifTag(Vif1Packet);
150 sceVif1PkCloseDirectCode(Vif1Packet);
151
153 srand(flicker_seed);
154
155 if (flicker_count >= 5) {
156 flicker_height = flicker_width = 1.0f + 0.1f * rand() / 2147483648.0f;
157 flicker_count = 0;
158 }
159
160 world[0] = pos[0];
161 world[1] = pos[1] + 4.6f;
162 world[2] = pos[2];
163 world[3] = 1.0f;
164
165 if (MGRotTransPers3DSprite(top_left, bottom_right, world, 45.0f * flicker_width * scale, 45.0f * flicker_height * scale / 2.0f, 1) == 1) {
166 top_right[0] = bottom_right[0];
167 top_right[1] = top_left[1];
168 top_right[2] = top_left[2];
169 top_right[3] = top_left[3];
170 bottom_left[0] = top_left[0];
171 bottom_left[1] = bottom_right[1];
172 bottom_left[2] = bottom_right[2];
173 bottom_left[3] = bottom_right[3];
174 world[0] += camera_direction[0];
175 world[1] += camera_direction[1];
176 world[2] += camera_direction[2];
177
178 if (MGRotTransPers3DSprite(near_top_left, near_bottom_right, world, 45.0f * scale + flicker_width, (45.0f * scale + flicker_height) / 2.0f, 0) == 1) {
179 top_right[2] = top_left[2] = bottom_left[2] = bottom_right[2] = near_top_left[2];
180 }
181
182 set3DSpriteFog(Vif1Packet, core, CRect_i_(0, 0, 64, 64), top_left, top_right, bottom_left, bottom_right, 0x80);
183 }
184 }
185
186 sceVif1PkCnt(Vif1Packet, 0);
187 sceVif1PkOpenDirectCode(Vif1Packet, 0);
188 sceVif1PkOpenGifTag(Vif1Packet, *(u_long128 *) &GiftagAD);
189 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEX1_1, 0x61);
190 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEST_1, *(u_long *) &mgPixelTest);
191 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_ZBUF_1, *(u_long *) &mgZBuffer);
192 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_ALPHA_1, *(u_long *) &mgAlpha);
193 sceVif1PkCloseGifTag(Vif1Packet);
194 sceVif1PkCloseDirectCode(Vif1Packet);
195}
196
198 float phase = this->raster_phase + ((2.0f * (float) rand()) / 2.1474836e9f);
199 this->raster_phase = phase;
200
201 if (!(phase < 8.0f)) {
202 this->raster_phase = 0.0f;
203 }
204}
205
207 sceVu0FVECTOR world;
208 int top_left[4];
209 int bottom_right[4];
210
211 world[0] = pos[0];
212 world[1] = pos[1] + 3.0f;
213 world[2] = pos[2];
214 world[3] = 1.0f;
215
216 if (MGRotTransPers3DSprite(top_left, bottom_right, world, 15.0f, 16.0f, 0) != 1) {
217 return;
218 }
219
220 int x = (top_left[0] - 0x6C00) >> 4;
221 int y = (top_left[1] - GS_Y_OFFSET) >> 3;
222 int width = (bottom_right[0] - top_left[0]) >> 4;
223 int height = (bottom_right[1] - top_left[1]) >> 4;
224 height >>= 1;
225
226 if (x + width > 639 && x < 640) {
227 width = 639 - x;
228 }
229
230 if (x < 0 && x + width > 0) {
231 width = x + width;
232 x = 0;
233 }
234
235 if (y < 1) {
236 height += y >> 1;
237 y = 0;
238 }
239
240 sceGsTex0 blend = *reinterpret_cast<sceGsTex0 *>(&TexManager.GetTexture("blender", -1)->tex0);
241 blendTextuerTest(Vif1Packet, blend.TBP0, blend.TBW, blend.PSM, CRect_i_(x, y >> 1, width, height), TexManager.GetTexture("alpha01", -1), CRect_i_(0, 0, width, height), CRect_i_(0, 0, 64, 64), top_left[2] >> 4, raster_phase);
242 set2DSprite(Vif1Packet, TexManager.GetTexture("blender", -1), CRect_i_(x, y, width, height * 2), CRect_i_(1, 1, width - 2, height - 2));
243}
void GetRef(float *ref)
Definition camera.cpp:234
void GetPos(float *pos)
Definition camera.cpp:230
CTexture * core
Definition op_a.cpp:110
s32 flicker_count
Definition fireomni.hpp:27
float raster_phase
Definition fireomni.hpp:20
s32 texture_set
Definition op_a.cpp:109
float cell_phase
Definition fireomni.hpp:22
void RasterStep()
Definition fireomni.cpp:197
float flicker_height
Definition fireomni.hpp:24
s16 flicker_seed
Definition fireomni.hpp:25
sceVu0FVECTOR pos
Definition op_a.cpp:108
void DrawRaster()
Definition fireomni.cpp:206
float flicker_width
Definition fireomni.hpp:23
float flame_phase
Definition fireomni.hpp:21
void SetTexture(CTexture *core_texture, CTexture *glow_texture)
Definition fireomni.cpp:62
CTexture * glow
Definition op_a.cpp:111
short bpp
Definition texture.hpp:55
u_long tex0
Definition texture.hpp:57