Path: blob/master/RSDKv5/RSDK/Scene/Legacy/v4/ObjectLegacyv4.cpp
1174 views
1// Game Objects2int32 RSDK::Legacy::v4::objectEntityPos = 0;3int32 RSDK::Legacy::v4::curObjectType = 0;4RSDK::Legacy::v4::Entity RSDK::Legacy::v4::objectEntityList[LEGACY_v4_ENTITY_COUNT * 2]; //"regular" list & "storage" list5int32 RSDK::Legacy::v4::processObjectFlag[LEGACY_v4_ENTITY_COUNT];6RSDK::Legacy::v4::TypeGroupList RSDK::Legacy::v4::objectTypeGroupList[LEGACY_v4_TYPEGROUP_COUNT];78int32 RSDK::Legacy::v4::playerListPos = 0;910char RSDK::Legacy::v4::typeNames[LEGACY_v4_OBJECT_COUNT][0x40];1112void RSDK::Legacy::v4::ProcessStartupObjects()13{14scriptFrameCount = 0;15ClearAnimationData();16scriptEng.arrayPosition[8] = LEGACY_v4_TEMPENTITY_START;17OBJECT_BORDER_X1 = 0x80;18OBJECT_BORDER_X3 = 0x20;19OBJECT_BORDER_X2 = SCREEN_XSIZE + 0x80;20OBJECT_BORDER_X4 = SCREEN_XSIZE + 0x20;21Entity *entity = &objectEntityList[LEGACY_v4_TEMPENTITY_START];22// Dunno what this is meant for, but it's here in the original code so...23objectEntityList[TEMPENTITY_START + 1].type = objectEntityList[0].type;2425memset(foreachStack, -1, sizeof(foreachStack));26memset(jumpTableStack, 0, sizeof(jumpTableStack));2728for (int32 i = 0; i < LEGACY_v4_OBJECT_COUNT; ++i) {29ObjectScript *scriptInfo = &objectScriptList[i];30objectEntityPos = LEGACY_v4_TEMPENTITY_START;31curObjectType = i;32scriptInfo->frameListOffset = scriptFrameCount;33scriptInfo->spriteSheetID = 0;34entity->type = i;3536if (scriptCode[scriptInfo->eventStartup.scriptCodePtr] > 0)37ProcessScript(scriptInfo->eventStartup.scriptCodePtr, scriptInfo->eventStartup.jumpTablePtr, EVENT_SETUP);38scriptInfo->frameCount = scriptFrameCount - scriptInfo->frameListOffset;39}40entity->type = 0;41curObjectType = 0;42}4344void RSDK::Legacy::v4::ProcessObjects()45{46for (int32 i = 0; i < LEGACY_DRAWLAYER_COUNT; ++i) drawListEntries[i].listSize = 0;4748for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {49processObjectFlag[objectEntityPos] = false;50int32 x = 0, y = 0;51Entity *entity = &objectEntityList[objectEntityPos];52x = entity->xpos >> 16;53y = entity->ypos >> 16;5455switch (entity->priority) {56case PRIORITY_BOUNDS:57processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X1 && x < xScrollOffset + OBJECT_BORDER_X258&& y > yScrollOffset - OBJECT_BORDER_Y1 && y < yScrollOffset + OBJECT_BORDER_Y2;59break;6061case PRIORITY_ACTIVE:62case PRIORITY_ALWAYS:63case PRIORITY_ACTIVE_SMALL: processObjectFlag[objectEntityPos] = true; break;6465case PRIORITY_XBOUNDS:66processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X1 && x < OBJECT_BORDER_X2 + xScrollOffset;67break;6869case PRIORITY_XBOUNDS_DESTROY:70processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X1 && x < xScrollOffset + OBJECT_BORDER_X2;71if (!processObjectFlag[objectEntityPos]) {72processObjectFlag[objectEntityPos] = false;73entity->type = OBJ_TYPE_BLANKOBJECT;74}75break;7677case PRIORITY_INACTIVE: processObjectFlag[objectEntityPos] = false; break;78case PRIORITY_BOUNDS_SMALL:79processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X3 && x < OBJECT_BORDER_X4 + xScrollOffset80&& y > yScrollOffset - OBJECT_BORDER_Y3 && y < yScrollOffset + OBJECT_BORDER_Y4;81break;8283default: break;84}8586if (processObjectFlag[objectEntityPos] && entity->type > OBJ_TYPE_BLANKOBJECT) {87ObjectScript *scriptInfo = &objectScriptList[entity->type];88if (scriptCode[scriptInfo->eventUpdate.scriptCodePtr] > 0)89ProcessScript(scriptInfo->eventUpdate.scriptCodePtr, scriptInfo->eventUpdate.jumpTablePtr, EVENT_MAIN);9091if (entity->drawOrder < LEGACY_DRAWLAYER_COUNT)92drawListEntries[entity->drawOrder].entityRefs[drawListEntries[entity->drawOrder].listSize++] = objectEntityPos;93}94}9596for (int32 g = 0; g < LEGACY_v4_TYPEGROUP_COUNT; ++g) objectTypeGroupList[g].listSize = 0;9798for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {99Entity *entity = &objectEntityList[objectEntityPos];100if (processObjectFlag[objectEntityPos] && entity->objectInteractions) {101// Custom Group102if (entity->groupID >= LEGACY_v4_OBJECT_COUNT) {103TypeGroupList *listCustom = &objectTypeGroupList[objectEntityList[objectEntityPos].groupID];104listCustom->entityRefs[listCustom->listSize++] = objectEntityPos;105}106107// Type-Specific list108TypeGroupList *listType = &objectTypeGroupList[objectEntityList[objectEntityPos].type];109listType->entityRefs[listType->listSize++] = objectEntityPos;110111// All Entities list112TypeGroupList *listAll = &objectTypeGroupList[GROUP_ALL];113listAll->entityRefs[listAll->listSize++] = objectEntityPos;114}115}116}117void RSDK::Legacy::v4::ProcessPausedObjects()118{119for (int32 i = 0; i < LEGACY_DRAWLAYER_COUNT; ++i) drawListEntries[i].listSize = 0;120121for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {122Entity *entity = &objectEntityList[objectEntityPos];123124if (entity->priority == PRIORITY_ALWAYS && entity->type > OBJ_TYPE_BLANKOBJECT) {125ObjectScript *scriptInfo = &objectScriptList[entity->type];126if (scriptCode[scriptInfo->eventUpdate.scriptCodePtr] > 0)127ProcessScript(scriptInfo->eventUpdate.scriptCodePtr, scriptInfo->eventUpdate.jumpTablePtr, EVENT_MAIN);128129if (entity->drawOrder < LEGACY_DRAWLAYER_COUNT)130drawListEntries[entity->drawOrder].entityRefs[drawListEntries[entity->drawOrder].listSize++] = objectEntityPos;131}132}133}134void RSDK::Legacy::v4::ProcessFrozenObjects()135{136for (int32 g = 0; g < LEGACY_DRAWLAYER_COUNT; ++g) drawListEntries[g].listSize = 0;137138for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {139processObjectFlag[objectEntityPos] = false;140int32 x = 0, y = 0;141Entity *entity = &objectEntityList[objectEntityPos];142x = entity->xpos >> 16;143y = entity->ypos >> 16;144145switch (entity->priority) {146case PRIORITY_BOUNDS:147processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X1 && x < xScrollOffset + OBJECT_BORDER_X2148&& y > yScrollOffset - OBJECT_BORDER_Y1 && y < yScrollOffset + OBJECT_BORDER_Y2;149break;150151case PRIORITY_ACTIVE:152case PRIORITY_ALWAYS:153case PRIORITY_ACTIVE_SMALL: processObjectFlag[objectEntityPos] = true; break;154155case PRIORITY_XBOUNDS:156processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X1 && x < OBJECT_BORDER_X2 + xScrollOffset;157break;158159case PRIORITY_XBOUNDS_DESTROY:160processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X1 && x < xScrollOffset + OBJECT_BORDER_X2;161if (!processObjectFlag[objectEntityPos]) {162processObjectFlag[objectEntityPos] = false;163entity->type = OBJ_TYPE_BLANKOBJECT;164}165break;166167case PRIORITY_INACTIVE: processObjectFlag[objectEntityPos] = false; break;168169case PRIORITY_BOUNDS_SMALL:170processObjectFlag[objectEntityPos] = x > xScrollOffset - OBJECT_BORDER_X3 && x < OBJECT_BORDER_X4 + xScrollOffset171&& y > yScrollOffset - OBJECT_BORDER_Y3 && y < yScrollOffset + OBJECT_BORDER_Y4;172break;173174default: break;175}176177if (processObjectFlag[objectEntityPos] && entity->type > OBJ_TYPE_BLANKOBJECT) {178ObjectScript *scriptInfo = &objectScriptList[entity->type];179if (scriptCode[scriptInfo->eventUpdate.scriptCodePtr] > 0 && entity->priority == PRIORITY_ALWAYS)180ProcessScript(scriptInfo->eventUpdate.scriptCodePtr, scriptInfo->eventUpdate.jumpTablePtr, EVENT_MAIN);181182if (entity->drawOrder < LEGACY_DRAWLAYER_COUNT)183drawListEntries[entity->drawOrder].entityRefs[drawListEntries[entity->drawOrder].listSize++] = objectEntityPos;184}185}186187for (int32 g = 0; g < LEGACY_v4_TYPEGROUP_COUNT; ++g) objectTypeGroupList[g].listSize = 0;188189for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {190Entity *entity = &objectEntityList[objectEntityPos];191if (processObjectFlag[objectEntityPos] && entity->objectInteractions) {192// Custom Group193if (entity->groupID >= LEGACY_v4_OBJECT_COUNT) {194TypeGroupList *listCustom = &objectTypeGroupList[objectEntityList[objectEntityPos].groupID];195listCustom->entityRefs[listCustom->listSize++] = objectEntityPos;196}197198// Type-Specific list199TypeGroupList *listType = &objectTypeGroupList[objectEntityList[objectEntityPos].type];200listType->entityRefs[listType->listSize++] = objectEntityPos;201202// All Entities list203TypeGroupList *listAll = &objectTypeGroupList[GROUP_ALL];204listAll->entityRefs[listAll->listSize++] = objectEntityPos;205}206}207}208void RSDK::Legacy::v4::Process2PObjects()209{210for (int32 i = 0; i < LEGACY_DRAWLAYER_COUNT; ++i) drawListEntries[i].listSize = 0;211212int32 boundX1 = -(0x200 << 16);213int32 boundX2 = (0x200 << 16);214int32 boundX3 = -(0x180 << 16);215int32 boundX4 = (0x180 << 16);216217int32 boundY1 = -(0x180 << 16);218int32 boundY2 = (0x180 << 16);219int32 boundY3 = -(0x100 << 16);220int32 boundY4 = (0x100 << 16);221222for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {223processObjectFlag[objectEntityPos] = false;224int32 x = 0, y = 0;225226Entity *entity = &objectEntityList[objectEntityPos];227x = entity->xpos;228y = entity->ypos;229230// Set these here, they could (and prolly are) updated after objects231Entity *entityP1 = &objectEntityList[0];232int32 XPosP1 = entityP1->xpos;233int32 YPosP1 = entityP1->ypos;234235Entity *entityP2 = &objectEntityList[1];236int32 XPosP2 = entityP2->xpos;237int32 YPosP2 = entityP2->ypos;238239switch (entity->priority) {240case PRIORITY_BOUNDS:241processObjectFlag[objectEntityPos] = x > XPosP1 + boundX1 && x < XPosP1 + boundX2 && y > YPosP1 + boundY1 && y < YPosP1 + boundY2;242if (!processObjectFlag[objectEntityPos]) {243processObjectFlag[objectEntityPos] = x > XPosP2 + boundX1 && x < XPosP2 + boundX2 && y > YPosP2 + boundY1 && y < YPosP2 + boundY2;244}245break;246247case PRIORITY_ACTIVE:248case PRIORITY_ALWAYS:249case PRIORITY_ACTIVE_SMALL: processObjectFlag[objectEntityPos] = true; break;250251case PRIORITY_XBOUNDS:252processObjectFlag[objectEntityPos] = x > XPosP1 + boundX1 && x < XPosP1 + boundX2;253if (!processObjectFlag[objectEntityPos]) {254processObjectFlag[objectEntityPos] = x > XPosP2 + boundX1 && x < XPosP2 + boundX2;255}256break;257258case PRIORITY_XBOUNDS_DESTROY:259processObjectFlag[objectEntityPos] = x > XPosP1 + boundX1 && x < XPosP1 + boundX2;260if (!processObjectFlag[objectEntityPos]) {261processObjectFlag[objectEntityPos] = x > XPosP2 + boundX1 && x < XPosP2 + boundX2;262}263264if (!processObjectFlag[objectEntityPos])265entity->type = OBJ_TYPE_BLANKOBJECT;266break;267268case PRIORITY_INACTIVE: processObjectFlag[objectEntityPos] = false; break;269270case PRIORITY_BOUNDS_SMALL:271processObjectFlag[objectEntityPos] = x > XPosP1 + boundX3 && x < XPosP1 + boundX4 && y > YPosP1 + boundY3 && y < YPosP1 + boundY4;272if (!processObjectFlag[objectEntityPos]) {273processObjectFlag[objectEntityPos] = x > XPosP2 + boundX3 && x < XPosP2 + boundX4 && y > YPosP2 + boundY3 && y < YPosP2 + boundY4;274}275break;276277default: break;278}279280if (processObjectFlag[objectEntityPos] && entity->type > OBJ_TYPE_BLANKOBJECT) {281ObjectScript *scriptInfo = &objectScriptList[entity->type];282if (scriptCode[scriptInfo->eventUpdate.scriptCodePtr] > 0)283ProcessScript(scriptInfo->eventUpdate.scriptCodePtr, scriptInfo->eventUpdate.jumpTablePtr, EVENT_MAIN);284285if (entity->drawOrder < LEGACY_DRAWLAYER_COUNT)286drawListEntries[entity->drawOrder].entityRefs[drawListEntries[entity->drawOrder].listSize++] = objectEntityPos;287}288}289290for (int32 i = 0; i < LEGACY_v4_TYPEGROUP_COUNT; ++i) objectTypeGroupList[i].listSize = 0;291292for (objectEntityPos = 0; objectEntityPos < LEGACY_v4_ENTITY_COUNT; ++objectEntityPos) {293Entity *entity = &objectEntityList[objectEntityPos];294if (processObjectFlag[objectEntityPos] && entity->objectInteractions) {295// Custom Group296if (entity->groupID >= LEGACY_v4_OBJECT_COUNT) {297TypeGroupList *listCustom = &objectTypeGroupList[objectEntityList[objectEntityPos].groupID];298listCustom->entityRefs[listCustom->listSize++] = objectEntityPos;299}300301// Type-Specific list302TypeGroupList *listType = &objectTypeGroupList[objectEntityList[objectEntityPos].type];303listType->entityRefs[listType->listSize++] = objectEntityPos;304305// All Entities list306TypeGroupList *listAll = &objectTypeGroupList[GROUP_ALL];307listAll->entityRefs[listAll->listSize++] = objectEntityPos;308}309}310}311312void RSDK::Legacy::v4::SetObjectTypeName(const char *objectName, int32 objectID)313{314int32 objPos = 0;315int32 typePos = 0;316while (objectName[objPos]) {317if (objectName[objPos] != ' ')318typeNames[objectID][typePos++] = objectName[objPos];319++objPos;320}321typeNames[objectID][typePos] = 0;322PrintLog(PRINT_NORMAL, "Set Object (%d) name to: %s", objectID, objectName);323}324325void RSDK::Legacy::v4::ProcessObjectControl(RSDK::Legacy::v4::Entity *entity)326{327if ((uint8)entity->controlMode < CONT_P4) {328int32 controllerID = entity->controlMode + 1;329330RSDK::ControllerState *controller = &RSDK::controller[controllerID];331RSDK::AnalogState *stickL = &RSDK::stickL[controllerID];332333entity->up = stickL->keyUp.down || controller->keyUp.down;334entity->down = stickL->keyDown.down || controller->keyDown.down;335entity->left = stickL->keyLeft.down || controller->keyLeft.down;336entity->right = stickL->keyRight.down | controller->keyRight.down;337338if (entity->left && entity->right) {339entity->left = false;340entity->right = false;341}342343entity->jumpPress = controller->keyB.press || controller->keyA.press || controller->keyC.press;344entity->jumpHold = controller->keyB.down || controller->keyA.down || controller->keyC.down;345}346}347348