Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-2-2013-Decompilation
Path: blob/main/RSDKv4/Scene.hpp
817 views
1
#ifndef SCENE_H
2
#define SCENE_H
3
4
#define LAYER_COUNT (9)
5
#define DEFORM_STORE (256)
6
#define DEFORM_SIZE (320)
7
#define DEFORM_COUNT (DEFORM_STORE + DEFORM_SIZE)
8
#define PARALLAX_COUNT (0x100)
9
10
#define TILE_COUNT (0x400)
11
#define TILE_SIZE (0x10)
12
#define CHUNK_SIZE (0x80)
13
#define TILE_DATASIZE (TILE_SIZE * TILE_SIZE)
14
#define TILESET_SIZE (TILE_COUNT * TILE_DATASIZE)
15
16
#define TILELAYER_CHUNK_W (0x100)
17
#define TILELAYER_CHUNK_H (0x100)
18
#define TILELAYER_CHUNK_COUNT (TILELAYER_CHUNK_W * TILELAYER_CHUNK_H)
19
#define TILELAYER_LINESCROLL_COUNT (TILELAYER_CHUNK_H * CHUNK_SIZE)
20
21
#define CHUNKTILE_COUNT (0x200 * (8 * 8))
22
23
#define CPATH_COUNT (2)
24
25
enum StageListNames {
26
STAGELIST_PRESENTATION,
27
STAGELIST_REGULAR,
28
STAGELIST_BONUS,
29
STAGELIST_SPECIAL,
30
STAGELIST_MAX, // StageList size
31
};
32
33
enum TileLayerTypes {
34
LAYER_NOSCROLL,
35
LAYER_HSCROLL,
36
LAYER_VSCROLL,
37
LAYER_3DFLOOR,
38
LAYER_3DSKY,
39
};
40
41
enum StageModes {
42
STAGEMODE_LOAD,
43
STAGEMODE_NORMAL,
44
STAGEMODE_PAUSED,
45
STAGEMODE_FROZEN,
46
47
#if !RETRO_REV00
48
STAGEMODE_2P,
49
#endif
50
51
STAGEMODE_NORMAL_STEP,
52
STAGEMODE_PAUSED_STEP,
53
STAGEMODE_FROZEN_STEP,
54
55
#if !RETRO_REV00
56
STAGEMODE_2P_STEP,
57
#endif
58
};
59
60
enum TileInfo {
61
TILEINFO_INDEX,
62
TILEINFO_DIRECTION,
63
TILEINFO_VISUALPLANE,
64
TILEINFO_SOLIDITYA,
65
TILEINFO_SOLIDITYB,
66
TILEINFO_FLAGSA,
67
TILEINFO_ANGLEA,
68
TILEINFO_FLAGSB,
69
TILEINFO_ANGLEB,
70
};
71
72
enum DeformationModes {
73
DEFORM_FG,
74
DEFORM_FG_WATER,
75
DEFORM_BG,
76
DEFORM_BG_WATER,
77
};
78
79
enum CameraStyles {
80
CAMERASTYLE_FOLLOW,
81
CAMERASTYLE_EXTENDED,
82
CAMERASTYLE_EXTENDED_OFFSET_L,
83
CAMERASTYLE_EXTENDED_OFFSET_R,
84
CAMERASTYLE_HLOCKED,
85
};
86
87
struct SceneInfo {
88
char name[0x40];
89
char folder[0x40];
90
char id[0x40];
91
bool highlighted;
92
};
93
94
struct CollisionMasks {
95
sbyte floorMasks[TILE_COUNT * TILE_SIZE];
96
sbyte lWallMasks[TILE_COUNT * TILE_SIZE];
97
sbyte rWallMasks[TILE_COUNT * TILE_SIZE];
98
sbyte roofMasks[TILE_COUNT * TILE_SIZE];
99
uint angles[TILE_COUNT];
100
byte flags[TILE_COUNT];
101
};
102
103
struct TileLayer {
104
ushort tiles[TILELAYER_CHUNK_COUNT];
105
byte lineScroll[TILELAYER_LINESCROLL_COUNT];
106
int parallaxFactor;
107
int scrollSpeed;
108
int scrollPos;
109
int angle;
110
int xpos;
111
int ypos;
112
int zpos;
113
int deformationOffset;
114
int deformationOffsetW;
115
byte type;
116
byte xsize;
117
byte ysize;
118
};
119
120
struct LineScroll {
121
int parallaxFactor[PARALLAX_COUNT];
122
int scrollSpeed[PARALLAX_COUNT];
123
int scrollPos[PARALLAX_COUNT];
124
int linePos[PARALLAX_COUNT];
125
int deform[PARALLAX_COUNT];
126
byte entryCount;
127
};
128
129
struct Tiles128x128 {
130
int gfxDataPos[CHUNKTILE_COUNT];
131
ushort tileIndex[CHUNKTILE_COUNT];
132
byte direction[CHUNKTILE_COUNT];
133
byte visualPlane[CHUNKTILE_COUNT];
134
byte collisionFlags[CPATH_COUNT][CHUNKTILE_COUNT];
135
};
136
137
extern int stageListCount[STAGELIST_MAX];
138
extern char stageListNames[STAGELIST_MAX][0x20];
139
extern SceneInfo stageList[STAGELIST_MAX][0x100];
140
141
extern int stageMode;
142
143
extern int cameraTarget;
144
extern int cameraStyle;
145
extern int cameraEnabled;
146
extern int cameraAdjustY;
147
extern int xScrollOffset;
148
extern int yScrollOffset;
149
extern int cameraXPos;
150
extern int cameraYPos;
151
extern int cameraShift;
152
extern int cameraLockedY;
153
extern int cameraShakeX;
154
extern int cameraShakeY;
155
extern int cameraLag;
156
extern int cameraLagStyle;
157
158
extern int curXBoundary1;
159
extern int newXBoundary1;
160
extern int curYBoundary1;
161
extern int newYBoundary1;
162
extern int curXBoundary2;
163
extern int curYBoundary2;
164
extern int waterLevel;
165
extern int waterDrawPos;
166
extern int newXBoundary2;
167
extern int newYBoundary2;
168
169
extern int SCREEN_SCROLL_LEFT;
170
extern int SCREEN_SCROLL_RIGHT;
171
#define SCREEN_SCROLL_UP ((SCREEN_YSIZE / 2) - 16)
172
#define SCREEN_SCROLL_DOWN ((SCREEN_YSIZE / 2) + 16)
173
174
extern int lastXSize;
175
extern int lastYSize;
176
177
extern bool pauseEnabled;
178
extern bool timeEnabled;
179
extern bool debugMode;
180
extern int frameCounter;
181
extern int stageMilliseconds;
182
extern int stageSeconds;
183
extern int stageMinutes;
184
185
// Category and Scene IDs
186
extern int activeStageList;
187
extern int stageListPosition;
188
extern char currentStageFolder[0x100];
189
extern int actID;
190
191
extern char titleCardText[0x100];
192
extern byte titleCardWord2;
193
194
extern byte activeTileLayers[4];
195
extern byte tLayerMidPoint;
196
extern TileLayer stageLayouts[LAYER_COUNT];
197
198
extern int bgDeformationData0[DEFORM_COUNT];
199
extern int bgDeformationData1[DEFORM_COUNT];
200
extern int bgDeformationData2[DEFORM_COUNT];
201
extern int bgDeformationData3[DEFORM_COUNT];
202
203
extern LineScroll hParallax;
204
extern LineScroll vParallax;
205
206
extern Tiles128x128 tiles128x128;
207
extern CollisionMasks collisionMasks[2];
208
209
extern byte tilesetGFXData[TILESET_SIZE];
210
211
extern ushort tile3DFloorBuffer[0x100 * 0x100];
212
extern bool drawStageGFXHQ;
213
214
void InitFirstStage();
215
void InitStartingStage(int list, int stage, int player);
216
void ProcessStage();
217
218
void ProcessParallaxAutoScroll();
219
220
void ResetBackgroundSettings();
221
inline void ResetCurrentStageFolder() { strcpy(currentStageFolder, ""); }
222
inline bool CheckCurrentStageFolder(int stage)
223
{
224
if (strcmp(currentStageFolder, stageList[activeStageList][stage].folder) == 0) {
225
return true;
226
}
227
else {
228
strcpy(currentStageFolder, stageList[activeStageList][stage].folder);
229
return false;
230
}
231
}
232
233
void LoadStageFiles();
234
int LoadActFile(const char *ext, int stageID, FileInfo *info);
235
int LoadStageFile(const char *filePath, int stageID, FileInfo *info);
236
237
void LoadActLayout();
238
void LoadStageBackground();
239
void LoadStageChunks();
240
void LoadStageCollisions();
241
void LoadStageGIFFile(int stageID);
242
243
inline void Init3DFloorBuffer(int layerID)
244
{
245
for (int y = 0; y < TILELAYER_CHUNK_H; ++y) {
246
for (int x = 0; x < TILELAYER_CHUNK_W; ++x) {
247
int c = stageLayouts[layerID].tiles[(x >> 3) + (y >> 3 << 8)] << 6;
248
int tx = x & 7;
249
tile3DFloorBuffer[x + (y << 8)] = c + tx + ((y & 7) << 3);
250
}
251
}
252
}
253
254
inline void Copy16x16Tile(ushort dest, ushort src)
255
{
256
byte *destPtr = &tilesetGFXData[TILELAYER_CHUNK_W * dest];
257
byte *srcPtr = &tilesetGFXData[TILELAYER_CHUNK_W * src];
258
int cnt = TILE_DATASIZE;
259
while (cnt--) *destPtr++ = *srcPtr++;
260
}
261
262
void SetLayerDeformation(int selectedDef, int waveLength, int waveWidth, int waveType, int YPos, int waveSize);
263
264
void SetPlayerScreenPosition(Entity *target);
265
void SetPlayerScreenPositionCDStyle(Entity *target);
266
void SetPlayerHLockedScreenPosition(Entity *target);
267
void SetPlayerLockedScreenPosition(Entity *target);
268
void SetPlayerScreenPositionFixed(Entity *target);
269
270
#endif // !SCENE_H
271
272