Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Scene/Legacy/SceneLegacy.cpp
1168 views
1
2
#include "v3/SceneLegacyv3.cpp"
3
#include "v4/SceneLegacyv4.cpp"
4
5
int32 RSDK::Legacy::stageMode = 0;
6
7
RSDK::Legacy::Camera RSDK::Legacy::cameras[2];
8
RSDK::Legacy::Camera *RSDK::Legacy::currentCamera = NULL;
9
10
int32 RSDK::Legacy::xScrollOffset = 0;
11
int32 RSDK::Legacy::yScrollOffset = 0;
12
int32 RSDK::Legacy::cameraShift = 0;
13
int32 RSDK::Legacy::cameraLockedY = 0;
14
int32 RSDK::Legacy::cameraShakeX = 0;
15
int32 RSDK::Legacy::cameraShakeY = 0;
16
int32 RSDK::Legacy::cameraLag = 0;
17
int32 RSDK::Legacy::cameraLagStyle = 0;
18
19
int32 RSDK::Legacy::curXBoundary1 = 0;
20
int32 RSDK::Legacy::newXBoundary1 = 0;
21
int32 RSDK::Legacy::curYBoundary1 = 0;
22
int32 RSDK::Legacy::newYBoundary1 = 0;
23
int32 RSDK::Legacy::curXBoundary2 = 0;
24
int32 RSDK::Legacy::curYBoundary2 = 0;
25
int32 RSDK::Legacy::waterLevel = 0;
26
int32 RSDK::Legacy::waterDrawPos = 0;
27
int32 RSDK::Legacy::newXBoundary2 = 0;
28
int32 RSDK::Legacy::newYBoundary2 = 0;
29
30
int32 RSDK::Legacy::SCREEN_SCROLL_LEFT = Legacy::SCREEN_CENTERX - 8;
31
int32 RSDK::Legacy::SCREEN_SCROLL_RIGHT = Legacy::SCREEN_CENTERX + 8;
32
33
int32 RSDK::Legacy::lastYSize = -1;
34
int32 RSDK::Legacy::lastXSize = -1;
35
36
bool32 RSDK::Legacy::pauseEnabled = true;
37
bool32 RSDK::Legacy::timeEnabled = true;
38
bool32 RSDK::Legacy::debugMode = false;
39
int32 RSDK::Legacy::frameCounter = 0;
40
int32 RSDK::Legacy::stageMilliseconds = 0;
41
int32 RSDK::Legacy::stageSeconds = 0;
42
int32 RSDK::Legacy::stageMinutes = 0;
43
44
bool32 RSDK::Legacy::anyPress = false;
45
46
// Category and Scene IDs
47
char RSDK::Legacy::currentStageFolder[0x100];
48
int32 RSDK::Legacy::actID = 0;
49
50
char RSDK::Legacy::titleCardText[0x100];
51
uint8 RSDK::Legacy::titleCardWord2 = 0;
52
53
uint8 RSDK::Legacy::activeTileLayers[4];
54
uint8 RSDK::Legacy::tLayerMidPoint;
55
RSDK::Legacy::TileLayer RSDK::Legacy::stageLayouts[LEGACY_LAYER_COUNT];
56
57
int32 RSDK::Legacy::bgDeformationData0[LEGACY_DEFORM_COUNT];
58
int32 RSDK::Legacy::bgDeformationData1[LEGACY_DEFORM_COUNT];
59
int32 RSDK::Legacy::bgDeformationData2[LEGACY_DEFORM_COUNT];
60
int32 RSDK::Legacy::bgDeformationData3[LEGACY_DEFORM_COUNT];
61
62
RSDK::Legacy::LineScroll RSDK::Legacy::hParallax;
63
RSDK::Legacy::LineScroll RSDK::Legacy::vParallax;
64
65
uint16 RSDK::Legacy::tile3DFloorBuffer[0x100 * 0x100];
66
67
RSDK::Legacy::Tiles128x128 RSDK::Legacy::tiles128x128;
68
RSDK::Legacy::CollisionMasks RSDK::Legacy::collisionMasks[2];
69
70
uint8 RSDK::Legacy::tilesetGFXData[LEGACY_TILESET_SIZE];
71
72
void RSDK::Legacy::GetStageFilepath(char *dest, const char *filePath)
73
{
74
StrCopy(dest, "Data/Stages/");
75
StrAdd(dest, sceneInfo.listData[sceneInfo.listPos].folder);
76
StrAdd(dest, "/");
77
StrAdd(dest, filePath);
78
}
79
80
int32 RSDK::Legacy::LoadStageFile(const char *filePath, FileInfo *info)
81
{
82
char dest[0x40];
83
GetStageFilepath(dest, filePath);
84
return LoadFile(info, dest, FMODE_RB);
85
}
86
87
int32 RSDK::Legacy::LoadActFile(const char *ext, FileInfo *info)
88
{
89
char dest[0x40];
90
91
StrCopy(dest, "Data/Stages/");
92
StrAdd(dest, sceneInfo.listData[sceneInfo.listPos].folder);
93
StrAdd(dest, "/Act");
94
StrAdd(dest, sceneInfo.listData[sceneInfo.listPos].id);
95
StrAdd(dest, ext);
96
97
ConvertStringToInteger(sceneInfo.listData[sceneInfo.listPos].id, &actID);
98
99
return LoadFile(info, dest, FMODE_RB);
100
}
101
102
void RSDK::Legacy::LoadStageChunks()
103
{
104
FileInfo info;
105
InitFileInfo(&info);
106
107
if (LoadStageFile("128x128Tiles.bin", &info)) {
108
uint8 entry[3];
109
for (int32 i = 0; i < LEGACY_CHUNKTILE_COUNT; ++i) {
110
ReadBytes(&info, entry, 3);
111
entry[0] -= (uint8)((entry[0] >> 6) << 6);
112
113
tiles128x128.visualPlane[i] = (uint8)(entry[0] >> 4);
114
entry[0] -= 16 * (entry[0] >> 4);
115
116
tiles128x128.direction[i] = (uint8)(entry[0] >> 2);
117
entry[0] -= 4 * (entry[0] >> 2);
118
119
tiles128x128.tileIndex[i] = entry[1] + (entry[0] << 8);
120
tiles128x128.gfxDataPos[i] = tiles128x128.tileIndex[i] << 8;
121
122
tiles128x128.collisionFlags[0][i] = entry[2] >> 4;
123
tiles128x128.collisionFlags[1][i] = entry[2] - ((entry[2] >> 4) << 4);
124
}
125
CloseFile(&info);
126
}
127
}
128
129
void RSDK::Legacy::LoadStageCollisions()
130
{
131
FileInfo info;
132
InitFileInfo(&info);
133
134
if (LoadStageFile("CollisionMasks.bin", &info)) {
135
int32 tileIndex = 0;
136
137
for (int32 t = 0; t < LEGACY_TILE_COUNT; ++t) {
138
for (int32 p = 0; p < LEGACY_CPATH_COUNT; ++p) {
139
uint8 flags = ReadInt8(&info);
140
bool32 isCeiling = flags >> 4;
141
collisionMasks[p].flags[t] = flags & 0xF;
142
143
collisionMasks[p].angles[t] = ReadInt8(&info);
144
collisionMasks[p].angles[t] |= ReadInt8(&info) << 8;
145
collisionMasks[p].angles[t] |= ReadInt8(&info) << 16;
146
collisionMasks[p].angles[t] |= ReadInt8(&info) << 24;
147
148
if (isCeiling) // Ceiling Tile
149
{
150
for (int32 c = 0; c < TILE_SIZE; c += 2) {
151
uint8 buffer = ReadInt8(&info);
152
collisionMasks[p].roofMasks[c + tileIndex] = buffer >> 4;
153
collisionMasks[p].roofMasks[c + tileIndex + 1] = buffer & 0xF;
154
}
155
156
// Has Collision (Pt 1)
157
uint8 solid = ReadInt8(&info);
158
int32 id = 1;
159
for (int32 c = 0; c < TILE_SIZE / 2; ++c) {
160
if (solid & id) {
161
collisionMasks[p].floorMasks[c + tileIndex + 8] = 0;
162
}
163
else {
164
collisionMasks[p].floorMasks[c + tileIndex + 8] = 0x40;
165
collisionMasks[p].roofMasks[c + tileIndex + 8] = -0x40;
166
}
167
id <<= 1;
168
}
169
170
// Has Collision (Pt 2)
171
solid = ReadInt8(&info);
172
id = 1;
173
for (int32 c = 0; c < TILE_SIZE / 2; ++c) {
174
if (solid & id) {
175
collisionMasks[p].floorMasks[c + tileIndex] = 0;
176
}
177
else {
178
collisionMasks[p].floorMasks[c + tileIndex] = 0x40;
179
collisionMasks[p].roofMasks[c + tileIndex] = -0x40;
180
}
181
id <<= 1;
182
}
183
184
// LWall rotations
185
for (int32 c = 0; c < TILE_SIZE; ++c) {
186
int32 h = 0;
187
while (h > -1) {
188
if (h == TILE_SIZE) {
189
collisionMasks[p].lWallMasks[c + tileIndex] = 0x40;
190
h = -1;
191
}
192
else if (c > collisionMasks[p].roofMasks[h + tileIndex]) {
193
++h;
194
}
195
else {
196
collisionMasks[p].lWallMasks[c + tileIndex] = h;
197
h = -1;
198
}
199
}
200
}
201
202
// RWall rotations
203
for (int32 c = 0; c < TILE_SIZE; ++c) {
204
int32 h = TILE_SIZE - 1;
205
while (h < TILE_SIZE) {
206
if (h == -1) {
207
collisionMasks[p].rWallMasks[c + tileIndex] = -0x40;
208
h = TILE_SIZE;
209
}
210
else if (c > collisionMasks[p].roofMasks[h + tileIndex]) {
211
--h;
212
}
213
else {
214
collisionMasks[p].rWallMasks[c + tileIndex] = h;
215
h = TILE_SIZE;
216
}
217
}
218
}
219
}
220
else // Regular Tile
221
{
222
for (int32 c = 0; c < TILE_SIZE; c += 2) {
223
uint8 buffer = ReadInt8(&info);
224
collisionMasks[p].floorMasks[c + tileIndex] = buffer >> 4;
225
collisionMasks[p].floorMasks[c + tileIndex + 1] = buffer & 0xF;
226
}
227
228
uint8 solid = ReadInt8(&info);
229
int32 id = 1;
230
for (int32 c = 0; c < TILE_SIZE / 2; ++c) // HasCollision
231
{
232
if (solid & id) {
233
collisionMasks[p].roofMasks[c + tileIndex + 8] = 0xF;
234
}
235
else {
236
collisionMasks[p].floorMasks[c + tileIndex + 8] = 0x40;
237
collisionMasks[p].roofMasks[c + tileIndex + 8] = -0x40;
238
}
239
id <<= 1;
240
}
241
242
solid = ReadInt8(&info);
243
id = 1;
244
for (int32 c = 0; c < TILE_SIZE / 2; ++c) // HasCollision (pt 2)
245
{
246
if (solid & id) {
247
collisionMasks[p].roofMasks[c + tileIndex] = 0xF;
248
}
249
else {
250
collisionMasks[p].floorMasks[c + tileIndex] = 0x40;
251
collisionMasks[p].roofMasks[c + tileIndex] = -0x40;
252
}
253
id <<= 1;
254
}
255
256
// LWall rotations
257
for (int32 c = 0; c < TILE_SIZE; ++c) {
258
int32 h = 0;
259
while (h > -1) {
260
if (h == TILE_SIZE) {
261
collisionMasks[p].lWallMasks[c + tileIndex] = 0x40;
262
h = -1;
263
}
264
else if (c < collisionMasks[p].floorMasks[h + tileIndex]) {
265
++h;
266
}
267
else {
268
collisionMasks[p].lWallMasks[c + tileIndex] = h;
269
h = -1;
270
}
271
}
272
}
273
274
// RWall rotations
275
for (int32 c = 0; c < TILE_SIZE; ++c) {
276
int32 h = TILE_SIZE - 1;
277
while (h < TILE_SIZE) {
278
if (h == -1) {
279
collisionMasks[p].rWallMasks[c + tileIndex] = -0x40;
280
h = TILE_SIZE;
281
}
282
else if (c < collisionMasks[p].floorMasks[h + tileIndex]) {
283
--h;
284
}
285
else {
286
collisionMasks[p].rWallMasks[c + tileIndex] = h;
287
h = TILE_SIZE;
288
}
289
}
290
}
291
}
292
}
293
tileIndex += 16;
294
}
295
296
CloseFile(&info);
297
}
298
}
299
void RSDK::Legacy::LoadStageGIFFile()
300
{
301
ImageGIF tileset;
302
303
char dest[0x40];
304
GetStageFilepath(dest, "16x16Tiles.gif");
305
306
if (tileset.Load(dest, true) && tileset.width == TILE_SIZE && tileset.height <= LEGACY_TILE_COUNT * TILE_SIZE) {
307
tileset.pixels = tilesetGFXData;
308
tileset.Load(NULL, false);
309
310
for (int32 c = 128; c < 256; ++c) {
311
uint8 red = (tileset.palette[c] >> 0x10);
312
uint8 green = (tileset.palette[c] >> 0x08);
313
uint8 blue = (tileset.palette[c] >> 0x00);
314
SetPaletteEntry(-1, c, red, green, blue);
315
}
316
317
#if RETRO_USE_ORIGINAL_CODE
318
tileset.palette = NULL;
319
tileset.decoder = NULL;
320
#endif
321
tileset.pixels = NULL;
322
323
tileset.Close();
324
}
325
}
326
327
void RSDK::Legacy::ProcessInput()
328
{
329
RSDK::ProcessInput();
330
331
anyPress = controller->keyA.press || controller->keyB.press || controller->keyC.press || controller->keyX.press || controller->keyY.press
332
|| controller->keyZ.press || controller->keyStart.press || controller->keySelect.press;
333
SetGlobalVariableByName("input.pressButton", anyPress);
334
}
335
336
void RSDK::Legacy::ProcessSceneTimer()
337
{
338
if (timeEnabled) {
339
if (++frameCounter == 60) {
340
frameCounter = 0;
341
if (++stageSeconds > 59) {
342
stageSeconds = 0;
343
if (++stageMinutes > 59)
344
stageMinutes = 0;
345
}
346
}
347
stageMilliseconds = 100 * frameCounter / 60;
348
}
349
else {
350
frameCounter = 60 * stageMilliseconds / 100;
351
}
352
}
353
354
void RSDK::Legacy::ResetBackgroundSettings()
355
{
356
for (int32 i = 0; i < LEGACY_LAYER_COUNT; ++i) {
357
stageLayouts[i].deformationOffset = 0;
358
stageLayouts[i].deformationOffsetW = 0;
359
stageLayouts[i].scrollPos = 0;
360
}
361
362
for (int32 i = 0; i < LEGACY_PARALLAX_COUNT; ++i) {
363
hParallax.scrollPos[i] = 0;
364
vParallax.scrollPos[i] = 0;
365
}
366
367
for (int32 i = 0; i < LEGACY_DEFORM_COUNT; ++i) {
368
bgDeformationData0[i] = 0;
369
bgDeformationData1[i] = 0;
370
bgDeformationData2[i] = 0;
371
bgDeformationData3[i] = 0;
372
}
373
}
374
375
void RSDK::Legacy::SetLayerDeformation(int32 selectedDef, int32 waveLength, int32 waveWidth, int32 waveType, int32 YPos, int32 waveSize)
376
{
377
int32 *deformPtr = nullptr;
378
switch (selectedDef) {
379
case DEFORM_FG: deformPtr = bgDeformationData0; break;
380
case DEFORM_FG_WATER: deformPtr = bgDeformationData1; break;
381
case DEFORM_BG: deformPtr = bgDeformationData2; break;
382
case DEFORM_BG_WATER: deformPtr = bgDeformationData3; break;
383
default: break;
384
}
385
386
int32 shift = 9;
387
388
int32 id = 0;
389
if (waveType == 1) {
390
id = YPos;
391
for (int32 i = 0; i < waveSize; ++i) {
392
deformPtr[id] = waveWidth * sin512LookupTable[(i << 9) / waveLength & 0x1FF] >> shift;
393
++id;
394
}
395
}
396
else {
397
for (int32 i = 0; i < 0x200 * 0x100; i += 0x200) {
398
int32 sine = waveWidth * sin512LookupTable[i / waveLength & 0x1FF] >> shift;
399
deformPtr[id] = sine;
400
if (deformPtr[id] >= waveWidth)
401
deformPtr[id] = waveWidth - 1;
402
++id;
403
}
404
}
405
406
switch (selectedDef) {
407
case DEFORM_FG:
408
for (int32 i = LEGACY_DEFORM_STORE; i < LEGACY_DEFORM_COUNT; ++i) bgDeformationData0[i] = bgDeformationData0[i - LEGACY_DEFORM_STORE];
409
break;
410
411
case DEFORM_FG_WATER:
412
for (int32 i = LEGACY_DEFORM_STORE; i < LEGACY_DEFORM_COUNT; ++i) bgDeformationData1[i] = bgDeformationData1[i - LEGACY_DEFORM_STORE];
413
break;
414
415
case DEFORM_BG:
416
for (int32 i = LEGACY_DEFORM_STORE; i < LEGACY_DEFORM_COUNT; ++i) bgDeformationData2[i] = bgDeformationData2[i - LEGACY_DEFORM_STORE];
417
break;
418
419
case DEFORM_BG_WATER:
420
for (int32 i = LEGACY_DEFORM_STORE; i < LEGACY_DEFORM_COUNT; ++i) bgDeformationData3[i] = bgDeformationData3[i - LEGACY_DEFORM_STORE];
421
break;
422
423
default: break;
424
}
425
}
426
427
void RSDK::Legacy::InitCameras()
428
{
429
memset(cameras, 0, sizeof(cameras));
430
cameras[0].enabled = true;
431
cameras[1].enabled = true;
432
cameras[0].target = -1;
433
cameras[1].target = -1;
434
435
currentCamera = &cameras[0];
436
}
437