Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-2-2013-Decompilation
Path: blob/main/RSDKv4/Object.hpp
817 views
1
#ifndef OBJECT_H
2
#define OBJECT_H
3
4
#define NATIVEENTITY_COUNT (0x100)
5
6
#define ENTITY_COUNT (0x4A0)
7
#define TEMPENTITY_START (ENTITY_COUNT - 0x80)
8
#define OBJECT_COUNT (0x100)
9
#define TYPEGROUP_COUNT (0x103)
10
11
enum ObjectControlModes {
12
CONTROLMODE_NONE = -1,
13
CONTROLMODE_NORMAL = 0,
14
};
15
16
struct TypeGroupList {
17
int entityRefs[ENTITY_COUNT];
18
int listSize;
19
};
20
21
struct Entity {
22
int xpos;
23
int ypos;
24
int xvel;
25
int yvel;
26
int speed;
27
int values[48];
28
int state;
29
int angle;
30
int scale;
31
int rotation;
32
int alpha;
33
int animationTimer;
34
int animationSpeed;
35
int lookPosX;
36
int lookPosY;
37
ushort groupID;
38
byte type;
39
byte propertyValue;
40
byte priority;
41
byte drawOrder;
42
byte direction;
43
byte inkEffect;
44
byte animation;
45
byte prevAnimation;
46
byte frame;
47
byte collisionMode;
48
byte collisionPlane;
49
sbyte controlMode;
50
byte controlLock;
51
byte pushing;
52
byte visible;
53
byte tileCollisions;
54
byte objectInteractions;
55
byte gravity;
56
byte left;
57
byte right;
58
byte up;
59
byte down;
60
byte jumpPress;
61
byte jumpHold;
62
byte scrollTracking;
63
// was 3 on S1 release, but bumped up to 5 for S2
64
byte floorSensors[RETRO_REV00 ? 3 : 5];
65
};
66
67
struct NativeEntityBase {
68
void (*eventCreate)(void *objPtr);
69
void (*eventMain)(void *objPtr);
70
int slotID;
71
int objectID;
72
};
73
74
struct NativeEntity {
75
void (*eventCreate)(void *objPtr);
76
void (*eventMain)(void *objPtr);
77
int slotID;
78
int objectID;
79
void *extra[0x100];
80
};
81
82
enum ObjectTypes {
83
OBJ_TYPE_BLANKOBJECT = 0 // 0 is always blank obj
84
};
85
86
enum ObjectGroups {
87
GROUP_ALL = 0 // 0 is always "all"
88
};
89
90
enum ObjectPriority {
91
// The entity is active if the entity is on screen or within 128 pixels of the screen borders on any axis
92
PRIORITY_BOUNDS,
93
// The entity is always active, unless the stage state is PAUSED/FROZEN
94
PRIORITY_ACTIVE,
95
// Same as PRIORITY_ACTIVE, the entity even runs when the stage state is PAUSED/FROZEN
96
PRIORITY_ALWAYS,
97
// Same as PRIORITY_BOUNDS, however it only does checks on the x-axis, so when in bounds on the x-axis, the y position doesn't matter
98
PRIORITY_XBOUNDS,
99
// Same as PRIORITY_XBOUNDS, however the entity's type will be set to BLANK OBJECT when it becomes inactive
100
PRIORITY_XBOUNDS_DESTROY,
101
// Never Active.
102
PRIORITY_INACTIVE,
103
// Same as PRIORITY_BOUNDS, but uses the smaller bounds (32px off screen rather than the normal 128)
104
PRIORITY_BOUNDS_SMALL,
105
// Same as PRIORITY_ACTIVE, but uses the smaller bounds in object.outOfBounds
106
PRIORITY_ACTIVE_SMALL
107
};
108
109
// Native Objects
110
extern int nativeEntityPos;
111
112
extern int activeEntityList[NATIVEENTITY_COUNT];
113
extern byte objectRemoveFlag[NATIVEENTITY_COUNT];
114
extern NativeEntity objectEntityBank[NATIVEENTITY_COUNT];
115
extern int nativeEntityCount;
116
117
extern int nativeEntityCountBackup;
118
extern int backupEntityList[NATIVEENTITY_COUNT];
119
extern NativeEntity objectEntityBackup[NATIVEENTITY_COUNT];
120
121
extern int nativeEntityCountBackupS;
122
extern int backupEntityListS[NATIVEENTITY_COUNT];
123
extern NativeEntity objectEntityBackupS[NATIVEENTITY_COUNT];
124
125
// Game Objects
126
extern int objectEntityPos;
127
extern int curObjectType;
128
extern Entity objectEntityList[ENTITY_COUNT * 2];
129
extern int processObjectFlag[ENTITY_COUNT];
130
extern TypeGroupList objectTypeGroupList[TYPEGROUP_COUNT];
131
132
extern char typeNames[OBJECT_COUNT][0x40];
133
134
extern int OBJECT_BORDER_X1;
135
extern int OBJECT_BORDER_X2;
136
extern int OBJECT_BORDER_X3;
137
extern int OBJECT_BORDER_X4;
138
extern const int OBJECT_BORDER_Y1;
139
extern const int OBJECT_BORDER_Y2;
140
extern const int OBJECT_BORDER_Y3;
141
extern const int OBJECT_BORDER_Y4;
142
143
void ProcessStartupObjects();
144
void ProcessObjects();
145
void ProcessPausedObjects();
146
void ProcessFrozenObjects();
147
#if !RETRO_REV00
148
void Process2PObjects();
149
#endif
150
151
void SetObjectTypeName(const char *objectName, int objectID);
152
153
extern int playerListPos;
154
155
void ProcessObjectControl(Entity *entity);
156
157
void InitNativeObjectSystem();
158
NativeEntity *CreateNativeObject(void (*objCreate)(void *objPtr), void (*objMain)(void *objPtr));
159
void RemoveNativeObject(NativeEntityBase *NativeEntry);
160
void ResetNativeObject(NativeEntityBase *obj, void (*objCreate)(void *objPtr), void (*objMain)(void *objPtr));
161
void ProcessNativeObjects();
162
inline void BackupNativeObjects()
163
{
164
memcpy(backupEntityList, activeEntityList, sizeof(activeEntityList));
165
memcpy(objectEntityBackup, objectEntityBank, sizeof(objectEntityBank));
166
nativeEntityCountBackup = nativeEntityCount;
167
}
168
inline void BackupNativeObjectsSettings()
169
{
170
memcpy(backupEntityListS, activeEntityList, sizeof(activeEntityList));
171
memcpy(objectEntityBackupS, objectEntityBank, sizeof(objectEntityBank));
172
nativeEntityCountBackupS = nativeEntityCount;
173
}
174
void RestoreNativeObjects();
175
void RestoreNativeObjectsNoFade();
176
void RestoreNativeObjectsSettings();
177
inline NativeEntity *GetNativeObject(uint objID)
178
{
179
if (objID >= NATIVEENTITY_COUNT)
180
return nullptr;
181
else
182
return &objectEntityBank[objID];
183
}
184
185
// Custom, used for cleaning purposes
186
inline void RemoveNativeObjectType(void (*eventCreate)(void *objPtr), void (*eventMain)(void *objPtr))
187
{
188
for (int i = nativeEntityCount - 1; i >= 0; --i) {
189
NativeEntity *entity = &objectEntityBank[activeEntityList[i]];
190
if (entity->eventCreate == eventCreate && entity->eventMain == eventMain) {
191
RemoveNativeObject((NativeEntityBase *)entity);
192
}
193
}
194
}
195
inline void ClearNativeObjects()
196
{
197
nativeEntityCount = 0;
198
memset(objectEntityBank, 0, sizeof(objectEntityBank));
199
}
200
201
#endif // !OBJECT_H
202
203