Path: blob/main/RSDKv4/Object.hpp
817 views
#ifndef OBJECT_H1#define OBJECT_H23#define NATIVEENTITY_COUNT (0x100)45#define ENTITY_COUNT (0x4A0)6#define TEMPENTITY_START (ENTITY_COUNT - 0x80)7#define OBJECT_COUNT (0x100)8#define TYPEGROUP_COUNT (0x103)910enum ObjectControlModes {11CONTROLMODE_NONE = -1,12CONTROLMODE_NORMAL = 0,13};1415struct TypeGroupList {16int entityRefs[ENTITY_COUNT];17int listSize;18};1920struct Entity {21int xpos;22int ypos;23int xvel;24int yvel;25int speed;26int values[48];27int state;28int angle;29int scale;30int rotation;31int alpha;32int animationTimer;33int animationSpeed;34int lookPosX;35int lookPosY;36ushort groupID;37byte type;38byte propertyValue;39byte priority;40byte drawOrder;41byte direction;42byte inkEffect;43byte animation;44byte prevAnimation;45byte frame;46byte collisionMode;47byte collisionPlane;48sbyte controlMode;49byte controlLock;50byte pushing;51byte visible;52byte tileCollisions;53byte objectInteractions;54byte gravity;55byte left;56byte right;57byte up;58byte down;59byte jumpPress;60byte jumpHold;61byte scrollTracking;62// was 3 on S1 release, but bumped up to 5 for S263byte floorSensors[RETRO_REV00 ? 3 : 5];64};6566struct NativeEntityBase {67void (*eventCreate)(void *objPtr);68void (*eventMain)(void *objPtr);69int slotID;70int objectID;71};7273struct NativeEntity {74void (*eventCreate)(void *objPtr);75void (*eventMain)(void *objPtr);76int slotID;77int objectID;78void *extra[0x100];79};8081enum ObjectTypes {82OBJ_TYPE_BLANKOBJECT = 0 // 0 is always blank obj83};8485enum ObjectGroups {86GROUP_ALL = 0 // 0 is always "all"87};8889enum ObjectPriority {90// The entity is active if the entity is on screen or within 128 pixels of the screen borders on any axis91PRIORITY_BOUNDS,92// The entity is always active, unless the stage state is PAUSED/FROZEN93PRIORITY_ACTIVE,94// Same as PRIORITY_ACTIVE, the entity even runs when the stage state is PAUSED/FROZEN95PRIORITY_ALWAYS,96// 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 matter97PRIORITY_XBOUNDS,98// Same as PRIORITY_XBOUNDS, however the entity's type will be set to BLANK OBJECT when it becomes inactive99PRIORITY_XBOUNDS_DESTROY,100// Never Active.101PRIORITY_INACTIVE,102// Same as PRIORITY_BOUNDS, but uses the smaller bounds (32px off screen rather than the normal 128)103PRIORITY_BOUNDS_SMALL,104// Same as PRIORITY_ACTIVE, but uses the smaller bounds in object.outOfBounds105PRIORITY_ACTIVE_SMALL106};107108// Native Objects109extern int nativeEntityPos;110111extern int activeEntityList[NATIVEENTITY_COUNT];112extern byte objectRemoveFlag[NATIVEENTITY_COUNT];113extern NativeEntity objectEntityBank[NATIVEENTITY_COUNT];114extern int nativeEntityCount;115116extern int nativeEntityCountBackup;117extern int backupEntityList[NATIVEENTITY_COUNT];118extern NativeEntity objectEntityBackup[NATIVEENTITY_COUNT];119120extern int nativeEntityCountBackupS;121extern int backupEntityListS[NATIVEENTITY_COUNT];122extern NativeEntity objectEntityBackupS[NATIVEENTITY_COUNT];123124// Game Objects125extern int objectEntityPos;126extern int curObjectType;127extern Entity objectEntityList[ENTITY_COUNT * 2];128extern int processObjectFlag[ENTITY_COUNT];129extern TypeGroupList objectTypeGroupList[TYPEGROUP_COUNT];130131extern char typeNames[OBJECT_COUNT][0x40];132133extern int OBJECT_BORDER_X1;134extern int OBJECT_BORDER_X2;135extern int OBJECT_BORDER_X3;136extern int OBJECT_BORDER_X4;137extern const int OBJECT_BORDER_Y1;138extern const int OBJECT_BORDER_Y2;139extern const int OBJECT_BORDER_Y3;140extern const int OBJECT_BORDER_Y4;141142void ProcessStartupObjects();143void ProcessObjects();144void ProcessPausedObjects();145void ProcessFrozenObjects();146#if !RETRO_REV00147void Process2PObjects();148#endif149150void SetObjectTypeName(const char *objectName, int objectID);151152extern int playerListPos;153154void ProcessObjectControl(Entity *entity);155156void InitNativeObjectSystem();157NativeEntity *CreateNativeObject(void (*objCreate)(void *objPtr), void (*objMain)(void *objPtr));158void RemoveNativeObject(NativeEntityBase *NativeEntry);159void ResetNativeObject(NativeEntityBase *obj, void (*objCreate)(void *objPtr), void (*objMain)(void *objPtr));160void ProcessNativeObjects();161inline void BackupNativeObjects()162{163memcpy(backupEntityList, activeEntityList, sizeof(activeEntityList));164memcpy(objectEntityBackup, objectEntityBank, sizeof(objectEntityBank));165nativeEntityCountBackup = nativeEntityCount;166}167inline void BackupNativeObjectsSettings()168{169memcpy(backupEntityListS, activeEntityList, sizeof(activeEntityList));170memcpy(objectEntityBackupS, objectEntityBank, sizeof(objectEntityBank));171nativeEntityCountBackupS = nativeEntityCount;172}173void RestoreNativeObjects();174void RestoreNativeObjectsNoFade();175void RestoreNativeObjectsSettings();176inline NativeEntity *GetNativeObject(uint objID)177{178if (objID >= NATIVEENTITY_COUNT)179return nullptr;180else181return &objectEntityBank[objID];182}183184// Custom, used for cleaning purposes185inline void RemoveNativeObjectType(void (*eventCreate)(void *objPtr), void (*eventMain)(void *objPtr))186{187for (int i = nativeEntityCount - 1; i >= 0; --i) {188NativeEntity *entity = &objectEntityBank[activeEntityList[i]];189if (entity->eventCreate == eventCreate && entity->eventMain == eventMain) {190RemoveNativeObject((NativeEntityBase *)entity);191}192}193}194inline void ClearNativeObjects()195{196nativeEntityCount = 0;197memset(objectEntityBank, 0, sizeof(objectEntityBank));198}199200#endif // !OBJECT_H201202203