Path: blob/master/SonicMania/Objects/MMZ/FarPlane.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: FarPlane Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectFarPlane *FarPlane;1011void FarPlane_Update(void) {}1213void FarPlane_LateUpdate(void)14{15RSDK_THIS(FarPlane);1617if (self->active == ACTIVE_ALWAYS) {18FarPlane_SetupEntities();19}20else if (self->active == ACTIVE_BOUNDS) {21self->active = ACTIVE_NORMAL;22RSDK.GetTileLayer(FarPlane->layerID)->drawGroup[0] = 0;2324FarPlane->originPos.x = self->origin.x;25FarPlane->originPos.y = self->origin.y;2627FarPlane->position.x = self->position.x;28FarPlane->position.y = self->position.y;2930RSDK.SetDrawGroupProperties(1, false, FarPlane_DrawHook_ApplyFarPlane);31RSDK.SetDrawGroupProperties(3, false, FarPlane_DrawHook_RemoveFarPlane);3233FarPlane_SetEntityActivities(ACTIVE_NORMAL);34}35else if (!RSDK.CheckOnScreen(self, NULL)) {36self->active = ACTIVE_BOUNDS;37RSDK.GetTileLayer(FarPlane->layerID)->drawGroup[0] = DRAWGROUP_COUNT;3839RSDK.SetDrawGroupProperties(1, false, StateMachine_None);40RSDK.SetDrawGroupProperties(3, false, StateMachine_None);4142FarPlane_SetEntityActivities(ACTIVE_NEVER);43}44}4546void FarPlane_StaticUpdate(void) {}4748void FarPlane_Draw(void)49{50RSDK_THIS(FarPlane);5152if (SceneInfo->currentDrawGroup) {53RSDK.SetActivePalette(0, 0, ScreenInfo->size.y);54}55else {56int32 x = (ScreenInfo->position.x + ScreenInfo->center.x) << 16;57int32 y = (ScreenInfo->position.y + ScreenInfo->center.y) << 16;5859FarPlane->screenPos.x = (x + self->origin.x - self->position.x) & 0xFFFE0000;60FarPlane->screenPos.y = (y + self->origin.y - self->position.y) & 0xFFFE0000;6162FarPlane->worldPos.x = self->position.x - ((self->position.x - x) >> 1) + 0x8000;63FarPlane->worldPos.y = self->position.y - ((self->position.y - y) >> 1) + 0x8000;6465if (!SceneInfo->currentScreenID)66RSDK.AddDrawListRef(1, SceneInfo->entitySlot);67}68}6970void FarPlane_Create(void *data)71{72RSDK_THIS(FarPlane);7374if (!SceneInfo->inEditor) {75self->updateRange.x = self->size.x + (self->size.x >> 1);76self->updateRange.y = self->size.y + (self->size.y >> 1);77self->active = ACTIVE_ALWAYS;78self->visible = true;79self->drawGroup = 0;80}81}8283void FarPlane_StageLoad(void)84{85FarPlane->layerID = RSDK.GetTileLayerID("Far Plane");8687if (FarPlane->layerID != (uint16)-1) {88TileLayer *farPlane = RSDK.GetTileLayer(FarPlane->layerID);89farPlane->drawGroup[0] = DRAWGROUP_COUNT;90farPlane->scanlineCallback = FarPlane_Scanline_FarPlaneView;9192RSDK.GetTileLayer(Zone->fgLayer[0])->drawGroup[0] = 2;93RSDK.GetTileLayer(Zone->fgLayer[1])->drawGroup[0] = 7;9495RSDK.SetDrawGroupProperties(1, false, StateMachine_None);96RSDK.SetDrawGroupProperties(2, false, StateMachine_None);9798RSDK.CopyPalette(0, 0, 3, 0, 128);99RSDK.CopyPalette(0, 144, 3, 144, 112);100RSDK.CopyPalette(3, 0, 4, 0, 255);101102#if MANIA_USE_PLUS103if (SceneInfo->filter & FILTER_MANIA)104#endif105RSDK.SetLimitedFade(4, 0, 3, 96, 128, 143);106107RSDK.CopyTileLayer(FarPlane->layerID, 0, 192, Zone->fgLayer[0], 0, 192, 1024, 208);108109for (int32 s = 0; s < PLAYER_COUNT; ++s) {110Zone->cameraBoundsB[s] -= 2048;111Zone->deathBoundary[s] -= 2048 << 16;112}113114++Zone->objectDrawGroup[0];115++Zone->playerDrawGroup[0];116++Zone->fgDrawGroup[1];117++Zone->objectDrawGroup[1];118++Zone->playerDrawGroup[1];119120RSDK.ClearCameras();121122EntityCamera *camera = RSDK_GET_ENTITY(SLOT_CAMERA1, Camera);123RSDK.AddCamera(&camera->center, ScreenInfo[camera->screenID].center.x << 16, ScreenInfo[camera->screenID].center.y << 16, 0);124}125}126127void FarPlane_SetupEntities(void)128{129RSDK_THIS(FarPlane);130131self->entityCount = 0;132for (int32 i = 0; i < SCENEENTITY_COUNT && self->entityCount < FARPLANE_ENTITY_COUNT; ++i) {133Entity *child = RSDK_GET_ENTITY_GEN(i);134if (abs(self->origin.x - child->position.x) < self->size.x && abs(self->origin.y - child->position.y) < self->size.y) {135self->entitySlots[self->entityCount++] = i;136child->active = ACTIVE_NEVER;137child->drawGroup = 1;138}139}140141self->active = ACTIVE_BOUNDS;142}143144void FarPlane_SetEntityActivities(uint8 active)145{146RSDK_THIS(FarPlane);147148for (int32 i = 0; i < self->entityCount; ++i) {149RSDK_GET_ENTITY_GEN(self->entitySlots[i])->active = active;150}151}152153void FarPlane_DrawHook_ApplyFarPlane(void)154{155int32 id = 0;156for (int32 i = 0; i < 0x200 && id < 0x200; ++i) {157Entity *entity = RSDK.GetDrawListRef(1, i);158if (!entity)159break;160161FarPlane->positionList[id].x = entity->position.x;162FarPlane->positionList[id].y = entity->position.y;163164entity->position.x = FarPlane->worldPos.x + ((entity->position.x - FarPlane->originPos.x) >> 1);165entity->position.y = FarPlane->worldPos.y + ((entity->position.y - FarPlane->originPos.y) >> 1);166entity->drawFX |= FX_SCALE;167entity->scale.x = 0x100;168entity->scale.y = 0x100;169id++;170}171172for (int32 i = 0; i < 0x200 && id < 0x200; ++i) {173Entity *entity = RSDK.GetDrawListRef(2, i);174if (!entity)175break;176177FarPlane->positionList[id].x = entity->position.x;178FarPlane->positionList[id].y = entity->position.y;179entity->position.x = FarPlane->worldPos.x + ((entity->position.x - FarPlane->originPos.x) >> 1);180entity->position.y = FarPlane->worldPos.y + ((entity->position.y - FarPlane->originPos.y) >> 1);181entity->drawFX |= FX_SCALE;182entity->scale.x = 0x100;183entity->scale.y = 0x100;184id++;185}186187foreach_active(InvincibleStars, invincibleStars)188{189if (invincibleStars->drawGroup < 3 && id < 0x200) {190invincibleStars->starOffset = 10;191invincibleStars->drawFX = FX_SCALE;192invincibleStars->scale.x = 0x100;193invincibleStars->scale.y = 0x100;194195for (int32 s = 0; s < 8; ++s) {196FarPlane->positionList[id].x = invincibleStars->starPos[s].x;197FarPlane->positionList[id].y = invincibleStars->starPos[s].y;198199invincibleStars->starPos[s].x = FarPlane->worldPos.x + ((invincibleStars->starPos[s].x - FarPlane->originPos.x) >> 1);200invincibleStars->starPos[s].y = FarPlane->worldPos.y + ((invincibleStars->starPos[s].y - FarPlane->originPos.y) >> 1);201202id++;203}204}205}206207foreach_active(ImageTrail, imageTrail)208{209if (imageTrail->drawGroup < 3 && id < 0x200) {210imageTrail->scale.x = 0x100;211imageTrail->scale.y = 0x100;212213FarPlane->positionList[id].x = imageTrail->currentPos.x;214FarPlane->positionList[id].y = imageTrail->currentPos.y;215216imageTrail->currentPos.x = FarPlane->worldPos.x + ((imageTrail->currentPos.x - FarPlane->originPos.x) >> 1);217imageTrail->currentPos.y = FarPlane->worldPos.y + ((imageTrail->currentPos.y - FarPlane->originPos.y) >> 1);218219id++;220221for (int32 s = 0; s < 7; ++s) {222FarPlane->positionList[id].x = imageTrail->statePos[s].x;223FarPlane->positionList[id].y = imageTrail->statePos[s].y;224225imageTrail->statePos[s].x = FarPlane->worldPos.x + ((imageTrail->statePos[s].x - FarPlane->originPos.x) >> 1);226imageTrail->statePos[s].y = FarPlane->worldPos.y + ((imageTrail->statePos[s].y - FarPlane->originPos.y) >> 1);227228id++;229}230}231}232}233234void FarPlane_DrawHook_RemoveFarPlane(void)235{236int32 id = 0;237for (int32 i = 0; i < 0x200 && id < 0x200; ++i) {238Entity *entity = RSDK.GetDrawListRef(1, i);239if (!entity)240break;241242entity->position.x = FarPlane->positionList[id].x;243entity->position.y = FarPlane->positionList[id].y;244id++;245}246247for (int32 i = 0; i < 0x200 && id < 0x200; ++i) {248Entity *entity = RSDK.GetDrawListRef(2, i);249if (!entity)250break;251252entity->position.x = FarPlane->positionList[id].x;253entity->position.y = FarPlane->positionList[id].y;254id++;255}256257foreach_active(InvincibleStars, invincibleStars)258{259if (invincibleStars->drawGroup == 1 && id < 0x200) {260for (int32 s = 0; s < 8; ++s) {261invincibleStars->starPos[s].x = FarPlane->positionList[id].x;262invincibleStars->starPos[s].y = FarPlane->positionList[id].y;263id++;264}265}266}267268foreach_active(ImageTrail, imageTrail)269{270if (imageTrail->drawGroup == 1 && id < 0x200) {271imageTrail->currentPos.x = FarPlane->positionList[id].x;272imageTrail->currentPos.y = FarPlane->positionList[id].y;273id++;274275for (int32 s = 0; s < 7; ++s) {276imageTrail->statePos[s].x = FarPlane->positionList[id].x;277imageTrail->statePos[s].y = FarPlane->positionList[id].y;278id++;279}280}281}282}283284void FarPlane_Scanline_FarPlaneView(ScanlineInfo *scanline)285{286int32 x = FarPlane->screenPos.x - (ScreenInfo->center.x << 17);287int32 y = FarPlane->screenPos.y - (ScreenInfo->center.y << 17);288289for (int32 h = 0; h < ScreenInfo->size.y; ++h) {290scanline->position.x = x;291scanline->position.y = y;292293scanline->deform.x = 0x20000;294scanline->deform.y = 0;295296y += 0x20000;297scanline++;298}299300RSDK.CopyPalette(0, 0, 4, 0, 128);301RSDK.SetActivePalette(4, 0, ScreenInfo->size.y);302}303304#if GAME_INCLUDE_EDITOR305void FarPlane_EditorDraw(void)306{307RSDK_THIS(FarPlane);308309self->updateRange.x = self->size.x << 1;310self->updateRange.y = self->size.y << 1;311312DrawHelpers_DrawRectOutline(self->position.x, self->position.y, self->size.x << 1, self->size.y << 1, 0xFF0000);313314if (showGizmos()) {315RSDK_DRAWING_OVERLAY(true);316317DrawHelpers_DrawRectOutline(self->origin.x, self->origin.y, self->size.x << 1, self->size.y << 1, 0xFFFF00);318319DrawHelpers_DrawArrow(self->position.x, self->position.y, self->origin.x, self->origin.y, 0x00FF00, INK_NONE, 0xFF);320321RSDK_DRAWING_OVERLAY(false);322}323}324325void FarPlane_EditorLoad(void) {}326#endif327328void FarPlane_Serialize(void)329{330RSDK_EDITABLE_VAR(FarPlane, VAR_VECTOR2, size);331RSDK_EDITABLE_VAR(FarPlane, VAR_VECTOR2, origin);332}333334335