Path: blob/master/RSDKv5/RSDK/Scene/Legacy/SceneLegacy.cpp
1168 views
1#include "v3/SceneLegacyv3.cpp"2#include "v4/SceneLegacyv4.cpp"34int32 RSDK::Legacy::stageMode = 0;56RSDK::Legacy::Camera RSDK::Legacy::cameras[2];7RSDK::Legacy::Camera *RSDK::Legacy::currentCamera = NULL;89int32 RSDK::Legacy::xScrollOffset = 0;10int32 RSDK::Legacy::yScrollOffset = 0;11int32 RSDK::Legacy::cameraShift = 0;12int32 RSDK::Legacy::cameraLockedY = 0;13int32 RSDK::Legacy::cameraShakeX = 0;14int32 RSDK::Legacy::cameraShakeY = 0;15int32 RSDK::Legacy::cameraLag = 0;16int32 RSDK::Legacy::cameraLagStyle = 0;1718int32 RSDK::Legacy::curXBoundary1 = 0;19int32 RSDK::Legacy::newXBoundary1 = 0;20int32 RSDK::Legacy::curYBoundary1 = 0;21int32 RSDK::Legacy::newYBoundary1 = 0;22int32 RSDK::Legacy::curXBoundary2 = 0;23int32 RSDK::Legacy::curYBoundary2 = 0;24int32 RSDK::Legacy::waterLevel = 0;25int32 RSDK::Legacy::waterDrawPos = 0;26int32 RSDK::Legacy::newXBoundary2 = 0;27int32 RSDK::Legacy::newYBoundary2 = 0;2829int32 RSDK::Legacy::SCREEN_SCROLL_LEFT = Legacy::SCREEN_CENTERX - 8;30int32 RSDK::Legacy::SCREEN_SCROLL_RIGHT = Legacy::SCREEN_CENTERX + 8;3132int32 RSDK::Legacy::lastYSize = -1;33int32 RSDK::Legacy::lastXSize = -1;3435bool32 RSDK::Legacy::pauseEnabled = true;36bool32 RSDK::Legacy::timeEnabled = true;37bool32 RSDK::Legacy::debugMode = false;38int32 RSDK::Legacy::frameCounter = 0;39int32 RSDK::Legacy::stageMilliseconds = 0;40int32 RSDK::Legacy::stageSeconds = 0;41int32 RSDK::Legacy::stageMinutes = 0;4243bool32 RSDK::Legacy::anyPress = false;4445// Category and Scene IDs46char RSDK::Legacy::currentStageFolder[0x100];47int32 RSDK::Legacy::actID = 0;4849char RSDK::Legacy::titleCardText[0x100];50uint8 RSDK::Legacy::titleCardWord2 = 0;5152uint8 RSDK::Legacy::activeTileLayers[4];53uint8 RSDK::Legacy::tLayerMidPoint;54RSDK::Legacy::TileLayer RSDK::Legacy::stageLayouts[LEGACY_LAYER_COUNT];5556int32 RSDK::Legacy::bgDeformationData0[LEGACY_DEFORM_COUNT];57int32 RSDK::Legacy::bgDeformationData1[LEGACY_DEFORM_COUNT];58int32 RSDK::Legacy::bgDeformationData2[LEGACY_DEFORM_COUNT];59int32 RSDK::Legacy::bgDeformationData3[LEGACY_DEFORM_COUNT];6061RSDK::Legacy::LineScroll RSDK::Legacy::hParallax;62RSDK::Legacy::LineScroll RSDK::Legacy::vParallax;6364uint16 RSDK::Legacy::tile3DFloorBuffer[0x100 * 0x100];6566RSDK::Legacy::Tiles128x128 RSDK::Legacy::tiles128x128;67RSDK::Legacy::CollisionMasks RSDK::Legacy::collisionMasks[2];6869uint8 RSDK::Legacy::tilesetGFXData[LEGACY_TILESET_SIZE];7071void RSDK::Legacy::GetStageFilepath(char *dest, const char *filePath)72{73StrCopy(dest, "Data/Stages/");74StrAdd(dest, sceneInfo.listData[sceneInfo.listPos].folder);75StrAdd(dest, "/");76StrAdd(dest, filePath);77}7879int32 RSDK::Legacy::LoadStageFile(const char *filePath, FileInfo *info)80{81char dest[0x40];82GetStageFilepath(dest, filePath);83return LoadFile(info, dest, FMODE_RB);84}8586int32 RSDK::Legacy::LoadActFile(const char *ext, FileInfo *info)87{88char dest[0x40];8990StrCopy(dest, "Data/Stages/");91StrAdd(dest, sceneInfo.listData[sceneInfo.listPos].folder);92StrAdd(dest, "/Act");93StrAdd(dest, sceneInfo.listData[sceneInfo.listPos].id);94StrAdd(dest, ext);9596ConvertStringToInteger(sceneInfo.listData[sceneInfo.listPos].id, &actID);9798return LoadFile(info, dest, FMODE_RB);99}100101void RSDK::Legacy::LoadStageChunks()102{103FileInfo info;104InitFileInfo(&info);105106if (LoadStageFile("128x128Tiles.bin", &info)) {107uint8 entry[3];108for (int32 i = 0; i < LEGACY_CHUNKTILE_COUNT; ++i) {109ReadBytes(&info, entry, 3);110entry[0] -= (uint8)((entry[0] >> 6) << 6);111112tiles128x128.visualPlane[i] = (uint8)(entry[0] >> 4);113entry[0] -= 16 * (entry[0] >> 4);114115tiles128x128.direction[i] = (uint8)(entry[0] >> 2);116entry[0] -= 4 * (entry[0] >> 2);117118tiles128x128.tileIndex[i] = entry[1] + (entry[0] << 8);119tiles128x128.gfxDataPos[i] = tiles128x128.tileIndex[i] << 8;120121tiles128x128.collisionFlags[0][i] = entry[2] >> 4;122tiles128x128.collisionFlags[1][i] = entry[2] - ((entry[2] >> 4) << 4);123}124CloseFile(&info);125}126}127128void RSDK::Legacy::LoadStageCollisions()129{130FileInfo info;131InitFileInfo(&info);132133if (LoadStageFile("CollisionMasks.bin", &info)) {134int32 tileIndex = 0;135136for (int32 t = 0; t < LEGACY_TILE_COUNT; ++t) {137for (int32 p = 0; p < LEGACY_CPATH_COUNT; ++p) {138uint8 flags = ReadInt8(&info);139bool32 isCeiling = flags >> 4;140collisionMasks[p].flags[t] = flags & 0xF;141142collisionMasks[p].angles[t] = ReadInt8(&info);143collisionMasks[p].angles[t] |= ReadInt8(&info) << 8;144collisionMasks[p].angles[t] |= ReadInt8(&info) << 16;145collisionMasks[p].angles[t] |= ReadInt8(&info) << 24;146147if (isCeiling) // Ceiling Tile148{149for (int32 c = 0; c < TILE_SIZE; c += 2) {150uint8 buffer = ReadInt8(&info);151collisionMasks[p].roofMasks[c + tileIndex] = buffer >> 4;152collisionMasks[p].roofMasks[c + tileIndex + 1] = buffer & 0xF;153}154155// Has Collision (Pt 1)156uint8 solid = ReadInt8(&info);157int32 id = 1;158for (int32 c = 0; c < TILE_SIZE / 2; ++c) {159if (solid & id) {160collisionMasks[p].floorMasks[c + tileIndex + 8] = 0;161}162else {163collisionMasks[p].floorMasks[c + tileIndex + 8] = 0x40;164collisionMasks[p].roofMasks[c + tileIndex + 8] = -0x40;165}166id <<= 1;167}168169// Has Collision (Pt 2)170solid = ReadInt8(&info);171id = 1;172for (int32 c = 0; c < TILE_SIZE / 2; ++c) {173if (solid & id) {174collisionMasks[p].floorMasks[c + tileIndex] = 0;175}176else {177collisionMasks[p].floorMasks[c + tileIndex] = 0x40;178collisionMasks[p].roofMasks[c + tileIndex] = -0x40;179}180id <<= 1;181}182183// LWall rotations184for (int32 c = 0; c < TILE_SIZE; ++c) {185int32 h = 0;186while (h > -1) {187if (h == TILE_SIZE) {188collisionMasks[p].lWallMasks[c + tileIndex] = 0x40;189h = -1;190}191else if (c > collisionMasks[p].roofMasks[h + tileIndex]) {192++h;193}194else {195collisionMasks[p].lWallMasks[c + tileIndex] = h;196h = -1;197}198}199}200201// RWall rotations202for (int32 c = 0; c < TILE_SIZE; ++c) {203int32 h = TILE_SIZE - 1;204while (h < TILE_SIZE) {205if (h == -1) {206collisionMasks[p].rWallMasks[c + tileIndex] = -0x40;207h = TILE_SIZE;208}209else if (c > collisionMasks[p].roofMasks[h + tileIndex]) {210--h;211}212else {213collisionMasks[p].rWallMasks[c + tileIndex] = h;214h = TILE_SIZE;215}216}217}218}219else // Regular Tile220{221for (int32 c = 0; c < TILE_SIZE; c += 2) {222uint8 buffer = ReadInt8(&info);223collisionMasks[p].floorMasks[c + tileIndex] = buffer >> 4;224collisionMasks[p].floorMasks[c + tileIndex + 1] = buffer & 0xF;225}226227uint8 solid = ReadInt8(&info);228int32 id = 1;229for (int32 c = 0; c < TILE_SIZE / 2; ++c) // HasCollision230{231if (solid & id) {232collisionMasks[p].roofMasks[c + tileIndex + 8] = 0xF;233}234else {235collisionMasks[p].floorMasks[c + tileIndex + 8] = 0x40;236collisionMasks[p].roofMasks[c + tileIndex + 8] = -0x40;237}238id <<= 1;239}240241solid = ReadInt8(&info);242id = 1;243for (int32 c = 0; c < TILE_SIZE / 2; ++c) // HasCollision (pt 2)244{245if (solid & id) {246collisionMasks[p].roofMasks[c + tileIndex] = 0xF;247}248else {249collisionMasks[p].floorMasks[c + tileIndex] = 0x40;250collisionMasks[p].roofMasks[c + tileIndex] = -0x40;251}252id <<= 1;253}254255// LWall rotations256for (int32 c = 0; c < TILE_SIZE; ++c) {257int32 h = 0;258while (h > -1) {259if (h == TILE_SIZE) {260collisionMasks[p].lWallMasks[c + tileIndex] = 0x40;261h = -1;262}263else if (c < collisionMasks[p].floorMasks[h + tileIndex]) {264++h;265}266else {267collisionMasks[p].lWallMasks[c + tileIndex] = h;268h = -1;269}270}271}272273// RWall rotations274for (int32 c = 0; c < TILE_SIZE; ++c) {275int32 h = TILE_SIZE - 1;276while (h < TILE_SIZE) {277if (h == -1) {278collisionMasks[p].rWallMasks[c + tileIndex] = -0x40;279h = TILE_SIZE;280}281else if (c < collisionMasks[p].floorMasks[h + tileIndex]) {282--h;283}284else {285collisionMasks[p].rWallMasks[c + tileIndex] = h;286h = TILE_SIZE;287}288}289}290}291}292tileIndex += 16;293}294295CloseFile(&info);296}297}298void RSDK::Legacy::LoadStageGIFFile()299{300ImageGIF tileset;301302char dest[0x40];303GetStageFilepath(dest, "16x16Tiles.gif");304305if (tileset.Load(dest, true) && tileset.width == TILE_SIZE && tileset.height <= LEGACY_TILE_COUNT * TILE_SIZE) {306tileset.pixels = tilesetGFXData;307tileset.Load(NULL, false);308309for (int32 c = 128; c < 256; ++c) {310uint8 red = (tileset.palette[c] >> 0x10);311uint8 green = (tileset.palette[c] >> 0x08);312uint8 blue = (tileset.palette[c] >> 0x00);313SetPaletteEntry(-1, c, red, green, blue);314}315316#if RETRO_USE_ORIGINAL_CODE317tileset.palette = NULL;318tileset.decoder = NULL;319#endif320tileset.pixels = NULL;321322tileset.Close();323}324}325326void RSDK::Legacy::ProcessInput()327{328RSDK::ProcessInput();329330anyPress = controller->keyA.press || controller->keyB.press || controller->keyC.press || controller->keyX.press || controller->keyY.press331|| controller->keyZ.press || controller->keyStart.press || controller->keySelect.press;332SetGlobalVariableByName("input.pressButton", anyPress);333}334335void RSDK::Legacy::ProcessSceneTimer()336{337if (timeEnabled) {338if (++frameCounter == 60) {339frameCounter = 0;340if (++stageSeconds > 59) {341stageSeconds = 0;342if (++stageMinutes > 59)343stageMinutes = 0;344}345}346stageMilliseconds = 100 * frameCounter / 60;347}348else {349frameCounter = 60 * stageMilliseconds / 100;350}351}352353void RSDK::Legacy::ResetBackgroundSettings()354{355for (int32 i = 0; i < LEGACY_LAYER_COUNT; ++i) {356stageLayouts[i].deformationOffset = 0;357stageLayouts[i].deformationOffsetW = 0;358stageLayouts[i].scrollPos = 0;359}360361for (int32 i = 0; i < LEGACY_PARALLAX_COUNT; ++i) {362hParallax.scrollPos[i] = 0;363vParallax.scrollPos[i] = 0;364}365366for (int32 i = 0; i < LEGACY_DEFORM_COUNT; ++i) {367bgDeformationData0[i] = 0;368bgDeformationData1[i] = 0;369bgDeformationData2[i] = 0;370bgDeformationData3[i] = 0;371}372}373374void RSDK::Legacy::SetLayerDeformation(int32 selectedDef, int32 waveLength, int32 waveWidth, int32 waveType, int32 YPos, int32 waveSize)375{376int32 *deformPtr = nullptr;377switch (selectedDef) {378case DEFORM_FG: deformPtr = bgDeformationData0; break;379case DEFORM_FG_WATER: deformPtr = bgDeformationData1; break;380case DEFORM_BG: deformPtr = bgDeformationData2; break;381case DEFORM_BG_WATER: deformPtr = bgDeformationData3; break;382default: break;383}384385int32 shift = 9;386387int32 id = 0;388if (waveType == 1) {389id = YPos;390for (int32 i = 0; i < waveSize; ++i) {391deformPtr[id] = waveWidth * sin512LookupTable[(i << 9) / waveLength & 0x1FF] >> shift;392++id;393}394}395else {396for (int32 i = 0; i < 0x200 * 0x100; i += 0x200) {397int32 sine = waveWidth * sin512LookupTable[i / waveLength & 0x1FF] >> shift;398deformPtr[id] = sine;399if (deformPtr[id] >= waveWidth)400deformPtr[id] = waveWidth - 1;401++id;402}403}404405switch (selectedDef) {406case DEFORM_FG:407for (int32 i = LEGACY_DEFORM_STORE; i < LEGACY_DEFORM_COUNT; ++i) bgDeformationData0[i] = bgDeformationData0[i - LEGACY_DEFORM_STORE];408break;409410case DEFORM_FG_WATER:411for (int32 i = LEGACY_DEFORM_STORE; i < LEGACY_DEFORM_COUNT; ++i) bgDeformationData1[i] = bgDeformationData1[i - LEGACY_DEFORM_STORE];412break;413414case DEFORM_BG:415for (int32 i = LEGACY_DEFORM_STORE; i < LEGACY_DEFORM_COUNT; ++i) bgDeformationData2[i] = bgDeformationData2[i - LEGACY_DEFORM_STORE];416break;417418case DEFORM_BG_WATER:419for (int32 i = LEGACY_DEFORM_STORE; i < LEGACY_DEFORM_COUNT; ++i) bgDeformationData3[i] = bgDeformationData3[i - LEGACY_DEFORM_STORE];420break;421422default: break;423}424}425426void RSDK::Legacy::InitCameras()427{428memset(cameras, 0, sizeof(cameras));429cameras[0].enabled = true;430cameras[1].enabled = true;431cameras[0].target = -1;432cameras[1].target = -1;433434currentCamera = &cameras[0];435}436437