Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Scene/Legacy/v4/ObjectLegacyv4.cpp
1174 views
1
2
// Game Objects
3
int32 RSDK::Legacy::v4::objectEntityPos = 0;
4
int32 RSDK::Legacy::v4::curObjectType = 0;
5
RSDK::Legacy::v4::Entity RSDK::Legacy::v4::objectEntityList[LEGACY_v4_ENTITY_COUNT * 2]; //"regular" list & "storage" list
6
int32 RSDK::Legacy::v4::processObjectFlag[LEGACY_v4_ENTITY_COUNT];
7
RSDK::Legacy::v4::TypeGroupList RSDK::Legacy::v4::objectTypeGroupList[LEGACY_v4_TYPEGROUP_COUNT];
8
9
int32 RSDK::Legacy::v4::playerListPos = 0;
10
11
char RSDK::Legacy::v4::typeNames[LEGACY_v4_OBJECT_COUNT][0x40];
12
13
void RSDK::Legacy::v4::ProcessStartupObjects()
14
{
15
scriptFrameCount = 0;
16
ClearAnimationData();
17
scriptEng.arrayPosition[8] = LEGACY_v4_TEMPENTITY_START;
18
OBJECT_BORDER_X1 = 0x80;
19
OBJECT_BORDER_X3 = 0x20;
20
OBJECT_BORDER_X2 = SCREEN_XSIZE + 0x80;
21
OBJECT_BORDER_X4 = SCREEN_XSIZE + 0x20;
22
Entity *entity = &objectEntityList[LEGACY_v4_TEMPENTITY_START];
23
// Dunno what this is meant for, but it's here in the original code so...
24
objectEntityList[TEMPENTITY_START + 1].type = objectEntityList[0].type;
25
26
memset(foreachStack, -1, sizeof(foreachStack));
27
memset(jumpTableStack, 0, sizeof(jumpTableStack));
28
29
for (int32 i = 0; i < LEGACY_v4_OBJECT_COUNT; ++i) {
30
ObjectScript *scriptInfo = &objectScriptList[i];
31
objectEntityPos = LEGACY_v4_TEMPENTITY_START;
32
curObjectType = i;
33
scriptInfo->frameListOffset = scriptFrameCount;
34
scriptInfo->spriteSheetID = 0;
35
entity->type = i;
36
37
if (scriptCode[scriptInfo->eventStartup.scriptCodePtr] > 0)
38
ProcessScript(scriptInfo->eventStartup.scriptCodePtr, scriptInfo->eventStartup.jumpTablePtr, EVENT_SETUP);
39
scriptInfo->frameCount = scriptFrameCount - scriptInfo->frameListOffset;
40
}
41
entity->type = 0;
42
curObjectType = 0;
43
}
44
45
void RSDK::Legacy::v4::ProcessObjects()
46
{
47
for (int32 i = 0; i < LEGACY_DRAWLAYER_COUNT; ++i) drawListEntries[i].listSize = 0;
48
49
for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {
50
processObjectFlag[objectEntityPos] = false;
51
int32 x = 0, y = 0;
52
Entity *entity = &objectEntityList[objectEntityPos];
53
x = entity->xpos >> 16;
54
y = entity->ypos >> 16;
55
56
switch (entity->priority) {
57
case PRIORITY_BOUNDS:
58
processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X1 && x < xScrollOffset + OBJECT_BORDER_X2
59
&& y > yScrollOffset - OBJECT_BORDER_Y1 && y < yScrollOffset + OBJECT_BORDER_Y2;
60
break;
61
62
case PRIORITY_ACTIVE:
63
case PRIORITY_ALWAYS:
64
case PRIORITY_ACTIVE_SMALL: processObjectFlag[objectEntityPos] = true; break;
65
66
case PRIORITY_XBOUNDS:
67
processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X1 && x < OBJECT_BORDER_X2 + xScrollOffset;
68
break;
69
70
case PRIORITY_XBOUNDS_DESTROY:
71
processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X1 && x < xScrollOffset + OBJECT_BORDER_X2;
72
if (!processObjectFlag[objectEntityPos]) {
73
processObjectFlag[objectEntityPos] = false;
74
entity->type = OBJ_TYPE_BLANKOBJECT;
75
}
76
break;
77
78
case PRIORITY_INACTIVE: processObjectFlag[objectEntityPos] = false; break;
79
case PRIORITY_BOUNDS_SMALL:
80
processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X3 && x < OBJECT_BORDER_X4 + xScrollOffset
81
&& y > yScrollOffset - OBJECT_BORDER_Y3 && y < yScrollOffset + OBJECT_BORDER_Y4;
82
break;
83
84
default: break;
85
}
86
87
if (processObjectFlag[objectEntityPos] && entity->type > OBJ_TYPE_BLANKOBJECT) {
88
ObjectScript *scriptInfo = &objectScriptList[entity->type];
89
if (scriptCode[scriptInfo->eventUpdate.scriptCodePtr] > 0)
90
ProcessScript(scriptInfo->eventUpdate.scriptCodePtr, scriptInfo->eventUpdate.jumpTablePtr, EVENT_MAIN);
91
92
if (entity->drawOrder < LEGACY_DRAWLAYER_COUNT)
93
drawListEntries[entity->drawOrder].entityRefs[drawListEntries[entity->drawOrder].listSize++] = objectEntityPos;
94
}
95
}
96
97
for (int32 g = 0; g < LEGACY_v4_TYPEGROUP_COUNT; ++g) objectTypeGroupList[g].listSize = 0;
98
99
for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {
100
Entity *entity = &objectEntityList[objectEntityPos];
101
if (processObjectFlag[objectEntityPos] && entity->objectInteractions) {
102
// Custom Group
103
if (entity->groupID >= LEGACY_v4_OBJECT_COUNT) {
104
TypeGroupList *listCustom = &objectTypeGroupList[objectEntityList[objectEntityPos].groupID];
105
listCustom->entityRefs[listCustom->listSize++] = objectEntityPos;
106
}
107
108
// Type-Specific list
109
TypeGroupList *listType = &objectTypeGroupList[objectEntityList[objectEntityPos].type];
110
listType->entityRefs[listType->listSize++] = objectEntityPos;
111
112
// All Entities list
113
TypeGroupList *listAll = &objectTypeGroupList[GROUP_ALL];
114
listAll->entityRefs[listAll->listSize++] = objectEntityPos;
115
}
116
}
117
}
118
void RSDK::Legacy::v4::ProcessPausedObjects()
119
{
120
for (int32 i = 0; i < LEGACY_DRAWLAYER_COUNT; ++i) drawListEntries[i].listSize = 0;
121
122
for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {
123
Entity *entity = &objectEntityList[objectEntityPos];
124
125
if (entity->priority == PRIORITY_ALWAYS && entity->type > OBJ_TYPE_BLANKOBJECT) {
126
ObjectScript *scriptInfo = &objectScriptList[entity->type];
127
if (scriptCode[scriptInfo->eventUpdate.scriptCodePtr] > 0)
128
ProcessScript(scriptInfo->eventUpdate.scriptCodePtr, scriptInfo->eventUpdate.jumpTablePtr, EVENT_MAIN);
129
130
if (entity->drawOrder < LEGACY_DRAWLAYER_COUNT)
131
drawListEntries[entity->drawOrder].entityRefs[drawListEntries[entity->drawOrder].listSize++] = objectEntityPos;
132
}
133
}
134
}
135
void RSDK::Legacy::v4::ProcessFrozenObjects()
136
{
137
for (int32 g = 0; g < LEGACY_DRAWLAYER_COUNT; ++g) drawListEntries[g].listSize = 0;
138
139
for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {
140
processObjectFlag[objectEntityPos] = false;
141
int32 x = 0, y = 0;
142
Entity *entity = &objectEntityList[objectEntityPos];
143
x = entity->xpos >> 16;
144
y = entity->ypos >> 16;
145
146
switch (entity->priority) {
147
case PRIORITY_BOUNDS:
148
processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X1 && x < xScrollOffset + OBJECT_BORDER_X2
149
&& y > yScrollOffset - OBJECT_BORDER_Y1 && y < yScrollOffset + OBJECT_BORDER_Y2;
150
break;
151
152
case PRIORITY_ACTIVE:
153
case PRIORITY_ALWAYS:
154
case PRIORITY_ACTIVE_SMALL: processObjectFlag[objectEntityPos] = true; break;
155
156
case PRIORITY_XBOUNDS:
157
processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X1 && x < OBJECT_BORDER_X2 + xScrollOffset;
158
break;
159
160
case PRIORITY_XBOUNDS_DESTROY:
161
processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X1 && x < xScrollOffset + OBJECT_BORDER_X2;
162
if (!processObjectFlag[objectEntityPos]) {
163
processObjectFlag[objectEntityPos] = false;
164
entity->type = OBJ_TYPE_BLANKOBJECT;
165
}
166
break;
167
168
case PRIORITY_INACTIVE: processObjectFlag[objectEntityPos] = false; break;
169
170
case PRIORITY_BOUNDS_SMALL:
171
processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X3 && x < OBJECT_BORDER_X4 + xScrollOffset
172
&& y > yScrollOffset - OBJECT_BORDER_Y3 && y < yScrollOffset + OBJECT_BORDER_Y4;
173
break;
174
175
default: break;
176
}
177
178
if (processObjectFlag[objectEntityPos] && entity->type > OBJ_TYPE_BLANKOBJECT) {
179
ObjectScript *scriptInfo = &objectScriptList[entity->type];
180
if (scriptCode[scriptInfo->eventUpdate.scriptCodePtr] > 0 && entity->priority == PRIORITY_ALWAYS)
181
ProcessScript(scriptInfo->eventUpdate.scriptCodePtr, scriptInfo->eventUpdate.jumpTablePtr, EVENT_MAIN);
182
183
if (entity->drawOrder < LEGACY_DRAWLAYER_COUNT)
184
drawListEntries[entity->drawOrder].entityRefs[drawListEntries[entity->drawOrder].listSize++] = objectEntityPos;
185
}
186
}
187
188
for (int32 g = 0; g < LEGACY_v4_TYPEGROUP_COUNT; ++g) objectTypeGroupList[g].listSize = 0;
189
190
for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {
191
Entity *entity = &objectEntityList[objectEntityPos];
192
if (processObjectFlag[objectEntityPos] && entity->objectInteractions) {
193
// Custom Group
194
if (entity->groupID >= LEGACY_v4_OBJECT_COUNT) {
195
TypeGroupList *listCustom = &objectTypeGroupList[objectEntityList[objectEntityPos].groupID];
196
listCustom->entityRefs[listCustom->listSize++] = objectEntityPos;
197
}
198
199
// Type-Specific list
200
TypeGroupList *listType = &objectTypeGroupList[objectEntityList[objectEntityPos].type];
201
listType->entityRefs[listType->listSize++] = objectEntityPos;
202
203
// All Entities list
204
TypeGroupList *listAll = &objectTypeGroupList[GROUP_ALL];
205
listAll->entityRefs[listAll->listSize++] = objectEntityPos;
206
}
207
}
208
}
209
void RSDK::Legacy::v4::Process2PObjects()
210
{
211
for (int32 i = 0; i < LEGACY_DRAWLAYER_COUNT; ++i) drawListEntries[i].listSize = 0;
212
213
int32 boundX1 = -(0x200 << 16);
214
int32 boundX2 = (0x200 << 16);
215
int32 boundX3 = -(0x180 << 16);
216
int32 boundX4 = (0x180 << 16);
217
218
int32 boundY1 = -(0x180 << 16);
219
int32 boundY2 = (0x180 << 16);
220
int32 boundY3 = -(0x100 << 16);
221
int32 boundY4 = (0x100 << 16);
222
223
for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {
224
processObjectFlag[objectEntityPos] = false;
225
int32 x = 0, y = 0;
226
227
Entity *entity = &objectEntityList[objectEntityPos];
228
x = entity->xpos;
229
y = entity->ypos;
230
231
// Set these here, they could (and prolly are) updated after objects
232
Entity *entityP1 = &objectEntityList[0];
233
int32 XPosP1 = entityP1->xpos;
234
int32 YPosP1 = entityP1->ypos;
235
236
Entity *entityP2 = &objectEntityList[1];
237
int32 XPosP2 = entityP2->xpos;
238
int32 YPosP2 = entityP2->ypos;
239
240
switch (entity->priority) {
241
case PRIORITY_BOUNDS:
242
processObjectFlag[objectEntityPos] = x > XPosP1 + boundX1 && x < XPosP1 + boundX2 && y > YPosP1 + boundY1 && y < YPosP1 + boundY2;
243
if (!processObjectFlag[objectEntityPos]) {
244
processObjectFlag[objectEntityPos] = x > XPosP2 + boundX1 && x < XPosP2 + boundX2 && y > YPosP2 + boundY1 && y < YPosP2 + boundY2;
245
}
246
break;
247
248
case PRIORITY_ACTIVE:
249
case PRIORITY_ALWAYS:
250
case PRIORITY_ACTIVE_SMALL: processObjectFlag[objectEntityPos] = true; break;
251
252
case PRIORITY_XBOUNDS:
253
processObjectFlag[objectEntityPos] = x > XPosP1 + boundX1 && x < XPosP1 + boundX2;
254
if (!processObjectFlag[objectEntityPos]) {
255
processObjectFlag[objectEntityPos] = x > XPosP2 + boundX1 && x < XPosP2 + boundX2;
256
}
257
break;
258
259
case PRIORITY_XBOUNDS_DESTROY:
260
processObjectFlag[objectEntityPos] = x > XPosP1 + boundX1 && x < XPosP1 + boundX2;
261
if (!processObjectFlag[objectEntityPos]) {
262
processObjectFlag[objectEntityPos] = x > XPosP2 + boundX1 && x < XPosP2 + boundX2;
263
}
264
265
if (!processObjectFlag[objectEntityPos])
266
entity->type = OBJ_TYPE_BLANKOBJECT;
267
break;
268
269
case PRIORITY_INACTIVE: processObjectFlag[objectEntityPos] = false; break;
270
271
case PRIORITY_BOUNDS_SMALL:
272
processObjectFlag[objectEntityPos] = x > XPosP1 + boundX3 && x < XPosP1 + boundX4 && y > YPosP1 + boundY3 && y < YPosP1 + boundY4;
273
if (!processObjectFlag[objectEntityPos]) {
274
processObjectFlag[objectEntityPos] = x > XPosP2 + boundX3 && x < XPosP2 + boundX4 && y > YPosP2 + boundY3 && y < YPosP2 + boundY4;
275
}
276
break;
277
278
default: break;
279
}
280
281
if (processObjectFlag[objectEntityPos] && entity->type > OBJ_TYPE_BLANKOBJECT) {
282
ObjectScript *scriptInfo = &objectScriptList[entity->type];
283
if (scriptCode[scriptInfo->eventUpdate.scriptCodePtr] > 0)
284
ProcessScript(scriptInfo->eventUpdate.scriptCodePtr, scriptInfo->eventUpdate.jumpTablePtr, EVENT_MAIN);
285
286
if (entity->drawOrder < LEGACY_DRAWLAYER_COUNT)
287
drawListEntries[entity->drawOrder].entityRefs[drawListEntries[entity->drawOrder].listSize++] = objectEntityPos;
288
}
289
}
290
291
for (int32 i = 0; i < LEGACY_v4_TYPEGROUP_COUNT; ++i) objectTypeGroupList[i].listSize = 0;
292
293
for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {
294
Entity *entity = &objectEntityList[objectEntityPos];
295
if (processObjectFlag[objectEntityPos] && entity->objectInteractions) {
296
// Custom Group
297
if (entity->groupID >= LEGACY_v4_OBJECT_COUNT) {
298
TypeGroupList *listCustom = &objectTypeGroupList[objectEntityList[objectEntityPos].groupID];
299
listCustom->entityRefs[listCustom->listSize++] = objectEntityPos;
300
}
301
302
// Type-Specific list
303
TypeGroupList *listType = &objectTypeGroupList[objectEntityList[objectEntityPos].type];
304
listType->entityRefs[listType->listSize++] = objectEntityPos;
305
306
// All Entities list
307
TypeGroupList *listAll = &objectTypeGroupList[GROUP_ALL];
308
listAll->entityRefs[listAll->listSize++] = objectEntityPos;
309
}
310
}
311
}
312
313
void RSDK::Legacy::v4::SetObjectTypeName(const char *objectName, int32 objectID)
314
{
315
int32 objPos = 0;
316
int32 typePos = 0;
317
while (objectName[objPos]) {
318
if (objectName[objPos] != ' ')
319
typeNames[objectID][typePos++] = objectName[objPos];
320
++objPos;
321
}
322
typeNames[objectID][typePos] = 0;
323
PrintLog(PRINT_NORMAL, "Set Object (%d) name to: %s", objectID, objectName);
324
}
325
326
void RSDK::Legacy::v4::ProcessObjectControl(RSDK::Legacy::v4::Entity *entity)
327
{
328
if ((uint8)entity->controlMode < CONT_P4) {
329
int32 controllerID = entity->controlMode + 1;
330
331
RSDK::ControllerState *controller = &RSDK::controller[controllerID];
332
RSDK::AnalogState *stickL = &RSDK::stickL[controllerID];
333
334
entity->up = stickL->keyUp.down || controller->keyUp.down;
335
entity->down = stickL->keyDown.down || controller->keyDown.down;
336
entity->left = stickL->keyLeft.down || controller->keyLeft.down;
337
entity->right = stickL->keyRight.down | controller->keyRight.down;
338
339
if (entity->left && entity->right) {
340
entity->left = false;
341
entity->right = false;
342
}
343
344
entity->jumpPress = controller->keyB.press || controller->keyA.press || controller->keyC.press;
345
entity->jumpHold = controller->keyB.down || controller->keyA.down || controller->keyC.down;
346
}
347
}
348