diff --git a/.clang-format b/.clang-format index 0f9c62b..4c85b16 100644 --- a/.clang-format +++ b/.clang-format @@ -12,7 +12,7 @@ AllowShortLoopsOnASingleLine: true BinPackArguments: true BinPackParameters: true SpaceAfterCStyleCast: false -BreakBeforeBraces: Attach +BreakBeforeBraces: Custom BreakBeforeTernaryOperators: true BreakBeforeBinaryOperators: NonAssignment Cpp11BracedListStyle: false @@ -23,7 +23,6 @@ AlignConsecutiveAssignments: true AlignConsecutiveDeclarations: false AlignConsecutiveMacros: true UseTab: Never -BreakBeforeBraces: Custom BraceWrapping: AfterClass: true AfterControlStatement: false diff --git a/CMakeLists.txt b/CMakeLists.txt index e560a72..294966b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.10) project(RetroEngine) @@ -27,6 +27,7 @@ set(RETRO_FILES Nexus/fcaseopen.c Nexus/main.cpp Nexus/Math.cpp + Nexus/ModAPI.cpp Nexus/Object.cpp Nexus/Palette.cpp Nexus/Player.cpp diff --git a/Makefile b/Makefile index d80bc53..f220583 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ SOURCES = \ Nexus/Input.cpp \ Nexus/main.cpp \ Nexus/Math.cpp \ + Nexus/ModAPI.cpp \ Nexus/Object.cpp \ Nexus/Palette.cpp \ Nexus/Player.cpp \ diff --git a/Nexus/Animation.cpp b/Nexus/Animation.cpp index 59ac27f..346f1ae 100644 --- a/Nexus/Animation.cpp +++ b/Nexus/Animation.cpp @@ -1,10 +1,10 @@ #include "RetroEngine.hpp" -SpriteFrame scriptFrames[SPRITEFRAME_COUNT]; -int scriptFrameCount = 0; +SpriteFrame ScriptFrames[SPRITEFRAME_COUNT]; +int ScriptFramesNo = 0; SpriteFrame animFrames[SPRITEFRAME_COUNT]; -Hitbox hitboxList[HITBOX_COUNT]; +Hitbox PlayerCBoxes[HITBOX_COUNT]; void LoadPlayerAnimation(const char *filePath, int playerID) { @@ -25,7 +25,7 @@ void LoadPlayerAnimation(const char *filePath, int playerID) FileRead(&fileBuffer, 1); FileRead(&fileBuffer, 1); - //Read & load each spritesheet + // Read & load each spritesheet for (int s = 0; s < 4; ++s) { FileRead(&fileBuffer, 1); if (fileBuffer) { @@ -54,10 +54,10 @@ void LoadPlayerAnimation(const char *filePath, int playerID) byte animCount = 0; FileRead(&animCount, 1); - //Read animations + // Read animations int frameID = playerID << 10; for (int a = 0; a < animCount; ++a) { - SpriteAnimation *anim = &playerScriptList[playerID].animations[a]; + SpriteAnimation *anim = &PlayerScriptList[playerID].animations[a]; FileRead(&anim->frameCount, 1); FileRead(&anim->speed, 1); FileRead(&anim->loopPoint, 1); @@ -85,11 +85,11 @@ void LoadPlayerAnimation(const char *filePath, int playerID) } } - //Read Hitboxes + // Read Hitboxes FileRead(&fileBuffer, 1); int hitboxID = playerID << 3; for (int i = 0; i < fileBuffer; ++i) { - Hitbox *hitbox = &hitboxList[hitboxID++]; + Hitbox *hitbox = &PlayerCBoxes[hitboxID++]; for (int d = 0; d < HITBOX_DIR_COUNT; ++d) { FileRead(&hitbox->left[d], 1); FileRead(&hitbox->top[d], 1); @@ -97,18 +97,15 @@ void LoadPlayerAnimation(const char *filePath, int playerID) FileRead(&hitbox->bottom[d], 1); } } - playerScriptList[playerID].startWalkSpeed = playerScriptList[playerID].animations[ANI_WALKING].speed - 20; - playerScriptList[playerID].startRunSpeed = playerScriptList[playerID].animations[ANI_RUNNING].speed; - playerScriptList[playerID].startJumpSpeed = playerScriptList[playerID].animations[ANI_JUMPING].speed - 48; + PlayerScriptList[playerID].startWalkSpeed = PlayerScriptList[playerID].animations[ANI_WALKING].speed - 20; + PlayerScriptList[playerID].startRunSpeed = PlayerScriptList[playerID].animations[ANI_RUNNING].speed; + PlayerScriptList[playerID].startJumpSpeed = PlayerScriptList[playerID].animations[ANI_JUMPING].speed - 48; CloseFile(); } } void ClearAnimationData() { - for (int f = 0; f < SPRITEFRAME_COUNT; ++f) MEM_ZERO(scriptFrames[f]); - //for (int f = 0; f < SPRITEFRAME_COUNT; ++f) MEM_ZERO(animFrames[f]); - //for (int h = 0; h < HITBOX_COUNT; ++h) MEM_ZERO(hitboxList[h]); - - scriptFrameCount = 0; + for (int f = 0; f < SPRITEFRAME_COUNT; ++f) MEM_ZERO(ScriptFrames[f]); + ScriptFramesNo = 0; } diff --git a/Nexus/Animation.hpp b/Nexus/Animation.hpp index 09ad8ae..6d45674 100644 --- a/Nexus/Animation.hpp +++ b/Nexus/Animation.hpp @@ -33,11 +33,11 @@ struct Hitbox { sbyte bottom[HITBOX_DIR_COUNT]; }; -extern SpriteFrame scriptFrames[SPRITEFRAME_COUNT]; -extern int scriptFrameCount; +extern SpriteFrame ScriptFrames[SPRITEFRAME_COUNT]; +extern int ScriptFramesNo; extern SpriteFrame animFrames[SPRITEFRAME_COUNT]; -extern Hitbox hitboxList[HITBOX_COUNT]; +extern Hitbox PlayerCBoxes[HITBOX_COUNT]; void LoadPlayerAnimation(const char *filePath, int playerID); void ClearAnimationData(); diff --git a/Nexus/Audio.cpp b/Nexus/Audio.cpp index e6e8a72..49686b9 100644 --- a/Nexus/Audio.cpp +++ b/Nexus/Audio.cpp @@ -2,11 +2,11 @@ #include #include -int globalSFXCount = 0; -int stageSFXCount = 0; +int NoGlobalSFX = 0; +int NoStageSFX = 0; -int masterVolume = MAX_VOLUME; -int trackID = -1; +int MusicVolume = MAX_VOLUME; +int CurrentMusicTrack = -1; int sfxVolume = MAX_VOLUME; int bgmVolume = MAX_VOLUME; bool audioEnabled = false; @@ -47,7 +47,7 @@ SDL_AudioDeviceID audioDevice; #define MIX_BUFFER_SAMPLES (256) -int InitAudioPlayback() +int InitSoundDevice() { StopAllSfx(); //"init" #if RETRO_USING_SDL1 || RETRO_USING_SDL2 @@ -58,13 +58,13 @@ int InitAudioPlayback() want.channels = AUDIO_CHANNELS; want.callback = ProcessAudioPlayback; - #if RETRO_USING_SDL2 +#if RETRO_USING_SDL2 if ((audioDevice = SDL_OpenAudioDevice(nullptr, 0, &want, &audioDeviceFormat, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE)) > 0) { audioEnabled = true; SDL_PauseAudioDevice(audioDevice, 0); } else { - printLog("Unable to open audio device: %s", SDL_GetError()); + PrintLog("Unable to open audio device: %s", SDL_GetError()); audioEnabled = false; return true; // no audio but game wont crash now } @@ -75,7 +75,7 @@ int InitAudioPlayback() SDL_PauseAudio(0); } else { - printLog("Unable to open audio device: %s", SDL_GetError()); + PrintLog("Unable to open audio device: %s", SDL_GetError()); audioEnabled = false; return true; // no audio but game wont crash now } @@ -133,8 +133,8 @@ void LoadGlobalSfx() // Read SFX FileRead(&fileBuffer, 1); - globalSFXCount = fileBuffer; - for (byte s = 0; s < globalSFXCount; ++s) { + NoGlobalSFX = fileBuffer; + for (byte s = 0; s < NoGlobalSFX; ++s) { FileRead(&fileBuffer, 1); FileRead(strBuffer, fileBuffer); strBuffer[fileBuffer] = 0; @@ -147,7 +147,6 @@ void LoadGlobalSfx() CloseFile(); } - // sfxDataPosStage = sfxDataPos; nextChannelPos = 0; for (int i = 0; i < CHANNEL_COUNT; ++i) sfxChannels[i].sfxID = -1; } @@ -216,7 +215,7 @@ void ProcessMusicStream(Sint32 *stream, size_t bytes_wanted) return; } if (bytes_done != 0) - ProcessAudioMixing(stream, musInfo.buffer, bytes_done / sizeof(Sint16), (bgmVolume * masterVolume) / MAX_VOLUME, 0); + ProcessAudioMixing(stream, musInfo.buffer, bytes_done / sizeof(Sint16), (bgmVolume * MusicVolume) / MAX_VOLUME, 0); #endif #if RETRO_USING_SDL1 @@ -247,7 +246,7 @@ void ProcessMusicStream(Sint32 *stream, size_t bytes_wanted) bytes_gotten += bytes_read; } else { - printLog("Music read error: vorbis error: %d", bytes_read); + PrintLog("Music read error: vorbis error: %d", bytes_read); } } @@ -266,7 +265,7 @@ void ProcessMusicStream(Sint32 *stream, size_t bytes_wanted) } if (cvtResult == 0) - ProcessAudioMixing(stream, (const Sint16 *)convert.buf, bytes_gotten / sizeof(Sint16), (bgmVolume * masterVolume) / MAX_VOLUME, + ProcessAudioMixing(stream, (const Sint16 *)convert.buf, bytes_gotten / sizeof(Sint16), (bgmVolume * MusicVolume) / MAX_VOLUME, 0); if (convert.len > 0 && convert.buf) @@ -446,7 +445,7 @@ void LoadMusic(void *userdata) musInfo.stream = SDL_NewAudioStream(AUDIO_S16, musInfo.vorbisFile.vi->channels, musInfo.vorbisFile.vi->rate, audioDeviceFormat.format, audioDeviceFormat.channels, audioDeviceFormat.freq); if (!musInfo.stream) { - printLog("Failed to create stream: %s", SDL_GetError()); + PrintLog("Failed to create stream: %s", SDL_GetError()); } #endif @@ -459,8 +458,8 @@ void LoadMusic(void *userdata) musInfo.buffer = new Sint16[MIX_BUFFER_SAMPLES]; musicStatus = MUSIC_PLAYING; - masterVolume = MAX_VOLUME; - trackID = trackBuffer; + MusicVolume = MAX_VOLUME; + CurrentMusicTrack = trackBuffer; trackBuffer = -1; } } @@ -508,7 +507,7 @@ void LoadSfx(char *filePath, byte sfxID) FileRead(sfx, info.fileSize); CloseFile(); - //Un-encrypt sfx + // unencrypt sfx if (info.encrypted) { for (int i = 0; i < info.fileSize; ++i) sfx[i] ^= 0xFF; } @@ -517,7 +516,7 @@ void LoadSfx(char *filePath, byte sfxID) SDL_LockAudio(); SDL_RWops *src = SDL_RWFromMem(sfx, info.fileSize); if (src == NULL) { - printLog("Unable to open sfx: %s", info.fileName); + PrintLog("Unable to open sfx: %s", info.fileName); } else { SDL_AudioSpec wav_spec; @@ -528,7 +527,7 @@ void LoadSfx(char *filePath, byte sfxID) SDL_RWclose(src); delete[] sfx; if (wav == NULL) { - printLog("Unable to read sfx: %s", info.fileName); + PrintLog("Unable to read sfx: %s", info.fileName); } else { SDL_AudioCVT convert; diff --git a/Nexus/Audio.hpp b/Nexus/Audio.hpp index 1e28a05..cf745d4 100644 --- a/Nexus/Audio.hpp +++ b/Nexus/Audio.hpp @@ -59,11 +59,11 @@ enum MusicStatuses { MUSIC_READY = 4, }; -extern int globalSFXCount; -extern int stageSFXCount; +extern int NoGlobalSFX; +extern int NoStageSFX; -extern int masterVolume; -extern int trackID; +extern int MusicVolume; +extern int CurrentMusicTrack; extern int sfxVolume; extern int bgmVolume; extern bool audioEnabled; @@ -82,7 +82,7 @@ extern MusicPlaybackInfo musInfo; extern SDL_AudioSpec audioDeviceFormat; #endif -int InitAudioPlayback(); +int InitSoundDevice(); void LoadGlobalSfx(); #if RETRO_USING_SDL1 || RETRO_USING_SDL2 @@ -166,7 +166,7 @@ inline void SetMusicVolume(int volume) volume = 0; if (volume > MAX_VOLUME) volume = MAX_VOLUME; - masterVolume = volume; + MusicVolume = volume; } inline void PauseSound() @@ -189,7 +189,7 @@ inline void StopAllSfx() inline void ReleaseGlobalSfx() { StopAllSfx(); - for (int i = globalSFXCount - 1; i >= 0; --i) { + for (int i = NoGlobalSFX - 1; i >= 0; --i) { if (sfxList[i].loaded) { StrCopy(sfxList[i].name, ""); free(sfxList[i].buffer); @@ -197,11 +197,11 @@ inline void ReleaseGlobalSfx() sfxList[i].loaded = false; } } - globalSFXCount = 0; + NoGlobalSFX = 0; } inline void ReleaseStageSfx() { - for (int i = stageSFXCount + globalSFXCount; i >= globalSFXCount; --i) { + for (int i = NoStageSFX + NoGlobalSFX; i >= NoGlobalSFX; --i) { if (sfxList[i].loaded) { StrCopy(sfxList[i].name, ""); free(sfxList[i].buffer); @@ -209,10 +209,10 @@ inline void ReleaseStageSfx() sfxList[i].loaded = false; } } - stageSFXCount = 0; + NoStageSFX = 0; } -inline void ReleaseAudioDevice() +inline void ReleaseSoundDevice() { StopMusic(); StopAllSfx(); diff --git a/Nexus/Collision.cpp b/Nexus/Collision.cpp index 99e6003..9c29289 100644 --- a/Nexus/Collision.cpp +++ b/Nexus/Collision.cpp @@ -1,15 +1,14 @@ #include "RetroEngine.hpp" #include -int collisionLeft = 0; -int collisionTop = 0; -int collisionRight = 0; -int collisionBottom = 0; +int CollisionLeft = 0; +int CollisionTop = 0; +int CollisionRight = 0; +int CollisionBottom = 0; CollisionSensor sensors[6]; -void FindFloorPosition(Player *player, CollisionSensor *sensor, int startY) -{ +void FindFloorPosition(Player *player, CollisionSensor *sensor, int startY) { int c = 0; int angle = sensor->angle; int tsm1 = (TILE_SIZE - 1); @@ -22,51 +21,51 @@ void FindFloorPosition(Player *player, CollisionSensor *sensor, int startY) int chunkY = YPos >> 7; int tileY = (YPos & 0x7F) >> 4; if (XPos > -1 && YPos > -1) { - int tile = stageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; + int tile = StageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; tile += tileX + (tileY << 3); - int tileIndex = tiles128x128.tileIndex[tile]; - if (tiles128x128.collisionFlags[player->collisionPlane][tile] != SOLID_LRB - && tiles128x128.collisionFlags[player->collisionPlane][tile] != SOLID_NONE) { - switch (tiles128x128.direction[tile]) { + int tileIndex = StageTiles.tileIndex[tile]; + if (StageTiles.collisionFlags[player->collisionPlane][tile] != SOLID_LRB + && StageTiles.collisionFlags[player->collisionPlane][tile] != SOLID_NONE) { + switch (StageTiles.direction[tile]) { case FLIP_NONE: { c = (XPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].floorMasks[c] >= 0x40) + if (TileCollisions[player->collisionPlane].floorMasks[c] >= 0x40) break; - sensor->YPos = collisionMasks[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = TileCollisions[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - sensor->angle = collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF; + sensor->angle = TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF; break; } case FLIP_X: { c = tsm1 - (XPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].floorMasks[c] >= 0x40) + if (TileCollisions[player->collisionPlane].floorMasks[c] >= 0x40) break; - sensor->YPos = collisionMasks[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = TileCollisions[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - sensor->angle = 0x100 - (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF); + sensor->angle = 0x100 - (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF); break; } case FLIP_Y: { c = (XPos & 15) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].roofMasks[c] <= -0x40) + if (TileCollisions[player->collisionPlane].roofMasks[c] <= -0x40) break; - sensor->YPos = tsm1 - collisionMasks[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = tsm1 - TileCollisions[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - byte cAngle = (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24; + byte cAngle = (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24; sensor->angle = (byte)(-0x80 - cAngle); break; } case FLIP_XY: { c = tsm1 - (XPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].roofMasks[c] <= -0x40) + if (TileCollisions[player->collisionPlane].roofMasks[c] <= -0x40) break; - sensor->YPos = tsm1 - collisionMasks[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = tsm1 - TileCollisions[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - byte cAngle = (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24; + byte cAngle = (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24; sensor->angle = 0x100 - (byte)(-0x80 - cAngle); break; } @@ -86,12 +85,10 @@ void FindFloorPosition(Player *player, CollisionSensor *sensor, int startY) sensor->collided = false; sensor->angle = angle; i = TILE_SIZE * 3; - } - else if (sensor->YPos - startY > (TILE_SIZE / 2)) { + } else if (sensor->YPos - startY > (TILE_SIZE / 2)) { sensor->YPos = startY << 16; sensor->collided = false; - } - else if (sensor->YPos - startY < -(TILE_SIZE / 2)) { + } else if (sensor->YPos - startY < -(TILE_SIZE / 2)) { sensor->YPos = startY << 16; sensor->collided = false; } @@ -100,8 +97,7 @@ void FindFloorPosition(Player *player, CollisionSensor *sensor, int startY) } } } -void FindLWallPosition(Player *player, CollisionSensor *sensor, int startX) -{ +void FindLWallPosition(Player *player, CollisionSensor *sensor, int startX) { int c = 0; int angle = sensor->angle; int tsm1 = (TILE_SIZE - 1); @@ -114,50 +110,50 @@ void FindLWallPosition(Player *player, CollisionSensor *sensor, int startX) int chunkY = YPos >> 7; int tileY = (YPos & 0x7F) >> 4; if (XPos > -1 && YPos > -1) { - int tile = stageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; + int tile = StageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; tile = tile + tileX + (tileY << 3); - int tileIndex = tiles128x128.tileIndex[tile]; - if (tiles128x128.collisionFlags[player->collisionPlane][tile] < SOLID_NONE) { - switch (tiles128x128.direction[tile]) { + int tileIndex = StageTiles.tileIndex[tile]; + if (StageTiles.collisionFlags[player->collisionPlane][tile] < SOLID_NONE) { + switch (StageTiles.direction[tile]) { case FLIP_NONE: { c = (YPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].lWallMasks[c] >= 0x40) + if (TileCollisions[player->collisionPlane].lWallMasks[c] >= 0x40) break; - sensor->XPos = collisionMasks[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = TileCollisions[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; - sensor->angle = ((collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF00) >> 8); + sensor->angle = ((TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF00) >> 8); break; } case FLIP_X: { c = (YPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].rWallMasks[c] <= -0x40) + if (TileCollisions[player->collisionPlane].rWallMasks[c] <= -0x40) break; - sensor->XPos = tsm1 - collisionMasks[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = tsm1 - TileCollisions[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; - sensor->angle = 0x100 - ((collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF0000) >> 16); + sensor->angle = 0x100 - ((TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF0000) >> 16); break; } case FLIP_Y: { c = tsm1 - (YPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].lWallMasks[c] >= 0x40) + if (TileCollisions[player->collisionPlane].lWallMasks[c] >= 0x40) break; - sensor->XPos = collisionMasks[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = TileCollisions[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; - int cAngle = (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF00) >> 8; + int cAngle = (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF00) >> 8; sensor->angle = (byte)(-0x80 - cAngle); break; } case FLIP_XY: { c = tsm1 - (YPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].rWallMasks[c] <= -0x40) + if (TileCollisions[player->collisionPlane].rWallMasks[c] <= -0x40) break; - sensor->XPos = tsm1 - collisionMasks[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = tsm1 - TileCollisions[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; - int cAngle = (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF0000) >> 16; + int cAngle = (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF0000) >> 16; sensor->angle = 0x100 - (byte)(-0x80 - cAngle); break; } @@ -175,12 +171,10 @@ void FindLWallPosition(Player *player, CollisionSensor *sensor, int startX) sensor->collided = false; sensor->angle = angle; i = TILE_SIZE * 3; - } - else if (sensor->XPos - startX > TILE_SIZE / 2) { + } else if (sensor->XPos - startX > TILE_SIZE / 2) { sensor->XPos = startX << 16; sensor->collided = false; - } - else if (sensor->XPos - startX < -(TILE_SIZE / 2)) { + } else if (sensor->XPos - startX < -(TILE_SIZE / 2)) { sensor->XPos = startX << 16; sensor->collided = false; } @@ -189,8 +183,7 @@ void FindLWallPosition(Player *player, CollisionSensor *sensor, int startX) } } } -void FindRoofPosition(Player *player, CollisionSensor *sensor, int startY) -{ +void FindRoofPosition(Player *player, CollisionSensor *sensor, int startY) { int c = 0; int angle = sensor->angle; int tsm1 = (TILE_SIZE - 1); @@ -203,50 +196,50 @@ void FindRoofPosition(Player *player, CollisionSensor *sensor, int startY) int chunkY = YPos >> 7; int tileY = (YPos & 0x7F) >> 4; if (XPos > -1 && YPos > -1) { - int tile = stageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; + int tile = StageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; tile = tile + tileX + (tileY << 3); - int tileIndex = tiles128x128.tileIndex[tile]; - if (tiles128x128.collisionFlags[player->collisionPlane][tile] < SOLID_NONE) { - switch (tiles128x128.direction[tile]) { + int tileIndex = StageTiles.tileIndex[tile]; + if (StageTiles.collisionFlags[player->collisionPlane][tile] < SOLID_NONE) { + switch (StageTiles.direction[tile]) { case FLIP_NONE: { c = (XPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].roofMasks[c] <= -0x40) + if (TileCollisions[player->collisionPlane].roofMasks[c] <= -0x40) break; - sensor->YPos = collisionMasks[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = TileCollisions[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - sensor->angle = (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24; + sensor->angle = (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24; break; } case FLIP_X: { c = tsm1 - (XPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].roofMasks[c] <= -0x40) + if (TileCollisions[player->collisionPlane].roofMasks[c] <= -0x40) break; - sensor->YPos = collisionMasks[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = TileCollisions[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - sensor->angle = 0x100 - ((collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24); + sensor->angle = 0x100 - ((TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24); break; } case FLIP_Y: { c = (XPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].floorMasks[c] >= 0x40) + if (TileCollisions[player->collisionPlane].floorMasks[c] >= 0x40) break; - sensor->YPos = tsm1 - collisionMasks[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = tsm1 - TileCollisions[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - byte cAngle = collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF; + byte cAngle = TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF; sensor->angle = (byte)(-0x80 - cAngle); break; } case FLIP_XY: { c = tsm1 - (XPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].floorMasks[c] >= 0x40) + if (TileCollisions[player->collisionPlane].floorMasks[c] >= 0x40) break; - sensor->YPos = tsm1 - collisionMasks[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = tsm1 - TileCollisions[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - byte cAngle = collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF; + byte cAngle = TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF; sensor->angle = 0x100 - (byte)(-0x80 - cAngle); break; } @@ -273,8 +266,7 @@ void FindRoofPosition(Player *player, CollisionSensor *sensor, int startY) } } } -void FindRWallPosition(Player *player, CollisionSensor *sensor, int startX) -{ +void FindRWallPosition(Player *player, CollisionSensor *sensor, int startX) { int c; int angle = sensor->angle; int tsm1 = (TILE_SIZE - 1); @@ -287,50 +279,50 @@ void FindRWallPosition(Player *player, CollisionSensor *sensor, int startX) int chunkY = YPos >> 7; int tileY = (YPos & 0x7F) >> 4; if (XPos > -1 && YPos > -1) { - int tile = stageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; + int tile = StageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; tile = tile + tileX + (tileY << 3); - int tileIndex = tiles128x128.tileIndex[tile]; - if (tiles128x128.collisionFlags[player->collisionPlane][tile] < SOLID_NONE) { - switch (tiles128x128.direction[tile]) { + int tileIndex = StageTiles.tileIndex[tile]; + if (StageTiles.collisionFlags[player->collisionPlane][tile] < SOLID_NONE) { + switch (StageTiles.direction[tile]) { case FLIP_NONE: { c = (YPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].rWallMasks[c] <= -0x40) + if (TileCollisions[player->collisionPlane].rWallMasks[c] <= -0x40) break; - sensor->XPos = collisionMasks[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = TileCollisions[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; - sensor->angle = (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF0000) >> 16; + sensor->angle = (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF0000) >> 16; break; } case FLIP_X: { c = (YPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].lWallMasks[c] >= 0x40) + if (TileCollisions[player->collisionPlane].lWallMasks[c] >= 0x40) break; - sensor->XPos = tsm1 - collisionMasks[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = tsm1 - TileCollisions[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; - sensor->angle = 0x100 - ((collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF00) >> 8); + sensor->angle = 0x100 - ((TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF00) >> 8); break; } case FLIP_Y: { c = tsm1 - (YPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].rWallMasks[c] <= -0x40) + if (TileCollisions[player->collisionPlane].rWallMasks[c] <= -0x40) break; - sensor->XPos = collisionMasks[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = TileCollisions[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; - int cAngle = (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF0000) >> 16; + int cAngle = (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF0000) >> 16; sensor->angle = (byte)(-0x80 - cAngle); break; } case FLIP_XY: { c = tsm1 - (YPos & tsm1) + (tileIndex << 4); - if (collisionMasks[player->collisionPlane].lWallMasks[c] >= 0x40) + if (TileCollisions[player->collisionPlane].lWallMasks[c] >= 0x40) break; - sensor->XPos = tsm1 - collisionMasks[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = tsm1 - TileCollisions[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; - int cAngle = (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF00) >> 8; + int cAngle = (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF00) >> 8; sensor->angle = 0x100 - (byte)(-0x80 - cAngle); break; } @@ -348,12 +340,10 @@ void FindRWallPosition(Player *player, CollisionSensor *sensor, int startX) sensor->collided = false; sensor->angle = angle; i = TILE_SIZE * 3; - } - else if (sensor->XPos - startX > (TILE_SIZE / 2)) { + } else if (sensor->XPos - startX > (TILE_SIZE / 2)) { sensor->XPos = startX >> 16; sensor->collided = false; - } - else if (sensor->XPos - startX < -(TILE_SIZE / 2)) { + } else if (sensor->XPos - startX < -(TILE_SIZE / 2)) { sensor->XPos = startX << 16; sensor->collided = false; } @@ -363,8 +353,7 @@ void FindRWallPosition(Player *player, CollisionSensor *sensor, int startX) } } -void FloorCollision(Player *player, CollisionSensor *sensor) -{ +void FloorCollision(Player *player, CollisionSensor *sensor) { int c; int startY = sensor->YPos >> 16; int tsm1 = (TILE_SIZE - 1); @@ -377,53 +366,53 @@ void FloorCollision(Player *player, CollisionSensor *sensor) int chunkY = YPos >> 7; int tileY = (YPos & 0x7F) >> 4; if (XPos > -1 && YPos > -1) { - int tile = stageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; + int tile = StageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; tile += tileX + (tileY << 3); - int tileIndex = tiles128x128.tileIndex[tile]; - if (tiles128x128.collisionFlags[player->collisionPlane][tile] != SOLID_LRB - && tiles128x128.collisionFlags[player->collisionPlane][tile] != SOLID_NONE) { - switch (tiles128x128.direction[tile]) { + int tileIndex = StageTiles.tileIndex[tile]; + if (StageTiles.collisionFlags[player->collisionPlane][tile] != SOLID_LRB + && StageTiles.collisionFlags[player->collisionPlane][tile] != SOLID_NONE) { + switch (StageTiles.direction[tile]) { case FLIP_NONE: { c = (XPos & tsm1) + (tileIndex << 4); - if ((YPos & tsm1) <= collisionMasks[player->collisionPlane].floorMasks[c] + i - TILE_SIZE - || collisionMasks[player->collisionPlane].floorMasks[c] >= tsm1) + if ((YPos & tsm1) <= TileCollisions[player->collisionPlane].floorMasks[c] + i - TILE_SIZE + || TileCollisions[player->collisionPlane].floorMasks[c] >= tsm1) break; - sensor->YPos = collisionMasks[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = TileCollisions[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - sensor->angle = collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF; + sensor->angle = TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF; break; } case FLIP_X: { c = tsm1 - (XPos & tsm1) + (tileIndex << 4); - if ((YPos & tsm1) <= collisionMasks[player->collisionPlane].floorMasks[c] + i - TILE_SIZE - || collisionMasks[player->collisionPlane].floorMasks[c] >= tsm1) + if ((YPos & tsm1) <= TileCollisions[player->collisionPlane].floorMasks[c] + i - TILE_SIZE + || TileCollisions[player->collisionPlane].floorMasks[c] >= tsm1) break; - sensor->YPos = collisionMasks[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = TileCollisions[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - sensor->angle = 0x100 - (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF); + sensor->angle = 0x100 - (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF); break; } case FLIP_Y: { c = (XPos & tsm1) + (tileIndex << 4); - if ((YPos & tsm1) <= tsm1 - collisionMasks[player->collisionPlane].roofMasks[c] + i - TILE_SIZE) + if ((YPos & tsm1) <= tsm1 - TileCollisions[player->collisionPlane].roofMasks[c] + i - TILE_SIZE) break; - sensor->YPos = tsm1 - collisionMasks[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = tsm1 - TileCollisions[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - int cAngle = (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24; + int cAngle = (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24; sensor->angle = (byte)(-0x80 - cAngle); break; } case FLIP_XY: { c = tsm1 - (XPos & tsm1) + (tileIndex << 4); - if ((YPos & tsm1) <= tsm1 - collisionMasks[player->collisionPlane].roofMasks[c] + i - TILE_SIZE) + if ((YPos & tsm1) <= tsm1 - TileCollisions[player->collisionPlane].roofMasks[c] + i - TILE_SIZE) break; - sensor->YPos = tsm1 - collisionMasks[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = tsm1 - TileCollisions[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - int cAngle = (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24; + int cAngle = (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24; sensor->angle = 0x100 - (byte)(-0x80 - cAngle); break; } @@ -440,8 +429,7 @@ void FloorCollision(Player *player, CollisionSensor *sensor) if (sensor->YPos - startY > (TILE_SIZE - 2)) { sensor->YPos = startY << 16; sensor->collided = false; - } - else if (sensor->YPos - startY < -(TILE_SIZE + 1)) { + } else if (sensor->YPos - startY < -(TILE_SIZE + 1)) { sensor->YPos = startY << 16; sensor->collided = false; } @@ -450,8 +438,7 @@ void FloorCollision(Player *player, CollisionSensor *sensor) } } } -void LWallCollision(Player *player, CollisionSensor *sensor) -{ +void LWallCollision(Player *player, CollisionSensor *sensor) { int c; int startX = sensor->XPos >> 16; int tsm1 = (TILE_SIZE - 1); @@ -464,45 +451,45 @@ void LWallCollision(Player *player, CollisionSensor *sensor) int chunkY = YPos >> 7; int tileY = (YPos & 0x7F) >> 4; if (XPos > -1 && YPos > -1) { - int tile = stageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; + int tile = StageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; tile += tileX + (tileY << 3); - int tileIndex = tiles128x128.tileIndex[tile]; - if (tiles128x128.collisionFlags[player->collisionPlane][tile] != SOLID_TOP - && tiles128x128.collisionFlags[player->collisionPlane][tile] < SOLID_NONE) { - switch (tiles128x128.direction[tile]) { + int tileIndex = StageTiles.tileIndex[tile]; + if (StageTiles.collisionFlags[player->collisionPlane][tile] != SOLID_TOP + && StageTiles.collisionFlags[player->collisionPlane][tile] < SOLID_NONE) { + switch (StageTiles.direction[tile]) { case FLIP_NONE: { c = (YPos & tsm1) + (tileIndex << 4); - if ((XPos & tsm1) <= collisionMasks[player->collisionPlane].lWallMasks[c] + i - TILE_SIZE) + if ((XPos & tsm1) <= TileCollisions[player->collisionPlane].lWallMasks[c] + i - TILE_SIZE) break; - sensor->XPos = collisionMasks[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = TileCollisions[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; break; } case FLIP_X: { c = (YPos & tsm1) + (tileIndex << 4); - if ((XPos & tsm1) <= tsm1 - collisionMasks[player->collisionPlane].rWallMasks[c] + i - TILE_SIZE) + if ((XPos & tsm1) <= tsm1 - TileCollisions[player->collisionPlane].rWallMasks[c] + i - TILE_SIZE) break; - sensor->XPos = tsm1 - collisionMasks[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = tsm1 - TileCollisions[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; break; } case FLIP_Y: { c = tsm1 - (YPos & tsm1) + (tileIndex << 4); - if ((XPos & tsm1) <= collisionMasks[player->collisionPlane].lWallMasks[c] + i - TILE_SIZE) + if ((XPos & tsm1) <= TileCollisions[player->collisionPlane].lWallMasks[c] + i - TILE_SIZE) break; - sensor->XPos = collisionMasks[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = TileCollisions[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; break; } case FLIP_XY: { c = tsm1 - (YPos & tsm1) + (tileIndex << 4); - if ((XPos & tsm1) <= tsm1 - collisionMasks[player->collisionPlane].rWallMasks[c] + i - TILE_SIZE) + if ((XPos & tsm1) <= tsm1 - TileCollisions[player->collisionPlane].rWallMasks[c] + i - TILE_SIZE) break; - sensor->XPos = tsm1 - collisionMasks[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = tsm1 - TileCollisions[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; break; } @@ -513,8 +500,7 @@ void LWallCollision(Player *player, CollisionSensor *sensor) if (sensor->XPos - startX > tsm1) { sensor->XPos = startX << 16; sensor->collided = false; - } - else if (sensor->XPos - startX < -tsm1) { + } else if (sensor->XPos - startX < -tsm1) { sensor->XPos = startX << 16; sensor->collided = false; } @@ -523,8 +509,7 @@ void LWallCollision(Player *player, CollisionSensor *sensor) } } } -void RoofCollision(Player *player, CollisionSensor *sensor) -{ +void RoofCollision(Player *player, CollisionSensor *sensor) { int c; int startY = sensor->YPos >> 16; int tsm1 = (TILE_SIZE - 1); @@ -537,50 +522,50 @@ void RoofCollision(Player *player, CollisionSensor *sensor) int chunkY = YPos >> 7; int tileY = (YPos & 0x7F) >> 4; if (XPos > -1 && YPos > -1) { - int tile = stageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; + int tile = StageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; tile += tileX + (tileY << 3); - int tileIndex = tiles128x128.tileIndex[tile]; - if (tiles128x128.collisionFlags[player->collisionPlane][tile] != SOLID_TOP - && tiles128x128.collisionFlags[player->collisionPlane][tile] < SOLID_NONE) { - switch (tiles128x128.direction[tile]) { + int tileIndex = StageTiles.tileIndex[tile]; + if (StageTiles.collisionFlags[player->collisionPlane][tile] != SOLID_TOP + && StageTiles.collisionFlags[player->collisionPlane][tile] < SOLID_NONE) { + switch (StageTiles.direction[tile]) { case FLIP_NONE: { c = (XPos & tsm1) + (tileIndex << 4); - if ((YPos & tsm1) >= collisionMasks[player->collisionPlane].roofMasks[c] + TILE_SIZE - i) + if ((YPos & tsm1) >= TileCollisions[player->collisionPlane].roofMasks[c] + TILE_SIZE - i) break; - sensor->YPos = collisionMasks[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = TileCollisions[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - sensor->angle = ((collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24); + sensor->angle = ((TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24); break; } case FLIP_X: { c = tsm1 - (XPos & tsm1) + (tileIndex << 4); - if ((YPos & tsm1) >= collisionMasks[player->collisionPlane].roofMasks[c] + TILE_SIZE - i) + if ((YPos & tsm1) >= TileCollisions[player->collisionPlane].roofMasks[c] + TILE_SIZE - i) break; - sensor->YPos = collisionMasks[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = TileCollisions[player->collisionPlane].roofMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - sensor->angle = 0x100 - ((collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24); + sensor->angle = 0x100 - ((TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF000000) >> 24); break; } case FLIP_Y: { c = (XPos & tsm1) + (tileIndex << 4); - if ((YPos & tsm1) >= tsm1 - collisionMasks[player->collisionPlane].floorMasks[c] + TILE_SIZE - i) + if ((YPos & tsm1) >= tsm1 - TileCollisions[player->collisionPlane].floorMasks[c] + TILE_SIZE - i) break; - sensor->YPos = tsm1 - collisionMasks[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = tsm1 - TileCollisions[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - sensor->angle = (byte)(-0x80 - (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF)); + sensor->angle = (byte)(-0x80 - (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF)); break; } case FLIP_XY: { c = tsm1 - (XPos & tsm1) + (tileIndex << 4); - if ((YPos & tsm1) >= tsm1 - collisionMasks[player->collisionPlane].floorMasks[c] + TILE_SIZE - i) + if ((YPos & tsm1) >= tsm1 - TileCollisions[player->collisionPlane].floorMasks[c] + TILE_SIZE - i) break; - sensor->YPos = tsm1 - collisionMasks[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); + sensor->YPos = tsm1 - TileCollisions[player->collisionPlane].floorMasks[c] + (chunkY << 7) + (tileY << 4); sensor->collided = true; - sensor->angle = 0x100 - (byte)(-0x80 - (collisionMasks[player->collisionPlane].angles[tileIndex] & 0xFF)); + sensor->angle = 0x100 - (byte)(-0x80 - (TileCollisions[player->collisionPlane].angles[tileIndex] & 0xFF)); break; } } @@ -596,8 +581,7 @@ void RoofCollision(Player *player, CollisionSensor *sensor) if (sensor->YPos - startY > (TILE_SIZE - 2)) { sensor->YPos = startY << 16; sensor->collided = false; - } - else if (sensor->YPos - startY < -(TILE_SIZE - 2)) { + } else if (sensor->YPos - startY < -(TILE_SIZE - 2)) { sensor->YPos = startY << 16; sensor->collided = false; } @@ -606,8 +590,7 @@ void RoofCollision(Player *player, CollisionSensor *sensor) } } } -void RWallCollision(Player *player, CollisionSensor *sensor) -{ +void RWallCollision(Player *player, CollisionSensor *sensor) { int c; int startX = sensor->XPos >> 16; int tsm1 = (TILE_SIZE - 1); @@ -620,45 +603,45 @@ void RWallCollision(Player *player, CollisionSensor *sensor) int chunkY = YPos >> 7; int tileY = (YPos & 0x7F) >> 4; if (XPos > -1 && YPos > -1) { - int tile = stageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; + int tile = StageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6; tile += tileX + (tileY << 3); - int tileIndex = tiles128x128.tileIndex[tile]; - if (tiles128x128.collisionFlags[player->collisionPlane][tile] != SOLID_TOP - && tiles128x128.collisionFlags[player->collisionPlane][tile] < SOLID_NONE) { - switch (tiles128x128.direction[tile]) { + int tileIndex = StageTiles.tileIndex[tile]; + if (StageTiles.collisionFlags[player->collisionPlane][tile] != SOLID_TOP + && StageTiles.collisionFlags[player->collisionPlane][tile] < SOLID_NONE) { + switch (StageTiles.direction[tile]) { case FLIP_NONE: { c = (YPos & tsm1) + (tileIndex << 4); - if ((XPos & tsm1) >= collisionMasks[player->collisionPlane].rWallMasks[c] + TILE_SIZE - i) + if ((XPos & tsm1) >= TileCollisions[player->collisionPlane].rWallMasks[c] + TILE_SIZE - i) break; - sensor->XPos = collisionMasks[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = TileCollisions[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; break; } case FLIP_X: { c = (YPos & tsm1) + (tileIndex << 4); - if ((XPos & tsm1) >= tsm1 - collisionMasks[player->collisionPlane].lWallMasks[c] + TILE_SIZE - i) + if ((XPos & tsm1) >= tsm1 - TileCollisions[player->collisionPlane].lWallMasks[c] + TILE_SIZE - i) break; - sensor->XPos = tsm1 - collisionMasks[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = tsm1 - TileCollisions[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; break; } case FLIP_Y: { c = tsm1 - (YPos & tsm1) + (tileIndex << 4); - if ((XPos & tsm1) >= collisionMasks[player->collisionPlane].rWallMasks[c] + TILE_SIZE - i) + if ((XPos & tsm1) >= TileCollisions[player->collisionPlane].rWallMasks[c] + TILE_SIZE - i) break; - sensor->XPos = collisionMasks[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = TileCollisions[player->collisionPlane].rWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; break; } case FLIP_XY: { c = tsm1 - (YPos & tsm1) + (tileIndex << 4); - if ((XPos & tsm1) >= tsm1 - collisionMasks[player->collisionPlane].lWallMasks[c] + TILE_SIZE - i) + if ((XPos & tsm1) >= tsm1 - TileCollisions[player->collisionPlane].lWallMasks[c] + TILE_SIZE - i) break; - sensor->XPos = tsm1 - collisionMasks[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); + sensor->XPos = tsm1 - TileCollisions[player->collisionPlane].lWallMasks[c] + (chunkX << 7) + (tileX << 4); sensor->collided = true; break; } @@ -669,8 +652,7 @@ void RWallCollision(Player *player, CollisionSensor *sensor) if (sensor->XPos - startX > tsm1) { sensor->XPos = startX << 16; sensor->collided = false; - } - else if (sensor->XPos - startX < -tsm1) { + } else if (sensor->XPos - startX < -tsm1) { sensor->XPos = startX << 16; sensor->collided = false; } @@ -680,14 +662,13 @@ void RWallCollision(Player *player, CollisionSensor *sensor) } } -void ProcessTracedCollision(Player *player) -{ - PlayerScript *script = &playerScriptList[activePlayer]; - Hitbox *playerHitbox = getPlayerHitbox(script); - collisionLeft = playerHitbox->left[0]; - collisionTop = playerHitbox->top[0]; - collisionRight = playerHitbox->right[0]; - collisionBottom = playerHitbox->bottom[0]; +void ProcessTracedCollision(Player *player) { + PlayerScript *script = &PlayerScriptList[PlayerNo]; + Hitbox *playerHitbox = GetPlayerCBox(script); + CollisionLeft = playerHitbox->left[0]; + CollisionTop = playerHitbox->top[0]; + CollisionRight = playerHitbox->right[0]; + CollisionBottom = playerHitbox->bottom[0]; byte movingDown = 0; byte movingUp = 0; @@ -696,26 +677,24 @@ void ProcessTracedCollision(Player *player) if (player->XVelocity < 0) { movingRight = 0; - } - else { + } else { movingRight = 1; - sensors[0].YPos = ((collisionTop + 4) << 16) + player->YPos; - sensors[1].YPos = ((collisionBottom - 4) << 16) + player->YPos; - sensors[0].XPos = (collisionRight << 16) + player->XPos; - sensors[1].XPos = (collisionRight << 16) + player->XPos; + sensors[0].YPos = ((CollisionTop + 4) << 16) + player->YPos; + sensors[1].YPos = ((CollisionBottom - 4) << 16) + player->YPos; + sensors[0].XPos = (CollisionRight << 16) + player->XPos; + sensors[1].XPos = (CollisionRight << 16) + player->XPos; } if (player->XVelocity > 0) { movingLeft = 0; - } - else { + } else { movingLeft = 1; - sensors[2].YPos = ((collisionTop + 4) << 16) + player->YPos; - sensors[3].YPos = ((collisionBottom - 4) << 16) + player->YPos; - sensors[2].XPos = ((collisionLeft - 1) << 16) + player->XPos; - sensors[3].XPos = ((collisionLeft - 1) << 16) + player->XPos; + sensors[2].YPos = ((CollisionTop + 4) << 16) + player->YPos; + sensors[3].YPos = ((CollisionBottom - 4) << 16) + player->YPos; + sensors[2].XPos = ((CollisionLeft - 1) << 16) + player->XPos; + sensors[3].XPos = ((CollisionLeft - 1) << 16) + player->XPos; } - sensors[4].XPos = ((collisionLeft + 1) << 16) + player->XPos; - sensors[5].XPos = ((collisionRight - 2) << 16) + player->XPos; + sensors[4].XPos = ((CollisionLeft + 1) << 16) + player->XPos; + sensors[5].XPos = ((CollisionRight - 2) << 16) + player->XPos; sensors[0].collided = false; sensors[1].collided = false; sensors[2].collided = false; @@ -727,22 +706,21 @@ void ProcessTracedCollision(Player *player) movingUp = 0; if (player->YVelocity < 0) { movingUp = 1; - sensors[4].YPos = ((collisionTop - 1) << 16) + player->YPos; - sensors[5].YPos = ((collisionTop - 1) << 16) + player->YPos; - } - else if (player->YVelocity > 0) { + sensors[4].YPos = ((CollisionTop - 1) << 16) + player->YPos; + sensors[5].YPos = ((CollisionTop - 1) << 16) + player->YPos; + } else if (player->YVelocity > 0) { movingDown = 1; - sensors[4].YPos = (collisionBottom << 16) + player->YPos; - sensors[5].YPos = (collisionBottom << 16) + player->YPos; + sensors[4].YPos = (CollisionBottom << 16) + player->YPos; + sensors[5].YPos = (CollisionBottom << 16) + player->YPos; } int xDif = ((player->XVelocity + player->XPos) >> 16) - (player->XPos >> 16); int yDif = ((player->YVelocity + player->YPos) >> 16) - (player->YPos >> 16); int absXDif = abs(xDif); int absYDif = abs(yDif); - int cnt = 1; - int XVel = player->XVelocity; - int YVel = player->YVelocity; + int cnt = 1; + int XVel = player->XVelocity; + int YVel = player->YVelocity; if (absXDif || absYDif) { if (absXDif <= absYDif) { @@ -752,8 +730,7 @@ void ProcessTracedCollision(Player *player) YVel = 0x10000; else YVel = -0x10000; - } - else { + } else { YVel = (yDif << 16) / absXDif; cnt = absXDif; if (xDif >= 0) @@ -808,8 +785,7 @@ void ProcessTracedCollision(Player *player) movingDown = 2; cnt = 0; } - } - else if (movingUp == 1) { + } else if (movingUp == 1) { for (int i = 4; i < 6; i++) { if (!sensors[i].collided) { sensors[i].XPos += XVel; @@ -830,17 +806,14 @@ void ProcessTracedCollision(Player *player) player->speed = 0; if (!sensors[0].collided || !sensors[1].collided) { if (sensors[0].collided) { - player->XPos = (sensors[0].XPos - collisionRight) << 16; - } - else if (sensors[1].collided) { - player->XPos = (sensors[1].XPos - collisionRight) << 16; + player->XPos = (sensors[0].XPos - CollisionRight) << 16; + } else if (sensors[1].collided) { + player->XPos = (sensors[1].XPos - CollisionRight) << 16; } - } - else if (sensors[0].XPos >= sensors[1].XPos) { - player->XPos = (sensors[1].XPos - collisionRight) << 16; - } - else { - player->XPos = (sensors[0].XPos - collisionRight) << 16; + } else if (sensors[0].XPos >= sensors[1].XPos) { + player->XPos = (sensors[1].XPos - CollisionRight) << 16; + } else { + player->XPos = (sensors[0].XPos - CollisionRight) << 16; } } if (movingLeft == 2) { @@ -848,21 +821,17 @@ void ProcessTracedCollision(Player *player) player->speed = 0; if (!sensors[2].collided || !sensors[3].collided) { if (sensors[2].collided) { - player->XPos = (sensors[2].XPos - collisionLeft + 1) << 16; + player->XPos = (sensors[2].XPos - CollisionLeft + 1) << 16; + } else if (sensors[3].collided) { + player->XPos = (sensors[3].XPos - CollisionLeft + 1) << 16; } - else if (sensors[3].collided) { - player->XPos = (sensors[3].XPos - collisionLeft + 1) << 16; - } - } - else if (sensors[2].XPos <= sensors[3].XPos) { - player->XPos = (sensors[3].XPos - collisionLeft + 1) << 16; - } - else { - player->XPos = (sensors[2].XPos - collisionLeft + 1) << 16; + } else if (sensors[2].XPos <= sensors[3].XPos) { + player->XPos = (sensors[3].XPos - CollisionLeft + 1) << 16; + } else { + player->XPos = (sensors[2].XPos - CollisionLeft + 1) << 16; } } - } - else { + } else { player->XPos += player->XVelocity; } @@ -875,20 +844,17 @@ void ProcessTracedCollision(Player *player) player->gravity = 0; if (sensors[4].collided && sensors[5].collided) { if (sensors[4].YPos >= sensors[5].YPos) { - player->YPos = (sensors[5].YPos - collisionBottom) << 16; + player->YPos = (sensors[5].YPos - CollisionBottom) << 16; player->angle = sensors[5].angle; - } - else { - player->YPos = (sensors[4].YPos - collisionBottom) << 16; + } else { + player->YPos = (sensors[4].YPos - CollisionBottom) << 16; player->angle = sensors[4].angle; } - } - else if (sensors[4].collided) { - player->YPos = (sensors[4].YPos - collisionBottom) << 16; + } else if (sensors[4].collided) { + player->YPos = (sensors[4].YPos - CollisionBottom) << 16; player->angle = sensors[4].angle; - } - else if (sensors[5].collided) { - player->YPos = (sensors[5].YPos - collisionBottom) << 16; + } else if (sensors[5].collided) { + player->YPos = (sensors[5].YPos - CollisionBottom) << 16; player->angle = sensors[5].angle; } if (player->angle > 0xA0 && player->angle < 0xE0 && player->collisionMode != CMODE_LWALL) { @@ -899,30 +865,26 @@ void ProcessTracedCollision(Player *player) } player->rotation = player->angle; - player->speed += (player->YVelocity * sinVal256[player->angle] >> 8); - player->YVelocity = 0; + player->speed += (player->YVelocity * SinValue256[player->angle] >> 8); + player->YVelocity = 0; } if (movingUp == 2) { player->YVelocity = 0; if (sensors[4].collided && sensors[5].collided) { if (sensors[4].YPos <= sensors[5].YPos) { - player->YPos = (sensors[5].YPos - collisionTop + 1) << 16; - } - else { - player->YPos = (sensors[4].YPos - collisionTop + 1) << 16; + player->YPos = (sensors[5].YPos - CollisionTop + 1) << 16; + } else { + player->YPos = (sensors[4].YPos - CollisionTop + 1) << 16; } - } - else if (sensors[4].collided) { - player->YPos = (sensors[4].YPos - collisionTop + 1) << 16; - } - else if (sensors[5].collided) { - player->YPos = (sensors[5].YPos - collisionTop + 1) << 16; + } else if (sensors[4].collided) { + player->YPos = (sensors[4].YPos - CollisionTop + 1) << 16; + } else if (sensors[5].collided) { + player->YPos = (sensors[5].YPos - CollisionTop + 1) << 16; } } } -void ProcessPathGrip(Player *player) -{ +void ProcessPathGrip(Player *player) { int cos; int sin; sensors[4].XPos = player->XPos; @@ -939,14 +901,13 @@ void ProcessPathGrip(Player *player) while (checkDist > -1) { if (checkDist >= 1) { - cos = cosVal256[player->angle] << 10; - sin = sinVal256[player->angle] << 10; + cos = CosValue256[player->angle] << 10; + sin = SinValue256[player->angle] << 10; checkDist--; - } - else { - cos = absSpeed * cosVal256[player->angle] >> 8; - sin = absSpeed * sinVal256[player->angle] >> 8; - checkDist = -1; + } else { + cos = absSpeed * CosValue256[player->angle] >> 8; + sin = absSpeed * SinValue256[player->angle] >> 8; + checkDist = -1; } if (player->speed < 0) { @@ -978,15 +939,13 @@ void ProcessPathGrip(Player *player) if (sensors[i].YPos == sensors[tileDistance].YPos && (sensors[i].angle < 0x08 || sensors[i].angle > 0xF8)) tileDistance = i; } - } - else if (sensors[i].collided) + } else if (sensors[i].collided) tileDistance = i; } if (tileDistance <= -1) { checkDist = -1; - } - else { + } else { sensors[0].YPos = sensors[tileDistance].YPos << 16; sensors[0].angle = sensors[tileDistance].angle; sensors[1].YPos = sensors[0].YPos; @@ -996,7 +955,7 @@ void ProcessPathGrip(Player *player) sensors[3].YPos = sensors[0].YPos - 0x40000; sensors[3].angle = sensors[0].angle; sensors[4].XPos = sensors[1].XPos; - sensors[4].YPos = sensors[0].YPos - (collisionBottom << 16); + sensors[4].YPos = sensors[0].YPos - (CollisionBottom << 16); } sensors[3].XPos += cos; @@ -1025,16 +984,14 @@ void ProcessPathGrip(Player *player) if (sensors[i].XPos < sensors[tileDistance].XPos && sensors[i].collided) { tileDistance = i; } - } - else if (sensors[i].collided) { + } else if (sensors[i].collided) { tileDistance = i; } } if (tileDistance <= -1) { checkDist = -1; - } - else { + } else { sensors[0].XPos = sensors[tileDistance].XPos << 16; sensors[0].angle = sensors[tileDistance].angle; sensors[1].XPos = sensors[0].XPos; @@ -1042,7 +999,7 @@ void ProcessPathGrip(Player *player) sensors[2].XPos = sensors[0].XPos; sensors[2].angle = sensors[0].angle; sensors[4].YPos = sensors[1].YPos; - sensors[4].XPos = sensors[1].XPos - (collisionRight << 16); + sensors[4].XPos = sensors[1].XPos - (CollisionRight << 16); } if ((sensors[0].angle < 0x20 || sensors[0].angle > 0xE0) && player->collisionMode != CMODE_FLOOR) @@ -1064,16 +1021,14 @@ void ProcessPathGrip(Player *player) if (sensors[i].YPos > sensors[tileDistance].YPos && sensors[i].collided) { tileDistance = i; } - } - else if (sensors[i].collided) { + } else if (sensors[i].collided) { tileDistance = i; } } if (tileDistance <= -1) { checkDist = -1; - } - else { + } else { sensors[0].YPos = sensors[tileDistance].YPos << 16; sensors[0].angle = sensors[tileDistance].angle; sensors[1].YPos = sensors[0].YPos; @@ -1083,12 +1038,12 @@ void ProcessPathGrip(Player *player) sensors[3].YPos = sensors[0].YPos + 0x40000; sensors[3].angle = sensors[0].angle; sensors[4].XPos = sensors[1].XPos; - sensors[4].YPos = sensors[0].YPos - ((collisionTop - 1) << 16); + sensors[4].YPos = sensors[0].YPos - ((CollisionTop - 1) << 16); } sensors[3].XPos += cos; if (player->speed > 0) - RWallCollision(player,&sensors[3]); + RWallCollision(player, &sensors[3]); if (player->speed < 0) LWallCollision(player, &sensors[3]); if (sensors[0].angle > 0xA0 && sensors[0].angle < 0xE0 && player->collisionMode != CMODE_LWALL) @@ -1110,16 +1065,14 @@ void ProcessPathGrip(Player *player) if (sensors[i].XPos > sensors[tileDistance].XPos && sensors[i].collided) { tileDistance = i; } - } - else if (sensors[i].collided) { + } else if (sensors[i].collided) { tileDistance = i; } } if (tileDistance <= -1) { checkDist = -1; - } - else { + } else { sensors[0].XPos = sensors[tileDistance].XPos << 16; sensors[0].angle = sensors[tileDistance].angle; sensors[1].XPos = sensors[0].XPos; @@ -1127,7 +1080,7 @@ void ProcessPathGrip(Player *player) sensors[2].XPos = sensors[0].XPos; sensors[2].angle = sensors[0].angle; sensors[4].YPos = sensors[1].YPos; - sensors[4].XPos = sensors[1].XPos - ((collisionLeft - 1) << 16); + sensors[4].XPos = sensors[1].XPos - ((CollisionLeft - 1) << 16); } if ((sensors[0].angle < 0x20 || sensors[0].angle > 0xE0) && player->collisionMode != CMODE_FLOOR) @@ -1157,37 +1110,34 @@ void ProcessPathGrip(Player *player) if (!sensors[3].collided) { player->pushing = 0; player->XPos = sensors[4].XPos; - } - else { + } else { if (player->speed > 0) - player->XPos = (sensors[3].XPos - collisionRight) << 16; + player->XPos = (sensors[3].XPos - CollisionRight) << 16; if (player->speed < 0) - player->XPos = (sensors[3].XPos - collisionLeft + 1) << 16; + player->XPos = (sensors[3].XPos - CollisionLeft + 1) << 16; player->speed = 0; if ((player->left || player->right) && player->pushing < 2) player->pushing++; } player->YPos = sensors[4].YPos; - } - else { + } else { player->gravity = 1; player->collisionMode = CMODE_FLOOR; - player->XVelocity = cosVal256[player->angle] * player->speed >> 8; - player->YVelocity = sinVal256[player->angle] * player->speed >> 8; + player->XVelocity = CosValue256[player->angle] * player->speed >> 8; + player->YVelocity = SinValue256[player->angle] * player->speed >> 8; player->speed = player->XVelocity; player->angle = 0; if (!sensors[3].collided) { player->pushing = 0; - player->XPos += player->XVelocity; - } - else { + player->XPos += player->XVelocity; + } else { if (player->speed > 0) - player->XPos = (sensors[3].XPos - collisionRight) << 16; + player->XPos = (sensors[3].XPos - CollisionRight) << 16; if (player->speed < 0) - player->XPos = (sensors[3].XPos - collisionLeft + 1) << 16; + player->XPos = (sensors[3].XPos - CollisionLeft + 1) << 16; player->speed = 0; if ((player->left || player->right) && player->pushing < 2) @@ -1201,16 +1151,14 @@ void ProcessPathGrip(Player *player) if (!sensors[0].collided && !sensors[1].collided && !sensors[2].collided) { player->gravity = 1; player->collisionMode = CMODE_FLOOR; - player->XVelocity = cosVal256[player->angle] * player->speed >> 8; - player->YVelocity = sinVal256[player->angle] * player->speed >> 8; - player->speed = player->XVelocity; - player->angle = 0; - } - else if (player->speed >= 0x20000 || player->speed <= -1) { + player->XVelocity = CosValue256[player->angle] * player->speed >> 8; + player->YVelocity = SinValue256[player->angle] * player->speed >> 8; + player->speed = player->XVelocity; + player->angle = 0; + } else if (player->speed >= 0x20000 || player->speed <= -1) { player->angle = sensors[0].angle; player->rotation = player->angle; - } - else { + } else { player->gravity = 1; player->angle = 0; player->collisionMode = CMODE_FLOOR; @@ -1225,16 +1173,14 @@ void ProcessPathGrip(Player *player) if (!sensors[0].collided && !sensors[1].collided && !sensors[2].collided) { player->gravity = 1; player->collisionMode = CMODE_FLOOR; - player->XVelocity = cosVal256[player->angle] * player->speed >> 8; - player->YVelocity = sinVal256[player->angle] * player->speed >> 8; - player->angle = 0; - player->speed = player->XVelocity; - } - else if (player->speed <= -0x20000 || player->speed >= 0x20000) { + player->XVelocity = CosValue256[player->angle] * player->speed >> 8; + player->YVelocity = SinValue256[player->angle] * player->speed >> 8; + player->angle = 0; + player->speed = player->XVelocity; + } else if (player->speed <= -0x20000 || player->speed >= 0x20000) { player->angle = sensors[0].angle; player->rotation = player->angle; - } - else { + } else { player->gravity = 1; player->angle = 0; player->collisionMode = CMODE_FLOOR; @@ -1243,13 +1189,12 @@ void ProcessPathGrip(Player *player) if (!sensors[3].collided) { player->XPos = sensors[4].XPos; - } - else { + } else { if (player->speed > 0) - player->XPos = (sensors[3].XPos - collisionRight) << 16; + player->XPos = (sensors[3].XPos - CollisionRight) << 16; if (player->speed < 0) - player->XPos = (sensors[3].XPos - collisionLeft + 1) << 16; + player->XPos = (sensors[3].XPos - CollisionLeft + 1) << 16; player->speed = 0; } player->YPos = sensors[4].YPos; @@ -1259,16 +1204,14 @@ void ProcessPathGrip(Player *player) if (!sensors[0].collided && !sensors[1].collided && !sensors[2].collided) { player->gravity = 1; player->collisionMode = CMODE_FLOOR; - player->XVelocity = cosVal256[player->angle] * player->speed >> 8; - player->YVelocity = sinVal256[player->angle] * player->speed >> 8; - player->speed = player->XVelocity; - player->angle = 0; - } - else if (player->speed <= -0x20000 || player->speed >= 1) { + player->XVelocity = CosValue256[player->angle] * player->speed >> 8; + player->YVelocity = SinValue256[player->angle] * player->speed >> 8; + player->speed = player->XVelocity; + player->angle = 0; + } else if (player->speed <= -0x20000 || player->speed >= 1) { player->angle = sensors[0].angle; player->rotation = player->angle; - } - else { + } else { player->gravity = 1; player->angle = 0; player->collisionMode = CMODE_FLOOR; @@ -1283,17 +1226,16 @@ void ProcessPathGrip(Player *player) } } -void SetPathGripSensors(Player *player) -{ - PlayerScript *script = &playerScriptList[activePlayer]; - Hitbox *playerHitbox = getPlayerHitbox(script); +void SetPathGripSensors(Player *player) { + PlayerScript *script = &PlayerScriptList[PlayerNo]; + Hitbox *playerHitbox = GetPlayerCBox(script); switch (player->collisionMode) { case CMODE_FLOOR: { - collisionLeft = playerHitbox->left[0]; - collisionTop = playerHitbox->top[0]; - collisionRight = playerHitbox->right[0]; - collisionBottom = playerHitbox->bottom[0]; - sensors[0].YPos = sensors[4].YPos + (collisionBottom << 16); + CollisionLeft = playerHitbox->left[0]; + CollisionTop = playerHitbox->top[0]; + CollisionRight = playerHitbox->right[0]; + CollisionBottom = playerHitbox->bottom[0]; + sensors[0].YPos = sensors[4].YPos + (CollisionBottom << 16); sensors[1].YPos = sensors[0].YPos; sensors[2].YPos = sensors[0].YPos; sensors[3].YPos = sensors[4].YPos + 0x40000; @@ -1301,18 +1243,18 @@ void SetPathGripSensors(Player *player) sensors[1].XPos = sensors[4].XPos; sensors[2].XPos = sensors[4].XPos + (playerHitbox->right[1] << 16); if (player->speed > 0) { - sensors[3].XPos = sensors[4].XPos + ((collisionRight + 1) << 16); + sensors[3].XPos = sensors[4].XPos + ((CollisionRight + 1) << 16); return; } - sensors[3].XPos = sensors[4].XPos + ((collisionLeft - 1) << 16); + sensors[3].XPos = sensors[4].XPos + ((CollisionLeft - 1) << 16); return; } case CMODE_LWALL: { - collisionLeft = playerHitbox->left[2]; - collisionTop = playerHitbox->top[2]; - collisionRight = playerHitbox->right[2]; - collisionBottom = playerHitbox->bottom[2]; - sensors[0].XPos = sensors[4].XPos + (collisionRight << 16); + CollisionLeft = playerHitbox->left[2]; + CollisionTop = playerHitbox->top[2]; + CollisionRight = playerHitbox->right[2]; + CollisionBottom = playerHitbox->bottom[2]; + sensors[0].XPos = sensors[4].XPos + (CollisionRight << 16); sensors[1].XPos = sensors[0].XPos; sensors[2].XPos = sensors[0].XPos; sensors[3].XPos = sensors[4].XPos + 0x40000; @@ -1320,18 +1262,18 @@ void SetPathGripSensors(Player *player) sensors[1].YPos = sensors[4].YPos; sensors[2].YPos = sensors[4].YPos + (playerHitbox->bottom[3] << 16); if (player->speed > 0) { - sensors[3].YPos = sensors[4].YPos + (collisionTop << 16); + sensors[3].YPos = sensors[4].YPos + (CollisionTop << 16); return; } - sensors[3].YPos = sensors[4].YPos + ((collisionBottom - 1) << 16); + sensors[3].YPos = sensors[4].YPos + ((CollisionBottom - 1) << 16); return; } case CMODE_ROOF: { - collisionLeft = playerHitbox->left[4]; - collisionTop = playerHitbox->top[4]; - collisionRight = playerHitbox->right[4]; - collisionBottom = playerHitbox->bottom[4]; - sensors[0].YPos = sensors[4].YPos + ((collisionTop - 1) << 16); + CollisionLeft = playerHitbox->left[4]; + CollisionTop = playerHitbox->top[4]; + CollisionRight = playerHitbox->right[4]; + CollisionBottom = playerHitbox->bottom[4]; + sensors[0].YPos = sensors[4].YPos + ((CollisionTop - 1) << 16); sensors[1].YPos = sensors[0].YPos; sensors[2].YPos = sensors[0].YPos; sensors[3].YPos = sensors[4].YPos - 0x40000; @@ -1339,18 +1281,18 @@ void SetPathGripSensors(Player *player) sensors[1].XPos = sensors[4].XPos; sensors[2].XPos = sensors[4].XPos + (playerHitbox->right[5] << 16); if (player->speed < 0) { - sensors[3].XPos = sensors[4].XPos + ((collisionRight + 1) << 16); + sensors[3].XPos = sensors[4].XPos + ((CollisionRight + 1) << 16); return; } - sensors[3].XPos = sensors[4].XPos + ((collisionLeft - 1) << 16); + sensors[3].XPos = sensors[4].XPos + ((CollisionLeft - 1) << 16); return; } case CMODE_RWALL: { - collisionLeft = playerHitbox->left[6]; - collisionTop = playerHitbox->top[6]; - collisionRight = playerHitbox->right[6]; - collisionBottom = playerHitbox->bottom[6]; - sensors[0].XPos = sensors[4].XPos + ((collisionLeft - 1) << 16); + CollisionLeft = playerHitbox->left[6]; + CollisionTop = playerHitbox->top[6]; + CollisionRight = playerHitbox->right[6]; + CollisionBottom = playerHitbox->bottom[6]; + sensors[0].XPos = sensors[4].XPos + ((CollisionLeft - 1) << 16); sensors[1].XPos = sensors[0].XPos; sensors[2].XPos = sensors[0].XPos; sensors[3].XPos = sensors[4].XPos - 0x40000; @@ -1358,141 +1300,137 @@ void SetPathGripSensors(Player *player) sensors[1].YPos = sensors[4].YPos; sensors[2].YPos = sensors[4].YPos + (playerHitbox->bottom[7] << 16); if (player->speed > 0) { - sensors[3].YPos = sensors[4].YPos + (collisionBottom << 16); + sensors[3].YPos = sensors[4].YPos + (CollisionBottom << 16); return; } - sensors[3].YPos = sensors[4].YPos + ((collisionTop - 1) << 16); + sensors[3].YPos = sensors[4].YPos + ((CollisionTop - 1) << 16); return; } default: return; } } -void ProcessPlayerTileCollisions(Player *player) -{ - player->flailing[0] = 0; - player->flailing[1] = 0; - player->flailing[2] = 0; - scriptEng.checkResult = false; +void ProcessPlayerTileCollisions(Player *player) { + player->flailing[0] = 0; + player->flailing[1] = 0; + player->flailing[2] = 0; if (player->gravity == 1) ProcessTracedCollision(player); else ProcessPathGrip(player); } -void ObjectFloorCollision(int xOffset, int yOffset, int cPath) -{ - scriptEng.checkResult = false; - Entity *entity = &objectEntityList[objectLoop]; +void ObjectFloorCollision(int xOffset, int yOffset, int cPath) { + ScriptEng.checkResult = false; + Entity *entity = &ObjectEntityList[ObjectLoop]; int c = 0; int XPos = (entity->XPos >> 16) + xOffset; int YPos = (entity->YPos >> 16) + yOffset; - if (XPos > 0 && XPos < stageLayouts[0].xsize << 7 && YPos > 0 && YPos < stageLayouts[0].ysize << 7) { + if (XPos > 0 && XPos < StageLayouts[0].xsize << 7 && YPos > 0 && YPos < StageLayouts[0].ysize << 7) { int chunkX = XPos >> 7; int tileX = (XPos & 0x7F) >> 4; int chunkY = YPos >> 7; int tileY = (YPos & 0x7F) >> 4; - int chunk = (stageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6) + tileX + (tileY << 3); - int tileIndex = tiles128x128.tileIndex[chunk]; - if (tiles128x128.collisionFlags[cPath][chunk] != SOLID_LRB && tiles128x128.collisionFlags[cPath][chunk] != SOLID_NONE) { - switch (tiles128x128.direction[chunk]) { + int chunk = (StageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6) + tileX + (tileY << 3); + int tileIndex = StageTiles.tileIndex[chunk]; + if (StageTiles.collisionFlags[cPath][chunk] != SOLID_LRB && StageTiles.collisionFlags[cPath][chunk] != SOLID_NONE) { + switch (StageTiles.direction[chunk]) { case 0: { c = (XPos & 15) + (tileIndex << 4); - if ((YPos & 15) <= collisionMasks[cPath].floorMasks[c]) { + if ((YPos & 15) <= TileCollisions[cPath].floorMasks[c]) { break; } - YPos = collisionMasks[cPath].floorMasks[c] + (chunkY << 7) + (tileY << 4); - scriptEng.checkResult = true; + YPos = TileCollisions[cPath].floorMasks[c] + (chunkY << 7) + (tileY << 4); + ScriptEng.checkResult = true; break; } case 1: { c = 15 - (XPos & 15) + (tileIndex << 4); - if ((YPos & 15) <= collisionMasks[cPath].floorMasks[c]) { + if ((YPos & 15) <= TileCollisions[cPath].floorMasks[c]) { break; } - YPos = collisionMasks[cPath].floorMasks[c] + (chunkY << 7) + (tileY << 4); - scriptEng.checkResult = true; + YPos = TileCollisions[cPath].floorMasks[c] + (chunkY << 7) + (tileY << 4); + ScriptEng.checkResult = true; break; } case 2: { c = (XPos & 15) + (tileIndex << 4); - if ((YPos & 15) <= 15 - collisionMasks[cPath].roofMasks[c]) { + if ((YPos & 15) <= 15 - TileCollisions[cPath].roofMasks[c]) { break; } - YPos = 15 - collisionMasks[cPath].roofMasks[c] + (chunkY << 7) + (tileY << 4); - scriptEng.checkResult = true; + YPos = 15 - TileCollisions[cPath].roofMasks[c] + (chunkY << 7) + (tileY << 4); + ScriptEng.checkResult = true; break; } case 3: { c = 15 - (XPos & 15) + (tileIndex << 4); - if ((YPos & 15) <= 15 - collisionMasks[cPath].roofMasks[c]) { + if ((YPos & 15) <= 15 - TileCollisions[cPath].roofMasks[c]) { break; } - YPos = 15 - collisionMasks[cPath].roofMasks[c] + (chunkY << 7) + (tileY << 4); - scriptEng.checkResult = true; + YPos = 15 - TileCollisions[cPath].roofMasks[c] + (chunkY << 7) + (tileY << 4); + ScriptEng.checkResult = true; break; } } } - if (scriptEng.checkResult) { + if (ScriptEng.checkResult) { entity->YPos = (YPos - yOffset) << 16; } } } -void ObjectFloorGrip(int xOffset, int yOffset, int cPath) -{ +void ObjectFloorGrip(int xOffset, int yOffset, int cPath) { int c; - scriptEng.checkResult = false; - Entity *entity = &objectEntityList[objectLoop]; + ScriptEng.checkResult = false; + Entity *entity = &ObjectEntityList[ObjectLoop]; int XPos = (entity->XPos >> 16) + xOffset; int YPos = (entity->YPos >> 16) + yOffset; int chunkX = YPos; YPos = YPos - 16; for (int i = 3; i > 0; i--) { - if (XPos > 0 && XPos < stageLayouts[0].xsize << 7 && YPos > 0 && YPos < stageLayouts[0].ysize << 7 && !scriptEng.checkResult) { + if (XPos > 0 && XPos < StageLayouts[0].xsize << 7 && YPos > 0 && YPos < StageLayouts[0].ysize << 7 && !ScriptEng.checkResult) { int chunkX = XPos >> 7; int tileX = (XPos & 0x7F) >> 4; int chunkY = YPos >> 7; int tileY = (YPos & 0x7F) >> 4; - int chunk = (stageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6) + tileX + (tileY << 3); - int tileIndex = tiles128x128.tileIndex[chunk]; - if (tiles128x128.collisionFlags[cPath][chunk] != SOLID_LRB && tiles128x128.collisionFlags[cPath][chunk] != SOLID_NONE) { - switch (tiles128x128.direction[chunk]) { + int chunk = (StageLayouts[0].tiles[chunkX + (chunkY << 8)] << 6) + tileX + (tileY << 3); + int tileIndex = StageTiles.tileIndex[chunk]; + if (StageTiles.collisionFlags[cPath][chunk] != SOLID_LRB && StageTiles.collisionFlags[cPath][chunk] != SOLID_NONE) { + switch (StageTiles.direction[chunk]) { case 0: { c = (XPos & 15) + (tileIndex << 4); - if (collisionMasks[cPath].floorMasks[c] >= 64) { + if (TileCollisions[cPath].floorMasks[c] >= 64) { break; } - entity->YPos = collisionMasks[cPath].floorMasks[c] + (chunkY << 7) + (tileY << 4); - scriptEng.checkResult = true; + entity->YPos = TileCollisions[cPath].floorMasks[c] + (chunkY << 7) + (tileY << 4); + ScriptEng.checkResult = true; break; } case 1: { c = 15 - (XPos & 15) + (tileIndex << 4); - if (collisionMasks[cPath].floorMasks[c] >= 64) { + if (TileCollisions[cPath].floorMasks[c] >= 64) { break; } - entity->YPos = collisionMasks[cPath].floorMasks[c] + (chunkY << 7) + (tileY << 4); - scriptEng.checkResult = true; + entity->YPos = TileCollisions[cPath].floorMasks[c] + (chunkY << 7) + (tileY << 4); + ScriptEng.checkResult = true; break; } case 2: { c = (XPos & 15) + (tileIndex << 4); - if (collisionMasks[cPath].roofMasks[c] <= -64) { + if (TileCollisions[cPath].roofMasks[c] <= -64) { break; } - entity->YPos = 15 - collisionMasks[cPath].roofMasks[c] + (chunkY << 7) + (tileY << 4); - scriptEng.checkResult = true; + entity->YPos = 15 - TileCollisions[cPath].roofMasks[c] + (chunkY << 7) + (tileY << 4); + ScriptEng.checkResult = true; break; } case 3: { c = 15 - (XPos & 15) + (tileIndex << 4); - if (collisionMasks[cPath].roofMasks[c] <= -64) { + if (TileCollisions[cPath].roofMasks[c] <= -64) { break; } - entity->YPos = 15 - collisionMasks[cPath].roofMasks[c] + (chunkY << 7) + (tileY << 4); - scriptEng.checkResult = true; + entity->YPos = 15 - TileCollisions[cPath].roofMasks[c] + (chunkY << 7) + (tileY << 4); + ScriptEng.checkResult = true; break; } } @@ -1500,43 +1438,41 @@ void ObjectFloorGrip(int xOffset, int yOffset, int cPath) } YPos += 16; } - if (scriptEng.checkResult) { + if (ScriptEng.checkResult) { if (abs(entity->YPos - chunkX) < 16) { entity->YPos = (entity->YPos - yOffset) << 16; return; } entity->YPos = (chunkX - yOffset) << 16; - scriptEng.checkResult = false; + ScriptEng.checkResult = false; } } -void TouchCollision(int left, int top, int right, int bottom) -{ - Player *player = &playerList[activePlayer]; - PlayerScript *script = &playerScriptList[activePlayer]; - Hitbox *playerHitbox = getPlayerHitbox(script); - - collisionLeft = player->XPos >> 16; - collisionTop = player->YPos >> 16; - collisionRight = collisionLeft; - collisionBottom = collisionTop; - collisionLeft += playerHitbox->left[0]; - collisionTop += playerHitbox->top[0]; - collisionRight += playerHitbox->right[0]; - collisionBottom += playerHitbox->bottom[0]; - scriptEng.checkResult = collisionRight > left && collisionLeft < right && collisionBottom > top && collisionTop < bottom; +void BasicCollision(int left, int top, int right, int bottom) { + Player *player = &PlayerList[PlayerNo]; + PlayerScript *script = &PlayerScriptList[PlayerNo]; + Hitbox *playerHitbox = GetPlayerCBox(script); + + CollisionLeft = player->XPos >> 16; + CollisionTop = player->YPos >> 16; + CollisionRight = CollisionLeft; + CollisionBottom = CollisionTop; + CollisionLeft += playerHitbox->left[0]; + CollisionTop += playerHitbox->top[0]; + CollisionRight += playerHitbox->right[0]; + CollisionBottom += playerHitbox->bottom[0]; + ScriptEng.checkResult = CollisionRight > left && CollisionLeft < right && CollisionBottom > top && CollisionTop < bottom; } -void BoxCollision(int left, int top, int right, int bottom) -{ - Player *player = &playerList[activePlayer]; - PlayerScript *script = &playerScriptList[activePlayer]; - Hitbox *playerHitbox = getPlayerHitbox(script); - - collisionLeft = playerHitbox->left[0]; - collisionTop = playerHitbox->top[0]; - collisionRight = playerHitbox->right[0]; - collisionBottom = playerHitbox->bottom[0]; - scriptEng.checkResult = false; +void BoxCollision(int left, int top, int right, int bottom) { + Player *player = &PlayerList[PlayerNo]; + PlayerScript *script = &PlayerScriptList[PlayerNo]; + Hitbox *playerHitbox = GetPlayerCBox(script); + + CollisionLeft = playerHitbox->left[0]; + CollisionTop = playerHitbox->top[0]; + CollisionRight = playerHitbox->right[0]; + CollisionBottom = playerHitbox->bottom[0]; + ScriptEng.checkResult = false; int spd = 0; switch (player->collisionMode) { @@ -1555,10 +1491,10 @@ void BoxCollision(int left, int top, int right, int bottom) sensors[0].collided = false; sensors[1].collided = false; sensors[2].collided = false; - sensors[0].XPos = player->XPos + ((collisionLeft + 2) << 16); + sensors[0].XPos = player->XPos + ((CollisionLeft + 2) << 16); sensors[1].XPos = player->XPos; - sensors[2].XPos = player->XPos + ((collisionRight - 2) << 16); - sensors[0].YPos = player->YPos + (collisionBottom << 16); + sensors[2].XPos = player->XPos + ((CollisionRight - 2) << 16); + sensors[0].YPos = player->YPos + (CollisionBottom << 16); sensors[1].YPos = sensors[0].YPos; sensors[2].YPos = sensors[0].YPos; if (player->YVelocity > -1) { @@ -1574,19 +1510,18 @@ void BoxCollision(int left, int top, int right, int bottom) player->XVelocity = 0; player->speed = 0; } - player->YPos = top - (collisionBottom << 16); + player->YPos = top - (CollisionBottom << 16); player->gravity = 0; player->YVelocity = 0; player->angle = 0; player->rotation = 0; - scriptEng.checkResult = true; - } - else { + ScriptEng.checkResult = true; + } else { sensors[0].collided = false; sensors[1].collided = false; - sensors[0].XPos = player->XPos + ((collisionLeft + 2) << 16); - sensors[1].XPos = player->XPos + ((collisionRight - 2) << 16); - sensors[0].YPos = player->YPos + (collisionTop << 16); + sensors[0].XPos = player->XPos + ((CollisionLeft + 2) << 16); + sensors[1].XPos = player->XPos + ((CollisionRight - 2) << 16); + sensors[0].YPos = player->YPos + (CollisionTop << 16); sensors[1].YPos = sensors[0].YPos; for (int i = 0; i < 2; ++i) { if (sensors[i].XPos > left && sensors[i].XPos < right && sensors[i].YPos <= bottom && player->YPos - player->YVelocity > bottom) { @@ -1595,16 +1530,15 @@ void BoxCollision(int left, int top, int right, int bottom) } if (sensors[1].collided || sensors[0].collided) { if (player->gravity == 1) { - player->YPos = bottom - (collisionTop << 16); + player->YPos = bottom - (CollisionTop << 16); } if (player->YVelocity < 1) player->YVelocity = 0; - scriptEng.checkResult = 4; - } - else { + ScriptEng.checkResult = 4; + } else { sensors[0].collided = false; sensors[1].collided = false; - sensors[0].XPos = player->XPos + (collisionRight << 16); + sensors[0].XPos = player->XPos + (CollisionRight << 16); sensors[1].XPos = sensors[0].XPos; sensors[0].YPos = player->YPos - 0x20000; sensors[1].YPos = player->YPos + 0x80000; @@ -1614,19 +1548,18 @@ void BoxCollision(int left, int top, int right, int bottom) } } if (sensors[1].collided || sensors[0].collided) { - player->XPos = left - (collisionRight << 16); + player->XPos = left - (CollisionRight << 16); if (player->XVelocity > 0) { if (!player->direction) player->pushing = 2; player->XVelocity = 0; player->speed = 0; } - scriptEng.checkResult = 2; - } - else { + ScriptEng.checkResult = 2; + } else { sensors[0].collided = false; sensors[1].collided = false; - sensors[0].XPos = player->XPos + (collisionLeft << 16); + sensors[0].XPos = player->XPos + (CollisionLeft << 16); sensors[1].XPos = sensors[0].XPos; sensors[0].YPos = player->YPos - 0x20000; sensors[1].YPos = player->YPos + 0x80000; @@ -1638,23 +1571,22 @@ void BoxCollision(int left, int top, int right, int bottom) } if (sensors[1].collided || (sensors[0].collided)) { - player->XPos = right - (collisionLeft << 16); + player->XPos = right - (CollisionLeft << 16); if (player->XVelocity < 0) { if (player->direction == FLIP_X) player->pushing = 2; player->XVelocity = 0; player->speed = 0; } - scriptEng.checkResult = 3; + ScriptEng.checkResult = 3; } } } } - } - else { + } else { sensors[0].collided = false; sensors[1].collided = false; - sensors[0].XPos = player->XPos + (collisionRight << 16); + sensors[0].XPos = player->XPos + (CollisionRight << 16); sensors[1].XPos = sensors[0].XPos; sensors[0].YPos = player->YPos - 0x20000; sensors[1].YPos = player->YPos + 0x80000; @@ -1664,19 +1596,18 @@ void BoxCollision(int left, int top, int right, int bottom) } } if (sensors[1].collided || sensors[0].collided) { - player->XPos = left - (collisionRight << 16); + player->XPos = left - (CollisionRight << 16); if (player->XVelocity > 0) { if (!player->direction) player->pushing = 2; player->XVelocity = 0; player->speed = 0; } - scriptEng.checkResult = 2; - } - else { + ScriptEng.checkResult = 2; + } else { sensors[0].collided = false; sensors[1].collided = false; - sensors[0].XPos = player->XPos + (collisionLeft << 16); + sensors[0].XPos = player->XPos + (CollisionLeft << 16); sensors[1].XPos = sensors[0].XPos; sensors[0].YPos = player->YPos - 0x20000; sensors[1].YPos = player->YPos + 0x80000; @@ -1686,7 +1617,7 @@ void BoxCollision(int left, int top, int right, int bottom) } } if (sensors[1].collided || sensors[0].collided) { - player->XPos = right - (collisionLeft << 16); + player->XPos = right - (CollisionLeft << 16); if (player->XVelocity < 0) { if (player->direction == FLIP_X) { player->pushing = 2; @@ -1694,16 +1625,15 @@ void BoxCollision(int left, int top, int right, int bottom) player->XVelocity = 0; player->speed = 0; } - scriptEng.checkResult = 3; - } - else { + ScriptEng.checkResult = 3; + } else { sensors[0].collided = false; sensors[1].collided = false; sensors[2].collided = false; - sensors[0].XPos = player->XPos + ((collisionLeft + 2) << 16); + sensors[0].XPos = player->XPos + ((CollisionLeft + 2) << 16); sensors[1].XPos = player->XPos; - sensors[2].XPos = player->XPos + ((collisionRight - 2) << 16); - sensors[0].YPos = player->YPos + (collisionBottom << 16); + sensors[2].XPos = player->XPos + ((CollisionRight - 2) << 16); + sensors[0].YPos = player->YPos + (CollisionBottom << 16); sensors[1].YPos = sensors[0].YPos; sensors[2].YPos = sensors[0].YPos; if (player->YVelocity > -1) { @@ -1719,19 +1649,18 @@ void BoxCollision(int left, int top, int right, int bottom) player->XVelocity = 0; player->speed = 0; } - player->YPos = top - (collisionBottom << 16); + player->YPos = top - (CollisionBottom << 16); player->gravity = 0; player->YVelocity = 0; player->angle = 0; player->rotation = 0; - scriptEng.checkResult = true; - } - else { + ScriptEng.checkResult = true; + } else { sensors[0].collided = false; sensors[1].collided = false; - sensors[0].XPos = player->XPos + ((collisionLeft + 2) << 16); - sensors[1].XPos = player->XPos + ((collisionRight - 2) << 16); - sensors[0].YPos = player->YPos + (collisionTop << 16); + sensors[0].XPos = player->XPos + ((CollisionLeft + 2) << 16); + sensors[1].XPos = player->XPos + ((CollisionRight - 2) << 16); + sensors[0].YPos = player->YPos + (CollisionTop << 16); sensors[1].YPos = sensors[0].YPos; for (int i = 0; i < 2; ++i) { if (sensors[i].XPos > left && sensors[i].XPos < right && sensors[i].YPos <= bottom @@ -1742,37 +1671,36 @@ void BoxCollision(int left, int top, int right, int bottom) if (sensors[1].collided || sensors[0].collided) { if (player->gravity == 1) { - player->YPos = bottom - (collisionTop << 16); + player->YPos = bottom - (CollisionTop << 16); } if (player->YVelocity < 1) player->YVelocity = 0; - scriptEng.checkResult = 4; + ScriptEng.checkResult = 4; } } } } } } -void PlatformCollision(int left, int top, int right, int bottom) -{ - Player *player = &playerList[activePlayer]; - PlayerScript *script = &playerScriptList[activePlayer]; - Hitbox *playerHitbox = getPlayerHitbox(script); - - collisionLeft = playerHitbox->left[0]; - collisionTop = playerHitbox->top[0]; - collisionRight = playerHitbox->right[0]; - collisionBottom = playerHitbox->bottom[0]; +void PlatformCollision(int left, int top, int right, int bottom) { + Player *player = &PlayerList[PlayerNo]; + PlayerScript *script = &PlayerScriptList[PlayerNo]; + Hitbox *playerHitbox = GetPlayerCBox(script); + + CollisionLeft = playerHitbox->left[0]; + CollisionTop = playerHitbox->top[0]; + CollisionRight = playerHitbox->right[0]; + CollisionBottom = playerHitbox->bottom[0]; sensors[0].collided = false; sensors[1].collided = false; sensors[2].collided = false; - sensors[0].XPos = player->XPos + ((collisionLeft + 1) << 16); + sensors[0].XPos = player->XPos + ((CollisionLeft + 1) << 16); sensors[1].XPos = player->XPos; - sensors[2].XPos = player->XPos + (collisionRight << 16); - sensors[0].YPos = player->YPos + (collisionBottom << 16); + sensors[2].XPos = player->XPos + (CollisionRight << 16); + sensors[0].YPos = player->YPos + (CollisionBottom << 16); sensors[1].YPos = sensors[0].YPos; sensors[2].YPos = sensors[0].YPos; - scriptEng.checkResult = false; + ScriptEng.checkResult = false; for (int i = 0; i < 3; ++i) { if (sensors[i].XPos > left && sensors[i].XPos < right && sensors[i].YPos > top - 2 && sensors[i].YPos < bottom && player->YVelocity >= 0) { sensors[i].collided = 1; @@ -1786,10 +1714,10 @@ void PlatformCollision(int left, int top, int right, int bottom) player->XVelocity = 0; player->speed = 0; } - player->YPos = top - (collisionBottom << 16); + player->YPos = top - (CollisionBottom << 16); player->gravity = 0; player->YVelocity = 0; player->angle = 0; player->rotation = 0; - scriptEng.checkResult = true; + ScriptEng.checkResult = true; } \ No newline at end of file diff --git a/Nexus/Collision.hpp b/Nexus/Collision.hpp index b04eebe..e249d94 100644 --- a/Nexus/Collision.hpp +++ b/Nexus/Collision.hpp @@ -36,16 +36,21 @@ struct CollisionSensor bool collided; }; -extern int collisionLeft; -extern int collisionTop; -extern int collisionRight; -extern int collisionBottom; +extern int CollisionLeft; +extern int CollisionTop; +extern int CollisionRight; +extern int CollisionBottom; extern CollisionSensor sensors[6]; -inline Hitbox *getPlayerHitbox(PlayerScript *script) +inline Hitbox *GetPlayerCBox(PlayerScript *script) { - return &hitboxList[script->animations[playerList[activePlayer].animation].frames[playerList[activePlayer].frame].hitboxID]; + return &PlayerCBoxes[script->animations[PlayerList[PlayerNo].animation].frames[PlayerList[PlayerNo].frame].hitboxID]; +} + +inline Hitbox *GetPlayerCBoxInstance(Player *player, PlayerScript *script) +{ + return &PlayerCBoxes[script->animations[player->animation].frames[player->frame].hitboxID]; } void FindFloorPosition(Player *player, CollisionSensor *sensor, int startYPos); @@ -63,7 +68,7 @@ void ProcessTracedCollision(Player *player); void ProcessPlayerTileCollisions(Player *player); -void TouchCollision(int left, int top, int right, int bottom); +void BasicCollision(int left, int top, int right, int bottom); void BoxCollision(int left, int top, int right, int bottom); void PlatformCollision(int left, int top, int right, int bottom); diff --git a/Nexus/Debug.cpp b/Nexus/Debug.cpp index 93565b1..a2e2aa0 100644 --- a/Nexus/Debug.cpp +++ b/Nexus/Debug.cpp @@ -4,320 +4,317 @@ int modOffset = 0; #endif -void InitSystemMenu() -{ - xScrollOffset = 0; - yScrollOffset = 0; +void InitSystemMenu() { + XScrollOffset = 0; + YScrollOffset = 0; StopMusic(); StopAllSfx(); ReleaseStageSfx(); - fadeMode = 0; + PaletteMode = 0; #if !RETRO_USE_ORIGINAL_CODE - if (Engine.usingBinFile + if (Engine.UseBinFile || ((Engine.startList_Game != 0xFF && Engine.startList_Game) || (Engine.startStage_Game != 0xFF && Engine.startStage_Game))) { #else - if (Engine.usingBinFile) { + if (Engine.UseBinFile) { #endif ClearGraphicsData(); - for (int i = 0; i < PLAYER_COUNT; ++i) playerScriptList[i].scriptPath[0] = 0; + for (int i = 0; i < PLAYER_COUNT; ++i) PlayerScriptList[i].scriptPath[0] = 0; LoadPalette("Data/Palettes/MasterPalette.act", 0, 256); LoadPlayerFromList(0, 0); - Engine.gameMode = ENGINE_MAINGAME; - stageMode = STAGEMODE_LOAD; + Engine.GameMode = ENGINE_MAINGAME; + StageMode = STAGEMODE_LOAD; #if !RETRO_USE_ORIGINAL_CODE - activeStageList = Engine.startList_Game == 0xFF ? 0 : Engine.startList_Game; - stageListPosition = Engine.startStage_Game == 0xFF ? 0 : Engine.startStage_Game; + ActiveStageList = Engine.startList_Game == 0xFF ? 0 : Engine.startList_Game; + StageListPosition = Engine.startStage_Game == 0xFF ? 0 : Engine.startStage_Game; #else - activeStageList = 0; - stageListPosition = 0; + ActiveStageList = 0; + StageListPosition = 0; #endif - } - else { - Engine.gameMode = ENGINE_SYSMENU; + } else { + Engine.GameMode = ENGINE_SYSMENU; ClearGraphicsData(); LoadPalette("Data/Palettes/MasterPalette.act", 0, 256); - textMenuSurfaceNo = 0; + TextMenuSurfaceNo = 0; LoadGIFFile("Data/Game/SystemText.gif", 0); - stageMode = DEVMENU_MAIN; - SetupTextMenu(&gameMenu[0], 0); - AddTextMenuEntry(&gameMenu[0], "RETRO SONIC DEFAULT MENU"); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], "1 PLAYER"); - AddTextMenuEntry(&gameMenu[0], " "); + StageMode = DEVMENU_MAIN; + SetupTextMenu(&GameMenu[0], 0); + AddTextMenuEntry(&GameMenu[0], "RETRO SONIC DEFAULT MENU"); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], "1 PLAYER"); + AddTextMenuEntry(&GameMenu[0], " "); #if RETRO_USE_MOD_LOADER - AddTextMenuEntry(&gameMenu[0], "MODS"); - AddTextMenuEntry(&gameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], "MODS"); + AddTextMenuEntry(&GameMenu[0], " "); #endif - AddTextMenuEntry(&gameMenu[0], "QUIT"); - gameMenu[0].alignment = MENU_ALIGN_CENTER; - gameMenu[0].selectionCount = 2; - gameMenu[0].selection1 = 0; - gameMenu[0].selection2 = 7; + AddTextMenuEntry(&GameMenu[0], "QUIT"); + GameMenu[0].alignment = MENU_ALIGN_CENTER; + GameMenu[0].selectionCount = 2; + GameMenu[0].selection1 = 0; + GameMenu[0].selection2 = 7; } } -void ProcessSystemMenu() -{ +void ProcessSystemMenu() { ClearScreen(0xF0); #if !RETRO_USE_ORIGINAL_CODE - keyDown.start = false; - keyDown.B = false; - keyDown.up = false; - keyDown.down = false; - CheckKeyDown(&keyDown, 0xFF); - CheckKeyPress(&keyPress, 0xFF); + GKeyDown.start = false; + GKeyDown.B = false; + GKeyDown.up = false; + GKeyDown.down = false; + CheckKeyDown(&GKeyDown, 0xFF); + CheckKeyPress(&GKeyPress, 0xFF); #else - CheckKeyPress(&keyPress, 0x83); + CheckKeyPress(&GKeyPress, 0x83); #endif - - switch (stageMode) { + + switch (StageMode) { case DEVMENU_MAIN: // Main Menu { - if (keyPress.down) - gameMenu[0].selection2 += 2; + if (GKeyPress.down) + GameMenu[0].selection2 += 2; - if (keyPress.up) - gameMenu[0].selection2 -= 2; + if (GKeyPress.up) + GameMenu[0].selection2 -= 2; - if (gameMenu[0].selection2 > (RETRO_USE_MOD_LOADER ? 11 : 9)) - gameMenu[0].selection2 = 7; - if (gameMenu[0].selection2 < 7) - gameMenu[0].selection2 = (RETRO_USE_MOD_LOADER ? 11 : 9); + if (GameMenu[0].selection2 > (RETRO_USE_MOD_LOADER ? 11 : 9)) + GameMenu[0].selection2 = 7; + if (GameMenu[0].selection2 < 7) + GameMenu[0].selection2 = (RETRO_USE_MOD_LOADER ? 11 : 9); - DrawTextMenu(&gameMenu[0], SCREEN_CENTERX, 72); + DrawTextMenu(&GameMenu[0], SCREEN_CENTERX, 72); #if !RETRO_USE_ORIGINAL_CODE - if (keyPress.start || keyPress.A) { + if (GKeyPress.start || GKeyPress.A) { #else - if (keyPress.start) { + if (GKeyPress.start) { #endif - if (gameMenu[0].selection2 == 7) { - SetupTextMenu(&gameMenu[0], 0); - AddTextMenuEntry(&gameMenu[0], "CHOOSE A PLAYER"); - SetupTextMenu(&gameMenu[1], 0); - LoadConfigListText(&gameMenu[1], 0); - gameMenu[1].alignment = MENU_ALIGN_LEFT; - gameMenu[1].selectionCount = 1; - gameMenu[1].selection1 = 0; - stageMode = DEVMENU_PLAYERSEL; + if (GameMenu[0].selection2 == 7) { + SetupTextMenu(&GameMenu[0], 0); + AddTextMenuEntry(&GameMenu[0], "CHOOSE A PLAYER"); + SetupTextMenu(&GameMenu[1], 0); + LoadConfigListText(&GameMenu[1], 0); + GameMenu[1].alignment = MENU_ALIGN_LEFT; + GameMenu[1].selectionCount = 1; + GameMenu[1].selection1 = 0; + StageMode = DEVMENU_PLAYERSEL; } #if RETRO_USE_MOD_LOADER - else if (gameMenu[0].selection2 == 9) { - SetupTextMenu(&gameMenu[0], 0); - AddTextMenuEntry(&gameMenu[0], "MOD LIST"); - SetupTextMenu(&gameMenu[1], 0); + else if (GameMenu[0].selection2 == 9) { + SetupTextMenu(&GameMenu[0], 0); + AddTextMenuEntry(&GameMenu[0], "MOD LIST"); + SetupTextMenu(&GameMenu[1], 0); char buffer[0x100]; int visible = modList.size() > 18 ? 18 : modList.size(); for (int m = 0; m < visible; ++m) { StrCopy(buffer, modList[m].name.c_str()); - StrAdd(buffer, ": "); + StrAdd(buffer, " "); StrAdd(buffer, modList[m].active ? " Active" : "Inactive"); for (int c = 0; c < StrLength(buffer); ++c) buffer[c] = toupper(buffer[c]); - AddTextMenuEntry(&gameMenu[1], buffer); + AddTextMenuEntry(&GameMenu[1], buffer); } modOffset = 0; - gameMenu[1].alignment = MENU_ALIGN_RIGHT; - gameMenu[1].selectionCount = 3; - gameMenu[1].selection1 = 0; + GameMenu[1].alignment = MENU_ALIGN_RIGHT; + GameMenu[1].selectionCount = 3; + GameMenu[1].selection1 = 0; - gameMenu[0].alignment = MENU_ALIGN_CENTER; - gameMenu[0].selectionCount = 1; - stageMode = DEVMENU_MODMENU; + GameMenu[0].alignment = MENU_ALIGN_CENTER; + GameMenu[0].selectionCount = 1; + StageMode = DEVMENU_MODMENU; } #endif else { - Engine.gameMode = ENGINE_EXITGAME; + Engine.GameMode = ENGINE_EXITGAME; } } #if !RETRO_USE_ORIGINAL_CODE - else if (keyPress.B && Engine.usingBinFile) { + else if (GKeyPress.B && Engine.UseBinFile) { ClearGraphicsData(); ClearAnimationData(); LoadPalette("Data/Palettes/MasterPalette.act", 0, 256); - activeStageList = 0; - stageMode = STAGEMODE_LOAD; - Engine.gameMode = ENGINE_MAINGAME; - stageListPosition = 0; + ActiveStageList = 0; + StageMode = STAGEMODE_LOAD; + Engine.GameMode = ENGINE_MAINGAME; + StageListPosition = 0; } #endif break; } case DEVMENU_PLAYERSEL: // Selecting Player { - if (keyPress.down) - ++gameMenu[1].selection1; - if (keyPress.up) - --gameMenu[1].selection1; - if (gameMenu[1].selection1 == gameMenu[1].rowCount) - gameMenu[1].selection1 = 0; + if (GKeyPress.down) + ++GameMenu[1].selection1; + if (GKeyPress.up) + --GameMenu[1].selection1; + if (GameMenu[1].selection1 == GameMenu[1].rowCount) + GameMenu[1].selection1 = 0; - if (gameMenu[1].selection1 < 0) - gameMenu[1].selection1 = gameMenu[1].rowCount - 1; + if (GameMenu[1].selection1 < 0) + GameMenu[1].selection1 = GameMenu[1].rowCount - 1; - DrawTextMenu(&gameMenu[0], SCREEN_CENTERX - 4, 72); - DrawTextMenu(&gameMenu[1], SCREEN_CENTERX - 40, 96); + DrawTextMenu(&GameMenu[0], SCREEN_CENTERX - 4, 72); + DrawTextMenu(&GameMenu[1], SCREEN_CENTERX - 40, 96); #if !RETRO_USE_ORIGINAL_CODE - if (keyPress.start || keyPress.A) { + if (GKeyPress.start || GKeyPress.A) { #else - if (keyPress.start) { + if (GKeyPress.start) { #endif - LoadPlayerFromList(gameMenu[1].selection1, 0); - SetupTextMenu(&gameMenu[0], 0); - AddTextMenuEntry(&gameMenu[0], "SELECT A STAGE LIST"); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " PRESENTATION"); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " REGULAR"); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " SPECIAL"); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " BONUS"); - gameMenu[0].alignment = MENU_ALIGN_LEFT; - gameMenu[0].selection2 = 3; - stageMode = DEVMENU_STAGELISTSEL; + LoadPlayerFromList(GameMenu[1].selection1, 0); + SetupTextMenu(&GameMenu[0], 0); + AddTextMenuEntry(&GameMenu[0], "SELECT A STAGE LIST"); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " PRESENTATION"); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " REGULAR"); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " SPECIAL"); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " BONUS"); + GameMenu[0].alignment = MENU_ALIGN_LEFT; + GameMenu[0].selection2 = 3; + StageMode = DEVMENU_STAGELISTSEL; } #if !RETRO_USE_ORIGINAL_CODE - else if (keyPress.B) { - stageMode = DEVMENU_MAIN; - SetupTextMenu(&gameMenu[0], 0); - AddTextMenuEntry(&gameMenu[0], "RETRO SONIC DEFAULT MENU"); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], "1 PLAYER"); - AddTextMenuEntry(&gameMenu[0], " "); + else if (GKeyPress.B) { + StageMode = DEVMENU_MAIN; + SetupTextMenu(&GameMenu[0], 0); + AddTextMenuEntry(&GameMenu[0], "RETRO SONIC DEFAULT MENU"); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], "1 PLAYER"); + AddTextMenuEntry(&GameMenu[0], " "); #if RETRO_USE_MOD_LOADER - AddTextMenuEntry(&gameMenu[0], "MODS"); - AddTextMenuEntry(&gameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], "MODS"); + AddTextMenuEntry(&GameMenu[0], " "); #endif - AddTextMenuEntry(&gameMenu[0], "QUIT"); - stageMode = DEVMENU_MAIN; - gameMenu[0].alignment = MENU_ALIGN_CENTER; - gameMenu[0].selectionCount = 2; - gameMenu[0].selection1 = 0; - gameMenu[0].selection2 = 7; + AddTextMenuEntry(&GameMenu[0], "QUIT"); + StageMode = DEVMENU_MAIN; + GameMenu[0].alignment = MENU_ALIGN_CENTER; + GameMenu[0].selectionCount = 2; + GameMenu[0].selection1 = 0; + GameMenu[0].selection2 = 7; } #endif break; } case DEVMENU_STAGELISTSEL: // Selecting Category { - if (keyPress.down) - gameMenu[0].selection2 += 2; - if (keyPress.up) - gameMenu[0].selection2 -= 2; + if (GKeyPress.down) + GameMenu[0].selection2 += 2; + if (GKeyPress.up) + GameMenu[0].selection2 -= 2; - if (gameMenu[0].selection2 > 9) - gameMenu[0].selection2 = 3; + if (GameMenu[0].selection2 > 9) + GameMenu[0].selection2 = 3; - if (gameMenu[0].selection2 < 3) - gameMenu[0].selection2 = 9; + if (GameMenu[0].selection2 < 3) + GameMenu[0].selection2 = 9; - DrawTextMenu(&gameMenu[0], SCREEN_CENTERX - 80, 72); + DrawTextMenu(&GameMenu[0], SCREEN_CENTERX - 80, 72); bool nextMenu = false; - switch (gameMenu[0].selection2) { - case 3: //Presentation + switch (GameMenu[0].selection2) { + case 3: // Presentation if (stageListCount[0] > 0) nextMenu = true; - activeStageList = 0; + ActiveStageList = 0; break; - case 5: //Regular + case 5: // Regular if (stageListCount[1] > 0) nextMenu = true; - activeStageList = 1; + ActiveStageList = 1; break; - case 7: //Special + case 7: // Special if (stageListCount[3] > 0) nextMenu = true; - activeStageList = 3; + ActiveStageList = 3; break; - case 9: //Bonus + case 9: // Bonus if (stageListCount[2] > 0) nextMenu = true; - activeStageList = 2; + ActiveStageList = 2; break; default: break; } #if !RETRO_USE_ORIGINAL_CODE - if ((keyPress.start || keyPress.A) && nextMenu) { + if ((GKeyPress.start || GKeyPress.A) && nextMenu) { #else - if (keyPress.start && nextMenu) { + if (GKeyPress.start && nextMenu) { #endif - SetupTextMenu(&gameMenu[0], 0); - AddTextMenuEntry(&gameMenu[0], "SELECT A STAGE"); - SetupTextMenu(&gameMenu[1], 0); - LoadConfigListText(&gameMenu[1], ((gameMenu[0].selection2 - 3) >> 1) + 1); - gameMenu[1].alignment = MENU_ALIGN_RIGHT; - gameMenu[1].selectionCount = 3; - gameMenu[1].selection1 = 0; + SetupTextMenu(&GameMenu[0], 0); + AddTextMenuEntry(&GameMenu[0], "SELECT A STAGE"); + SetupTextMenu(&GameMenu[1], 0); + LoadConfigListText(&GameMenu[1], ((GameMenu[0].selection2 - 3) >> 1) + 1); + GameMenu[1].alignment = MENU_ALIGN_RIGHT; + GameMenu[1].selectionCount = 3; + GameMenu[1].selection1 = 0; - gameMenu[0].alignment = MENU_ALIGN_CENTER; - gameMenu[0].selectionCount = 1; - stageMode = DEVMENU_STAGESEL; + GameMenu[0].alignment = MENU_ALIGN_CENTER; + GameMenu[0].selectionCount = 1; + StageMode = DEVMENU_STAGESEL; } #if !RETRO_USE_ORIGINAL_CODE - else if (keyPress.B) { - SetupTextMenu(&gameMenu[0], 0); - AddTextMenuEntry(&gameMenu[0], "CHOOSE A PLAYER"); - SetupTextMenu(&gameMenu[1], 0); - LoadConfigListText(&gameMenu[1], 0); - gameMenu[0].alignment = MENU_ALIGN_CENTER; - gameMenu[1].alignment = MENU_ALIGN_LEFT; - gameMenu[1].selectionCount = 1; - gameMenu[1].selection1 = 0; - stageMode = DEVMENU_PLAYERSEL; + else if (GKeyPress.B) { + SetupTextMenu(&GameMenu[0], 0); + AddTextMenuEntry(&GameMenu[0], "CHOOSE A PLAYER"); + SetupTextMenu(&GameMenu[1], 0); + LoadConfigListText(&GameMenu[1], 0); + GameMenu[0].alignment = MENU_ALIGN_CENTER; + GameMenu[1].alignment = MENU_ALIGN_LEFT; + GameMenu[1].selectionCount = 1; + GameMenu[1].selection1 = 0; + StageMode = DEVMENU_PLAYERSEL; } #endif break; } case DEVMENU_STAGESEL: // Selecting Stage { - if (keyPress.down) - ++gameMenu[1].selection1; - if (keyPress.up) - --gameMenu[1].selection1; - if (gameMenu[1].selection1 == gameMenu[1].rowCount) - gameMenu[1].selection1 = 0; - if (gameMenu[1].selection1 < 0) - gameMenu[1].selection1 = gameMenu[1].rowCount - 1; + if (GKeyPress.down) + ++GameMenu[1].selection1; + if (GKeyPress.up) + --GameMenu[1].selection1; + if (GameMenu[1].selection1 == GameMenu[1].rowCount) + GameMenu[1].selection1 = 0; + if (GameMenu[1].selection1 < 0) + GameMenu[1].selection1 = GameMenu[1].rowCount - 1; - DrawTextMenu(&gameMenu[0], SCREEN_CENTERX - 4, 40); - DrawTextMenu(&gameMenu[1], SCREEN_CENTERX + 100, 64); - if (keyPress.start || keyPress.A) { - debugMode = keyDown.A; - stageMode = STAGEMODE_LOAD; - Engine.gameMode = ENGINE_MAINGAME; - stageListPosition = gameMenu[1].selection1; + DrawTextMenu(&GameMenu[0], SCREEN_CENTERX - 4, 40); + DrawTextMenu(&GameMenu[1], SCREEN_CENTERX + 100, 64); + if (GKeyPress.start || GKeyPress.A) { + debugMode = GKeyDown.A; + StageMode = STAGEMODE_LOAD; + Engine.GameMode = ENGINE_MAINGAME; + StageListPosition = GameMenu[1].selection1; } #if !RETRO_USE_ORIGINAL_CODE - else if (keyPress.B) { - SetupTextMenu(&gameMenu[0], 0); - AddTextMenuEntry(&gameMenu[0], "SELECT A STAGE LIST"); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " PRESENTATION"); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " REGULAR"); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " SPECIAL"); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " BONUS"); - gameMenu[0].alignment = MENU_ALIGN_LEFT; - gameMenu[0].selection2 = (activeStageList << 1) + 3; - gameMenu[0].selection2 = gameMenu[0].selection2 == 7 ? 9 : gameMenu[0].selection2 == 9 ? 7 : gameMenu[0].selection2; - gameMenu[0].selectionCount = 2; - stageMode = DEVMENU_STAGELISTSEL; + else if (GKeyPress.B) { + SetupTextMenu(&GameMenu[0], 0); + AddTextMenuEntry(&GameMenu[0], "SELECT A STAGE LIST"); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " PRESENTATION"); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " REGULAR"); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " SPECIAL"); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " BONUS"); + GameMenu[0].alignment = MENU_ALIGN_LEFT; + GameMenu[0].selection2 = (ActiveStageList << 1) + 3; + GameMenu[0].selection2 = GameMenu[0].selection2 == 7 ? 9 : GameMenu[0].selection2 == 9 ? 7 : GameMenu[0].selection2; + GameMenu[0].selectionCount = 2; + StageMode = DEVMENU_STAGELISTSEL; } #endif break; @@ -325,99 +322,72 @@ void ProcessSystemMenu() #if RETRO_USE_MOD_LOADER case DEVMENU_MODMENU: // Mod Menu { - if (keyPress.down) - ++gameMenu[1].selection1; - if (keyPress.up) - --gameMenu[1].selection1; - - if (keyPress.left || keyPress.right) { - int offset = modOffset; - if (keyPress.left && modOffset - 18 >= 0) { - modOffset -= 18; - } - else if (keyPress.right && modOffset + 18 < modList.size()) { - modOffset += 18; - } + int preOption = GameMenu[1].selection1; + if (GKeyPress.down) + ++GameMenu[1].selection1; + if (GKeyPress.up) + --GameMenu[1].selection1; - if (offset != modOffset) { - SetupTextMenu(&gameMenu[0], 0); - AddTextMenuEntry(&gameMenu[0], "MOD LIST"); - SetupTextMenu(&gameMenu[1], 0); - - char buffer[0x100]; - int visible = (modList.size() - modOffset) > 18 ? (modOffset + 18) : modList.size(); - for (int m = modOffset; m < visible; ++m) { - StrCopy(buffer, modList[m].name.c_str()); - StrAdd(buffer, ": "); - StrAdd(buffer, modList[m].active ? " Active" : "Inactive"); - for (int c = 0; c < StrLength(buffer); ++c) buffer[c] = toupper(buffer[c]); - AddTextMenuEntry(&gameMenu[1], buffer); - } - - gameMenu[1].alignment = MENU_ALIGN_RIGHT; - gameMenu[1].selectionCount = 3; - gameMenu[1].selection1 = 0; - - gameMenu[0].alignment = MENU_ALIGN_CENTER; - gameMenu[0].selectionCount = 1; - stageMode = DEVMENU_MODMENU; - } - } - - if (gameMenu[1].selection1 >= gameMenu[1].rowCount) - gameMenu[1].selection1 = 0; - if (gameMenu[1].selection1 < 0) - gameMenu[1].selection1 = gameMenu[1].rowCount - 1; + if (GameMenu[1].selection1 >= GameMenu[1].rowCount) + GameMenu[1].selection1 = 0; + if (GameMenu[1].selection1 < 0) + GameMenu[1].selection1 = GameMenu[1].rowCount - 1; char buffer[0x100]; - if (keyPress.A || keyPress.start /*|| keyPress.left || keyPress.right*/) { - modList[modOffset + gameMenu[1].selection1].active ^= 1; - StrCopy(buffer, modList[modOffset + gameMenu[1].selection1].name.c_str()); - StrAdd(buffer, ": "); - StrAdd(buffer, (modList[modOffset + gameMenu[1].selection1].active ? " Active" : "Inactive")); + if (GameMenu[1].selection1 < modList.size() && (GKeyPress.A || GKeyPress.start || GKeyPress.left || GKeyPress.right)) { + modList[modOffset + GameMenu[1].selection1].active ^= 1; + StrCopy(buffer, modList[modOffset + GameMenu[1].selection1].name.c_str()); + StrAdd(buffer, " "); + StrAdd(buffer, (modList[modOffset + GameMenu[1].selection1].active ? " Active" : "Inactive")); for (int c = 0; c < StrLength(buffer); ++c) buffer[c] = toupper(buffer[c]); - EditTextMenuEntry(&gameMenu[1], buffer, gameMenu[1].selection1); + EditTextMenuEntry(&GameMenu[1], buffer, GameMenu[1].selection1); } - if (keyPress.B) { - stageMode = DEVMENU_MAIN; - SetupTextMenu(&gameMenu[0], 0); - AddTextMenuEntry(&gameMenu[0], "RETRO SONIC DEFAULT MENU"); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], "1 PLAYER"); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], "MODS"); - AddTextMenuEntry(&gameMenu[0], " "); - AddTextMenuEntry(&gameMenu[0], "QUIT"); - stageMode = DEVMENU_MAIN; - gameMenu[0].alignment = MENU_ALIGN_CENTER; - gameMenu[0].selectionCount = 2; - gameMenu[0].selection1 = 0; - gameMenu[0].selection2 = 7; + if (GKeyDown.C && GameMenu[1].selection1 != preOption) { + int option = GameMenu[1].selection1; + ModInfo swap = modList[preOption]; + modList[preOption] = modList[option]; + modList[option] = swap; + + SetupTextMenu(&GameMenu[0], 0); + AddTextMenuEntry(&GameMenu[0], "MOD LIST"); + SetupTextMenu(&GameMenu[1], 0); - //Reload entire engine - Engine.LoadGameConfig("Data/Game/GameConfig.bin"); -#if RETRO_USING_SDL1 || RETRO_USING_SDL2 - if (Engine.window) { - char gameTitle[0x40]; - sprintf(gameTitle, "%s%s", Engine.gameWindowText, Engine.usingBinFile ? "" : " (Using Data Folder)"); - SDL_SetWindowTitle(Engine.window, gameTitle); + char buffer[0x100]; + for (int m = 0; m < modList.size(); ++m) { + StrCopy(buffer, modList[m].name.c_str()); + StrAdd(buffer, " "); + StrAdd(buffer, modList[m].active ? " Active" : "Inactive"); + for (int c = 0; c < StrLength(buffer); ++c) buffer[c] = toupper(buffer[c]); + AddTextMenuEntry(&GameMenu[1], buffer); } -#endif + } - ReleaseGlobalSfx(); - LoadGlobalSfx(); + if (GKeyPress.B) { + StageMode = DEVMENU_MAIN; + SetupTextMenu(&GameMenu[0], 0); + AddTextMenuEntry(&GameMenu[0], "RETRO SONIC DEFAULT MENU"); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], "1 PLAYER"); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], "MODS"); + AddTextMenuEntry(&GameMenu[0], " "); + AddTextMenuEntry(&GameMenu[0], "QUIT"); + GameMenu[0].alignment = MENU_ALIGN_CENTER; + GameMenu[0].selectionCount = 2; + GameMenu[0].selection1 = 0; + GameMenu[0].selection2 = 7; - saveMods(); + RefreshEngine(); } - DrawTextMenu(&gameMenu[0], SCREEN_CENTERX - 4, 40); - DrawTextMenu(&gameMenu[1], SCREEN_CENTERX + 100, 64); + DrawTextMenu(&GameMenu[0], SCREEN_CENTERX - 4, 40); + DrawTextMenu(&GameMenu[1], SCREEN_CENTERX + 100, 64); break; } #endif diff --git a/Nexus/Debug.hpp b/Nexus/Debug.hpp index a97a691..df5478c 100644 --- a/Nexus/Debug.hpp +++ b/Nexus/Debug.hpp @@ -1,7 +1,7 @@ #ifndef DEBUG_H #define DEBUG_H -inline void printLog(const char *msg, ...) +inline void PrintLog(const char *msg, ...) { if (engineDebugMode) { char buffer[0x100]; diff --git a/Nexus/Drawing.cpp b/Nexus/Drawing.cpp index 5188a30..f193c80 100644 --- a/Nexus/Drawing.cpp +++ b/Nexus/Drawing.cpp @@ -1,29 +1,29 @@ #include "RetroEngine.hpp" + int SCREEN_XSIZE = 320; -int SCREEN_CENTERX = SCREEN_XSIZE / 2; +int SCREEN_CENTERX = (SCREEN_XSIZE / 2); -byte blendLookupTable[0x100 * 0x100]; +byte BlendLookupTable[0x100 * 0x100]; -byte tintTable0[0x100]; -byte tintTable1[0x100]; -byte tintTable2[0x100]; -byte tintTable3[0x100]; +byte TintLookupTable1[0x100]; +byte TintLookupTable2[0x100]; +byte TintLookupTable3[0x100]; +byte TintLookupTable4[0x100]; -DrawListEntry drawListEntries[DRAWLAYER_COUNT]; +DrawListEntry ObjectDrawOrderList[DRAWLAYER_COUNT]; -int gfxDataPosition; -GFXSurface gfxSurface[SURFACE_MAX]; -byte graphicData[GFXDATA_MAX]; +int GfxDataPosition; +GFXSurface GfxSurface[SURFACE_MAX]; +byte GraphicData[GFXDATA_MAX]; -int InitRenderDevice() -{ +int InitRenderDevice() { char gameTitle[0x40]; - sprintf(gameTitle, "%s%s", Engine.gameWindowText, Engine.usingBinFile ? "" : " (Using Data Folder)"); + sprintf(gameTitle, "%s%s", Engine.GameWindowText, Engine.UseBinFile ? "" : " (Using Data Folder)"); - Engine.pixelBuffer = new byte[SCREEN_XSIZE * SCREEN_YSIZE]; - memset(Engine.pixelBuffer, 0, (SCREEN_XSIZE * SCREEN_YSIZE) * sizeof(byte)); + Engine.FrameBuffer = new byte[SCREEN_XSIZE * SCREEN_YSIZE]; + memset(Engine.FrameBuffer, 0, (SCREEN_XSIZE * SCREEN_YSIZE) * sizeof(byte)); #if RETRO_USING_SDL2 SDL_Init(SDL_INIT_EVERYTHING); @@ -35,18 +35,18 @@ int InitRenderDevice() byte flags = 0; Engine.window = SDL_CreateWindow(gameTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_XSIZE * Engine.windowScale, - SCREEN_YSIZE * Engine.windowScale, SDL_WINDOW_ALLOW_HIGHDPI | flags); + SCREEN_YSIZE * Engine.windowScale, SDL_WINDOW_ALLOW_HIGHDPI | flags); Engine.renderer = SDL_CreateRenderer(Engine.window, -1, SDL_RENDERER_ACCELERATED); if (!Engine.window) { - printLog("ERROR: failed to create window!"); - Engine.gameMode = ENGINE_EXITGAME; + PrintLog("ERROR: failed to create window!"); + Engine.GameMode = ENGINE_EXITGAME; return 0; } if (!Engine.renderer) { - printLog("ERROR: failed to create renderer!"); - Engine.gameMode = ENGINE_EXITGAME; + PrintLog("ERROR: failed to create renderer!"); + Engine.GameMode = ENGINE_EXITGAME; return 0; } @@ -54,7 +54,7 @@ int InitRenderDevice() SDL_SetRenderDrawBlendMode(Engine.renderer, SDL_BLENDMODE_BLEND); int colourMode = 0; - if (Engine.colourMode == 1) + if (Engine.ColourMode == 1) colourMode = SDL_PIXELFORMAT_RGB565; else colourMode = SDL_PIXELFORMAT_RGB888; @@ -62,7 +62,7 @@ int InitRenderDevice() Engine.screenBuffer = SDL_CreateTexture(Engine.renderer, colourMode, SDL_TEXTUREACCESS_STREAMING, SCREEN_XSIZE, SCREEN_YSIZE); if (!Engine.screenBuffer) { - printLog("ERROR: failed to create screen buffer!\nerror msg: %s", SDL_GetError()); + PrintLog("ERROR: failed to create screen buffer!\nerror msg: %s", SDL_GetError()); return 0; } @@ -83,8 +83,7 @@ int InitRenderDevice() int winID = SDL_GetWindowDisplayIndex(Engine.window); if (SDL_GetCurrentDisplayMode(winID, &disp) == 0) { Engine.screenRefreshRate = disp.refresh_rate; - } - else { + } else { printf("error: %s", SDL_GetError()); } @@ -107,7 +106,7 @@ int InitRenderDevice() Engine.windowSurface = SDL_SetVideoMode(SCREEN_XSIZE * Engine.windowScale, SCREEN_YSIZE * Engine.windowScale, 32, SDL_SWSURFACE); if (!Engine.windowSurface) { - printLog("ERROR: failed to create window!\nerror msg: %s", SDL_GetError()); + PrintLog("ERROR: failed to create window!\nerror msg: %s", SDL_GetError()); return 0; } // Set the window caption @@ -117,14 +116,14 @@ int InitRenderDevice() SDL_CreateRGBSurface(0, SCREEN_XSIZE * Engine.windowScale, SCREEN_YSIZE * Engine.windowScale, 16, 0xF800, 0x7E0, 0x1F, 0x00); if (!Engine.screenBuffer) { - printLog("ERROR: failed to create screen buffer!\nerror msg: %s", SDL_GetError()); + PrintLog("ERROR: failed to create screen buffer!\nerror msg: %s", SDL_GetError()); return 0; } /*Engine.screenBuffer2x = SDL_SetVideoMode(SCREEN_XSIZE * 2, SCREEN_YSIZE * 2, 16, SDL_SWSURFACE); if (!Engine.screenBuffer2x) { - printLog("ERROR: failed to create screen buffer HQ!\nerror msg: %s", SDL_GetError()); + PrintLog("ERROR: failed to create screen buffer HQ!\nerror msg: %s", SDL_GetError()); return 0; }*/ @@ -152,13 +151,12 @@ int InitRenderDevice() return 1; } -void FlipScreen() -{ - if (Engine.gameMode == ENGINE_EXITGAME) +void FlipScreen() { + if (Engine.GameMode == ENGINE_EXITGAME) return; - // Clear the screen. This is needed to keep the - // pillarboxes in fullscreen from displaying garbage data. + // Clear the screen. This is needed to keep the + // pillarboxes in fullscreen from displaying garbage data. #if RETRO_USING_SDL2 SDL_RenderClear(Engine.renderer); #endif @@ -166,37 +164,36 @@ void FlipScreen() int pitch = 0; void *pixels = NULL; - switch (Engine.colourMode) { + switch (Engine.ColourMode) { case 0: // 8-bit { uint *frameBuffer = new uint[SCREEN_XSIZE * SCREEN_YSIZE]; memset(frameBuffer, 0, (SCREEN_XSIZE * SCREEN_YSIZE) * sizeof(uint)); - if (fadeMode) { + if (PaletteMode) { for (int y = 0; y < waterDrawPos; ++y) { for (int x = 0; x < SCREEN_XSIZE; ++x) { - Colour clr = palette8F[Engine.pixelBuffer[(y * SCREEN_XSIZE) + x]]; + Colour clr = TilePaletteF[Engine.FrameBuffer[(y * SCREEN_XSIZE) + x]]; frameBuffer[(y * SCREEN_XSIZE) + x] = PACK_RGB888(clr.r, clr.g, clr.b); } } for (int y = waterDrawPos; y < SCREEN_YSIZE; ++y) { for (int x = 0; x < SCREEN_XSIZE; ++x) { - Colour clr = palette8WF[Engine.pixelBuffer[(y * SCREEN_XSIZE) + x]]; + Colour clr = TilePaletteWF[Engine.FrameBuffer[(y * SCREEN_XSIZE) + x]]; frameBuffer[(y * SCREEN_XSIZE) + x] = PACK_RGB888(clr.r, clr.g, clr.b); } } - } - else { + } else { for (int y = 0; y < waterDrawPos; ++y) { for (int x = 0; x < SCREEN_XSIZE; ++x) { - Colour clr = palette8[Engine.pixelBuffer[(y * SCREEN_XSIZE) + x]]; + Colour clr = TilePalette[Engine.FrameBuffer[(y * SCREEN_XSIZE) + x]]; frameBuffer[(y * SCREEN_XSIZE) + x] = PACK_RGB888(clr.r, clr.g, clr.b); } } for (int y = waterDrawPos; y < SCREEN_YSIZE; ++y) { for (int x = 0; x < SCREEN_XSIZE; ++x) { - Colour clr = palette8W[Engine.pixelBuffer[(y * SCREEN_XSIZE) + x]]; + Colour clr = TilePaletteW[Engine.FrameBuffer[(y * SCREEN_XSIZE) + x]]; frameBuffer[(y * SCREEN_XSIZE) + x] = PACK_RGB888(clr.r, clr.g, clr.b); } } @@ -215,29 +212,28 @@ void FlipScreen() { ushort *frameBuffer = new ushort[SCREEN_XSIZE * SCREEN_YSIZE]; memset(frameBuffer, 0, (SCREEN_XSIZE * SCREEN_YSIZE) * sizeof(ushort)); - if (fadeMode) { + if (PaletteMode) { for (int y = 0; y < waterDrawPos; ++y) { for (int x = 0; x < SCREEN_XSIZE; ++x) { - frameBuffer[(y * SCREEN_XSIZE) + x] = palette16F[Engine.pixelBuffer[(y * SCREEN_XSIZE) + x]]; + frameBuffer[(y * SCREEN_XSIZE) + x] = TilePalette16F[Engine.FrameBuffer[(y * SCREEN_XSIZE) + x]]; } } for (int y = waterDrawPos; y < SCREEN_YSIZE; ++y) { for (int x = 0; x < SCREEN_XSIZE; ++x) { - frameBuffer[(y * SCREEN_XSIZE) + x] = palette16WF[Engine.pixelBuffer[(y * SCREEN_XSIZE) + x]]; + frameBuffer[(y * SCREEN_XSIZE) + x] = TilePaletteW16F[Engine.FrameBuffer[(y * SCREEN_XSIZE) + x]]; } } - } - else { + } else { for (int y = 0; y < waterDrawPos; ++y) { for (int x = 0; x < SCREEN_XSIZE; ++x) { - frameBuffer[(y * SCREEN_XSIZE) + x] = palette16[Engine.pixelBuffer[(y * SCREEN_XSIZE) + x]]; + frameBuffer[(y * SCREEN_XSIZE) + x] = TilePalette16[Engine.FrameBuffer[(y * SCREEN_XSIZE) + x]]; } } for (int y = waterDrawPos; y < SCREEN_YSIZE; ++y) { for (int x = 0; x < SCREEN_XSIZE; ++x) { - frameBuffer[(y * SCREEN_XSIZE) + x] = palette16W[Engine.pixelBuffer[(y * SCREEN_XSIZE) + x]]; + frameBuffer[(y * SCREEN_XSIZE) + x] = TilePaletteW16[Engine.FrameBuffer[(y * SCREEN_XSIZE) + x]]; } } } @@ -255,10 +251,10 @@ void FlipScreen() { uint *frameBuffer = new uint[SCREEN_XSIZE * SCREEN_YSIZE]; memset(frameBuffer, 0, (SCREEN_XSIZE * SCREEN_YSIZE) * sizeof(uint)); - if (fadeMode) { + if (PaletteMode) { for (int y = 0; y < waterDrawPos; ++y) { for (int x = 0; x < SCREEN_XSIZE; ++x) { - uint clr = palette32F[Engine.pixelBuffer[(y * SCREEN_XSIZE) + x]]; + uint clr = TilePalette32F[Engine.FrameBuffer[(y * SCREEN_XSIZE) + x]]; byte r = (clr >> 16) & 0xFF; byte g = (clr >> 8) & 0xFF; byte b = (clr >> 0) & 0xFF; @@ -268,18 +264,17 @@ void FlipScreen() for (int y = waterDrawPos; y < SCREEN_YSIZE; ++y) { for (int x = 0; x < SCREEN_XSIZE; ++x) { - uint clr = palette32WF[Engine.pixelBuffer[(y * SCREEN_XSIZE) + x]]; + uint clr = TilePaletteW32F[Engine.FrameBuffer[(y * SCREEN_XSIZE) + x]]; byte r = (clr >> 16) & 0xFF; byte g = (clr >> 8) & 0xFF; byte b = (clr >> 0) & 0xFF; frameBuffer[(y * SCREEN_XSIZE) + x] = PACK_RGB888(r, g, b); } } - } - else { + } else { for (int y = 0; y < waterDrawPos; ++y) { for (int x = 0; x < SCREEN_XSIZE; ++x) { - uint clr = palette32[Engine.pixelBuffer[(y * SCREEN_XSIZE) + x]]; + uint clr = TilePalette32[Engine.FrameBuffer[(y * SCREEN_XSIZE) + x]]; byte r = (clr >> 16) & 0xFF; byte g = (clr >> 8) & 0xFF; byte b = (clr >> 0) & 0xFF; @@ -289,7 +284,7 @@ void FlipScreen() for (int y = waterDrawPos; y < SCREEN_YSIZE; ++y) { for (int x = 0; x < SCREEN_XSIZE; ++x) { - uint clr = palette32W[Engine.pixelBuffer[(y * SCREEN_XSIZE) + x]]; + uint clr = TilePaletteW32[Engine.FrameBuffer[(y * SCREEN_XSIZE) + x]]; byte r = (clr >> 16) & 0xFF; byte g = (clr >> 8) & 0xFF; byte b = (clr >> 0) & 0xFF; @@ -317,10 +312,9 @@ void FlipScreen() #endif } -void ReleaseRenderDevice() -{ - if (Engine.pixelBuffer) - delete[] Engine.pixelBuffer; +void ReleaseRenderDevice() { + if (Engine.FrameBuffer) + delete[] Engine.FrameBuffer; #if RETRO_USING_SDL2 SDL_DestroyTexture(Engine.screenBuffer); Engine.screenBuffer = NULL; @@ -338,7 +332,7 @@ void ReleaseRenderDevice() void ClearScreen(byte index) { - byte *pixelBuffer = Engine.pixelBuffer; + byte *pixelBuffer = Engine.FrameBuffer; int cnt = SCREEN_XSIZE * SCREEN_YSIZE; while (cnt--) { *pixelBuffer = index; @@ -346,8 +340,7 @@ void ClearScreen(byte index) } } -void SetScreenSize(int width, int lineSize) -{ +void SetScreenSize(int width, int lineSize) { SCREEN_XSIZE = width; SCREEN_CENTERX = (width / 2); SCREEN_SCROLL_LEFT = SCREEN_CENTERX - 8; @@ -355,40 +348,29 @@ void SetScreenSize(int width, int lineSize) OBJECT_BORDER_X2 = width + 0x80; } -void DrawObjectList(int Layer) -{ - int size = drawListEntries[Layer].listSize; +void DrawObjectList(int Layer) { + int size = ObjectDrawOrderList[Layer].listSize; for (int i = 0; i < size; ++i) { - objectLoop = drawListEntries[Layer].entityRefs[i]; - int type = objectEntityList[objectLoop].type; + ObjectLoop = ObjectDrawOrderList[Layer].entityRefs[i]; + int type = ObjectEntityList[ObjectLoop].type; if (type == OBJ_TYPE_PLAYER) { - Player *player = &playerList[objectLoop]; + Player *player = &PlayerList[ObjectLoop]; ProcessPlayerAnimationChange(player); if (player->visible) { - DrawPlayer(player, &playerScriptList[player->type].animations[player->animation].frames[player->frame]); + DrawPlayer(player, &PlayerScriptList[player->type].animations[player->animation].frames[player->frame]); } - } - else if (type) { - activePlayer = 0; - if (scriptData[objectScriptList[type].subDraw.scriptCodePtr] > 0) - ProcessScript(objectScriptList[type].subDraw.scriptCodePtr, objectScriptList[type].subDraw.jumpTablePtr, SUB_DRAW); + } else if (type) { + PlayerNo = 0; + if (ScriptData[ObjectScriptList[type].subDraw.scriptCodePtr] > 0) + ProcessScript(ObjectScriptList[type].subDraw.scriptCodePtr, ObjectScriptList[type].subDraw.jumpTablePtr, SUB_DRAW); } } } -void DrawStageGFX() -{ - waterDrawPos = waterLevel - yScrollOffset; - - if (waterDrawPos < 0) - waterDrawPos = 0; - - if (waterDrawPos > SCREEN_YSIZE) - waterDrawPos = SCREEN_YSIZE; - +void DrawStageGfx() { DrawObjectList(0); if (activeTileLayers[0] < LAYER_COUNT) { - switch (stageLayouts[activeTileLayers[0]].type) { + switch (StageLayouts[activeTileLayers[0]].type) { case LAYER_HSCROLL: DrawHLineScrollLayer(0); break; case LAYER_VSCROLL: DrawVLineScrollLayer(0); break; case LAYER_3DCLOUD: Draw3DCloudLayer(0); break; @@ -398,7 +380,7 @@ void DrawStageGFX() DrawObjectList(1); if (activeTileLayers[1] < LAYER_COUNT) { - switch (stageLayouts[activeTileLayers[1]].type) { + switch (StageLayouts[activeTileLayers[1]].type) { case LAYER_HSCROLL: DrawHLineScrollLayer(1); break; case LAYER_VSCROLL: DrawVLineScrollLayer(1); break; case LAYER_3DCLOUD: Draw3DCloudLayer(1); break; @@ -408,7 +390,7 @@ void DrawStageGFX() DrawObjectList(2); if (activeTileLayers[2] < LAYER_COUNT) { - switch (stageLayouts[activeTileLayers[2]].type) { + switch (StageLayouts[activeTileLayers[2]].type) { case LAYER_HSCROLL: DrawHLineScrollLayer(2); break; case LAYER_VSCROLL: DrawVLineScrollLayer(2); break; case LAYER_3DCLOUD: Draw3DCloudLayer(2); break; @@ -419,7 +401,7 @@ void DrawStageGFX() DrawObjectList(3); DrawObjectList(4); if (activeTileLayers[3] < LAYER_COUNT) { - switch (stageLayouts[activeTileLayers[3]].type) { + switch (StageLayouts[activeTileLayers[3]].type) { case LAYER_HSCROLL: DrawHLineScrollLayer(3); break; case LAYER_VSCROLL: DrawVLineScrollLayer(3); break; case LAYER_3DCLOUD: Draw3DCloudLayer(3); break; @@ -431,23 +413,22 @@ void DrawStageGFX() DrawObjectList(6); } -void SetBlendTable(ushort alpha, byte type, byte a3, byte a4) -{ +void GenerateBlendTable(ushort alpha, byte type, byte a3, byte a4) { switch (type) { case 0: for (int y = 0; y < 256; ++y) { for (int x = 0; x < 256; ++x) { - ushort mixR = (ushort)((0xFF - alpha) * palette8[y].r + alpha * palette8[x].r) >> 8; - ushort mixG = (ushort)((0xFF - alpha) * palette8[y].g + alpha * palette8[x].g) >> 8; - ushort mixB = (ushort)((0xFF - alpha) * palette8[y].b + alpha * palette8[x].b) >> 8; + ushort mixR = (ushort)((0xFF - alpha) * TilePalette[y].r + alpha * TilePalette[x].r) >> 8; + ushort mixG = (ushort)((0xFF - alpha) * TilePalette[y].g + alpha * TilePalette[x].g) >> 8; + ushort mixB = (ushort)((0xFF - alpha) * TilePalette[y].b + alpha * TilePalette[x].b) >> 8; int index = 0; int r = -1; int g = -1; int b = -1; for (int i = 0; i < 256; ++i) { - int mixR2 = abs(palette8[i].r - mixR); - int mixG2 = abs(palette8[i].g - mixG); - int mixB2 = abs(palette8[i].b - mixB); + int mixR2 = abs(TilePalette[i].r - mixR); + int mixG2 = abs(TilePalette[i].g - mixG); + int mixB2 = abs(TilePalette[i].b - mixB); if (mixR2 < r && mixG2 < g && mixB2 < b) { r = mixR2; g = mixG2; @@ -455,62 +436,60 @@ void SetBlendTable(ushort alpha, byte type, byte a3, byte a4) index = i; } } - blendLookupTable[(0x100 * y) + x] = index; + BlendLookupTable[(0x100 * y) + x] = index; } } break; case 1: for (int y = 0; y < 0x100; ++y) { for (int x = 0; x < 0x100; ++x) { - int v1 = (byte)((palette8[y].b + palette8[y].g + palette8[y].r) / 3); - int v2 = (byte)((palette8[x].b + palette8[x].g + palette8[x].r) / 3); - blendLookupTable[0x100 * y + x] = a4 + a3 * ((ushort)((0xFF - alpha) * v1 + alpha * v2) >> 8) / 0x100; + int v1 = (byte)((TilePalette[y].b + TilePalette[y].g + TilePalette[y].r) / 3); + int v2 = (byte)((TilePalette[x].b + TilePalette[x].g + TilePalette[x].r) / 3); + BlendLookupTable[0x100 * y + x] = a4 + a3 * ((ushort)((0xFF - alpha) * v1 + alpha * v2) >> 8) / 0x100; } } break; } } -void SetTintTable(short alpha, short a2, byte type, byte a4, byte a5, byte tableID) -{ +void GenerateTintTable(short alpha, short a2, byte type, byte a4, byte a5, byte tableID) { byte *tintTable = NULL; switch (tableID) { - case 0: tintTable = tintTable0; break; - case 1: tintTable = tintTable1; break; - case 2: tintTable = tintTable2; break; - case 3: tintTable = tintTable3; break; + case 0: tintTable = TintLookupTable1; break; + case 1: tintTable = TintLookupTable2; break; + case 2: tintTable = TintLookupTable3; break; + case 3: tintTable = TintLookupTable4; break; default: break; } switch (type) { case 0: for (int i = 0; i < 256; ++i) { - byte val = (byte)((palette8[i].b + palette8[i].g + palette8[i].r) / 3); + byte val = (byte)((TilePalette[i].b + TilePalette[i].g + TilePalette[i].r) / 3); tintTable[i] = a5 + a4 * ((ushort)((0xFF - alpha) * val + alpha * a2) >> 8) / 256; } break; case 1: for (int i = 0; i < 256; ++i) { - tintTable[i] = a5 + a4 * ((ushort)((0xFF - alpha) * palette8[i].r + alpha * a2) >> 8) / 256; + tintTable[i] = a5 + a4 * ((ushort)((0xFF - alpha) * TilePalette[i].r + alpha * a2) >> 8) / 256; } break; case 2: for (int i = 0; i < 256; ++i) { - tintTable[i] = a5 + a4 * ((ushort)((0xFF - alpha) * palette8[i].g + alpha * a2) >> 8) / 256; + tintTable[i] = a5 + a4 * ((ushort)((0xFF - alpha) * TilePalette[i].g + alpha * a2) >> 8) / 256; } break; case 3: for (int i = 0; i < 256; ++i) { - tintTable[i] = a5 + a4 * ((ushort)((0xFF - alpha) * palette8[i].b + alpha * a2) >> 8) / 256; + tintTable[i] = a5 + a4 * ((ushort)((0xFF - alpha) * TilePalette[i].b + alpha * a2) >> 8) / 256; } break; default: break; } } -void DrawHLineScrollLayer(int layerID) -{ - TileLayer *layer = &stageLayouts[activeTileLayers[layerID]]; +void DrawHLineScrollLayer(int layerID) { + TileLayer *layer = &StageLayouts[activeTileLayers[layerID]]; int screenwidth16 = (SCREEN_XSIZE >> 4) - 1; int layerwidth = layer->xsize; int layerheight = layer->ysize; @@ -522,7 +501,7 @@ void DrawHLineScrollLayer(int layerID) int yscrollOffset = 0; if (activeTileLayers[layerID]) { // BG Layer - int yScroll = yScrollOffset * layer->parallaxFactor >> 6; + int yScroll = YScrollOffset * layer->parallaxFactor >> 6; int fullheight = layerheight << 7; layer->scrollPos += layer->scrollSpeed; if (layer->scrollPos > fullheight << 16) @@ -530,36 +509,35 @@ void DrawHLineScrollLayer(int layerID) yscrollOffset = (yScroll + (layer->scrollPos >> 16)) % fullheight; layerheight = fullheight >> 7; lineScroll = layer->lineScroll; - deformationData = &bgDeformationData2[(byte)(yscrollOffset + bgDeformationOffset)]; - deformationDataW = &bgDeformationData3[(byte)(yscrollOffset + waterDrawPos + bgDeformationOffsetW)]; - } - else { // FG Layer - lastXSize = layer->xsize; - yscrollOffset = yScrollOffset; + deformationData = &BGDeformationData3[(byte)(yscrollOffset + DeformationPos3)]; + deformationDataW = &BGDeformationData4[(byte)(yscrollOffset + waterDrawPos + DeformationPos4)]; + } else { // FG Layer + LastXSize = layer->xsize; + yscrollOffset = YScrollOffset; lineScroll = layer->lineScroll; - for (int i = 0; i < PARALLAX_COUNT; ++i) hParallax.linePos[i] = xScrollOffset; - deformationData = &bgDeformationData0[(byte)(yscrollOffset + fgDeformationOffset)]; - deformationDataW = &bgDeformationData1[(byte)(yscrollOffset + waterDrawPos + fgDeformationOffsetW)]; + for (int i = 0; i < PARALLAX_COUNT; ++i) HParallax.linePos[i] = XScrollOffset; + deformationData = &BGDeformationData1[(byte)(yscrollOffset + DeformationPos1)]; + deformationDataW = &BGDeformationData2[(byte)(yscrollOffset + waterDrawPos + DeformationPos2)]; } if (layer->type == LAYER_HSCROLL) { - if (lastXSize != layerwidth) { + if (LastXSize != layerwidth) { int fullLayerwidth = layerwidth << 7; - for (int i = 0; i < hParallax.entryCount; ++i) { - hParallax.linePos[i] = xScrollOffset * hParallax.parallaxFactor[i] >> 7; - hParallax.scrollPos[i] += hParallax.scrollSpeed[i]; - if (hParallax.scrollPos[i] > fullLayerwidth << 16) - hParallax.scrollPos[i] -= fullLayerwidth << 16; - if (hParallax.scrollPos[i] < 0) - hParallax.scrollPos[i] += fullLayerwidth << 16; - hParallax.linePos[i] += hParallax.scrollPos[i] >> 16; - hParallax.linePos[i] %= fullLayerwidth; + for (int i = 0; i < HParallax.entryCount; ++i) { + HParallax.linePos[i] = XScrollOffset * HParallax.parallaxFactor[i] >> 7; + HParallax.scrollPos[i] += HParallax.scrollSpeed[i]; + if (HParallax.scrollPos[i] > fullLayerwidth << 16) + HParallax.scrollPos[i] -= fullLayerwidth << 16; + if (HParallax.scrollPos[i] < 0) + HParallax.scrollPos[i] += fullLayerwidth << 16; + HParallax.linePos[i] += HParallax.scrollPos[i] >> 16; + HParallax.linePos[i] %= fullLayerwidth; } } - lastXSize = layerwidth; + LastXSize = layerwidth; } - byte *pixelBufferPtr = Engine.pixelBuffer; + byte *pixelBufferPtr = Engine.FrameBuffer; int tileYPos = yscrollOffset % (layerheight << 7); if (tileYPos < 0) tileYPos += layerheight << 7; @@ -572,21 +550,20 @@ void DrawHLineScrollLayer(int layerID) int drawableLines[2] = { waterDrawPos, SCREEN_YSIZE - waterDrawPos }; for (int i = 0; i < 2; ++i) { while (drawableLines[i]--) { - int chunkX = hParallax.linePos[*scrollIndex]; + int chunkX = HParallax.linePos[*scrollIndex]; if (i == 0) { int deform = 0; - if (hParallax.deform[*scrollIndex]) + if (HParallax.deform[*scrollIndex]) deform = *deformationData; // Fix for SS5 mobile bug - if (StrComp(stageList[activeStageList][stageListPosition].name, "5") && activeStageList == STAGELIST_SPECIAL) + if (StrComp(stageList[ActiveStageList][StageListPosition].name, "5") && ActiveStageList == STAGELIST_SPECIAL) deform >>= 4; chunkX += deform; ++deformationData; - } - else { - if (hParallax.deform[*scrollIndex]) + } else { + if (HParallax.deform[*scrollIndex]) chunkX += *deformationDataW; ++deformationDataW; } @@ -610,12 +587,12 @@ void DrawHLineScrollLayer(int layerID) int tilePxLineCnt = 0; // Draw the first tile to the left - if (tiles128x128.visualPlane[chunk] == (byte)aboveMidPoint) { + if (StageTiles.visualPlane[chunk] == (byte)aboveMidPoint) { tilePxLineCnt = TILE_SIZE - tilePxXPos; lineRemain -= tilePxLineCnt; - switch (tiles128x128.direction[chunk]) { + switch (StageTiles.direction[chunk]) { case FLIP_NONE: - gfxDataPtr = &tilesetGFXData[tileOffsetY + tiles128x128.gfxDataPos[chunk] + tilePxXPos]; + gfxDataPtr = &TileGfx[tileOffsetY + StageTiles.gfxDataPos[chunk] + tilePxXPos]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -625,7 +602,7 @@ void DrawHLineScrollLayer(int layerID) break; case FLIP_X: - gfxDataPtr = &tilesetGFXData[tileOffsetYFlipX + tiles128x128.gfxDataPos[chunk] - tilePxXPos]; + gfxDataPtr = &TileGfx[tileOffsetYFlipX + StageTiles.gfxDataPos[chunk] - tilePxXPos]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -635,7 +612,7 @@ void DrawHLineScrollLayer(int layerID) break; case FLIP_Y: - gfxDataPtr = &tilesetGFXData[tileOffsetYFlipY + tiles128x128.gfxDataPos[chunk] + tilePxXPos]; + gfxDataPtr = &TileGfx[tileOffsetYFlipY + StageTiles.gfxDataPos[chunk] + tilePxXPos]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -645,7 +622,7 @@ void DrawHLineScrollLayer(int layerID) break; case FLIP_XY: - gfxDataPtr = &tilesetGFXData[tileOffsetYFlipXY + tiles128x128.gfxDataPos[chunk] - tilePxXPos]; + gfxDataPtr = &TileGfx[tileOffsetYFlipXY + StageTiles.gfxDataPos[chunk] - tilePxXPos]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -655,8 +632,7 @@ void DrawHLineScrollLayer(int layerID) break; default: break; } - } - else { + } else { pixelBufferPtr += tileXPxRemain; lineRemain -= tileXPxRemain; } @@ -667,8 +643,7 @@ void DrawHLineScrollLayer(int layerID) while (tilesPerLine--) { if (chunkTileX < 8) { ++chunk; - } - else { + } else { if (++chunkXPos == layerwidth) chunkXPos = 0; chunkTileX = 0; @@ -677,10 +652,10 @@ void DrawHLineScrollLayer(int layerID) lineRemain -= TILE_SIZE; // Loop Unrolling (faster but messier code) - if (tiles128x128.visualPlane[chunk] == (byte)aboveMidPoint) { - switch (tiles128x128.direction[chunk]) { + if (StageTiles.visualPlane[chunk] == (byte)aboveMidPoint) { + switch (StageTiles.direction[chunk]) { case FLIP_NONE: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetY]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetY]; if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; ++pixelBufferPtr; @@ -748,7 +723,7 @@ void DrawHLineScrollLayer(int layerID) break; case FLIP_X: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetYFlipX]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetYFlipX]; if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; ++pixelBufferPtr; @@ -816,7 +791,7 @@ void DrawHLineScrollLayer(int layerID) break; case FLIP_Y: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetYFlipY]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetYFlipY]; if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; ++pixelBufferPtr; @@ -884,7 +859,7 @@ void DrawHLineScrollLayer(int layerID) break; case FLIP_XY: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetYFlipXY]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetYFlipXY]; if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; ++pixelBufferPtr; @@ -951,8 +926,7 @@ void DrawHLineScrollLayer(int layerID) --gfxDataPtr; break; } - } - else { + } else { pixelBufferPtr += TILE_SIZE; } ++chunkTileX; @@ -962,8 +936,7 @@ void DrawHLineScrollLayer(int layerID) while (lineRemain > 0) { if (chunkTileX++ < 8) { ++chunk; - } - else { + } else { chunkTileX = 0; if (++chunkXPos == layerwidth) chunkXPos = 0; @@ -973,10 +946,10 @@ void DrawHLineScrollLayer(int layerID) tilePxLineCnt = lineRemain >= TILE_SIZE ? TILE_SIZE : lineRemain; lineRemain -= tilePxLineCnt; - if (tiles128x128.visualPlane[chunk] == (byte)aboveMidPoint) { - switch (tiles128x128.direction[chunk]) { + if (StageTiles.visualPlane[chunk] == (byte)aboveMidPoint) { + switch (StageTiles.direction[chunk]) { case FLIP_NONE: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetY]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetY]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -986,7 +959,7 @@ void DrawHLineScrollLayer(int layerID) break; case FLIP_X: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetYFlipX]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetYFlipX]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -996,7 +969,7 @@ void DrawHLineScrollLayer(int layerID) break; case FLIP_Y: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetYFlipY]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetYFlipY]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -1006,7 +979,7 @@ void DrawHLineScrollLayer(int layerID) break; case FLIP_XY: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetYFlipXY]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetYFlipXY]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -1017,8 +990,7 @@ void DrawHLineScrollLayer(int layerID) default: break; } - } - else { + } else { pixelBufferPtr += tilePxLineCnt; } } @@ -1038,10 +1010,9 @@ void DrawHLineScrollLayer(int layerID) } } } -void DrawVLineScrollLayer(int layerID) -{ +void DrawVLineScrollLayer(int layerID) { - TileLayer *layer = &stageLayouts[activeTileLayers[layerID]]; + TileLayer *layer = &StageLayouts[activeTileLayers[layerID]]; if (!layer->xsize || !layer->ysize) return; @@ -1054,7 +1025,7 @@ void DrawVLineScrollLayer(int layerID) int xscrollOffset = 0; if (activeTileLayers[layerID]) { // BG Layer - int xScroll = xScrollOffset * layer->parallaxFactor >> 6; + int xScroll = XScrollOffset * layer->parallaxFactor >> 6; int fullLayerwidth = layerwidth << 7; layer->scrollPos += layer->scrollSpeed; if (layer->scrollPos > fullLayerwidth << 16) @@ -1062,36 +1033,35 @@ void DrawVLineScrollLayer(int layerID) xscrollOffset = (xScroll + (layer->scrollPos >> 16)) % fullLayerwidth; layerwidth = fullLayerwidth >> 7; lineScroll = layer->lineScroll; - deformationData = &bgDeformationData2[(byte)(xscrollOffset + bgDeformationOffset)]; - } - else { // FG Layer - lastYSize = layer->ysize; - xscrollOffset = xScrollOffset; + deformationData = &BGDeformationData3[(byte)(xscrollOffset + DeformationPos3)]; + } else { // FG Layer + LastYSize = layer->ysize; + xscrollOffset = XScrollOffset; lineScroll = layer->lineScroll; - vParallax.linePos[0] = yScrollOffset; - vParallax.deform[0] = true; - deformationData = &bgDeformationData0[(byte)(xScrollOffset + fgDeformationOffset)]; + VParallax.linePos[0] = YScrollOffset; + VParallax.deform[0] = true; + deformationData = &BGDeformationData1[(byte)(XScrollOffset + DeformationPos1)]; } if (layer->type == LAYER_VSCROLL) { - if (lastYSize != layerheight) { + if (LastYSize != layerheight) { int fullLayerheight = layerheight << 7; - for (int i = 0; i < vParallax.entryCount; ++i) { - vParallax.linePos[i] = yScrollOffset * vParallax.parallaxFactor[i] >> 7; + for (int i = 0; i < VParallax.entryCount; ++i) { + VParallax.linePos[i] = YScrollOffset * VParallax.parallaxFactor[i] >> 7; - vParallax.scrollPos[i] += vParallax.scrollPos[i] << 16; - if (vParallax.scrollPos[i] > fullLayerheight << 16) - vParallax.scrollPos[i] -= fullLayerheight << 16; + VParallax.scrollPos[i] += VParallax.scrollPos[i] << 16; + if (VParallax.scrollPos[i] > fullLayerheight << 16) + VParallax.scrollPos[i] -= fullLayerheight << 16; - vParallax.linePos[i] += vParallax.scrollPos[i] >> 16; - vParallax.linePos[i] %= fullLayerheight; + VParallax.linePos[i] += VParallax.scrollPos[i] >> 16; + VParallax.linePos[i] %= fullLayerheight; } layerheight = fullLayerheight >> 7; } - lastYSize = layerheight; + LastYSize = layerheight; } - byte *pixelBufferPtr = Engine.pixelBuffer; + byte *pixelBufferPtr = Engine.FrameBuffer; int tileXPos = xscrollOffset % (layerheight << 7); if (tileXPos < 0) tileXPos += layerheight << 7; @@ -1103,8 +1073,8 @@ void DrawVLineScrollLayer(int layerID) // Draw Above Water (if applicable) int drawableLines = SCREEN_XSIZE; while (drawableLines--) { - int chunkY = vParallax.linePos[*scrollIndex]; - if (vParallax.deform[*scrollIndex]) + int chunkY = VParallax.linePos[*scrollIndex]; + if (VParallax.deform[*scrollIndex]) chunkY += *deformationData; ++deformationData; ++scrollIndex; @@ -1128,11 +1098,11 @@ void DrawVLineScrollLayer(int layerID) int tilePxLineCnt = tileYPxRemain; // Draw the first tile to the left - if (tiles128x128.visualPlane[chunk] == (byte)aboveMidPoint) { + if (StageTiles.visualPlane[chunk] == (byte)aboveMidPoint) { lineRemain -= tilePxLineCnt; - switch (tiles128x128.direction[chunk]) { + switch (StageTiles.direction[chunk]) { case FLIP_NONE: - gfxDataPtr = &tilesetGFXData[TILE_SIZE * tileY + tileX16 + tiles128x128.gfxDataPos[chunk]]; + gfxDataPtr = &TileGfx[TILE_SIZE * tileY + tileX16 + StageTiles.gfxDataPos[chunk]]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -1142,7 +1112,7 @@ void DrawVLineScrollLayer(int layerID) break; case FLIP_X: - gfxDataPtr = &tilesetGFXData[TILE_SIZE * tileY + tileOffsetXFlipX + tiles128x128.gfxDataPos[chunk]]; + gfxDataPtr = &TileGfx[TILE_SIZE * tileY + tileOffsetXFlipX + StageTiles.gfxDataPos[chunk]]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -1152,7 +1122,7 @@ void DrawVLineScrollLayer(int layerID) break; case FLIP_Y: - gfxDataPtr = &tilesetGFXData[tileOffsetXFlipY + tiles128x128.gfxDataPos[chunk] - TILE_SIZE * tileY]; + gfxDataPtr = &TileGfx[tileOffsetXFlipY + StageTiles.gfxDataPos[chunk] - TILE_SIZE * tileY]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -1162,7 +1132,7 @@ void DrawVLineScrollLayer(int layerID) break; case FLIP_XY: - gfxDataPtr = &tilesetGFXData[tileOffsetXFlipXY + tiles128x128.gfxDataPos[chunk] - TILE_SIZE * tileY]; + gfxDataPtr = &TileGfx[tileOffsetXFlipXY + StageTiles.gfxDataPos[chunk] - TILE_SIZE * tileY]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -1173,8 +1143,7 @@ void DrawVLineScrollLayer(int layerID) default: break; } - } - else { + } else { pixelBufferPtr += SCREEN_XSIZE * tileYPxRemain; lineRemain -= tilePxLineCnt; } @@ -1186,8 +1155,7 @@ void DrawVLineScrollLayer(int layerID) while (tilesPerLine--) { if (chunkTileY < 8) { chunk += 8; - } - else { + } else { if (++chunkYPos == layerheight) chunkYPos = 0; @@ -1197,10 +1165,10 @@ void DrawVLineScrollLayer(int layerID) lineRemain -= TILE_SIZE; // Loop Unrolling (faster but messier code) - if (tiles128x128.visualPlane[chunk] == (byte)aboveMidPoint) { - switch (tiles128x128.direction[chunk]) { + if (StageTiles.visualPlane[chunk] == (byte)aboveMidPoint) { + switch (StageTiles.direction[chunk]) { case FLIP_NONE: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileX16]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileX16]; if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; pixelBufferPtr += SCREEN_XSIZE; @@ -1282,7 +1250,7 @@ void DrawVLineScrollLayer(int layerID) break; case FLIP_X: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetXFlipX]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetXFlipX]; if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; pixelBufferPtr += SCREEN_XSIZE; @@ -1364,7 +1332,7 @@ void DrawVLineScrollLayer(int layerID) break; case FLIP_Y: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetXFlipY]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetXFlipY]; if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; pixelBufferPtr += SCREEN_XSIZE; @@ -1446,7 +1414,7 @@ void DrawVLineScrollLayer(int layerID) break; case FLIP_XY: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetXFlipXY]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetXFlipXY]; if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; pixelBufferPtr += SCREEN_XSIZE; @@ -1527,8 +1495,7 @@ void DrawVLineScrollLayer(int layerID) pixelBufferPtr += SCREEN_XSIZE; break; } - } - else { + } else { pixelBufferPtr += SCREEN_XSIZE * TILE_SIZE; } ++chunkTileY; @@ -1538,8 +1505,7 @@ void DrawVLineScrollLayer(int layerID) while (lineRemain > 0) { if (chunkTileY < 8) { chunk += 8; - } - else { + } else { if (++chunkYPos == layerheight) chunkYPos = 0; @@ -1550,10 +1516,10 @@ void DrawVLineScrollLayer(int layerID) tilePxLineCnt = lineRemain >= TILE_SIZE ? TILE_SIZE : lineRemain; lineRemain -= tilePxLineCnt; - if (tiles128x128.visualPlane[chunk] == (byte)aboveMidPoint) { - switch (tiles128x128.direction[chunk]) { + if (StageTiles.visualPlane[chunk] == (byte)aboveMidPoint) { + switch (StageTiles.direction[chunk]) { case FLIP_NONE: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileX16]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileX16]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -1563,7 +1529,7 @@ void DrawVLineScrollLayer(int layerID) break; case FLIP_X: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetXFlipX]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetXFlipX]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -1573,7 +1539,7 @@ void DrawVLineScrollLayer(int layerID) break; case FLIP_Y: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetXFlipY]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetXFlipY]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -1583,7 +1549,7 @@ void DrawVLineScrollLayer(int layerID) break; case FLIP_XY: - gfxDataPtr = &tilesetGFXData[tiles128x128.gfxDataPos[chunk] + tileOffsetXFlipXY]; + gfxDataPtr = &TileGfx[StageTiles.gfxDataPos[chunk] + tileOffsetXFlipXY]; while (tilePxLineCnt--) { if (*gfxDataPtr > 0) *pixelBufferPtr = *gfxDataPtr; @@ -1594,8 +1560,7 @@ void DrawVLineScrollLayer(int layerID) default: break; } - } - else { + } else { pixelBufferPtr += SCREEN_XSIZE * tilePxLineCnt; } chunkTileY++; @@ -1617,10 +1582,9 @@ void DrawVLineScrollLayer(int layerID) pixelBufferPtr -= (SCREEN_XSIZE * SCREEN_YSIZE) - 1; } } -void Draw3DCloudLayer(int layerID) { TileLayer *layer = &stageLayouts[activeTileLayers[layerID]]; } +void Draw3DCloudLayer(int layerID) { TileLayer *layer = &StageLayouts[activeTileLayers[layerID]]; } -void DrawTintRectangle(int XPos, int YPos, int width, int height, byte tintID) -{ +void DrawTintRect(int XPos, int YPos, int width, int height, byte tintID) { if (width + XPos > SCREEN_XSIZE) width = SCREEN_XSIZE - XPos; if (XPos < 0) { @@ -1639,15 +1603,15 @@ void DrawTintRectangle(int XPos, int YPos, int width, int height, byte tintID) byte *tintTable = NULL; switch (tintID) { - case 0: tintTable = tintTable0; break; - case 1: tintTable = tintTable1; break; - case 2: tintTable = tintTable2; break; - case 3: tintTable = tintTable3; break; + case 0: tintTable = TintLookupTable1; break; + case 1: tintTable = TintLookupTable2; break; + case 2: tintTable = TintLookupTable3; break; + case 3: tintTable = TintLookupTable4; break; default: break; } int yOffset = SCREEN_XSIZE - width; - for (byte *pixelBufferPtr = &Engine.pixelBuffer[XPos + SCREEN_XSIZE * YPos];; pixelBufferPtr += yOffset) { + for (byte *pixelBufferPtr = &Engine.FrameBuffer[XPos + SCREEN_XSIZE * YPos];; pixelBufferPtr += yOffset) { height--; if (height < 0) break; @@ -1659,8 +1623,7 @@ void DrawTintRectangle(int XPos, int YPos, int width, int height, byte tintID) } } void DrawScaledTintMask(int direction, int XPos, int YPos, int pivotX, int pivotY, int scaleX, int scaleY, int width, int height, int sprX, int sprY, - int tintID, int sheetID) -{ + int tintID, int sheetID) { int roundedYPos = 0; int roundedXPos = 0; int truescaleX = 4 * scaleX; @@ -1683,8 +1646,7 @@ void DrawScaledTintMask(int direction, int XPos, int YPos, int pivotX, int pivot width += trueXPos; trueXPos = 0; } - } - else if (trueXPos < 0) { + } else if (trueXPos < 0) { sprX += trueXPos * -finalscaleX >> 11; roundedXPos = (ushort)trueXPos * -(short)finalscaleX & 0x7FF; width += trueXPos; @@ -1706,19 +1668,19 @@ void DrawScaledTintMask(int direction, int XPos, int YPos, int pivotX, int pivot byte *tintTable = NULL; switch (tintID) { - case 0: tintTable = tintTable0; break; - case 1: tintTable = tintTable1; break; - case 2: tintTable = tintTable2; break; - case 3: tintTable = tintTable3; break; + case 0: tintTable = TintLookupTable1; break; + case 1: tintTable = TintLookupTable2; break; + case 2: tintTable = TintLookupTable3; break; + case 3: tintTable = TintLookupTable4; break; default: break; } - GFXSurface *surface = &gfxSurface[sheetID]; + GFXSurface *surface = &GfxSurface[sheetID]; int pitch = SCREEN_XSIZE - width; int gfxwidth = surface->width; // byte *lineBuffer = &gfxLineBuffer[trueYPos]; - byte *gfxData = &graphicData[sprX + surface->width * sprY + surface->dataPosition]; - byte *pixelBufferPtr = &Engine.pixelBuffer[trueXPos + SCREEN_XSIZE * trueYPos]; + byte *gfxData = &GraphicData[sprX + surface->width * sprY + surface->dataPosition]; + byte *pixelBufferPtr = &Engine.FrameBuffer[trueXPos + SCREEN_XSIZE * trueYPos]; if (direction == FLIP_X) { byte *gfxDataPtr = &gfxData[widthM1]; int gfxPitch = 0; @@ -1740,8 +1702,7 @@ void DrawScaledTintMask(int direction, int XPos, int YPos, int pivotX, int pivot roundedYPos = offsetY & 0x7FF; gfxPitch = 0; } - } - else { + } else { int gfxPitch = 0; int h = height; while (h--) { @@ -1765,8 +1726,7 @@ void DrawScaledTintMask(int direction, int XPos, int YPos, int pivotX, int pivot } } -void DrawSprite(int XPos, int YPos, int width, int height, int sprX, int sprY, int sheetID) -{ +void DrawSprite(int XPos, int YPos, int width, int height, int sprX, int sprY, int sheetID) { if (width + XPos > SCREEN_XSIZE) width = SCREEN_XSIZE - XPos; if (XPos < 0) { @@ -1784,11 +1744,11 @@ void DrawSprite(int XPos, int YPos, int width, int height, int sprX, int sprY, i if (width <= 0 || height <= 0) return; - GFXSurface *surface = &gfxSurface[sheetID]; + GFXSurface *surface = &GfxSurface[sheetID]; int pitch = SCREEN_XSIZE - width; int gfxPitch = surface->width - width; - byte *gfxDataPtr = &graphicData[sprX + surface->width * sprY + surface->dataPosition]; - byte *pixelBufferPtr = &Engine.pixelBuffer[XPos + SCREEN_XSIZE * YPos]; + byte *gfxDataPtr = &GraphicData[sprX + surface->width * sprY + surface->dataPosition]; + byte *pixelBufferPtr = &Engine.FrameBuffer[XPos + SCREEN_XSIZE * YPos]; while (height--) { int w = width; while (w--) { @@ -1802,8 +1762,7 @@ void DrawSprite(int XPos, int YPos, int width, int height, int sprX, int sprY, i } } -void DrawSpriteNoKey(int XPos, int YPos, int width, int height, int sprX, int sprY, int sheetID) -{ +void DrawSpriteNoKey(int XPos, int YPos, int width, int height, int sprX, int sprY, int sheetID) { if (width + XPos > SCREEN_XSIZE) width = SCREEN_XSIZE - XPos; if (XPos < 0) { @@ -1821,11 +1780,11 @@ void DrawSpriteNoKey(int XPos, int YPos, int width, int height, int sprX, int sp if (width <= 0 || height <= 0) return; - GFXSurface *surface = &gfxSurface[sheetID]; + GFXSurface *surface = &GfxSurface[sheetID]; int pitch = SCREEN_XSIZE - width; int gfxPitch = surface->width - width; - byte *gfxDataPtr = &graphicData[sprX + surface->width * sprY + surface->dataPosition]; - byte *pixelBufferPtr = &Engine.pixelBuffer[XPos + SCREEN_XSIZE * YPos]; + byte *gfxDataPtr = &GraphicData[sprX + surface->width * sprY + surface->dataPosition]; + byte *pixelBufferPtr = &Engine.FrameBuffer[XPos + SCREEN_XSIZE * YPos]; while (height--) { int w = width; while (w--) { @@ -1838,8 +1797,7 @@ void DrawSpriteNoKey(int XPos, int YPos, int width, int height, int sprX, int sp } } -void DrawSpriteClipped(int XPos, int YPos, int width, int height, int sprX, int sprY, int sheetID, int clipY) -{ +void DrawSpriteClipped(int XPos, int YPos, int width, int height, int sprX, int sprY, int sheetID, int clipY) { if (width + XPos > SCREEN_XSIZE) width = SCREEN_XSIZE - XPos; if (XPos < 0) { @@ -1857,11 +1815,11 @@ void DrawSpriteClipped(int XPos, int YPos, int width, int height, int sprX, int if (width <= 0 || height <= 0) return; - GFXSurface *surface = &gfxSurface[sheetID]; + GFXSurface *surface = &GfxSurface[sheetID]; int pitch = SCREEN_XSIZE - width; int gfxPitch = surface->width - width; - byte *gfxDataPtr = &graphicData[sprX + surface->width * sprY + surface->dataPosition]; - byte *pixelBufferPtr = &Engine.pixelBuffer[XPos + SCREEN_XSIZE * YPos]; + byte *gfxDataPtr = &GraphicData[sprX + surface->width * sprY + surface->dataPosition]; + byte *pixelBufferPtr = &Engine.FrameBuffer[XPos + SCREEN_XSIZE * YPos]; while (height--) { int w = width; while (w--) { @@ -1875,9 +1833,8 @@ void DrawSpriteClipped(int XPos, int YPos, int width, int height, int sprX, int } } -void DrawSpriteScaled(int direction, int XPos, int YPos, int pivotX, int pivotY, int scaleX, int scaleY, int width, int height, int sprX, int sprY, - int sheetID) -{ +void DrawScaledSprite(int direction, int XPos, int YPos, int pivotX, int pivotY, int scaleX, int scaleY, int width, int height, int sprX, int sprY, + int sheetID) { int roundedYPos = 0; int roundedXPos = 0; int truescaleX = 4 * scaleX; @@ -1900,8 +1857,7 @@ void DrawSpriteScaled(int direction, int XPos, int YPos, int pivotX, int pivotY, width += trueXPos; trueXPos = 0; } - } - else if (trueXPos < 0) { + } else if (trueXPos < 0) { sprX += trueXPos * -finalscaleX >> 11; roundedXPos = (ushort)trueXPos * -(short)finalscaleX & 0x7FF; width += trueXPos; @@ -1921,11 +1877,11 @@ void DrawSpriteScaled(int direction, int XPos, int YPos, int pivotX, int pivotY, if (width <= 0 || height <= 0) return; - GFXSurface *surface = &gfxSurface[sheetID]; + GFXSurface *surface = &GfxSurface[sheetID]; int pitch = SCREEN_XSIZE - width; int gfxwidth = surface->width; - byte *gfxData = &graphicData[sprX + surface->width * sprY + surface->dataPosition]; - byte *pixelBufferPtr = &Engine.pixelBuffer[trueXPos + SCREEN_XSIZE * trueYPos]; + byte *gfxData = &GraphicData[sprX + surface->width * sprY + surface->dataPosition]; + byte *pixelBufferPtr = &Engine.FrameBuffer[trueXPos + SCREEN_XSIZE * trueYPos]; if (direction == FLIP_X) { byte *gfxDataPtr = &gfxData[widthM1]; int gfxPitch = 0; @@ -1947,8 +1903,7 @@ void DrawSpriteScaled(int direction, int XPos, int YPos, int pivotX, int pivotY, roundedYPos = offsetY & 0x7FF; gfxPitch = 0; } - } - else { + } else { int gfxPitch = 0; int h = height; while (h--) { @@ -1972,9 +1927,8 @@ void DrawSpriteScaled(int direction, int XPos, int YPos, int pivotX, int pivotY, } } -void DrawSpriteRotated(int direction, int XPos, int YPos, int pivotX, int pivotY, int sprX, int sprY, int width, int height, int rotation, - int sheetID) -{ +void DrawRotatedSprite(int direction, int XPos, int YPos, int pivotX, int pivotY, int sprX, int sprY, int width, int height, int rotation, + int sheetID) { int sprXPos = (pivotX + sprX) << 9; int sprYPos = (pivotY + sprY) << 9; int fullwidth = width + sprX; @@ -1984,8 +1938,8 @@ void DrawSpriteRotated(int direction, int XPos, int YPos, int pivotX, int pivotY angle += 0x200; if (angle) angle = 0x200 - angle; - int sine = sinVal512[angle]; - int cosine = cosVal512[angle]; + int sine = SinValue512[angle]; + int cosine = CosValue512[angle]; int XPositions[4]; int YPositions[4]; @@ -2000,8 +1954,7 @@ void DrawSpriteRotated(int direction, int XPos, int YPos, int pivotX, int pivotY int b = height - pivotY + 2; XPositions[3] = XPos + ((sine * b + cosine * a) >> 9); YPositions[3] = YPos + ((cosine * b - sine * a) >> 9); - } - else { + } else { XPositions[0] = XPos + ((sine * (-pivotY - 2) + cosine * (-pivotX - 2)) >> 9); YPositions[0] = YPos + ((cosine * (-pivotY - 2) - sine * (-pivotX - 2)) >> 9); XPositions[1] = XPos + ((sine * (-pivotY - 2) + cosine * (width - pivotX + 2)) >> 9); @@ -2051,16 +2004,16 @@ void DrawSpriteRotated(int direction, int XPos, int YPos, int pivotX, int pivotY if (maxX <= 0 || maxY <= 0) return; - GFXSurface *surface = &gfxSurface[sheetID]; + GFXSurface *surface = &GfxSurface[sheetID]; int pitch = SCREEN_XSIZE - maxX; - byte *pixelBufferPtr = &Engine.pixelBuffer[left + SCREEN_XSIZE * top]; + byte *pixelBufferPtr = &Engine.FrameBuffer[left + SCREEN_XSIZE * top]; int startX = left - XPos; int startY = top - YPos; int shiftPivot = (sprX << 9) - 1; fullwidth <<= 9; int shiftheight = (sprY << 9) - 1; fullheight <<= 9; - byte *gfxData = &graphicData[surface->dataPosition]; + byte *gfxData = &GraphicData[surface->dataPosition]; if (cosine < 0 || sine < 0) sprYPos += sine + cosine; @@ -2085,8 +2038,7 @@ void DrawSpriteRotated(int direction, int XPos, int YPos, int pivotX, int pivotY drawY += cosine; pixelBufferPtr += pitch; } - } - else { + } else { int drawX = sprXPos + cosine * startX - sine * startY; int drawY = cosine * startY + sprYPos + sine * startX; while (maxY--) { @@ -2110,8 +2062,7 @@ void DrawSpriteRotated(int direction, int XPos, int YPos, int pivotX, int pivotY } } -void DrawBlendedSprite(int XPos, int YPos, int width, int height, int sprX, int sprY, int sheetID) -{ +void DrawBlendedSprite(int XPos, int YPos, int width, int height, int sprX, int sprY, int sheetID) { if (width + XPos > SCREEN_XSIZE) width = SCREEN_XSIZE - XPos; if (XPos < 0) { @@ -2129,16 +2080,16 @@ void DrawBlendedSprite(int XPos, int YPos, int width, int height, int sprX, int if (width <= 0 || height <= 0) return; - GFXSurface *surface = &gfxSurface[sheetID]; + GFXSurface *surface = &GfxSurface[sheetID]; int pitch = SCREEN_XSIZE - width; int gfxPitch = surface->width - width; - byte *gfxData = &graphicData[sprX + surface->width * sprY + surface->dataPosition]; - byte *pixelBufferPtr = &Engine.pixelBuffer[XPos + SCREEN_XSIZE * YPos]; + byte *gfxData = &GraphicData[sprX + surface->width * sprY + surface->dataPosition]; + byte *pixelBufferPtr = &Engine.FrameBuffer[XPos + SCREEN_XSIZE * YPos]; while (height--) { int w = width; while (w--) { if (*gfxData > 0) - *pixelBufferPtr = blendLookupTable[(0x100 * *pixelBufferPtr) + *gfxData]; + *pixelBufferPtr = BlendLookupTable[(0x100 * *pixelBufferPtr) + *gfxData]; ++gfxData; ++pixelBufferPtr; } @@ -2147,32 +2098,38 @@ void DrawBlendedSprite(int XPos, int YPos, int width, int height, int sprX, int } } -void DrawTextMenuEntry(void *menu, int rowID, int XPos, int YPos, int textHighlight) -{ +void DrawTextMenuEntry(void *menu, int rowID, int XPos, int YPos, int textHighlight) { TextMenu *tMenu = (TextMenu *)menu; int id = tMenu->entryStart[rowID]; for (int i = 0; i < tMenu->entrySize[rowID]; ++i) { if (tMenu->textData[id] > 0) - DrawSprite(XPos + 8 * i, YPos, 8, 8, textHighlight, 8 * tMenu->textData[id] - 8, textMenuSurfaceNo); - id++; + DrawSprite(XPos + 8 * i, YPos, 8, 8, textHighlight, 8 * tMenu->textData[id] - 8, TextMenuSurfaceNo); + ++id; } } -void DrawStageTextEntry(void *menu, int rowID, int XPos, int YPos, int textHighlight) -{ +void DrawBlendedTextMenuEntry(void *menu, int rowID, int XPos, int YPos, int textHighlight) { + TextMenu *tMenu = (TextMenu *)menu; + int id = tMenu->entryStart[rowID]; + for (int i = 0; i < tMenu->entrySize[rowID]; ++i) { + if (tMenu->textData[id] > 0) + DrawBlendedSprite(XPos + 8 * i, YPos, 8, 8, textHighlight, 8 * tMenu->textData[id] - 8, TextMenuSurfaceNo); + ++id; + } +} +void DrawStageTextEntry(void *menu, int rowID, int XPos, int YPos, int textHighlight) { TextMenu *tMenu = (TextMenu *)menu; int id = tMenu->entryStart[rowID]; for (int i = 0; i < tMenu->entrySize[rowID]; ++i) { if (tMenu->textData[id] > 0) { if (i == tMenu->entrySize[rowID] - 1) - DrawSprite(XPos + 8 * i, YPos, 8, 8, 0, 8 * tMenu->textData[id] - 8, textMenuSurfaceNo); + DrawSprite(XPos + 8 * i, YPos, 8, 8, 0, 8 * tMenu->textData[id] - 8, TextMenuSurfaceNo); else - DrawSprite(XPos + 8 * i, YPos, 8, 8, textHighlight, 8 * tMenu->textData[id] - 8, textMenuSurfaceNo); + DrawSprite(XPos + 8 * i, YPos, 8, 8, textHighlight, 8 * tMenu->textData[id] - 8, TextMenuSurfaceNo); } id++; } } -void DrawTextMenu(void *menu, int XPos, int YPos) -{ +void DrawTextMenu(void *menu, int XPos, int YPos) { TextMenu *tMenu = (TextMenu *)menu; if (tMenu->selectionCount == 3) { tMenu->selection2 = -1; diff --git a/Nexus/Drawing.hpp b/Nexus/Drawing.hpp index a679c6f..50e75fb 100644 --- a/Nexus/Drawing.hpp +++ b/Nexus/Drawing.hpp @@ -26,38 +26,41 @@ struct GFXSurface { extern int SCREEN_XSIZE; extern int SCREEN_CENTERX; -extern byte blendLookupTable[0x100 * 0x100]; +extern byte BlendLookupTable[0x100 * 0x100]; -extern byte tintTable0[0x100]; -extern byte tintTable1[0x100]; -extern byte tintTable2[0x100]; -extern byte tintTable3[0x100]; +extern byte TintLookupTable1[0x100]; +extern byte TintLookupTable2[0x100]; +extern byte TintLookupTable3[0x100]; +extern byte TintLookupTable4[0x100]; -extern DrawListEntry drawListEntries[DRAWLAYER_COUNT]; +extern DrawListEntry ObjectDrawOrderList[DRAWLAYER_COUNT]; -extern int gfxDataPosition; -extern GFXSurface gfxSurface[SURFACE_MAX]; -extern byte graphicData[GFXDATA_MAX]; +extern int GfxDataPosition; +extern GFXSurface GfxSurface[SURFACE_MAX]; +extern byte GraphicData[GFXDATA_MAX]; int InitRenderDevice(); void FlipScreen(); void ReleaseRenderDevice(); -inline void ClearGraphicsData() -{ - for (int i = 0; i < SURFACE_MAX; ++i) StrCopy(gfxSurface[i].fileName, ""); - gfxDataPosition = 0; -} void ClearScreen(byte index); +inline void ClearGraphicsData() { + for (int i = 0; i < SURFACE_MAX; ++i) StrCopy(GfxSurface[i].fileName, ""); + GfxDataPosition = 0; +#if !RETRO_USE_ORIGINAL_CODE + MEM_ZERO(GfxSurface); +#endif +} + void SetScreenSize(int width, int lineSize); -void SetBlendTable(ushort alpha, byte type, byte a3, byte a4); -void SetTintTable(short alpha, short a2, byte type, byte a4, byte a5, byte tableID); +void GenerateBlendTable(ushort alpha, byte type, byte a3, byte a4); +void GenerateTintTable(short alpha, short a2, byte type, byte a4, byte a5, byte tableID); // Layer Drawing void DrawObjectList(int layer); -void DrawStageGFX(); +void DrawStageGfx(); // TileLayer Drawing void DrawHLineScrollLayer(int layerID); @@ -65,20 +68,21 @@ void DrawVLineScrollLayer(int layerID); void Draw3DCloudLayer(int layerID); // Shape Drawing -void DrawTintRectangle(int XPos, int YPos, int width, int height, byte tintID); +void DrawTintRect(int XPos, int YPos, int width, int height, byte tintID); void DrawScaledTintMask(int direction, int XPos, int YPos, int pivotX, int pivotY, int scaleX, int scaleY, int width, int height, int sprX, int sprY, int tintID, int sheetID); // Sprite Drawing void DrawSprite(int XPos, int YPos, int width, int height, int sprX, int sprY, int sheetID); -void DrawSpriteScaled(int direction, int XPos, int YPos, int pivotX, int pivotY, int scaleX, int scaleY, int width, int height, int sprX, int sprY, +void DrawScaledSprite(int direction, int XPos, int YPos, int pivotX, int pivotY, int scaleX, int scaleY, int width, int height, int sprX, int sprY, int sheetID); -void DrawSpriteRotated(int direction, int XPos, int YPos, int pivotX, int pivotY, int sprX, int sprY, int width, int height, int rotation, +void DrawRotatedSprite(int direction, int XPos, int YPos, int pivotX, int pivotY, int sprX, int sprY, int width, int height, int rotation, int sheetID); void DrawBlendedSprite(int XPos, int YPos, int width, int height, int sprX, int sprY, int sheetID); -//Text Menus +// Text Menus void DrawTextMenuEntry(void *menu, int rowID, int XPos, int YPos, int textHighlight); +void DrawBlendedTextMenuEntry(void *menu, int rowID, int XPos, int YPos, int textHighlight); void DrawStageTextEntry(void *menu, int rowID, int XPos, int YPos, int textHighlight); void DrawTextMenu(void *menu, int XPos, int YPos); diff --git a/Nexus/Ini.cpp b/Nexus/Ini.cpp index cb41dbf..8cd3b99 100644 --- a/Nexus/Ini.cpp +++ b/Nexus/Ini.cpp @@ -33,7 +33,7 @@ IniParser::IniParser(const char *filename, bool addPath) FileIO *f; if ((f = fOpen(pathBuffer, "r")) == NULL) { - printLog("ERROR: Couldn't open file '%s'!", filename); + PrintLog("ERROR: Couldn't open file '%s'!", filename); return; } @@ -274,7 +274,7 @@ void IniParser::Write(const char *filename, bool addPath) FileIO *f; if ((f = fOpen(pathBuffer, "w")) == NULL) { - printLog("ERROR: Couldn't open file '%s' for writing!", filename); + PrintLog("ERROR: Couldn't open file '%s' for writing!", filename); return; } diff --git a/Nexus/Input.cpp b/Nexus/Input.cpp index 746d01e..ff77100 100644 --- a/Nexus/Input.cpp +++ b/Nexus/Input.cpp @@ -3,8 +3,8 @@ #include #include -InputData keyPress = InputData(); -InputData keyDown = InputData(); +InputData GKeyPress = InputData(); +InputData GKeyDown = InputData(); bool anyPress = false; @@ -38,8 +38,7 @@ SDL_Joystick *controller = nullptr; #define normalize(val, minVal, maxVal) ((float)(val) - (float)(minVal)) / ((float)(maxVal) - (float)(minVal)) #if RETRO_USING_SDL2 -bool getControllerButton(byte buttonID) -{ +bool getControllerButton(byte buttonID) { bool pressed = false; for (int i = 0; i < controllers.size(); ++i) { @@ -48,8 +47,7 @@ bool getControllerButton(byte buttonID) if (SDL_GameControllerGetButton(controller, (SDL_GameControllerButton)buttonID)) { pressed |= true; continue; - } - else { + } else { switch (buttonID) { default: break; case SDL_CONTROLLER_BUTTON_DPAD_UP: { @@ -194,8 +192,7 @@ bool getControllerButton(byte buttonID) } #endif -void controllerInit(byte controllerID) -{ +void controllerInit(byte controllerID) { SDL_GameController *controller = SDL_GameControllerOpen(controllerID); if (controller) { controllers.push_back(controller); @@ -203,8 +200,7 @@ void controllerInit(byte controllerID) } } -void controllerClose(byte controllerID) -{ +void controllerClose(byte controllerID) { SDL_GameController *controller = SDL_GameControllerFromInstanceID(controllerID); if (controller) { SDL_GameControllerClose(controller); @@ -216,8 +212,7 @@ void controllerClose(byte controllerID) } } -void ProcessInput() -{ +void ReadInputDevice() { #if RETRO_USING_SDL2 int length = 0; const byte *keyState = SDL_GetKeyboardState(&length); @@ -228,19 +223,16 @@ void ProcessInput() inputDevice[i].setHeld(); if (!inputDevice[INPUT_ANY].hold) inputDevice[INPUT_ANY].setHeld(); - } - else if (inputDevice[i].hold) + } else if (inputDevice[i].hold) inputDevice[i].setReleased(); } - } - else if (inputType == 1) { + } else if (inputType == 1) { for (int i = 0; i < INPUT_ANY; i++) { if (getControllerButton(inputDevice[i].contMappings)) { inputDevice[i].setHeld(); if (!inputDevice[INPUT_ANY].hold) inputDevice[INPUT_ANY].setHeld(); - } - else if (inputDevice[i].hold) + } else if (inputDevice[i].hold) inputDevice[i].setReleased(); } } @@ -277,8 +269,7 @@ void ProcessInput() if (mouseHideTimer == 120) { SDL_ShowCursor(false); } - } - else { + } else { if (mouseHideTimer >= 120) SDL_ShowCursor(true); mouseHideTimer = 0; @@ -294,12 +285,10 @@ void ProcessInput() // There's a problem opening the joystick if (controller == NULL) { // Uh oh - } - else { + } else { inputType = 1; } - } - else { + } else { if (controller) { // Close the joystick SDL_JoystickClose(controller); @@ -314,19 +303,16 @@ void ProcessInput() inputDevice[i].setHeld(); inputDevice[INPUT_ANY].setHeld(); continue; - } - else if (inputDevice[i].hold) + } else if (inputDevice[i].hold) inputDevice[i].setReleased(); } - } - else if (inputType == 1 && controller) { + } else if (inputType == 1 && controller) { for (int i = 0; i < INPUT_MAX; i++) { if (SDL_JoystickGetButton(controller, inputDevice[i].contMappings)) { inputDevice[i].setHeld(); inputDevice[INPUT_ANY].setHeld(); continue; - } - else if (inputDevice[i].hold) + } else if (inputDevice[i].hold) inputDevice[i].setReleased(); } } @@ -358,8 +344,7 @@ void ProcessInput() } #endif -void CheckKeyPress(InputData *input, byte flags) -{ +void CheckKeyPress(InputData *input, byte flags) { if (flags & 0x1) input->up = inputDevice[INPUT_UP].press; if (flags & 0x2) @@ -380,8 +365,7 @@ void CheckKeyPress(InputData *input, byte flags) anyPress = inputDevice[INPUT_ANY].press; } -void CheckKeyDown(InputData *input, byte flags) -{ +void CheckKeyDown(InputData *input, byte flags) { if (flags & 0x1) input->up = inputDevice[INPUT_UP].hold; if (flags & 0x2) diff --git a/Nexus/Input.hpp b/Nexus/Input.hpp index e246254..184880e 100644 --- a/Nexus/Input.hpp +++ b/Nexus/Input.hpp @@ -43,8 +43,8 @@ struct InputButton { inline bool down() { return (press || hold); } }; -extern InputData keyPress; -extern InputData keyDown; +extern InputData GKeyPress; +extern InputData GKeyDown; extern bool anyPress; @@ -87,7 +87,7 @@ extern byte keyState[SDLK_LAST]; extern SDL_Joystick *controller; #endif -void ProcessInput(); +void ReadInputDevice(); #endif void CheckKeyPress(InputData *input, byte Flags); diff --git a/Nexus/Math.cpp b/Nexus/Math.cpp index ca59277..5b629d4 100644 --- a/Nexus/Math.cpp +++ b/Nexus/Math.cpp @@ -2,40 +2,39 @@ #include #include -#ifndef M_PI -#define M_PI 3.14159265358979323846264338327950288 +#ifndef RSDK_PI +#define RSDK_PI 3.1415927f #endif -int sinVal512[512]; -int cosVal512[512]; +int SinValue512[512]; +int CosValue512[512]; -int sinVal256[256]; -int cosVal256[256]; +int SinValue256[256]; +int CosValue256[256]; -void CalculateTrigAngles() -{ +void CalculateTrigAngles() { #if !RETRO_USE_ORIGINAL_CODE srand(time(NULL)); #endif for (int i = 0; i < 0x200; ++i) { - float Val = sinf(((float)i / 256) * M_PI); - sinVal512[i] = (signed int)(Val * 512.0); - Val = cosf(((float)i / 256) * M_PI); - cosVal512[i] = (signed int)(Val * 512.0); + float Val = sinf(((float)i / 256) * RSDK_PI); + SinValue512[i] = (signed int)(Val * 512.0); + Val = cosf(((float)i / 256) * RSDK_PI); + CosValue512[i] = (signed int)(Val * 512.0); } - cosVal512[0] = 0x200; - cosVal512[128] = 0; - cosVal512[256] = -0x200; - cosVal512[384] = 0; - sinVal512[0] = 0; - sinVal512[128] = 0x200; - sinVal512[256] = 0; - sinVal512[384] = -0x200; + CosValue512[0] = 0x200; + CosValue512[128] = 0; + CosValue512[256] = -0x200; + CosValue512[384] = 0; + SinValue512[0] = 0; + SinValue512[128] = 0x200; + SinValue512[256] = 0; + SinValue512[384] = -0x200; for (int i = 0; i < 0x100; ++i) { - sinVal256[i] = (sinVal512[i * 2] >> 1); - cosVal256[i] = (cosVal512[i * 2] >> 1); + SinValue256[i] = (SinValue512[i * 2] >> 1); + CosValue256[i] = (CosValue512[i * 2] >> 1); } } \ No newline at end of file diff --git a/Nexus/Math.hpp b/Nexus/Math.hpp index 9f2bc38..aaff861 100644 --- a/Nexus/Math.hpp +++ b/Nexus/Math.hpp @@ -1,49 +1,47 @@ #ifndef MATH_H #define MATH_H -//#define M_PI (3.1415927) - #define MEM_ZERO(x) memset(&(x), 0, sizeof((x))) #define MEM_ZEROP(x) memset((x), 0, sizeof(*(x))) -extern int sinVal512[0x200]; -extern int cosVal512[0x200]; +extern int SinValue512[0x200]; +extern int CosValue512[0x200]; -extern int sinVal256[0x100]; -extern int cosVal256[0x100]; +extern int SinValue256[0x100]; +extern int CosValue256[0x100]; // Setup Angles void CalculateTrigAngles(); -inline int sin512(int angle) { +inline int Sin512(int angle) { if (angle < 0) angle = 0x200 - angle; angle &= 0x1FF; - return sinVal512[angle]; + return SinValue512[angle]; } -inline int cos512(int angle) +inline int Cos512(int angle) { if (angle < 0) angle = 0x200 - angle; angle &= 0x1FF; - return cosVal512[angle]; + return CosValue512[angle]; } -inline int sin256(int angle) +inline int Sin256(int angle) { if (angle < 0) angle = 0x100 - angle; angle &= 0xFF; - return sinVal256[angle]; + return SinValue256[angle]; } -inline int cos256(int angle) +inline int Cos256(int angle) { if (angle < 0) angle = 0x100 - angle; angle &= 0xFF; - return cosVal256[angle]; + return CosValue256[angle]; } #endif // !MATH_H diff --git a/Nexus/ModAPI.cpp b/Nexus/ModAPI.cpp new file mode 100644 index 0000000..836e483 --- /dev/null +++ b/Nexus/ModAPI.cpp @@ -0,0 +1,297 @@ +#include "RetroEngine.hpp" + +#if RETRO_USE_MOD_LOADER +std::vector modList; +int activeMod = -1; +char modsPath[0x100]; + +#include +#include + +#if RETRO_PLATFORM == RETRO_ANDROID +namespace fs = std::__fs::filesystem; +#else +namespace fs = std::filesystem; +#endif + +fs::path ResolvePath(fs::path given) { + if (given.is_relative()) + given = fs::current_path() / given; // thanks for the weird syntax! + + for (auto &p : fs::directory_iterator{ given.parent_path() }) { + char pbuf[0x100]; + char gbuf[0x100]; + auto pf = p.path().filename(); + auto pstr = pf.string(); + std::transform(pstr.begin(), pstr.end(), pstr.begin(), [](char c) { return std::tolower(c); }); + auto gf = given.filename(); + auto gstr = gf.string(); + std::transform(gstr.begin(), gstr.end(), gstr.begin(), [](char c) { return std::tolower(c); }); + if (pstr == gstr) { + return p.path(); + } + } + return given; // might work might not! +} + +void InitMods() { + modList.clear(); + + char modBuf[0x100]; + sprintf(modBuf, "%smods", modsPath); + fs::path modPath = ResolvePath(modBuf); + + if (fs::exists(modPath) && fs::is_directory(modPath)) { + std::string mod_config = modPath.string() + "/modconfig.ini"; + FileIO *configFile = fOpen(mod_config.c_str(), "r"); + if (configFile) { + fClose(configFile); + IniParser modConfig(mod_config.c_str(), false); + + for (int m = 0; m < modConfig.items.size(); ++m) { + bool active = false; + ModInfo info; + modConfig.GetBool("mods", modConfig.items[m].key, &active); + if (LoadMod(&info, modPath.string(), modConfig.items[m].key, active)) + modList.push_back(info); + } + } + + try { + auto rdi = fs::directory_iterator(modPath); + for (auto de : rdi) { + if (de.is_directory()) { + fs::path modDirPath = de.path(); + + ModInfo info; + + std::string modDir = modDirPath.string().c_str(); + const std::string mod_inifile = modDir + "/mod.ini"; + std::string folder = modDirPath.filename().string(); + + bool flag = true; + for (int m = 0; m < modList.size(); ++m) { + if (modList[m].folder == folder) { + flag = false; + break; + } + } + + if (flag) { + if (LoadMod(&info, modPath.string(), modDirPath.filename().string(), false)) + modList.push_back(info); + } + } + } + } catch (fs::filesystem_error fe) { + PrintLog("Mods Folder Scanning Error: "); + PrintLog(fe.what()); + } + } +} + +bool LoadMod(ModInfo *info, std::string modsPath, std::string folder, bool active) { + if (!info) + return false; + + info->fileMap.clear(); + info->name = ""; + info->desc = ""; + info->author = ""; + info->version = ""; + info->folder = ""; + info->active = false; + + const std::string modDir = modsPath + "/" + folder; + + FileIO *f = fOpen((modDir + "/mod.ini").c_str(), "r"); + if (f) { + fClose(f); + IniParser modSettings((modDir + "/mod.ini").c_str(), false); + + info->name = "Unnamed Mod"; + info->desc = ""; + info->author = "Unknown Author"; + info->version = "1.0.0"; + info->folder = folder; + + char infoBuf[0x100]; + // Name + StrCopy(infoBuf, ""); + modSettings.GetString("", "Name", infoBuf); + if (!StrComp(infoBuf, "")) + info->name = infoBuf; + // Desc + StrCopy(infoBuf, ""); + modSettings.GetString("", "Description", infoBuf); + if (!StrComp(infoBuf, "")) + info->desc = infoBuf; + // Author + StrCopy(infoBuf, ""); + modSettings.GetString("", "Author", infoBuf); + if (!StrComp(infoBuf, "")) + info->author = infoBuf; + // Version + StrCopy(infoBuf, ""); + modSettings.GetString("", "Version", infoBuf); + if (!StrComp(infoBuf, "")) + info->version = infoBuf; + + info->active = active; + + ScanModFolder(info); + + return true; + } + return false; +} + +void ScanModFolder(ModInfo *info) { + if (!info) + return; + + char modBuf[0x100]; + sprintf(modBuf, "%smods", modsPath); + + fs::path modPath = ResolvePath(modBuf); + + const std::string modDir = modPath.string() + "/" + info->folder; + + // Check for Data/ replacements + fs::path dataPath = ResolvePath(modDir + "/Data"); + + if (fs::exists(dataPath) && fs::is_directory(dataPath)) { + try { + auto data_rdi = fs::recursive_directory_iterator(dataPath); + for (auto data_de : data_rdi) { + if (data_de.is_regular_file()) { + char modBuf[0x100]; + StrCopy(modBuf, data_de.path().string().c_str()); + char folderTest[4][0x10] = { + "Data/", + "Data\\", + "data/", + "data\\", + }; + int tokenPos = -1; + for (int i = 0; i < 4; ++i) { + tokenPos = FindStringToken(modBuf, folderTest[i], 1); + if (tokenPos >= 0) + break; + } + + if (tokenPos >= 0) { + char buffer[0x100]; + for (int i = StrLength(modBuf); i >= tokenPos; --i) { + buffer[i - tokenPos] = modBuf[i] == '\\' ? '/' : modBuf[i]; + } + + // PrintLog(modBuf); + std::string path(buffer); + std::string modPath(modBuf); + char pathLower[0x100]; + memset(pathLower, 0, sizeof(char) * 0x100); + for (int c = 0; c < path.size(); ++c) { + pathLower[c] = tolower(path.c_str()[c]); + } + + info->fileMap.insert(std::pair(pathLower, modBuf)); + } + } + } + } catch (fs::filesystem_error fe) { + PrintLog("Data Folder Scanning Error: "); + PrintLog(fe.what()); + } + } + + // Check for Scripts/ replacements + fs::path scriptPath = ResolvePath(modDir + "/Scripts"); + + if (fs::exists(scriptPath) && fs::is_directory(scriptPath)) { + try { + auto data_rdi = fs::recursive_directory_iterator(scriptPath); + for (auto data_de : data_rdi) { + if (data_de.is_regular_file()) { + char modBuf[0x100]; + StrCopy(modBuf, data_de.path().string().c_str()); + char folderTest[4][0x10] = { + "Scripts/", + "Scripts\\", + "scripts/", + "scripts\\", + }; + int tokenPos = -1; + for (int i = 0; i < 4; ++i) { + tokenPos = FindStringToken(modBuf, folderTest[i], 1); + if (tokenPos >= 0) + break; + } + + if (tokenPos >= 0) { + char buffer[0x100]; + for (int i = StrLength(modBuf); i >= tokenPos; --i) { + buffer[i - tokenPos] = modBuf[i] == '\\' ? '/' : modBuf[i]; + } + + // PrintLog(modBuf); + std::string path(buffer); + std::string modPath(modBuf); + char pathLower[0x100]; + memset(pathLower, 0, sizeof(char) * 0x100); + for (int c = 0; c < path.size(); ++c) { + pathLower[c] = tolower(path.c_str()[c]); + } + + info->fileMap.insert(std::pair(pathLower, modBuf)); + } + } + } + } catch (fs::filesystem_error fe) { + PrintLog("Script Folder Scanning Error: "); + PrintLog(fe.what()); + } + } +} + +void SaveMods() { + char modBuf[0x100]; + sprintf(modBuf, "%smods", modsPath); + fs::path modPath = ResolvePath(modBuf); + + if (fs::exists(modPath) && fs::is_directory(modPath)) { + std::string mod_config = modPath.string() + "/modconfig.ini"; + IniParser modConfig; + + for (int m = 0; m < modList.size(); ++m) { + ModInfo *info = &modList[m]; + + modConfig.SetBool("mods", info->folder.c_str(), info->active); + } + + modConfig.Write(mod_config.c_str(), false); + } +} + +void RefreshEngine() { + // Reload entire engine + Engine.LoadGameConfig("Data/Game/GameConfig.bin"); +#if RETRO_USING_SDL2 + if (Engine.window) { + char gameTitle[0x40]; + sprintf(gameTitle, "%s%s", Engine.GameWindowText, Engine.UseBinFile ? "" : " (Using Data Folder)"); + SDL_SetWindowTitle(Engine.window, gameTitle); + } +#elif RETRO_USING_SDL1 + char gameTitle[0x40]; + sprintf(gameTitle, "%s%s", Engine.GameWindowText, Engine.UseBinFile ? "" : " (Using Data Folder)"); + SDL_WM_SetCaption(gameTitle, NULL); +#endif + + ReleaseGlobalSfx(); + LoadGlobalSfx(); + + SaveMods(); +} + +#endif \ No newline at end of file diff --git a/Nexus/ModAPI.hpp b/Nexus/ModAPI.hpp new file mode 100644 index 0000000..2a8a34b --- /dev/null +++ b/Nexus/ModAPI.hpp @@ -0,0 +1,34 @@ +#ifndef MOD_API_H +#define MOD_API_H + +#if RETRO_USE_MOD_LOADER +#include +#include +#include + +struct ModInfo { + std::string name; + std::string desc; + std::string author; + std::string version; + std::map fileMap; + std::string folder; + bool active; +}; + +extern std::vector modList; +extern int activeMod; +extern char modsPath[0x100]; + +inline void SetActiveMod(int id) { activeMod = id; } + +void InitMods(); +bool LoadMod(ModInfo *info, std::string modsPath, std::string folder, bool active); +void ScanModFolder(ModInfo *info); +void SaveMods(); + +void RefreshEngine(); + +#endif + +#endif \ No newline at end of file diff --git a/Nexus/Nexus.vcxproj b/Nexus/Nexus.vcxproj index 5a83782..9b3f584 100644 --- a/Nexus/Nexus.vcxproj +++ b/Nexus/Nexus.vcxproj @@ -1,247 +1,249 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - {BD4A4266-8ED9-491E-B4CC-3F63F0D39C1B} - Win32Proj - Nexus - 10.0 - Nexus - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - $(SolutionDir)build\$(Platform)\$(Configuration)\ - Nexus - $(Platform)\$(Configuration)\ - - - true - $(SolutionDir)build\$(Platform)\$(Configuration)\ - Nexus_64 - - - false - $(SolutionDir)build\$(Platform)\$(Configuration)\ - Nexus - $(Platform)\$(Configuration)\ - - - false - $(SolutionDir)build\$(Platform)\$(Configuration)\ - Nexus_64 - - - - NotUsing - Level1 - true - _CRT_SECURE_NO_WARNINGS;USE_SW_REN;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(SolutionDir)dependencies/windows/SDL2/include/;$(SolutionDir)dependencies/windows/libogg/include/;$(SolutionDir)dependencies/windows/libvorbis/include/;$(SolutionDir)dependencies/windows/libtheora/include/;$(SolutionDir)dependencies/all/theoraplay/;%(AdditionalIncludeDirectories) - stdcpp17 - - - Windows - true - $(SolutionDir)dependencies/windows/SDL2/lib/$(PlatformTargetAsMSBuildArchitecture)/;$(SolutionDir)dependencies/windows/libvorbis/win32/VS2010/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libtheora/win32/VS2008/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libogg/win32/VS2015/$(Platform)/$(Configuration)/ - SDL2.lib;SDL2main.lib;libogg.lib;libvorbis_static.lib;libvorbisfile_static.lib;libtheora_static.lib;Shell32.lib;Advapi32.lib - - - copy /Y "$(SolutionDir)dependencies\windows\SDL2\lib\$(PlatformTargetAsMSBuildArchitecture)\SDL2.dll" "$(OutDir)" - - - copying SDL2 library DLL to the build directory. build should fail if it's not found - - - - - NotUsing - Level1 - true - _CRT_SECURE_NO_WARNINGS;USE_SW_REN;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(SolutionDir)dependencies/windows/SDL2/include/;$(SolutionDir)dependencies/windows/libogg/include/;$(SolutionDir)dependencies/windows/libvorbis/include/;$(SolutionDir)dependencies/windows/libtheora/include/;$(SolutionDir)dependencies/all/theoraplay/;%(AdditionalIncludeDirectories) - stdcpp17 - - - Windows - true - $(SolutionDir)dependencies/windows/SDL2/lib/$(PlatformTargetAsMSBuildArchitecture)/;$(SolutionDir)dependencies/windows/libvorbis/win32/VS2010/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libtheora/win32/VS2008/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libogg/win32/VS2015/$(Platform)/$(Configuration)/ - SDL2.lib;SDL2main.lib;libogg.lib;libvorbis_static.lib;libvorbisfile_static.lib;libtheora_static.lib;Shell32.lib;Advapi32.lib - - - copy /Y "$(SolutionDir)dependencies\windows\SDL2\lib\$(PlatformTargetAsMSBuildArchitecture)\SDL2.dll" "$(OutDir)" - - - copying SDL2 library DLL to the build directory. build should fail if it's not found - - - - - NotUsing - Level1 - true - true - true - _CRT_SECURE_NO_WARNINGS;USE_SW_REN;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(SolutionDir)dependencies/windows/SDL2/include/;$(SolutionDir)dependencies/windows/libogg/include/;$(SolutionDir)dependencies/windows/libvorbis/include/;$(SolutionDir)dependencies/windows/libtheora/include/;$(SolutionDir)dependencies/all/theoraplay/;%(AdditionalIncludeDirectories) - stdcpp17 - - - Windows - true - true - true - $(SolutionDir)dependencies/windows/SDL2/lib/$(PlatformTargetAsMSBuildArchitecture)/;$(SolutionDir)dependencies/windows/libvorbis/win32/VS2010/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libtheora/win32/VS2008/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libogg/win32/VS2015/$(Platform)/$(Configuration)/ - SDL2.lib;SDL2main.lib;libogg.lib;libvorbis_static.lib;libvorbisfile_static.lib;libtheora_static.lib;Shell32.lib;Advapi32.lib - - - copy /Y "$(SolutionDir)dependencies\windows\SDL2\lib\$(PlatformTargetAsMSBuildArchitecture)\SDL2.dll" "$(OutDir)" - copying SDL2 library DLL to the build directory. build should fail if it's not found - - - - - NotUsing - Level1 - true - true - true - _CRT_SECURE_NO_WARNINGS;USE_SW_REN;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(SolutionDir)dependencies/windows/SDL2/include/;$(SolutionDir)dependencies/windows/libogg/include/;$(SolutionDir)dependencies/windows/libvorbis/include/;$(SolutionDir)dependencies/windows/libtheora/include/;$(SolutionDir)dependencies/all/theoraplay/;%(AdditionalIncludeDirectories) - stdcpp17 - - - Windows - true - true - true - $(SolutionDir)dependencies/windows/SDL2/lib/$(PlatformTargetAsMSBuildArchitecture)/;$(SolutionDir)dependencies/windows/libvorbis/win32/VS2010/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libtheora/win32/VS2008/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libogg/win32/VS2015/$(Platform)/$(Configuration)/ - SDL2.lib;SDL2main.lib;libogg.lib;libvorbis_static.lib;libvorbisfile_static.lib;libtheora_static.lib;Shell32.lib;Advapi32.lib - - - copy /Y "$(SolutionDir)dependencies\windows\SDL2\lib\$(PlatformTargetAsMSBuildArchitecture)\SDL2.dll" "$(OutDir)" - copying SDL2 library DLL to the build directory. build should fail if it's not found - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {BD4A4266-8ED9-491E-B4CC-3F63F0D39C1B} + Win32Proj + Nexus + 10.0 + Nexus + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)build\$(Platform)\$(Configuration)\ + Nexus + $(Platform)\$(Configuration)\ + + + true + $(SolutionDir)build\$(Platform)\$(Configuration)\ + Nexus_64 + + + false + $(SolutionDir)build\$(Platform)\$(Configuration)\ + Nexus + $(Platform)\$(Configuration)\ + + + false + $(SolutionDir)build\$(Platform)\$(Configuration)\ + Nexus_64 + + + + NotUsing + Level1 + true + _CRT_SECURE_NO_WARNINGS;USE_SW_REN;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)dependencies/windows/SDL2/include/;$(SolutionDir)dependencies/windows/libogg/include/;$(SolutionDir)dependencies/windows/libvorbis/include/;$(SolutionDir)dependencies/windows/libtheora/include/;$(SolutionDir)dependencies/all/theoraplay/;%(AdditionalIncludeDirectories) + stdcpp17 + + + Windows + true + $(SolutionDir)dependencies/windows/SDL2/lib/$(PlatformTargetAsMSBuildArchitecture)/;$(SolutionDir)dependencies/windows/libvorbis/win32/VS2010/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libtheora/win32/VS2008/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libogg/win32/VS2015/$(Platform)/$(Configuration)/ + SDL2.lib;SDL2main.lib;libogg.lib;libvorbis_static.lib;libvorbisfile_static.lib;libtheora_static.lib;Shell32.lib;Advapi32.lib + + + copy /Y "$(SolutionDir)dependencies\windows\SDL2\lib\$(PlatformTargetAsMSBuildArchitecture)\SDL2.dll" "$(OutDir)" + + + copying SDL2 library DLL to the build directory. build should fail if it's not found + + + + + NotUsing + Level1 + true + _CRT_SECURE_NO_WARNINGS;USE_SW_REN;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)dependencies/windows/SDL2/include/;$(SolutionDir)dependencies/windows/libogg/include/;$(SolutionDir)dependencies/windows/libvorbis/include/;$(SolutionDir)dependencies/windows/libtheora/include/;$(SolutionDir)dependencies/all/theoraplay/;%(AdditionalIncludeDirectories) + stdcpp17 + + + Windows + true + $(SolutionDir)dependencies/windows/SDL2/lib/$(PlatformTargetAsMSBuildArchitecture)/;$(SolutionDir)dependencies/windows/libvorbis/win32/VS2010/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libtheora/win32/VS2008/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libogg/win32/VS2015/$(Platform)/$(Configuration)/ + SDL2.lib;SDL2main.lib;libogg.lib;libvorbis_static.lib;libvorbisfile_static.lib;libtheora_static.lib;Shell32.lib;Advapi32.lib + + + copy /Y "$(SolutionDir)dependencies\windows\SDL2\lib\$(PlatformTargetAsMSBuildArchitecture)\SDL2.dll" "$(OutDir)" + + + copying SDL2 library DLL to the build directory. build should fail if it's not found + + + + + NotUsing + Level1 + true + true + true + _CRT_SECURE_NO_WARNINGS;USE_SW_REN;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)dependencies/windows/SDL2/include/;$(SolutionDir)dependencies/windows/libogg/include/;$(SolutionDir)dependencies/windows/libvorbis/include/;$(SolutionDir)dependencies/windows/libtheora/include/;$(SolutionDir)dependencies/all/theoraplay/;%(AdditionalIncludeDirectories) + stdcpp17 + + + Windows + true + true + true + $(SolutionDir)dependencies/windows/SDL2/lib/$(PlatformTargetAsMSBuildArchitecture)/;$(SolutionDir)dependencies/windows/libvorbis/win32/VS2010/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libtheora/win32/VS2008/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libogg/win32/VS2015/$(Platform)/$(Configuration)/ + SDL2.lib;SDL2main.lib;libogg.lib;libvorbis_static.lib;libvorbisfile_static.lib;libtheora_static.lib;Shell32.lib;Advapi32.lib + + + copy /Y "$(SolutionDir)dependencies\windows\SDL2\lib\$(PlatformTargetAsMSBuildArchitecture)\SDL2.dll" "$(OutDir)" + copying SDL2 library DLL to the build directory. build should fail if it's not found + + + + + NotUsing + Level1 + true + true + true + _CRT_SECURE_NO_WARNINGS;USE_SW_REN;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)dependencies/windows/SDL2/include/;$(SolutionDir)dependencies/windows/libogg/include/;$(SolutionDir)dependencies/windows/libvorbis/include/;$(SolutionDir)dependencies/windows/libtheora/include/;$(SolutionDir)dependencies/all/theoraplay/;%(AdditionalIncludeDirectories) + stdcpp17 + + + Windows + true + true + true + $(SolutionDir)dependencies/windows/SDL2/lib/$(PlatformTargetAsMSBuildArchitecture)/;$(SolutionDir)dependencies/windows/libvorbis/win32/VS2010/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libtheora/win32/VS2008/$(Platform)/$(Configuration)/;$(SolutionDir)dependencies/windows/libogg/win32/VS2015/$(Platform)/$(Configuration)/ + SDL2.lib;SDL2main.lib;libogg.lib;libvorbis_static.lib;libvorbisfile_static.lib;libtheora_static.lib;Shell32.lib;Advapi32.lib + + + copy /Y "$(SolutionDir)dependencies\windows\SDL2\lib\$(PlatformTargetAsMSBuildArchitecture)\SDL2.dll" "$(OutDir)" + copying SDL2 library DLL to the build directory. build should fail if it's not found + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Nexus/Nexus.vcxproj.filters b/Nexus/Nexus.vcxproj.filters index 171afad..a06635e 100644 --- a/Nexus/Nexus.vcxproj.filters +++ b/Nexus/Nexus.vcxproj.filters @@ -1,157 +1,163 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Resource Files - - - - - Resource Files - - + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Source Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Resource Files + + + + + Resource Files + + \ No newline at end of file diff --git a/Nexus/Object.cpp b/Nexus/Object.cpp index 4771199..aa04563 100644 --- a/Nexus/Object.cpp +++ b/Nexus/Object.cpp @@ -1,73 +1,69 @@ #include "RetroEngine.hpp" -int objectLoop = 0; +int ObjectLoop = 0; int curObjectType = 0; -Entity objectEntityList[ENTITY_COUNT]; +Entity ObjectEntityList[ENTITY_COUNT]; int OBJECT_BORDER_X1 = 0x80; int OBJECT_BORDER_X2 = 0; const int OBJECT_BORDER_Y1 = 0x100; const int OBJECT_BORDER_Y2 = SCREEN_YSIZE + 0x100; -void ProcessStartupObjects() -{ - scriptFrameCount = 0; +void ProcessStartupScripts() { + ScriptFramesNo = 0; ClearAnimationData(); - activePlayer = 0; - activePlayerCount = 1; - scriptEng.arrayPosition[2] = TEMPENTITY_START; - Entity *entity = &objectEntityList[TEMPENTITY_START]; + PlayerNo = 0; + ScriptEng.arrayPosition[2] = TEMPENTITY_START; + Entity *entity = &ObjectEntityList[TEMPENTITY_START]; for (int i = 0; i < OBJECT_COUNT; ++i) { - ObjectScript *scriptInfo = &objectScriptList[i]; - objectLoop = TEMPENTITY_START; - curObjectType = i; - int frameStart = scriptFrameCount; - scriptInfo->frameStartPtr = &scriptFrames[scriptFrameCount]; - scriptInfo->spriteSheetID = 0; - entity->type = i; - if (scriptData[scriptInfo->subStartup.scriptCodePtr] > 0) + ObjectScript *scriptInfo = &ObjectScriptList[i]; + ObjectLoop = TEMPENTITY_START; + curObjectType = i; + int frameStart = ScriptFramesNo; + scriptInfo->frameStartPtr = &ScriptFrames[ScriptFramesNo]; + scriptInfo->spriteSheetID = 0; + entity->type = i; + if (ScriptData[scriptInfo->subStartup.scriptCodePtr] > 0) ProcessScript(scriptInfo->subStartup.scriptCodePtr, scriptInfo->subStartup.jumpTablePtr, SUB_SETUP); - scriptInfo->frameCount = scriptFrameCount - frameStart; + scriptInfo->frameCount = ScriptFramesNo - frameStart; } - entity->type = 0; - curObjectType = 0; + entity->type = 0; + curObjectType = 0; + ScriptFramesNo = 0; } -void ProcessObjects() -{ - for (int i = 0; i < DRAWLAYER_COUNT; ++i) drawListEntries[i].listSize = 0; +void ProcessObjects() { + for (int i = 0; i < DRAWLAYER_COUNT; ++i) ObjectDrawOrderList[i].listSize = 0; - for (objectLoop = 0; objectLoop < ENTITY_COUNT; ++objectLoop) { + for (ObjectLoop = 0; ObjectLoop < ENTITY_COUNT; ++ObjectLoop) { bool active = false; int x = 0, y = 0; - Entity *entity = &objectEntityList[objectLoop]; + Entity *entity = &ObjectEntityList[ObjectLoop]; if (entity->priority <= 0) { x = entity->XPos >> 16; y = entity->YPos >> 16; - active = x > xScrollOffset - OBJECT_BORDER_X1 && x < OBJECT_BORDER_X2 + xScrollOffset && y > yScrollOffset - OBJECT_BORDER_Y1 - && y < yScrollOffset + OBJECT_BORDER_Y2; - } - else { + active = x > XScrollOffset - OBJECT_BORDER_X1 && x < OBJECT_BORDER_X2 + XScrollOffset && y > YScrollOffset - OBJECT_BORDER_Y1 + && y < YScrollOffset + OBJECT_BORDER_Y2; + } else { active = true; } if (active && entity->type > OBJ_TYPE_BLANKOBJECT) { if (entity->type == OBJ_TYPE_PLAYER) { - if (objectLoop >= 2) { + if (ObjectLoop >= 2) { entity->type = OBJ_TYPE_BLANKOBJECT; - } - else { - Player *player = &playerList[objectLoop]; - PlayerScript *script = &playerScriptList[objectLoop]; + } else { + Player *player = &PlayerList[ObjectLoop]; + PlayerScript *script = &PlayerScriptList[ObjectLoop]; switch (entity->propertyValue) { case 0: - activePlayer = objectLoop; + PlayerNo = ObjectLoop; ProcessPlayerControl(player); player->animationSpeed = 0; - if (scriptData[script->scriptCodePtr_PlayerMain] > 0) + if (ScriptData[script->scriptCodePtr_PlayerMain] > 0) ProcessScript(script->scriptCodePtr_PlayerMain, script->jumpTablePtr_PlayerMain, SUB_PLAYERMAIN); - if (scriptData[script->scriptCodePtr_PlayerState[player->state]] > 0) + if (ScriptData[script->scriptCodePtr_PlayerState[player->state]] > 0) ProcessScript(script->scriptCodePtr_PlayerState[player->state], script->jumpTablePtr_PlayerState[player->state], SUB_PLAYERSTATE); ProcessPlayerAnimation(player); @@ -77,7 +73,7 @@ void ProcessObjects() case 1: ProcessPlayerControl(player); ProcessPlayerAnimation(player); - if (scriptData[script->scriptCodePtr_PlayerMain] > 0) + if (ScriptData[script->scriptCodePtr_PlayerMain] > 0) ProcessScript(script->scriptCodePtr_PlayerMain, script->jumpTablePtr_PlayerMain, SUB_PLAYERMAIN); if (player->tileCollisions) ProcessPlayerTileCollisions(player); @@ -85,37 +81,36 @@ void ProcessObjects() case 2: ProcessPlayerControl(player); ProcessDebugMode(player); - if (!objectLoop) { - cameraEnabled = true; - if (keyPress.B) { + if (!ObjectLoop) { + CameraEnabled = true; + if (GKeyPress.B) { player->tileCollisions = true; player->objectInteraction = true; - player->controlMode = 0; - objectEntityList[objectLoop].propertyValue = 0; + player->controlMode = CONTROLMODE_NORMAL; + ObjectEntityList[ObjectLoop].propertyValue = 0; } } break; } if (entity->drawOrder < DRAWLAYER_COUNT) - drawListEntries[entity->drawOrder].entityRefs[drawListEntries[entity->drawOrder].listSize++] = objectLoop; + ObjectDrawOrderList[entity->drawOrder].entityRefs[ObjectDrawOrderList[entity->drawOrder].listSize++] = ObjectLoop; } - } - else { - ObjectScript *scriptInfo = &objectScriptList[entity->type]; - activePlayer = 0; - if (scriptData[scriptInfo->subMain.scriptCodePtr] > 0) + } else { + ObjectScript *scriptInfo = &ObjectScriptList[entity->type]; + PlayerNo = 0; + if (ScriptData[scriptInfo->subMain.scriptCodePtr] > 0) ProcessScript(scriptInfo->subMain.scriptCodePtr, scriptInfo->subMain.jumpTablePtr, SUB_MAIN); - if (scriptData[scriptInfo->subPlayerInteraction.scriptCodePtr] > 0) { - while (activePlayer < activePlayerCount) { - if (playerList[activePlayer].objectInteraction) + if (ScriptData[scriptInfo->subPlayerInteraction.scriptCodePtr] > 0) { + while (PlayerNo < activePlayerCount) { + if (PlayerList[PlayerNo].objectInteraction) ProcessScript(scriptInfo->subPlayerInteraction.scriptCodePtr, scriptInfo->subPlayerInteraction.jumpTablePtr, SUB_PLAYERINTERACTION); - ++activePlayer; + ++PlayerNo; } } if (entity->drawOrder < DRAWLAYER_COUNT) - drawListEntries[entity->drawOrder].entityRefs[drawListEntries[entity->drawOrder].listSize++] = objectLoop; + ObjectDrawOrderList[entity->drawOrder].entityRefs[ObjectDrawOrderList[entity->drawOrder].listSize++] = ObjectLoop; } } } diff --git a/Nexus/Object.hpp b/Nexus/Object.hpp index 60cd5a7..c8841f6 100644 --- a/Nexus/Object.hpp +++ b/Nexus/Object.hpp @@ -31,16 +31,16 @@ enum ObjectPriority { PRIORITY_ALWAYS, }; -extern int objectLoop; +extern int ObjectLoop; extern int curObjectType; -extern Entity objectEntityList[ENTITY_COUNT]; +extern Entity ObjectEntityList[ENTITY_COUNT]; extern int OBJECT_BORDER_X1; extern int OBJECT_BORDER_X2; extern const int OBJECT_BORDER_Y1; extern const int OBJECT_BORDER_Y2; -void ProcessStartupObjects(); +void ProcessStartupScripts(); void ProcessObjects(); #endif // !OBJECT_H diff --git a/Nexus/Palette.cpp b/Nexus/Palette.cpp index 6187f5a..aef1be4 100644 --- a/Nexus/Palette.cpp +++ b/Nexus/Palette.cpp @@ -1,27 +1,26 @@ #include "RetroEngine.hpp" // Palettes (as RGB888 Colours) -uint palette32[PALETTE_SIZE]; -uint palette32W[PALETTE_SIZE]; -uint palette32F[PALETTE_SIZE]; -uint palette32WF[PALETTE_SIZE]; +uint TilePalette32[PALETTE_SIZE]; +uint TilePaletteW32[PALETTE_SIZE]; +uint TilePalette32F[PALETTE_SIZE]; +uint TilePaletteW32F[PALETTE_SIZE]; // Palettes (as RGB565 Colours) -ushort palette16[PALETTE_SIZE]; -ushort palette16W[PALETTE_SIZE]; -ushort palette16F[PALETTE_SIZE]; -ushort palette16WF[PALETTE_SIZE]; +ushort TilePalette16[PALETTE_SIZE]; +ushort TilePaletteW16[PALETTE_SIZE]; +ushort TilePalette16F[PALETTE_SIZE]; +ushort TilePaletteW16F[PALETTE_SIZE]; // Palettes (as RGB888 Colours) -Colour palette8[PALETTE_SIZE]; -Colour palette8W[PALETTE_SIZE]; -Colour palette8F[PALETTE_SIZE]; -Colour palette8WF[PALETTE_SIZE]; +Colour TilePalette[PALETTE_SIZE]; +Colour TilePaletteW[PALETTE_SIZE]; +Colour TilePaletteF[PALETTE_SIZE]; +Colour TilePaletteWF[PALETTE_SIZE]; -int fadeMode = 0; +int PaletteMode = 0; -void LoadPalette(const char *filePath, int startIndex, int endIndex) -{ +void LoadPalette(const char *filePath, int startIndex, int endIndex) { FileInfo info; if (LoadFile(filePath, &info)) { @@ -36,59 +35,56 @@ void LoadPalette(const char *filePath, int startIndex, int endIndex) } } -void SetFade(byte r, byte g, byte b, ushort a, int start, int end) -{ - fadeMode = 1; - if (a > 255) - a = 255; - if (end < 256) +void SetFade(byte r, byte g, byte b, ushort a, int start, int end) { + PaletteMode = 1; + if (a > 0xFF) + a = 0xFF; + if (end <= 0xFF) ++end; for (int i = start; i < end; ++i) { - byte red = (ushort)(r * a + (0xFF - a) * palette8[i].r) >> 8; - byte green = (ushort)(g * a + (0xFF - a) * palette8[i].g) >> 8; - byte blue = (ushort)(b * a + (0xFF - a) * palette8[i].b) >> 8; - palette16F[i] = RGB888_TO_RGB565(red, green, blue); - palette32F[i] = PACK_RGB888(red, green, blue); - palette8F[i].r = red; - palette8F[i].g = green; - palette8F[i].b = blue; + byte red = (ushort)(r * a + (0xFF - a) * TilePalette[i].r) >> 8; + byte green = (ushort)(g * a + (0xFF - a) * TilePalette[i].g) >> 8; + byte blue = (ushort)(b * a + (0xFF - a) * TilePalette[i].b) >> 8; + TilePalette16F[i] = RGB888_TO_RGB565(red, green, blue); + TilePalette32F[i] = PACK_RGB888(red, green, blue); + TilePaletteF[i].r = red; + TilePaletteF[i].g = green; + TilePaletteF[i].b = blue; - red = (ushort)(r * a + (0xFF - a) * palette8W[i].r) >> 8; - green = (ushort)(g * a + (0xFF - a) * palette8W[i].g) >> 8; - blue = (ushort)(b * a + (0xFF - a) * palette8W[i].b) >> 8; - palette16WF[i] = RGB888_TO_RGB565(red, green, blue); - palette32WF[i] = PACK_RGB888(red, green, blue); - palette8WF[i].r = red; - palette8WF[i].g = green; - palette8WF[i].b = blue; + red = (ushort)(r * a + (0xFF - a) * TilePaletteW[i].r) >> 8; + green = (ushort)(g * a + (0xFF - a) * TilePaletteW[i].g) >> 8; + blue = (ushort)(b * a + (0xFF - a) * TilePaletteW[i].b) >> 8; + TilePaletteW16F[i] = RGB888_TO_RGB565(red, green, blue); + TilePaletteW32F[i] = PACK_RGB888(red, green, blue); + TilePaletteWF[i].r = red; + TilePaletteWF[i].g = green; + TilePaletteWF[i].b = blue; } } -void SetWaterColour(byte r, byte g, byte b, ushort a) -{ - fadeMode = 1; - if (a > 255) - a = 255; - for (int i = 0; i < 0x100; ++i) { - byte red = (ushort)(r * a + (0xFF - a) * palette8[i].r) >> 8; - byte green = (ushort)(g * a + (0xFF - a) * palette8[i].g) >> 8; - byte blue = (ushort)(b * a + (0xFF - a) * palette8[i].b) >> 8; - palette16W[i] = RGB888_TO_RGB565(red, green, blue); - palette32W[i] = PACK_RGB888(red, green, blue); - palette8W[i].r = red; - palette8W[i].g = green; - palette8W[i].b = blue; +void SetWaterColour(byte r, byte g, byte b, ushort a) { + PaletteMode = 1; + if (a > 0xFF) + a = 0xFF; + for (int i = 0; i < PALETTE_SIZE; ++i) { + byte red = (ushort)(r * a + (0xFF - a) * TilePalette[i].r) >> 8; + byte green = (ushort)(g * a + (0xFF - a) * TilePalette[i].g) >> 8; + byte blue = (ushort)(b * a + (0xFF - a) * TilePalette[i].b) >> 8; + TilePaletteW16[i] = RGB888_TO_RGB565(red, green, blue); + TilePaletteW32[i] = PACK_RGB888(red, green, blue); + TilePaletteW[i].r = red; + TilePaletteW[i].g = green; + TilePaletteW[i].b = blue; } } -void WaterFlash() -{ - fadeMode = 5; - for (int i = 0; i < 0x100; ++i) { - palette16WF[i] = RGB888_TO_RGB565(0xFF, 0xFF, 0xFF); - palette32WF[i] = PACK_RGB888(0xFF, 0xFF, 0xFF); - palette8WF[i].r = 0xFF; - palette8WF[i].g = 0xFF; - palette8WF[i].b = 0xFF; +void WaterFlash() { + PaletteMode = 5; + for (int i = 0; i < PALETTE_SIZE; ++i) { + TilePaletteW16F[i] = RGB888_TO_RGB565(0xFF, 0xFF, 0xFF); + TilePaletteW32F[i] = PACK_RGB888(0xFF, 0xFF, 0xFF); + TilePaletteWF[i].r = 0xFF; + TilePaletteWF[i].g = 0xFF; + TilePaletteWF[i].b = 0xFF; } -} \ No newline at end of file +} diff --git a/Nexus/Palette.hpp b/Nexus/Palette.hpp index 8d8271c..0c19d81 100644 --- a/Nexus/Palette.hpp +++ b/Nexus/Palette.hpp @@ -11,24 +11,24 @@ struct Colour { }; // Palettes (as RGB888 Colours) -extern uint palette32[PALETTE_SIZE]; -extern uint palette32W[PALETTE_SIZE]; -extern uint palette32F[PALETTE_SIZE]; -extern uint palette32WF[PALETTE_SIZE]; +extern uint TilePalette32[PALETTE_SIZE]; +extern uint TilePaletteW32[PALETTE_SIZE]; +extern uint TilePalette32F[PALETTE_SIZE]; +extern uint TilePaletteW32F[PALETTE_SIZE]; // Palettes (as RGB565 Colours) -extern ushort palette16[PALETTE_SIZE]; -extern ushort palette16W[PALETTE_SIZE]; -extern ushort palette16F[PALETTE_SIZE]; -extern ushort palette16WF[PALETTE_SIZE]; +extern ushort TilePalette16[PALETTE_SIZE]; +extern ushort TilePaletteW16[PALETTE_SIZE]; +extern ushort TilePalette16F[PALETTE_SIZE]; +extern ushort TilePaletteW16F[PALETTE_SIZE]; -// Palettes (as RGB888 Colours) -extern Colour palette8[PALETTE_SIZE]; -extern Colour palette8W[PALETTE_SIZE]; -extern Colour palette8F[PALETTE_SIZE]; -extern Colour palette8WF[PALETTE_SIZE]; +// Water Flash Palettes (as RGB888 Colours) +extern Colour TilePalette[PALETTE_SIZE]; +extern Colour TilePaletteW[PALETTE_SIZE]; +extern Colour TilePaletteF[PALETTE_SIZE]; +extern Colour TilePaletteWF[PALETTE_SIZE]; -extern int fadeMode; +extern int PaletteMode; #define RGB888_TO_RGB565(r, g, b) ((b) >> 3) | (((g) >> 2) << 5) | (((r) >> 3) << 11) @@ -36,42 +36,39 @@ extern int fadeMode; void LoadPalette(const char *filePath, int startIndex, int endIndex); -inline void SetPaletteEntry(byte index, byte r, byte g, byte b) -{ - palette32[index] = PACK_RGB888(r, g, b); - palette16[index] = RGB888_TO_RGB565(r, g, b); - palette8[index].r = r; - palette8[index].g = g; - palette8[index].b = b; +inline void SetPaletteEntry(byte index, byte r, byte g, byte b) { + TilePalette32[index] = PACK_RGB888(r, g, b); + TilePalette16[index] = RGB888_TO_RGB565(r, g, b); + TilePalette[index].r = r; + TilePalette[index].g = g; + TilePalette[index].b = b; } -inline void RotatePalette(byte startIndex, byte endIndex, bool right) -{ +inline void RotatePalette(byte startIndex, byte endIndex, bool right) { if (right) { - Colour startClr8 = palette8[endIndex]; - ushort startClr16 = palette16[endIndex]; - uint startClr32 = palette32[endIndex]; + Colour startClr8 = TilePalette[endIndex]; + ushort startClr16 = TilePalette16[endIndex]; + uint startClr32 = TilePalette32[endIndex]; for (int i = endIndex; i > startIndex; --i) { - palette8[i] = palette8[i - 1]; - palette16[i] = palette16[i - 1]; - palette32[i] = palette32[i - 1]; + TilePalette[i] = TilePalette[i - 1]; + TilePalette16[i] = TilePalette16[i - 1]; + TilePalette32[i] = TilePalette32[i - 1]; } - palette8[startIndex] = startClr8; - palette16[startIndex] = startClr16; - palette32[startIndex] = startClr32; - } - else { - Colour startClr8 = palette8[startIndex]; - ushort startClr16 = palette16[startIndex]; - uint startClr32 = palette32[startIndex]; + TilePalette[startIndex] = startClr8; + TilePalette16[startIndex] = startClr16; + TilePalette32[startIndex] = startClr32; + } else { + Colour startClr8 = TilePalette[startIndex]; + ushort startClr16 = TilePalette16[startIndex]; + uint startClr32 = TilePalette32[startIndex]; for (int i = startIndex; i < endIndex; ++i) { - palette8[i] = palette8[i + 1]; - palette16[i] = palette16[i + 1]; - palette32[i] = palette32[i + 1]; + TilePalette[i] = TilePalette[i + 1]; + TilePalette16[i] = TilePalette16[i + 1]; + TilePalette32[i] = TilePalette32[i + 1]; } - palette8[endIndex] = startClr8; - palette16[endIndex] = startClr16; - palette32[endIndex] = startClr32; + TilePalette[endIndex] = startClr8; + TilePalette16[endIndex] = startClr16; + TilePalette32[endIndex] = startClr32; } } diff --git a/Nexus/Player.cpp b/Nexus/Player.cpp index 658d765..0d6ac4f 100644 --- a/Nexus/Player.cpp +++ b/Nexus/Player.cpp @@ -1,19 +1,18 @@ #include "RetroEngine.hpp" -Player playerList[PLAYER_COUNT]; -PlayerScript playerScriptList[PLAYER_COUNT]; -int activePlayer = 0; +Player PlayerList[PLAYER_COUNT]; +PlayerScript PlayerScriptList[PLAYER_COUNT]; +int PlayerNo = 0; int activePlayerCount = 1; -ushort upBuffer = 0; -ushort downBuffer = 0; -ushort leftBuffer = 0; -ushort rightBuffer = 0; -ushort jumpPressBuffer = 0; -ushort jumpHoldBuffer = 0; +ushort DelayUp = 0; +ushort DelayDown = 0; +ushort DelayLeft = 0; +ushort DelayRight = 0; +ushort DelayJumpPress = 0; +ushort DelayJumpHold = 0; -void LoadPlayerFromList(byte characterID, byte playerID) -{ +void LoadPlayerFromList(byte characterID, byte playerID) { FileInfo info; char strBuf[0x100]; byte fileBuffer = 0; @@ -70,12 +69,12 @@ void LoadPlayerFromList(byte characterID, byte playerID) FileRead(&count, 1); for (int p = 0; p < count; ++p) { FileRead(&strLen, 1); - FileRead(&strBuf, strLen); //player anim file + FileRead(&strBuf, strLen); // player anim file strBuf[strLen] = '\0'; FileRead(&strLen, 1); - FileRead(&playerScriptList[p].scriptPath, strLen); // player script file - playerScriptList[p].scriptPath[strLen] = '\0'; + FileRead(&PlayerScriptList[p].scriptPath, strLen); // player script file + PlayerScriptList[p].scriptPath[strLen] = '\0'; if (characterID == p) { GetFileInfo(&info); @@ -91,21 +90,19 @@ void LoadPlayerFromList(byte characterID, byte playerID) } } -void ProcessPlayerAnimationChange(Player *player) -{ +void ProcessPlayerAnimationChange(Player *player) { if (player->animation != player->prevAnimation) { if (player->animation == ANI_JUMPING) - player->YPos += (hitboxList[0].bottom[0] - hitboxList[1].bottom[0]) << 16; + player->YPos += (PlayerCBoxes[0].bottom[0] - PlayerCBoxes[1].bottom[0]) << 16; if (player->prevAnimation == ANI_JUMPING) - player->YPos -= (hitboxList[0].bottom[0] - hitboxList[1].bottom[0]) << 16; + player->YPos -= (PlayerCBoxes[0].bottom[0] - PlayerCBoxes[1].bottom[0]) << 16; player->prevAnimation = player->animation; player->frame = 0; player->animationTimer = 0; } } -void DrawPlayer(Player *player, SpriteFrame *frame) -{ +void DrawPlayer(Player *player, SpriteFrame *frame) { int rotation = 0; switch (player->animation) { case ANI_RUNNING: @@ -119,64 +116,59 @@ void DrawPlayer(Player *player, SpriteFrame *frame) break; default: break; } - DrawSpriteRotated(player->direction, player->screenXPos, player->screenYPos, -frame->pivotX, -frame->pivotY, frame->sprX, frame->sprY, + DrawRotatedSprite(player->direction, player->screenXPos, player->screenYPos, -frame->pivotX, -frame->pivotY, frame->sprX, frame->sprY, frame->width, frame->height, rotation, frame->sheetID); } -void ProcessPlayerControl(Player *Player) -{ - if (Player->controlMode == -1) { - upBuffer <<= 1; - upBuffer |= (byte)Player->up; - downBuffer <<= 1; - downBuffer |= (byte)Player->down; - leftBuffer <<= 1; - leftBuffer |= (byte)Player->left; - rightBuffer <<= 1; - rightBuffer |= (byte)Player->right; - jumpPressBuffer <<= 1; - jumpPressBuffer |= (byte)Player->jumpPress; - jumpHoldBuffer <<= 1; - jumpHoldBuffer |= (byte)Player->jumpHold; - } - else if (Player->controlMode == 1) { - Player->up = upBuffer >> 15; - Player->down = downBuffer >> 15; - Player->left = leftBuffer >> 15; - Player->right = rightBuffer >> 15; - Player->jumpPress = jumpPressBuffer >> 15; - Player->jumpHold = jumpHoldBuffer >> 15; - } - else { - Player->up = keyDown.up; - Player->down = keyDown.down; - if (!keyDown.left || !keyDown.right) { - Player->left = keyDown.left; - Player->right = keyDown.right; - } - else { +void ProcessPlayerControl(Player *Player) { + if (Player->controlMode == CONTROLMODE_NONE) { + DelayUp <<= 1; + DelayUp |= (byte)Player->up; + DelayDown <<= 1; + DelayDown |= (byte)Player->down; + DelayLeft <<= 1; + DelayLeft |= (byte)Player->left; + DelayRight <<= 1; + DelayRight |= (byte)Player->right; + DelayJumpPress <<= 1; + DelayJumpPress |= (byte)Player->jumpPress; + DelayJumpHold <<= 1; + DelayJumpHold |= (byte)Player->jumpHold; + } else if (Player->controlMode == CONTROLMODE_SIDEKICK) { + Player->up = DelayUp >> 15; + Player->down = DelayDown >> 15; + Player->left = DelayLeft >> 15; + Player->right = DelayRight >> 15; + Player->jumpPress = DelayJumpPress >> 15; + Player->jumpHold = DelayJumpHold >> 15; + } else if (Player->controlMode == CONTROLMODE_NORMAL) { + Player->up = GKeyDown.up; + Player->down = GKeyDown.down; + if (!GKeyDown.left || !GKeyDown.right) { + Player->left = GKeyDown.left; + Player->right = GKeyDown.right; + } else { Player->left = false; Player->right = false; } - Player->jumpHold = keyDown.C | keyDown.B | keyDown.A; - Player->jumpPress = keyPress.C | keyPress.B | keyPress.A; - upBuffer <<= 1; - upBuffer |= (byte)Player->up; - downBuffer <<= 1; - downBuffer |= (byte)Player->down; - leftBuffer <<= 1; - leftBuffer |= (byte)Player->left; - rightBuffer <<= 1; - rightBuffer |= (byte)Player->right; - jumpPressBuffer <<= 1; - jumpPressBuffer |= (byte)Player->jumpPress; - jumpHoldBuffer <<= 1; - jumpHoldBuffer |= (byte)Player->jumpHold; + Player->jumpHold = GKeyDown.C | GKeyDown.B | GKeyDown.A; + Player->jumpPress = GKeyPress.C | GKeyPress.B | GKeyPress.A; + DelayUp <<= 1; + DelayUp |= (byte)Player->up; + DelayDown <<= 1; + DelayDown |= (byte)Player->down; + DelayLeft <<= 1; + DelayLeft |= (byte)Player->left; + DelayRight <<= 1; + DelayRight |= (byte)Player->right; + DelayJumpPress <<= 1; + DelayJumpPress |= (byte)Player->jumpPress; + DelayJumpHold <<= 1; + DelayJumpHold |= (byte)Player->jumpHold; } } -void SetMovementStats(PlayerMovementStats *stats) -{ +void SetMovementStats(PlayerMovementStats *stats) { stats->topSpeed = 0x60000; stats->acceleration = 0xC00; stats->deceleration = 0xC00; @@ -187,21 +179,18 @@ void SetMovementStats(PlayerMovementStats *stats) stats->rollingDeceleration = 0x2000; } -void DefaultAirMovement(Player* player) -{ +void ProcessDefaultAirMovement(Player *player) { if (player->speed <= -player->stats.topSpeed) { if (player->left) player->direction = FLIP_X; - } - else if (player->left) { + } else if (player->left) { player->speed -= player->stats.airAcceleration; player->direction = FLIP_X; } if (player->speed >= player->stats.topSpeed) { if (player->right) player->direction = FLIP_NONE; - } - else if (player->right) { + } else if (player->right) { player->speed += player->stats.airAcceleration; player->direction = FLIP_NONE; } @@ -210,22 +199,19 @@ void DefaultAirMovement(Player* player) player->speed -= player->speed >> 5; } -void DefaultGravityFalse(Player *player) -{ +void ProcessDefaultGravityFalse(Player *player) { player->trackScroll = false; - player->XVelocity = (player->speed * cosVal256[player->angle]) >> 8; - player->YVelocity = (player->speed * sinVal256[player->angle]) >> 8; + player->XVelocity = (player->speed * CosValue256[player->angle]) >> 8; + player->YVelocity = (player->speed * SinValue256[player->angle]) >> 8; } -void DefaultGravityTrue(Player* player) -{ +void ProcessDefaultGravityTrue(Player *player) { player->trackScroll = true; player->YVelocity += player->stats.gravityStrength; if (player->YVelocity >= -0x33CB0) { player->timer = 0; - } - else if (!player->jumpHold && player->timer > 0) { - player->timer = 0; + } else if (!player->jumpHold && player->timer > 0) { + player->timer = 0; player->YVelocity = -0x3C800; player->speed -= player->speed >> 5; } @@ -237,29 +223,25 @@ void DefaultGravityTrue(Player* player) player->rotation = 0; } } - } - else { + } else { player->rotation -= 2; if (player->rotation < 1) player->rotation = 0; } } -void DefaultGroundMovement(Player *player) -{ +void ProcessDefaultGroundMovement(Player *player) { if ((signed int)player->frictionLoss <= 0) { if (player->left && player->speed > -player->stats.topSpeed) { if (player->speed <= 0) { player->speed -= player->stats.acceleration; player->skidding = 0; - } - else { + } else { if (player->speed > 0x40000) player->skidding = 16; if (player->speed >= 0x8000) { player->speed -= 0x8000; - } - else { + } else { player->speed = -0x8000; player->skidding = 0; } @@ -269,14 +251,12 @@ void DefaultGroundMovement(Player *player) if (player->speed >= 0) { player->speed += player->stats.acceleration; player->skidding = 0; - } - else { + } else { if (player->speed < -0x40000) player->skidding = 16; if (player->speed <= -0x8000) { player->speed += 0x8000; - } - else { + } else { player->speed = 0x8000; player->skidding = 0; } @@ -290,35 +270,31 @@ void DefaultGroundMovement(Player *player) if (player->left || player->right) { switch (player->collisionMode) { - case CMODE_FLOOR: - player->speed += sinVal256[player->angle] << 13 >> 8; - break; + case CMODE_FLOOR: player->speed += SinValue256[player->angle] << 13 >> 8; break; case CMODE_LWALL: if (player->angle >= 176) { - player->speed += (sinVal256[player->angle] << 13 >> 8); - } - else { + player->speed += (SinValue256[player->angle] << 13 >> 8); + } else { if (player->speed < -0x60000 || player->speed > 0x60000) - player->speed += sinVal256[player->angle] << 13 >> 8; + player->speed += SinValue256[player->angle] << 13 >> 8; else - player->speed += 0x1400 * sinVal256[player->angle] >> 8; + player->speed += 0x1400 * SinValue256[player->angle] >> 8; } break; case CMODE_ROOF: if (player->speed < -0x60000 || player->speed > 0x60000) - player->speed += sinVal256[player->angle] << 13 >> 8; + player->speed += SinValue256[player->angle] << 13 >> 8; else - player->speed += 0x1400 * sinVal256[player->angle] >> 8; + player->speed += 0x1400 * SinValue256[player->angle] >> 8; break; case CMODE_RWALL: if (player->angle <= 80) { - player->speed += sinVal256[player->angle] << 13 >> 8; - } - else { + player->speed += SinValue256[player->angle] << 13 >> 8; + } else { if (player->speed < -0x60000 || player->speed > 0x60000) - player->speed += sinVal256[player->angle] << 13 >> 8; + player->speed += SinValue256[player->angle] << 13 >> 8; else - player->speed += 0x1400 * sinVal256[player->angle] >> 8; + player->speed += 0x1400 * SinValue256[player->angle] >> 8; } break; default: break; @@ -340,8 +316,7 @@ void DefaultGroundMovement(Player *player) } } } - } - else { + } else { if (player->speed < 0) { player->speed += player->stats.deceleration; if (player->speed > 0) @@ -353,25 +328,23 @@ void DefaultGroundMovement(Player *player) player->speed = 0; } if (player->speed < -0x4000 || player->speed > 0x4000) - player->speed += sinVal256[player->angle] << 13 >> 8; + player->speed += SinValue256[player->angle] << 13 >> 8; if ((player->angle > 30 && player->angle < 64) || (player->angle > 192 && player->angle < 226)) { if (player->speed > -0x10000 && player->speed < 0x10000) player->frictionLoss = 30; } } - } - else { + } else { --player->frictionLoss; - player->speed = (sinVal256[player->angle] << 13 >> 8) + player->speed; + player->speed = (SinValue256[player->angle] << 13 >> 8) + player->speed; } } -void DefaultJumpAction(Player *player) -{ +void ProcessDefaultJumpAction(Player *player) { player->frictionLoss = 0; player->gravity = true; - player->XVelocity = (player->speed * cosVal256[player->angle] + player->stats.jumpStrength * sinVal256[player->angle]) >> 8; - player->YVelocity = (player->speed * sinVal256[player->angle] + -player->stats.jumpStrength * cosVal256[player->angle]) >> 8; + player->XVelocity = (player->speed * CosValue256[player->angle] + player->stats.jumpStrength * SinValue256[player->angle]) >> 8; + player->YVelocity = (player->speed * SinValue256[player->angle] + -player->stats.jumpStrength * CosValue256[player->angle]) >> 8; player->speed = player->XVelocity; player->trackScroll = true; player->animation = ANI_JUMPING; @@ -380,8 +353,7 @@ void DefaultJumpAction(Player *player) player->timer = 1; } -void DefaultRollingMovement(Player *player) -{ +void ProcessDefaultRollingMovement(Player *player) { if (player->right && player->speed < 0) player->speed += player->stats.rollingDeceleration; if (player->left && player->speed > 0) @@ -401,51 +373,45 @@ void DefaultRollingMovement(Player *player) player->state = 0; if (player->speed <= 0) { - if (sinVal256[player->angle] >= 0) { - player->speed += (player->stats.rollingDeceleration * sinVal256[player->angle] >> 8); - } - else { - player->speed += 0x5000 * sinVal256[player->angle] >> 8; + if (SinValue256[player->angle] >= 0) { + player->speed += (player->stats.rollingDeceleration * SinValue256[player->angle] >> 8); + } else { + player->speed += 0x5000 * SinValue256[player->angle] >> 8; } - } - else if (sinVal256[player->angle] <= 0) { - player->speed += (player->stats.rollingDeceleration * sinVal256[player->angle] >> 8); - } - else { - player->speed += 0x5000 * sinVal256[player->angle] >> 8; + } else if (SinValue256[player->angle] <= 0) { + player->speed += (player->stats.rollingDeceleration * SinValue256[player->angle] >> 8); + } else { + player->speed += 0x5000 * SinValue256[player->angle] >> 8; } if (player->speed > 0x180000) player->speed = 0x180000; } -void ProcessDebugMode(Player *player) -{ +void ProcessDebugMode(Player *player) { if (player->down || player->up || player->right || player->left) { if (player->speed < 0x100000) { player->speed += 0xC00; if (player->speed > 0x100000) player->speed = 0x100000; } - } - else { + } else { player->speed = 0; } - if (keyDown.left) + if (GKeyDown.left) player->XPos -= player->speed; - if (keyDown.right) + if (GKeyDown.right) player->XPos += player->speed; - if (keyDown.up) + if (GKeyDown.up) player->YPos -= player->speed; - if (keyDown.down) + if (GKeyDown.down) player->YPos += player->speed; } -void ProcessPlayerAnimation(Player *player) -{ - PlayerScript *script = &playerScriptList[player->type]; +void ProcessPlayerAnimation(Player *player) { + PlayerScript *script = &PlayerScriptList[player->type]; if (!player->gravity) { int speed = (player->jumpingSpeed * abs(player->speed) / 6 >> 16) + 48; if (speed > 0xF0) @@ -474,9 +440,9 @@ void ProcessPlayerAnimation(Player *player) player->animationTimer += script->animations[player->animation].speed; if (player->animation != player->prevAnimation) { if (player->animation == ANI_JUMPING) - player->YPos += (hitboxList[0].bottom[0] - hitboxList[1].bottom[0]) << 16; + player->YPos += (PlayerCBoxes[0].bottom[0] - PlayerCBoxes[1].bottom[0]) << 16; if (player->prevAnimation == ANI_JUMPING) - player->YPos -= (hitboxList[0].bottom[0] - hitboxList[1].bottom[0]) << 16; + player->YPos -= (PlayerCBoxes[0].bottom[0] - PlayerCBoxes[1].bottom[0]) << 16; player->prevAnimation = player->animation; player->frame = 0; player->animationTimer = 0; diff --git a/Nexus/Player.hpp b/Nexus/Player.hpp index 828b9e9..0e11f33 100644 --- a/Nexus/Player.hpp +++ b/Nexus/Player.hpp @@ -1,7 +1,7 @@ #ifndef PLAYER_H #define PLAYER_H -#define PLAYER_COUNT (0x2) +#define PLAYER_COUNT (0x2) enum PlayerAni { ANI_STOPPED, @@ -27,12 +27,17 @@ enum PlayerAni { ANI_FLAILINGRIGHT, ANI_SLIDING, ANI_FINISHPOSE = 23, - ANI_CORKSCREW = 34, - ANI_HANGING = 43, + ANI_CORKSCREW = 34, + ANI_HANGING = 43, }; -struct PlayerMovementStats -{ +enum PlayerControlModes { + CONTROLMODE_NONE = -1, + CONTROLMODE_NORMAL = 0, + CONTROLMODE_SIDEKICK = 1, +}; + +struct PlayerMovementStats { int topSpeed; int acceleration; int deceleration; @@ -104,18 +109,17 @@ struct PlayerScript { byte startJumpSpeed; }; - -extern Player playerList[PLAYER_COUNT]; -extern PlayerScript playerScriptList[PLAYER_COUNT]; -extern int activePlayer; +extern Player PlayerList[PLAYER_COUNT]; +extern PlayerScript PlayerScriptList[PLAYER_COUNT]; +extern int PlayerNo; extern int activePlayerCount; -extern ushort upBuffer; -extern ushort downBuffer; -extern ushort leftBuffer; -extern ushort rightBuffer; -extern ushort jumpPressBuffer; -extern ushort jumpHoldBuffer; +extern ushort DelayUp; +extern ushort DelayDown; +extern ushort DelayLeft; +extern ushort DelayRight; +extern ushort DelayJumpPress; +extern ushort DelayJumpHold; void LoadPlayerFromList(byte characterID, byte playerID); @@ -126,12 +130,12 @@ void ProcessPlayerControl(Player *player); void SetMovementStats(PlayerMovementStats *stats); -void DefaultAirMovement(Player *player); -void DefaultGravityFalse(Player *player); -void DefaultGravityTrue(Player *player); -void DefaultGroundMovement(Player *player); -void DefaultJumpAction(Player *player); -void DefaultRollingMovement(Player *player); +void ProcessDefaultAirMovement(Player *player); +void ProcessDefaultGravityFalse(Player *player); +void ProcessDefaultGravityTrue(Player *player); +void ProcessDefaultGroundMovement(Player *player); +void ProcessDefaultJumpAction(Player *player); +void ProcessDefaultRollingMovement(Player *player); void ProcessDebugMode(Player *player); void ProcessPlayerAnimation(Player *player); diff --git a/Nexus/Reader.cpp b/Nexus/Reader.cpp index 6875154..1342d52 100644 --- a/Nexus/Reader.cpp +++ b/Nexus/Reader.cpp @@ -4,71 +4,67 @@ char binFileName[0x400]; char fileName[0x100]; -byte fileBuffer[0x2000]; -int fileSize; -int vFileSize; -int readPos; -int readSize; -int bufferPosition; -int virtualFileOffset; +byte FileBuffer[0x2000]; +int FileSize; +int VFileSize; +int ReadPos; +int ReadSize; +int BufferPosition; +int VirtualFileOffset; byte isModdedFile = false; -FileIO *cFileHandle = nullptr; +FileIO *CFileHandle = nullptr; -bool CheckBinFile(const char *filePath) -{ +bool CheckBinFile(const char *filePath) { FileInfo info; - Engine.usingBinFile = false; + Engine.UseBinFile = false; Engine.usingDataFileStore = false; - cFileHandle = fOpen(filePath, "rb"); - if (cFileHandle) { - Engine.usingBinFile = true; + CFileHandle = fOpen(filePath, "rb"); + if (CFileHandle) { + Engine.UseBinFile = true; StrCopy(binFileName, filePath); - fClose(cFileHandle); - cFileHandle = NULL; + fClose(CFileHandle); + CFileHandle = NULL; return true; - } - else { - Engine.usingBinFile = false; - cFileHandle = NULL; + } else { + Engine.UseBinFile = false; + CFileHandle = NULL; return false; } return false; } -inline bool ends_with(std::string const &value, std::string const &ending) -{ +inline bool ends_with(std::string const &value, std::string const &ending) { if (ending.size() > value.size()) return false; return std::equal(ending.rbegin(), ending.rend(), value.rbegin()); } -bool LoadFile(const char *filePath, FileInfo *fileInfo) -{ +bool LoadFile(const char *filePath, FileInfo *fileInfo) { MEM_ZEROP(fileInfo); - if (cFileHandle) - fClose(cFileHandle); + if (CFileHandle) + fClose(CFileHandle); - cFileHandle = NULL; + CFileHandle = NULL; char filePathBuf[0x100]; StrCopy(filePathBuf, filePath); if (Engine.forceFolder) - Engine.usingBinFile = Engine.usingDataFileStore; + Engine.UseBinFile = Engine.usingDataFileStore; Engine.forceFolder = false; - Engine.usingDataFileStore = Engine.usingBinFile; + Engine.usingDataFileStore = Engine.UseBinFile; #if RETRO_USE_MOD_LOADER fileInfo->isMod = false; isModdedFile = false; #endif - bool addPath = true; + bool addPath = true; // Fixes any case differences char pathLower[0x100]; memset(pathLower, 0, sizeof(char) * 0x100); @@ -82,11 +78,11 @@ bool LoadFile(const char *filePath, FileInfo *fileInfo) std::map::const_iterator iter = modList[m].fileMap.find(pathLower); if (iter != modList[m].fileMap.cend()) { StrCopy(filePathBuf, iter->second.c_str()); - Engine.forceFolder = true; - Engine.usingBinFile = false; - fileInfo->isMod = true; - isModdedFile = true; - addPath = false; + Engine.forceFolder = true; + Engine.UseBinFile = false; + fileInfo->isMod = true; + isModdedFile = true; + addPath = false; break; } } @@ -104,58 +100,56 @@ bool LoadFile(const char *filePath, FileInfo *fileInfo) StrCopy(fileInfo->fileName, ""); StrCopy(fileName, ""); - if (Engine.usingBinFile && !Engine.forceFolder) { - cFileHandle = fOpen(binFileName, "rb"); - fSeek(cFileHandle, 0, SEEK_END); - fileSize = (int)fTell(cFileHandle); - bufferPosition = 0; - readSize = 0; - readPos = 0; + if (Engine.UseBinFile && !Engine.forceFolder) { + CFileHandle = fOpen(binFileName, "rb"); + fSeek(CFileHandle, 0, SEEK_END); + FileSize = (int)fTell(CFileHandle); + BufferPosition = 0; + ReadSize = 0; + ReadPos = 0; StrCopy(fileInfo->fileName, filePath); StrCopy(fileName, filePath); if (!ParseVirtualFileSystem(fileInfo)) { - fClose(cFileHandle); - cFileHandle = NULL; - printLog("Couldn't load file '%s'", filePathBuf); + fClose(CFileHandle); + CFileHandle = NULL; + PrintLog("Couldn't load file '%s'", filePathBuf); return false; } - fileInfo->readPos = readPos; - fileInfo->fileSize = vFileSize; - fileInfo->virtualFileOffset = virtualFileOffset; - fileInfo->bufferPosition = bufferPosition; + fileInfo->readPos = ReadPos; + fileInfo->fileSize = VFileSize; + fileInfo->virtualFileOffset = VirtualFileOffset; + fileInfo->bufferPosition = BufferPosition; fileInfo->encrypted = true; - } - else { + } else { StrCopy(fileInfo->fileName, filePathBuf); StrCopy(fileName, filePathBuf); - cFileHandle = fOpen(fileInfo->fileName, "rb"); - if (!cFileHandle) { - printLog("Couldn't load file '%s'", filePathBuf); + CFileHandle = fOpen(fileInfo->fileName, "rb"); + if (!CFileHandle) { + PrintLog("Couldn't load file '%s'", filePathBuf); return false; } - virtualFileOffset = 0; - fSeek(cFileHandle, 0, SEEK_END); - fileInfo->fileSize = (int)fTell(cFileHandle); - fileSize = fileInfo->fileSize; - fSeek(cFileHandle, 0, SEEK_SET); - readPos = 0; - fileInfo->readPos = readPos; + VirtualFileOffset = 0; + fSeek(CFileHandle, 0, SEEK_END); + fileInfo->fileSize = (int)fTell(CFileHandle); + FileSize = fileInfo->fileSize; + fSeek(CFileHandle, 0, SEEK_SET); + ReadPos = 0; + fileInfo->readPos = ReadPos; fileInfo->virtualFileOffset = 0; fileInfo->bufferPosition = 0; fileInfo->encrypted = false; } - bufferPosition = 0; - readSize = 0; + BufferPosition = 0; + ReadSize = 0; - printLog("Loaded File '%s'", filePathBuf); + PrintLog("Loaded File '%s'", filePathBuf); return true; } -bool ParseVirtualFileSystem(FileInfo *fileInfo) -{ +bool ParseVirtualFileSystem(FileInfo *fileInfo) { char filename[0x50]; char fullFilename[0x50]; char stringBuffer[0x50]; @@ -167,13 +161,12 @@ bool ParseVirtualFileSystem(FileInfo *fileInfo) byte fileBuffer = 0; int j = 0; - virtualFileOffset = 0; + VirtualFileOffset = 0; for (int i = 0; fileInfo->fileName[i]; i++) { if (fileInfo->fileName[i] == '/') { fNamePos = i; j = 0; - } - else { + } else { ++j; } fullFilename[i] = fileInfo->fileName[i]; @@ -183,11 +176,11 @@ bool ParseVirtualFileSystem(FileInfo *fileInfo) filename[j] = 0; fullFilename[fNamePos] = 0; - fSeek(cFileHandle, 0, SEEK_SET); - Engine.usingBinFile = false; - bufferPosition = 0; - readSize = 0; - readPos = 0; + fSeek(CFileHandle, 0, SEEK_SET); + Engine.UseBinFile = false; + BufferPosition = 0; + ReadSize = 0; + ReadPos = 0; FileRead(&fileBuffer, 1); headerSize = fileBuffer; @@ -224,9 +217,8 @@ bool ParseVirtualFileSystem(FileInfo *fileInfo) // Grab info for next dir to know when we've found an error // Ignore dir name we dont care if (i == dirCount - 1) { - nextFileOffset = fileSize - headerSize; // There is no next dir, so just make this the EOF - } - else { + nextFileOffset = FileSize - headerSize; // There is no next dir, so just make this the EOF + } else { FileRead(&fileBuffer, 1); for (j = 0; j < fileBuffer; ++j) { FileRead(&stringBuffer[j], 1); @@ -245,8 +237,7 @@ bool ParseVirtualFileSystem(FileInfo *fileInfo) } i = dirCount; - } - else { + } else { fileOffset = -1; FileRead(&fileBuffer, 1); FileRead(&fileBuffer, 1); @@ -257,24 +248,23 @@ bool ParseVirtualFileSystem(FileInfo *fileInfo) } if (fileOffset == -1) { - Engine.usingBinFile = true; + Engine.UseBinFile = true; return false; - } - else { - fSeek(cFileHandle, fileOffset + headerSize, SEEK_SET); - bufferPosition = 0; - readSize = 0; - readPos = 0; - virtualFileOffset = fileOffset + headerSize; + } else { + fSeek(CFileHandle, fileOffset + headerSize, SEEK_SET); + BufferPosition = 0; + ReadSize = 0; + ReadPos = 0; + VirtualFileOffset = fileOffset + headerSize; i = 0; while (i < 1) { FileRead(&fileBuffer, 1); - ++virtualFileOffset; + ++VirtualFileOffset; j = 0; while (j < fileBuffer) { FileRead(&stringBuffer[j], 1); ++j; - ++virtualFileOffset; + ++VirtualFileOffset; } stringBuffer[j] = 0; @@ -288,10 +278,9 @@ bool ParseVirtualFileSystem(FileInfo *fileInfo) j += fileBuffer << 16; FileRead(&fileBuffer, 1); j += fileBuffer << 24; - virtualFileOffset += 4; - vFileSize = j; - } - else { + VirtualFileOffset += 4; + VFileSize = j; + } else { FileRead(&fileBuffer, 1); j = fileBuffer; FileRead(&fileBuffer, 1); @@ -300,117 +289,107 @@ bool ParseVirtualFileSystem(FileInfo *fileInfo) j += fileBuffer << 16; FileRead(&fileBuffer, 1); j += fileBuffer << 24; - virtualFileOffset += 4; - virtualFileOffset += j; + VirtualFileOffset += 4; + VirtualFileOffset += j; } // No File has been found (next file would be in a new dir) - if (virtualFileOffset >= nextFileOffset + headerSize) { - Engine.usingBinFile = true; + if (VirtualFileOffset >= nextFileOffset + headerSize) { + Engine.UseBinFile = true; return false; } - fSeek(cFileHandle, virtualFileOffset, SEEK_SET); - bufferPosition = 0; - readSize = 0; - readPos = virtualFileOffset; + fSeek(CFileHandle, VirtualFileOffset, SEEK_SET); + BufferPosition = 0; + ReadSize = 0; + ReadPos = VirtualFileOffset; } - Engine.usingBinFile = true; + Engine.UseBinFile = true; return true; } - // Engine.usingBinFile = true; + // Engine.UseBinFile = true; return false; } -void FileRead(void *dest, int size) -{ +void FileRead(void *dest, int size) { byte *data = (byte *)dest; - if (readPos <= fileSize) { - if (Engine.usingBinFile && !Engine.forceFolder) { + if (ReadPos <= FileSize) { + if (Engine.UseBinFile && !Engine.forceFolder) { while (size > 0) { - if (bufferPosition == readSize) + if (BufferPosition == ReadSize) FillFileBuffer(); - *data++ = fileBuffer[bufferPosition++] ^ 0xFF; + *data++ = FileBuffer[BufferPosition++] ^ 0xFF; size--; } - } - else { + } else { while (size > 0) { - if (bufferPosition == readSize) + if (BufferPosition == ReadSize) FillFileBuffer(); - *data++ = fileBuffer[bufferPosition++]; + *data++ = FileBuffer[BufferPosition++]; size--; } } } } -void SetFileInfo(FileInfo *fileInfo) -{ +void SetFileInfo(FileInfo *fileInfo) { Engine.forceFolder = false; if (!fileInfo->isMod) { - Engine.usingBinFile = Engine.usingDataFileStore; - } - else { + Engine.UseBinFile = Engine.usingDataFileStore; + } else { Engine.forceFolder = true; } isModdedFile = fileInfo->isMod; - if (Engine.usingBinFile && !Engine.forceFolder) { - cFileHandle = fOpen(binFileName, "rb"); - virtualFileOffset = fileInfo->virtualFileOffset; - vFileSize = fileInfo->fileSize; - fSeek(cFileHandle, 0, SEEK_END); - fileSize = (int)fTell(cFileHandle); - readPos = fileInfo->readPos; - fSeek(cFileHandle, readPos, SEEK_SET); + if (Engine.UseBinFile && !Engine.forceFolder) { + CFileHandle = fOpen(binFileName, "rb"); + VirtualFileOffset = fileInfo->virtualFileOffset; + VFileSize = fileInfo->fileSize; + fSeek(CFileHandle, 0, SEEK_END); + FileSize = (int)fTell(CFileHandle); + ReadPos = fileInfo->readPos; + fSeek(CFileHandle, ReadPos, SEEK_SET); FillFileBuffer(); - bufferPosition = fileInfo->bufferPosition; - } - else { + BufferPosition = fileInfo->bufferPosition; + } else { StrCopy(fileName, fileInfo->fileName); - cFileHandle = fOpen(fileInfo->fileName, "rb"); - virtualFileOffset = 0; - fileSize = fileInfo->fileSize; - readPos = fileInfo->readPos; - fSeek(cFileHandle, readPos, SEEK_SET); + CFileHandle = fOpen(fileInfo->fileName, "rb"); + VirtualFileOffset = 0; + FileSize = fileInfo->fileSize; + ReadPos = fileInfo->readPos; + fSeek(CFileHandle, ReadPos, SEEK_SET); FillFileBuffer(); - bufferPosition = fileInfo->bufferPosition; + BufferPosition = fileInfo->bufferPosition; } } -size_t GetFilePosition() -{ - if (Engine.usingBinFile) - return bufferPosition + readPos - readSize - virtualFileOffset; +size_t GetFilePosition() { + if (Engine.UseBinFile) + return BufferPosition + ReadPos - ReadSize - VirtualFileOffset; else - return bufferPosition + readPos - readSize; + return BufferPosition + ReadPos - ReadSize; } -void SetFilePosition(int newPos) -{ - if (Engine.usingBinFile) { - readPos = virtualFileOffset + newPos; - } - else { - readPos = newPos; +void SetFilePosition(int newPos) { + if (Engine.UseBinFile) { + ReadPos = VirtualFileOffset + newPos; + } else { + ReadPos = newPos; } - fSeek(cFileHandle, readPos, SEEK_SET); + fSeek(CFileHandle, ReadPos, SEEK_SET); FillFileBuffer(); } -bool ReachedEndOfFile() -{ - if (Engine.usingBinFile) - return bufferPosition + readPos - readSize - virtualFileOffset >= vFileSize; +bool ReachedEndOfFile() { + if (Engine.UseBinFile) + return BufferPosition + ReadPos - ReadSize - VirtualFileOffset >= VFileSize; else - return bufferPosition + readPos - readSize >= fileSize; + return BufferPosition + ReadPos - ReadSize >= FileSize; } -bool LoadFile2(const char *filePath, FileInfo *fileInfo) -{ +bool LoadFile2(const char *filePath, FileInfo *fileInfo) { if (fileInfo->cFileHandle) fClose(fileInfo->cFileHandle); @@ -420,10 +399,10 @@ bool LoadFile2(const char *filePath, FileInfo *fileInfo) StrCopy(filePathBuf, filePath); if (Engine.forceFolder) - Engine.usingBinFile = Engine.usingDataFileStore; + Engine.UseBinFile = Engine.usingDataFileStore; Engine.forceFolder = false; - Engine.usingDataFileStore = Engine.usingBinFile; + Engine.usingDataFileStore = Engine.UseBinFile; #if RETRO_USE_MOD_LOADER fileInfo->isMod = false; @@ -443,11 +422,11 @@ bool LoadFile2(const char *filePath, FileInfo *fileInfo) std::map::const_iterator iter = modList[m].fileMap.find(pathLower); if (iter != modList[m].fileMap.cend()) { StrCopy(filePathBuf, iter->second.c_str()); - Engine.forceFolder = true; - Engine.usingBinFile = false; - fileInfo->isMod = true; - isModdedFile = true; - addPath = false; + Engine.forceFolder = true; + Engine.UseBinFile = false; + fileInfo->isMod = true; + isModdedFile = true; + addPath = false; break; } } @@ -464,12 +443,12 @@ bool LoadFile2(const char *filePath, FileInfo *fileInfo) StrCopy(fileInfo->fileName, ""); - if (Engine.usingBinFile && !Engine.forceFolder) { + if (Engine.UseBinFile && !Engine.forceFolder) { fileInfo->cFileHandle = fOpen(binFileName, "rb"); fSeek(fileInfo->cFileHandle, 0, SEEK_END); fileInfo->fileSize = (int)fTell(fileInfo->cFileHandle); fileInfo->bufferPosition = 0; - // readSize = 0; + // ReadSize = 0; fileInfo->readPos = 0; fileInfo->encrypted = true; @@ -477,7 +456,7 @@ bool LoadFile2(const char *filePath, FileInfo *fileInfo) if (!ParseVirtualFileSystem2(fileInfo)) { fClose(fileInfo->cFileHandle); fileInfo->cFileHandle = NULL; - printLog("Couldn't load file '%s'", filePathBuf); + PrintLog("Couldn't load file '%s'", filePathBuf); return false; } fileInfo->fileBuffer = (byte *)malloc(fileInfo->vFileSize); @@ -485,12 +464,11 @@ bool LoadFile2(const char *filePath, FileInfo *fileInfo) fileInfo->readPos = 0; fileInfo->bufferPosition = 0; fClose(fileInfo->cFileHandle); - } - else { + } else { StrCopy(fileInfo->fileName, filePathBuf); fileInfo->cFileHandle = fOpen(fileInfo->fileName, "rb"); if (!fileInfo->cFileHandle) { - printLog("Couldn't load file '%s'", filePathBuf); + PrintLog("Couldn't load file '%s'", filePathBuf); return false; } @@ -498,8 +476,8 @@ bool LoadFile2(const char *filePath, FileInfo *fileInfo) fileInfo->vFileSize = (int)fTell(fileInfo->cFileHandle); fileInfo->fileSize = fileInfo->vFileSize; fSeek(fileInfo->cFileHandle, 0, SEEK_SET); - readPos = 0; - fileInfo->readPos = readPos; + ReadPos = 0; + fileInfo->readPos = ReadPos; fileInfo->virtualFileOffset = 0; fileInfo->bufferPosition = 0; fileInfo->fileBuffer = (byte *)malloc(fileInfo->vFileSize); @@ -507,17 +485,16 @@ bool LoadFile2(const char *filePath, FileInfo *fileInfo) fileInfo->readPos = 0; fileInfo->bufferPosition = 0; fClose(fileInfo->cFileHandle); - fileInfo->encrypted = false; + fileInfo->encrypted = false; } fileInfo->bufferPosition = 0; - printLog("Loaded File '%s'", filePathBuf); + PrintLog("Loaded File '%s'", filePathBuf); return true; } -bool ParseVirtualFileSystem2(FileInfo *fileInfo) -{ +bool ParseVirtualFileSystem2(FileInfo *fileInfo) { char filename[0x50]; char fullFilename[0x50]; char stringBuffer[0x50]; @@ -534,8 +511,7 @@ bool ParseVirtualFileSystem2(FileInfo *fileInfo) if (fileInfo->fileName[i] == '/') { fNamePos = i; j = 0; - } - else { + } else { ++j; } fullFilename[i] = fileInfo->fileName[i]; @@ -546,9 +522,9 @@ bool ParseVirtualFileSystem2(FileInfo *fileInfo) fullFilename[fNamePos] = 0; fSeek(fileInfo->cFileHandle, 0, SEEK_SET); - Engine.usingBinFile = false; + Engine.UseBinFile = false; fileInfo->bufferPosition = 0; - // readSize = 0; + // ReadSize = 0; fileInfo->readPos = 0; FileRead2(fileInfo, &fileBuffer, 1, false); @@ -586,9 +562,8 @@ bool ParseVirtualFileSystem2(FileInfo *fileInfo) // Grab info for next dir to know when we've found an error // Ignore dir name we dont care if (i == dirCount - 1) { - nextFileOffset = fileSize - headerSize; // There is no next dir, so just make this the EOF - } - else { + nextFileOffset = FileSize - headerSize; // There is no next dir, so just make this the EOF + } else { FileRead2(fileInfo, &fileBuffer, 1, false); for (j = 0; j < fileBuffer; ++j) { FileRead2(fileInfo, &stringBuffer[j], 1, false); @@ -605,8 +580,7 @@ bool ParseVirtualFileSystem2(FileInfo *fileInfo) } i = dirCount; - } - else { + } else { fileOffset = -1; FileRead2(fileInfo, &fileBuffer, 1, false); FileRead2(fileInfo, &fileBuffer, 1, false); @@ -617,12 +591,11 @@ bool ParseVirtualFileSystem2(FileInfo *fileInfo) } if (fileOffset == -1) { - Engine.usingBinFile = true; + Engine.UseBinFile = true; return false; - } - else { + } else { fSeek(fileInfo->cFileHandle, fileOffset + headerSize, SEEK_SET); - fileInfo->bufferPosition = 0; + fileInfo->bufferPosition = 0; fileInfo->readPos = 0; fileInfo->virtualFileOffset = fileOffset + headerSize; i = 0; @@ -649,8 +622,7 @@ bool ParseVirtualFileSystem2(FileInfo *fileInfo) j += fileBuffer << 24; fileInfo->virtualFileOffset += 4; fileInfo->vFileSize = j; - } - else { + } else { FileRead2(fileInfo, &fileBuffer, 1, false); j = fileBuffer; FileRead2(fileInfo, &fileBuffer, 1, false); @@ -665,23 +637,22 @@ bool ParseVirtualFileSystem2(FileInfo *fileInfo) // No File has been found (next file would be in a new dir) if (fileInfo->virtualFileOffset >= nextFileOffset + headerSize) { - Engine.usingBinFile = true; + Engine.UseBinFile = true; return false; } fSeek(fileInfo->cFileHandle, fileInfo->virtualFileOffset, SEEK_SET); fileInfo->bufferPosition = 0; - // readSize = 0; + // ReadSize = 0; fileInfo->readPos = fileInfo->virtualFileOffset; } - Engine.usingBinFile = true; + Engine.UseBinFile = true; return true; } - // Engine.usingBinFile = true; + // Engine.UseBinFile = true; return false; } -size_t FileRead2(FileInfo *info, void *dest, int size, bool fromBuffer) -{ +size_t FileRead2(FileInfo *info, void *dest, int size, bool fromBuffer) { byte *data = (byte *)dest; int rPos = (int)GetFilePosition2(info); memset(data, 0, size); @@ -693,10 +664,9 @@ size_t FileRead2(FileInfo *info, void *dest, int size, bool fromBuffer) info->readPos += size; info->bufferPosition = 0; return size; - } - else { + } else { if (rPos <= info->fileSize) { - if (Engine.usingBinFile && !Engine.forceFolder) { + if (Engine.UseBinFile && !Engine.forceFolder) { int rSize = 0; if (rPos + size <= info->fileSize) rSize = size; @@ -713,8 +683,7 @@ size_t FileRead2(FileInfo *info, void *dest, int size, bool fromBuffer) } return result; - } - else { + } else { int rSize = 0; if (rPos + size <= info->fileSize) rSize = size; diff --git a/Nexus/Reader.hpp b/Nexus/Reader.hpp index 10ea3dc..f9ad949 100644 --- a/Nexus/Reader.hpp +++ b/Nexus/Reader.hpp @@ -52,16 +52,16 @@ struct FileInfo { extern char binFileName[0x400]; extern char fileName[0x100]; -extern byte fileBuffer[0x2000]; -extern int fileSize; -extern int vFileSize; -extern int readPos; -extern int readSize; -extern int bufferPosition; -extern int virtualFileOffset; +extern byte FileBuffer[0x2000]; +extern int FileSize; +extern int VFileSize; +extern int ReadPos; +extern int ReadSize; +extern int BufferPosition; +extern int VirtualFileOffset; extern byte isModdedFile; -extern FileIO *cFileHandle; +extern FileIO *CFileHandle; inline void CopyFilePath(char *dest, const char *src) { @@ -81,10 +81,10 @@ bool LoadFile(const char *filePath, FileInfo *fileInfo); inline bool CloseFile() { int result = 0; - if (cFileHandle) - result = fClose(cFileHandle); + if (CFileHandle) + result = fClose(CFileHandle); - cFileHandle = NULL; + CFileHandle = NULL; return result; } @@ -94,25 +94,25 @@ bool ParseVirtualFileSystem(FileInfo *fileInfo); inline size_t FillFileBuffer() { - if (readPos + 0x2000 <= fileSize) - readSize = 0x2000; + if (ReadPos + 0x2000 <= FileSize) + ReadSize = 0x2000; else - readSize = fileSize - readPos; + ReadSize = FileSize - ReadPos; - size_t result = fRead(fileBuffer, 1u, readSize, cFileHandle); - readPos += readSize; - bufferPosition = 0; + size_t result = fRead(FileBuffer, 1u, ReadSize, CFileHandle); + ReadPos += ReadSize; + BufferPosition = 0; return result; } inline void GetFileInfo(FileInfo *fileInfo) { StrCopy(fileInfo->fileName, fileName); - fileInfo->bufferPosition = bufferPosition; - fileInfo->readPos = readPos - readSize; - fileInfo->fileSize = fileSize; - fileInfo->vFileSize = vFileSize; - fileInfo->virtualFileOffset = virtualFileOffset; + fileInfo->bufferPosition = BufferPosition; + fileInfo->readPos = ReadPos - ReadSize; + fileInfo->fileSize = FileSize; + fileInfo->vFileSize = VFileSize; + fileInfo->virtualFileOffset = VirtualFileOffset; fileInfo->isMod = isModdedFile; } void SetFileInfo(FileInfo *fileInfo); diff --git a/Nexus/RetroEngine.cpp b/Nexus/RetroEngine.cpp index 2b6a569..29f8bd5 100644 --- a/Nexus/RetroEngine.cpp +++ b/Nexus/RetroEngine.cpp @@ -9,8 +9,7 @@ bool engineDebugMode = false; RetroEngine Engine = RetroEngine(); -inline int getLowerRate(int intendRate, int targetRate) -{ +inline int getLowerRate(int intendRate, int targetRate) { int result = 0; int valStore = 0; @@ -25,8 +24,7 @@ inline int getLowerRate(int intendRate, int targetRate) return result; } -bool processEvents() -{ +bool processEvents() { #if RETRO_USING_SDL1 || RETRO_USING_SDL2 while (SDL_PollEvent(&Engine.sdlEvents)) { // Main Events @@ -40,12 +38,12 @@ bool processEvents() Engine.isFullScreen = true; break; } - case SDL_WINDOWEVENT_CLOSE: Engine.gameMode = ENGINE_EXITGAME; return false; + case SDL_WINDOWEVENT_CLOSE: Engine.GameMode = ENGINE_EXITGAME; return false; } break; case SDL_CONTROLLERDEVICEADDED: controllerInit(Engine.sdlEvents.cdevice.which); break; case SDL_CONTROLLERDEVICEREMOVED: controllerClose(Engine.sdlEvents.cdevice.which); break; - case SDL_APP_TERMINATING: Engine.gameMode = ENGINE_EXITGAME; break; + case SDL_APP_TERMINATING: Engine.GameMode = ENGINE_EXITGAME; break; #endif case SDL_KEYDOWN: switch (Engine.sdlEvents.key.keysym.sym) { @@ -55,73 +53,57 @@ bool processEvents() if (Engine.devMenu) { #if RETRO_USE_MOD_LOADER // hacky patch because people can escape - if (Engine.gameMode == ENGINE_SYSMENU && stageMode == DEVMENU_MODMENU) { - // Reload entire engine - Engine.LoadGameConfig("Data/Game/GameConfig.bin"); -#if RETRO_USING_SDL1 || RETRO_USING_SDL2 - if (Engine.window) { - char gameTitle[0x40]; - sprintf(gameTitle, "%s%s", Engine.gameWindowText, Engine.usingBinFile ? "" : " (Using Data Folder)"); - SDL_SetWindowTitle(Engine.window, gameTitle); - } -#endif - - ReleaseStageSfx(); - ReleaseGlobalSfx(); - LoadGlobalSfx(); - - saveMods(); + if (Engine.GameMode == ENGINE_SYSMENU && StageMode == DEVMENU_MODMENU) { + RefreshEngine(); } #endif - Engine.gameMode = ENGINE_INITSYSMENU; - } - else { - Engine.gameMode = ENGINE_EXITGAME; + Engine.GameMode = ENGINE_INITSYSMENU; + } else { + Engine.GameMode = ENGINE_EXITGAME; return false; } break; case SDLK_F1: if (Engine.devMenu) { - activeStageList = 0; - stageListPosition = 0; - stageMode = STAGEMODE_LOAD; - Engine.gameMode = ENGINE_MAINGAME; - } - else { - Engine.running = false; + ActiveStageList = 0; + StageListPosition = 0; + StageMode = STAGEMODE_LOAD; + Engine.GameMode = ENGINE_MAINGAME; + } else { + Engine.GameRunning = false; } break; case SDLK_F2: if (Engine.devMenu) { - stageListPosition--; - while (stageListPosition < 0) { - activeStageList--; + StageListPosition--; + while (StageListPosition < 0) { + ActiveStageList--; - if (activeStageList < 0) - activeStageList = 3; - stageListPosition = stageListCount[activeStageList] - 1; + if (ActiveStageList < 0) + ActiveStageList = 3; + StageListPosition = stageListCount[ActiveStageList] - 1; } - stageMode = STAGEMODE_LOAD; - Engine.gameMode = ENGINE_MAINGAME; + StageMode = STAGEMODE_LOAD; + Engine.GameMode = ENGINE_MAINGAME; } break; case SDLK_F3: if (Engine.devMenu) { - stageListPosition++; - while (stageListPosition >= stageListCount[activeStageList]) { - activeStageList++; + StageListPosition++; + while (StageListPosition >= stageListCount[ActiveStageList]) { + ActiveStageList++; - stageListPosition = 0; + StageListPosition = 0; - if (activeStageList >= 4) - activeStageList = 0; + if (ActiveStageList >= 4) + ActiveStageList = 0; } - stageMode = STAGEMODE_LOAD; - Engine.gameMode = ENGINE_MAINGAME; + StageMode = STAGEMODE_LOAD; + Engine.GameMode = ENGINE_MAINGAME; } break; @@ -138,8 +120,7 @@ bool processEvents() SDL_RestoreWindow(Engine.window); SDL_SetWindowFullscreen(Engine.window, SDL_WINDOW_FULLSCREEN_DESKTOP); #endif - } - else { + } else { #if RETRO_USING_SDL1 Engine.windowSurface = SDL_SetVideoMode(SCREEN_XSIZE * Engine.windowScale, SCREEN_YSIZE * Engine.windowScale, 16, SDL_SWSURFACE); @@ -157,8 +138,8 @@ bool processEvents() case SDLK_F5: if (Engine.devMenu) { - currentStageFolder[0] = 0; // reload all assets & scripts - stageMode = STAGEMODE_LOAD; + CurrentStageFolder[0] = 0; // reload all assets & scripts + StageMode = STAGEMODE_LOAD; } break; @@ -214,19 +195,20 @@ bool processEvents() keyState[Engine.sdlEvents.key.keysym.sym] = 0; #endif break; - case SDL_QUIT: Engine.gameMode = ENGINE_EXITGAME; return false; + case SDL_QUIT: Engine.GameMode = ENGINE_EXITGAME; return false; } } #endif return true; } -void RetroEngine::Init() -{ +void RetroEngine::Init() { CalculateTrigAngles(); +#if !RETRO_USE_ORIGINAL_CODE InitUserdata(); +#endif #if RETRO_USE_MOD_LOADER - initMods(); + InitMods(); #endif char dest[0x200]; #if RETRO_PLATFORM == RETRO_UWP @@ -248,15 +230,15 @@ void RetroEngine::Init() #endif CheckBinFile(dest); - gameMode = ENGINE_EXITGAME; - running = false; + GameMode = ENGINE_EXITGAME; + GameRunning = false; if (LoadGameConfig("Data/Game/GameConfig.bin")) { if (InitRenderDevice()) { - if (InitAudioPlayback()) { + if (InitSoundDevice()) { InitSystemMenu(); ClearScriptData(); initialised = true; - running = true; + GameRunning = true; } } } @@ -267,12 +249,11 @@ void RetroEngine::Init() skipFrameIndex = refreshRate / lower; } -void RetroEngine::Run() -{ +void RetroEngine::Run() { unsigned long long targetFreq = SDL_GetPerformanceFrequency() / Engine.refreshRate; unsigned long long curTicks = 0; - - while (running) { + + while (GameRunning) { #if !RETRO_USE_ORIGINAL_CODE if (!vsync) { if (SDL_GetPerformanceCounter() < curTicks + targetFreq) @@ -280,17 +261,18 @@ void RetroEngine::Run() curTicks = SDL_GetPerformanceCounter(); } #endif - running = processEvents(); + GameRunning = processEvents(); for (int s = 0; s < gameSpeed; ++s) { - ProcessInput(); + ReadInputDevice(); if (!masterPaused || frameStep) { - switch (gameMode) { + switch (GameMode) { case ENGINE_SYSMENU: ProcessSystemMenu(); + FlipScreen(); break; - case ENGINE_MAINGAME: + case ENGINE_MAINGAME: ProcessStage(); break; case ENGINE_INITSYSMENU: @@ -298,21 +280,22 @@ void RetroEngine::Run() InitSystemMenu(); ResetCurrentStageFolder(); break; - case ENGINE_EXITGAME: running = false; break; + case ENGINE_EXITGAME: + GameRunning = false; + break; default: break; } } } - FlipScreen(); - frameStep = false; + frameStep = false; } - ReleaseAudioDevice(); + ReleaseSoundDevice(); ReleaseRenderDevice(); - writeSettings(); + WriteSettings(); #if RETRO_USE_MOD_LOADER - saveMods(); + SaveMods(); #endif #if RETRO_USING_SDL1 || RETRO_USING_SDL2 @@ -320,8 +303,7 @@ void RetroEngine::Run() #endif } -bool RetroEngine::LoadGameConfig(const char *filePath) -{ +bool RetroEngine::LoadGameConfig(const char *filePath) { FileInfo info; byte fileBuffer = 0; byte fileBuffer2 = 0; @@ -331,16 +313,16 @@ bool RetroEngine::LoadGameConfig(const char *filePath) if (LoadFile(filePath, &info)) { FileRead(&fileBuffer, 1); - FileRead(gameWindowText, fileBuffer); - gameWindowText[fileBuffer] = 0; + FileRead(GameWindowText, fileBuffer); + GameWindowText[fileBuffer] = 0; FileRead(&fileBuffer, 1); FileRead(&data, fileBuffer); // Load 'Data' data[fileBuffer] = 0; FileRead(&fileBuffer, 1); - FileRead(gameDescriptionText, fileBuffer); - gameDescriptionText[fileBuffer] = 0; + FileRead(GameDescriptionText, fileBuffer); + GameDescriptionText[fileBuffer] = 0; // Read Script Paths byte scriptCount = 0; @@ -352,22 +334,22 @@ bool RetroEngine::LoadGameConfig(const char *filePath) byte varCount = 0; FileRead(&varCount, 1); - globalVariablesCount = varCount; + NO_GLOBALVARIABLES = varCount; for (byte v = 0; v < varCount; ++v) { // Read Variable Name FileRead(&fileBuffer, 1); - FileRead(&globalVariableNames[v], fileBuffer); - globalVariableNames[v][fileBuffer] = 0; + FileRead(&GlobalVariableNames[v], fileBuffer); + GlobalVariableNames[v][fileBuffer] = 0; // Read Variable Value FileRead(&fileBuffer2, 1); - globalVariables[v] = fileBuffer2 << 24; + GlobalVariables[v] = fileBuffer2 << 24; FileRead(&fileBuffer2, 1); - globalVariables[v] += fileBuffer2 << 16; + GlobalVariables[v] += fileBuffer2 << 16; FileRead(&fileBuffer2, 1); - globalVariables[v] += fileBuffer2 << 8; + GlobalVariables[v] += fileBuffer2 << 8; FileRead(&fileBuffer2, 1); - globalVariables[v] += fileBuffer2; + GlobalVariables[v] += fileBuffer2; } // Read SFX @@ -424,7 +406,6 @@ bool RetroEngine::LoadGameConfig(const char *filePath) // Read Stage Mode FileRead(&fileBuffer, 1); stageList[cat][s].highlighted = fileBuffer; - } } diff --git a/Nexus/RetroEngine.hpp b/Nexus/RetroEngine.hpp index de5011d..762574c 100644 --- a/Nexus/RetroEngine.hpp +++ b/Nexus/RetroEngine.hpp @@ -11,7 +11,7 @@ #endif #ifndef RETRO_USE_MOD_LOADER -#define RETRO_USE_MOD_LOADER (0) +#define RETRO_USE_MOD_LOADER (0) #endif #if !RETRO_USE_ORIGINAL_CODE @@ -43,7 +43,7 @@ typedef unsigned int uint; #define RETRO_ANDROID (5) #define RETRO_WP7 (6) // Custom Platforms start here -#define RETRO_UWP (7) +#define RETRO_UWP (7) // Platform types (Game manages platform-specific code such as HUD position using this rather than the above) #define RETRO_STANDARD (0) @@ -83,15 +83,14 @@ typedef unsigned int uint; #define DEFAULT_SCREEN_XSIZE 320 #define DEFAULT_FULLSCREEN false #else -#define BASE_PATH "" +#define BASE_PATH "" #define RETRO_USING_MOUSE #define RETRO_USING_TOUCH #define DEFAULT_SCREEN_XSIZE 320 #define DEFAULT_FULLSCREEN false #endif -#if RETRO_PLATFORM == RETRO_WIN || RETRO_PLATFORM == RETRO_OSX || RETRO_PLATFORM == RETRO_iOS \ - || RETRO_PLATFORM == RETRO_UWP +#if RETRO_PLATFORM == RETRO_WIN || RETRO_PLATFORM == RETRO_OSX || RETRO_PLATFORM == RETRO_iOS || RETRO_PLATFORM == RETRO_UWP #define RETRO_USING_SDL1 (0) #define RETRO_USING_SDL2 (1) #else // Since its an else & not an elif these platforms probably aren't supported yet @@ -100,10 +99,10 @@ typedef unsigned int uint; #endif enum RetroStates { - ENGINE_SYSMENU = 0, - ENGINE_MAINGAME = 1, - ENGINE_INITSYSMENU = 2, - ENGINE_EXITGAME = 3, + ENGINE_SYSMENU = 0, + ENGINE_MAINGAME = 1, + ENGINE_INITSYSMENU = 2, + ENGINE_EXITGAME = 3, }; // General Defines @@ -152,25 +151,23 @@ extern bool engineDebugMode; #include "Video.hpp" #include "Userdata.hpp" #include "Debug.hpp" +#include "ModAPI.hpp" -class RetroEngine -{ +class RetroEngine { public: - RetroEngine() - { - } + RetroEngine() {} - bool usingBinFile = false; + bool UseBinFile = false; bool usingDataFileStore = false; bool forceFolder = false; char dataFile[0x80]; bool initialised = false; - bool running = false; + bool GameRunning = false; - int gameMode = 1; - byte colourMode = 1; //16-bit + int GameMode = ENGINE_MAINGAME; + byte ColourMode = 1; // 16-bit int frameSkipSetting = 0; int frameSkipTimer = 0; @@ -196,10 +193,10 @@ class RetroEngine bool LoadGameConfig(const char *Filepath); - char gameWindowText[0x40]; - char gameDescriptionText[0x100]; + char GameWindowText[0x40]; + char GameDescriptionText[0x100]; - byte *pixelBuffer = nullptr; + byte *FrameBuffer = nullptr; bool isFullScreen = false; diff --git a/Nexus/Scene.cpp b/Nexus/Scene.cpp index d1f9510..76fc911 100644 --- a/Nexus/Scene.cpp +++ b/Nexus/Scene.cpp @@ -10,211 +10,224 @@ char stageListNames[STAGELIST_MAX][0x20] = { }; SceneInfo stageList[STAGELIST_MAX][0x100]; -int stageMode = STAGEMODE_LOAD; - -int cameraStyle = CAMERASTYLE_FOLLOW; -int cameraEnabled = false; -int cameraAdjustY = 0; -int xScrollOffset = 0; -int yScrollOffset = 0; -int yScrollA = 0; -int yScrollB = SCREEN_YSIZE; -int xScrollA = 0; -int xScrollB = SCREEN_XSIZE; -int yScrollMove = 0; -int earthquakeX = 0; -int earthquakeY = 0; -int cameraLag = 0; - -int xBoundary1 = 0; -int newXBoundary1 = 0; -int yBoundary1 = 0; -int newYBoundary1 = 0; -int xBoundary2 = 0; -int yBoundary2 = 0; -int waterLevel = 0x7FFFFFF; +int StageMode = STAGEMODE_LOAD; + +int CameraStyle = CAMERASTYLE_FOLLOW; +int CameraEnabled = false; +int cameraAdjustY = 0; +int XScrollOffset = 0; +int YScrollOffset = 0; +int YScrollA = 0; +int YScrollB = SCREEN_YSIZE; +int XScrollA = 0; +int XScrollB = SCREEN_XSIZE; +int YScrollMove = 0; +int EarthquakeX = 0; +int EarthquakeY = 0; +int XScrollMove = 0; + +int XBoundary1 = 0; +int NewXBoundary1 = 0; +int YBoundary1 = 0; +int NewYBoundary1 = 0; +int XBoundary2 = 0; +int YBoundary2 = 0; +int WaterLevel = 0x7FFFFFF; int waterDrawPos = SCREEN_YSIZE; -int newXBoundary2 = 0; -int newYBoundary2 = 0; +int NewXBoundary2 = 0; +int NewYBoundary2 = 0; int SCREEN_SCROLL_LEFT = SCREEN_CENTERX - 8; int SCREEN_SCROLL_RIGHT = SCREEN_CENTERX + 8; -int lastYSize = -1; -int lastXSize = -1; +int LastYSize = -1; +int LastXSize = -1; -bool pauseEnabled = true; -bool timeEnabled = true; -bool debugMode = false; -int frameCounter = 0; -int stageMilliseconds = 0; -int stageSeconds = 0; -int stageMinutes = 0; +bool PauseEnabled = true; +bool TimeEnabled = true; +bool debugMode = false; +int FrameCounter = 0; +int MilliSeconds = 0; +int Seconds = 0; +int Minutes = 0; // Category and Scene IDs -int activeStageList = 0; -int stageListPosition = 0; -char currentStageFolder[0x100]; -int actID = 0; +int ActiveStageList = 0; +int StageListPosition = 0; +char CurrentStageFolder[0x100]; +int ActNumber = 0; char titleCardText[0x100]; byte titleCardWord2 = 0; byte activeTileLayers[4]; byte tLayerMidPoint; -TileLayer stageLayouts[LAYER_COUNT]; +TileLayer StageLayouts[LAYER_COUNT]; -int bgDeformationData0[DEFORM_COUNT]; -int bgDeformationData1[DEFORM_COUNT]; -int bgDeformationData2[DEFORM_COUNT]; -int bgDeformationData3[DEFORM_COUNT]; +int BGDeformationData1[DEFORM_COUNT]; +int BGDeformationData2[DEFORM_COUNT]; +int BGDeformationData3[DEFORM_COUNT]; +int BGDeformationData4[DEFORM_COUNT]; -int fgDeformationOffset = 0; -int fgDeformationOffsetW = 0; -int bgDeformationOffset = 0; -int bgDeformationOffsetW = 0; +int DeformationPos1 = 0; +int DeformationPos2 = 0; +int DeformationPos3 = 0; +int DeformationPos4 = 0; -LineScroll hParallax; -LineScroll vParallax; +LineScroll HParallax; +LineScroll VParallax; -Tiles128x128 tiles128x128; -CollisionMasks collisionMasks[2]; +Tiles128x128 StageTiles; +CollisionMasks TileCollisions[2]; -byte tilesetGFXData[TILESET_SIZE]; +byte TileGfx[TILESET_SIZE]; -void ProcessStage(void) -{ - switch (stageMode) { +void ProcessStage(void) { + switch (StageMode) { case STAGEMODE_LOAD: - cameraEnabled = true; - xScrollOffset = 0; - yScrollOffset = 0; - pauseEnabled = false; - timeEnabled = false; - stageMilliseconds = 0; - stageSeconds = 0; - stageMinutes = 0; + CameraEnabled = true; + XScrollOffset = 0; + YScrollOffset = 0; + PauseEnabled = false; + TimeEnabled = false; + MilliSeconds = 0; + Seconds = 0; + Minutes = 0; + LoadStageFiles(); for (int i = 0; i < PLAYER_COUNT; ++i) { - MEM_ZERO(playerList[i]); - playerList[i].visible = true; - playerList[i].gravity = 1; // Air - playerList[i].tileCollisions = true; - playerList[i].objectInteraction = true; + PlayerList[i].visible = true; + PlayerList[i].state = 0; + PlayerList[i].collisionPlane = 0; + PlayerList[i].collisionMode = 0; + PlayerList[i].gravity = 1; // Air + PlayerList[i].YVelocity = 0; + PlayerList[i].XVelocity = 0; + PlayerList[i].speed = 0; + PlayerList[i].direction = FLIP_NONE; + PlayerList[i].tileCollisions = true; + PlayerList[i].objectInteraction = true; } - LoadStageFiles(); - stageMode = STAGEMODE_NORMAL; + StageMode = STAGEMODE_NORMAL; break; case STAGEMODE_NORMAL: - if (fadeMode > 0) - fadeMode--; - - lastXSize = -1; - lastYSize = -1; - CheckKeyDown(&keyDown, 0xFF); - CheckKeyPress(&keyPress, 0xFF); - if (pauseEnabled && keyPress.start) { - stageMode = STAGEMODE_PAUSED; + if (PaletteMode > 0) + PaletteMode--; + + LastXSize = -1; + LastYSize = -1; + CheckKeyDown(&GKeyDown, 0xFF); + CheckKeyPress(&GKeyPress, 0xFF); + if (PauseEnabled && GKeyPress.start) { + StageMode = STAGEMODE_PAUSED; PauseSound(); } - if (timeEnabled) { - if (++frameCounter == Engine.refreshRate) { - frameCounter = 0; - if (++stageSeconds > 59) { - stageSeconds = 0; - if (++stageMinutes > 59) - stageMinutes = 0; + if (TimeEnabled) { +#if !RETRO_USE_ORIGINAL_CODE + if (++FrameCounter == Engine.refreshRate) { +#else + if (++FrameCounter == 60) { +#endif + FrameCounter = 0; + if (++Seconds > 59) { + Seconds = 0; + if (++Minutes > 59) + Minutes = 0; } } - stageMilliseconds = 100 * frameCounter / Engine.refreshRate; + MilliSeconds = 100 * FrameCounter / (!RETRO_USE_ORIGINAL_CODE ? Engine.refreshRate : 60); } // Update ProcessObjects(); - if (objectEntityList[0].type == OBJ_TYPE_PLAYER) { - if (cameraEnabled) { - switch (cameraStyle) { - case CAMERASTYLE_FOLLOW: SetPlayerScreenPosition(&playerList[0]); break; - case CAMERASTYLE_EXTENDED: SetPlayerScreenPositionCDStyle(&playerList[0]); break; + if (ObjectEntityList[0].type == OBJ_TYPE_PLAYER) { + if (CameraEnabled) { + switch (CameraStyle) { + case CAMERASTYLE_FOLLOW: SetPlayerScreenPosition(&PlayerList[0]); break; + case CAMERASTYLE_EXTENDED: SetPlayerScreenPositionCDStyle(&PlayerList[0]); break; default: break; } - } - else { - SetPlayerLockedScreenPosition(&playerList[0]); + } else { + SetPlayerLockedScreenPosition(&PlayerList[0]); } } - DrawStageGFX(); + DrawStageGfx(); + FlipScreen(); break; case STAGEMODE_PAUSED: - if (fadeMode > 0) - fadeMode--; - - lastXSize = -1; - lastYSize = -1; - CheckKeyDown(&keyDown, 0xFF); - CheckKeyPress(&keyPress, 0xFF); - - if (keyPress.C) { - keyPress.C = false; - if (timeEnabled) { - if (++frameCounter == Engine.refreshRate) { - frameCounter = 0; - if (++stageSeconds > 59) { - stageSeconds = 0; - if (++stageMinutes > 59) - stageMinutes = 0; + if (PaletteMode) + PaletteMode--; + + LastXSize = -1; + LastYSize = -1; + CheckKeyDown(&GKeyDown, 0xFF); + CheckKeyPress(&GKeyPress, 0xFF); + + if (GKeyPress.C) { + GKeyPress.C = false; + if (TimeEnabled) { +#if !RETRO_USE_ORIGINAL_CODE + if (++FrameCounter == Engine.refreshRate) { +#else + if (++FrameCounter == 60) { +#endif + FrameCounter = 0; + if (++Seconds > 59) { + Seconds = 0; + if (++Minutes > 59) + Minutes = 0; } } - stageMilliseconds = 100 * frameCounter / Engine.refreshRate; + MilliSeconds = 100 * FrameCounter / (!RETRO_USE_ORIGINAL_CODE ? Engine.refreshRate : 60); } // Update ProcessObjects(); - if (objectEntityList[0].type == OBJ_TYPE_PLAYER) { - if (cameraEnabled) { - switch (cameraStyle) { - case CAMERASTYLE_FOLLOW: SetPlayerScreenPosition(&playerList[0]); break; - case CAMERASTYLE_EXTENDED: SetPlayerScreenPositionCDStyle(&playerList[0]); break; + if (ObjectEntityList[0].type == OBJ_TYPE_PLAYER) { + if (CameraEnabled) { + switch (CameraStyle) { + case CAMERASTYLE_FOLLOW: SetPlayerScreenPosition(&PlayerList[0]); break; + case CAMERASTYLE_EXTENDED: SetPlayerScreenPositionCDStyle(&PlayerList[0]); break; default: break; } - } - else { - SetPlayerLockedScreenPosition(&playerList[0]); + } else { + SetPlayerLockedScreenPosition(&PlayerList[0]); } } - DrawStageGFX(); + DrawStageGfx(); } - if (pauseEnabled && keyPress.start) { - stageMode = STAGEMODE_NORMAL; + if (GKeyPress.start) { + StageMode = STAGEMODE_NORMAL; ResumeSound(); } break; } } -void LoadStageFiles(void) -{ +void LoadStageFiles(void) { StopAllSfx(); FileInfo infoStore; FileInfo info; byte fileBuffer = 0; byte fileBuffer2 = 0; - int scriptID = 2; + int scriptID = 2; char strBuffer[0x100]; - if (!CheckCurrentStageFolder(stageListPosition)) { - printLog("Loading Scene %s - %s", stageListNames[activeStageList], stageList[activeStageList][stageListPosition].name); + if (!CheckCurrentStageFolder(StageListPosition)) { +#if !RETRO_USE_ORIGINAL_CODE + PrintLog("Loading Scene %s - %s", stageListNames[ActiveStageList], stageList[ActiveStageList][StageListPosition].name); +#endif ReleaseStageSfx(); LoadPalette("Data/Palettes/MasterPalette.act", 0, 256); ClearScriptData(); for (int i = SPRITESHEETS_MAX; i > 0; i--) RemoveGraphicsFile((char *)"", i - 1); bool loadGlobals = false; - if (LoadStageFile("StageConfig.bin", stageListPosition, &info)) { + if (LoadStageFile("StageConfig.bin", StageListPosition, &info)) { FileRead(&loadGlobals, 1); CloseFile(); } @@ -240,7 +253,7 @@ void LoadStageFiles(void) CloseFile(); } - if (LoadStageFile("StageConfig.bin", stageListPosition, &info)) { + if (LoadStageFile("StageConfig.bin", StageListPosition, &info)) { FileRead(&fileBuffer, 1); // Load Globals for (int i = 96; i < 128; ++i) { byte clr[3]; @@ -261,79 +274,73 @@ void LoadStageFiles(void) } FileRead(&fileBuffer2, 1); - stageSFXCount = fileBuffer2; - for (int i = 0; i < stageSFXCount; ++i) { + NoStageSFX = fileBuffer2; + for (int i = 0; i < NoStageSFX; ++i) { FileRead(&fileBuffer2, 1); FileRead(strBuffer, fileBuffer2); strBuffer[fileBuffer2] = 0; GetFileInfo(&infoStore); CloseFile(); - LoadSfx(strBuffer, globalSFXCount + i); + LoadSfx(strBuffer, NoGlobalSFX + i); SetFileInfo(&infoStore); } CloseFile(); } FileInfo info; for (int p = 0; p < PLAYER_COUNT; ++p) { - if (playerScriptList[p].scriptPath[0]) - ParseScriptFile(playerScriptList[p].scriptPath, p); + if (PlayerScriptList[p].scriptPath[0]) + ParseScriptFile(PlayerScriptList[p].scriptPath, p); } - if (LoadStageFile("16x16Tiles.gif", stageListPosition, &info)) { - CloseFile(); - LoadStageGIFFile(stageListPosition); - } - else { - LoadStageGFXFile(stageListPosition); - } + LoadStageGIFFile(StageListPosition); + Load128x128Mappings(); LoadStageCollisions(); LoadStageBackground(); +#if !RETRO_USE_ORIGINAL_CODE + } else { + PrintLog("Reloading Scene %s - %s", stageListNames[ActiveStageList], stageList[ActiveStageList][StageListPosition].name); } - else { - printLog("Reloading Scene %s - %s", stageListNames[activeStageList], stageList[activeStageList][stageListPosition].name); - } - LoadStageChunks(); +#endif + for (int i = 0; i < TRACK_COUNT; ++i) SetMusicTrack((char *)"", i, false); for (int i = 0; i < ENTITY_COUNT; ++i) { - MEM_ZERO(objectEntityList[i]); - objectEntityList[i].drawOrder = 3; - objectEntityList[i].scale = 512; + MEM_ZERO(ObjectEntityList[i]); + ObjectEntityList[i].drawOrder = 3; + ObjectEntityList[i].scale = 512; } LoadActLayout(); - ProcessStartupObjects(); - xScrollA = (playerList[0].XPos >> 16) - SCREEN_CENTERX; - xScrollB = (playerList[0].XPos >> 16) - SCREEN_CENTERX + SCREEN_XSIZE; - yScrollA = (playerList[0].YPos >> 16) - SCREEN_SCROLL_UP; - yScrollB = (playerList[0].YPos >> 16) - SCREEN_SCROLL_UP + SCREEN_YSIZE; + ProcessStartupScripts(); + + XScrollA = (PlayerList[0].XPos >> 16) - SCREEN_CENTERX; + XScrollB = (PlayerList[0].XPos >> 16) - (SCREEN_CENTERX + SCREEN_XSIZE); + YScrollA = (PlayerList[0].YPos >> 16) - SCREEN_SCROLL_UP; + YScrollB = (PlayerList[0].YPos >> 16) - (SCREEN_SCROLL_UP + SCREEN_YSIZE); } -int LoadActFile(const char *ext, int stageID, FileInfo *info) -{ +int LoadActFile(const char *ext, int stageID, FileInfo *info) { char dest[0x40]; StrCopy(dest, "Data/Stages/"); - StrAdd(dest, stageList[activeStageList][stageID].folder); + StrAdd(dest, stageList[ActiveStageList][stageID].folder); StrAdd(dest, "/Act"); - StrAdd(dest, stageList[activeStageList][stageID].id); + StrAdd(dest, stageList[ActiveStageList][stageID].id); StrAdd(dest, ext); - ConvertStringToInteger(stageList[activeStageList][stageID].id, &actID); + ConvertStringToInteger(stageList[ActiveStageList][stageID].id, &ActNumber); return LoadFile(dest, info); } -int LoadStageFile(const char *filePath, int stageID, FileInfo *info) -{ +int LoadStageFile(const char *filePath, int stageID, FileInfo *info) { char dest[0x40]; StrCopy(dest, "Data/Stages/"); - StrAdd(dest, stageList[activeStageList][stageID].folder); + StrAdd(dest, stageList[ActiveStageList][stageID].folder); StrAdd(dest, "/"); StrAdd(dest, filePath); return LoadFile(dest, info); } -void LoadActLayout() -{ +void LoadActLayout() { FileInfo info; - if (LoadActFile(".bin", stageListPosition, &info)) { + if (LoadActFile(".bin", StageListPosition, &info)) { byte length = 0; FileRead(&length, 1); titleCardWord2 = (byte)length; @@ -348,24 +355,24 @@ void LoadActLayout() FileRead(activeTileLayers, 4); FileRead(&tLayerMidPoint, 1); - FileRead(&stageLayouts[0].xsize, 1); - FileRead(&stageLayouts[0].ysize, 1); - xBoundary1 = 0; - newXBoundary1 = 0; - yBoundary1 = 0; - newYBoundary1 = 0; - xBoundary2 = stageLayouts[0].xsize << 7; - yBoundary2 = stageLayouts[0].ysize << 7; - waterLevel = yBoundary2 + 128; - newXBoundary2 = stageLayouts[0].xsize << 7; - newYBoundary2 = stageLayouts[0].ysize << 7; + FileRead(&StageLayouts[0].xsize, 1); + FileRead(&StageLayouts[0].ysize, 1); + XBoundary1 = 0; + NewXBoundary1 = 0; + YBoundary1 = 0; + NewYBoundary1 = 0; + XBoundary2 = StageLayouts[0].xsize << 7; + YBoundary2 = StageLayouts[0].ysize << 7; + WaterLevel = YBoundary2 + 128; + NewXBoundary2 = StageLayouts[0].xsize << 7; + NewYBoundary2 = StageLayouts[0].ysize << 7; - for (int i = 0; i < 0x10000; ++i) stageLayouts[0].tiles[i] = 0; + for (int i = 0; i < 0x10000; ++i) StageLayouts[0].tiles[i] = 0; byte fileBuffer = 0; - for (int y = 0; y < stageLayouts[0].ysize; ++y) { - ushort *tiles = &stageLayouts[0].tiles[(y * 0x100)]; - for (int x = 0; x < stageLayouts[0].xsize; ++x) { + for (int y = 0; y < StageLayouts[0].ysize; ++y) { + ushort *tiles = &StageLayouts[0].tiles[(y * 0x100)]; + for (int x = 0; x < StageLayouts[0].xsize; ++x) { FileRead(&fileBuffer, 1); tiles[x] = fileBuffer << 8; FileRead(&fileBuffer, 1); @@ -388,8 +395,8 @@ void LoadActLayout() FileRead(&fileBuffer, 1); int objectCount = fileBuffer; FileRead(&fileBuffer, 1); - objectCount = (objectCount << 8) + fileBuffer; - Entity *object = &objectEntityList[32]; + objectCount = (objectCount << 8) + fileBuffer; + Entity *object = &ObjectEntityList[32]; for (int i = 0; i < objectCount; ++i) { FileRead(&fileBuffer, 1); object->type = fileBuffer; @@ -409,84 +416,82 @@ void LoadActLayout() object->YPos += fileBuffer; object->YPos <<= 16; - if (object->type == OBJ_TYPE_PLAYER && playerList[0].type == object->propertyValue) { - Entity *player = &objectEntityList[0]; + if (object->type == OBJ_TYPE_PLAYER && PlayerList[0].type == object->propertyValue) { + Entity *player = &ObjectEntityList[0]; player->type = OBJ_TYPE_PLAYER; player->drawOrder = 4; player->priority = true; - playerList[0].XPos = object->XPos; - playerList[0].YPos = object->YPos; - SetMovementStats(&playerList[0].stats); - playerList[0].walkingSpeed = playerScriptList[playerList[0].type].startWalkSpeed; - playerList[0].runningSpeed = playerScriptList[playerList[0].type].startRunSpeed; - playerList[0].jumpingSpeed = playerScriptList[playerList[0].type].startJumpSpeed; + PlayerList[0].XPos = object->XPos; + PlayerList[0].YPos = object->YPos; + SetMovementStats(&PlayerList[0].stats); + PlayerList[0].walkingSpeed = PlayerScriptList[PlayerList[0].type].startWalkSpeed; + PlayerList[0].runningSpeed = PlayerScriptList[PlayerList[0].type].startRunSpeed; + PlayerList[0].jumpingSpeed = PlayerScriptList[PlayerList[0].type].startJumpSpeed; object->type = OBJ_TYPE_BLANKOBJECT; } ++object; } - stageLayouts[0].type = LAYER_HSCROLL; + StageLayouts[0].type = LAYER_HSCROLL; CloseFile(); } } -void LoadStageBackground() -{ +void LoadStageBackground() { for (int i = 0; i < LAYER_COUNT; ++i) { - stageLayouts[i].type = LAYER_NOSCROLL; + StageLayouts[i].type = LAYER_NOSCROLL; } for (int i = 0; i < PARALLAX_COUNT; ++i) { - hParallax.scrollPos[i] = 0; - vParallax.scrollPos[i] = 0; + HParallax.scrollPos[i] = 0; + VParallax.scrollPos[i] = 0; } FileInfo info; - if (LoadStageFile("Backgrounds.bin", stageListPosition, &info)) { + if (LoadStageFile("Backgrounds.bin", StageListPosition, &info)) { byte fileBuffer = 0; byte layerCount = 0; FileRead(&layerCount, 1); - FileRead(&hParallax.entryCount, 1); - for (int i = 0; i < hParallax.entryCount; ++i) { + FileRead(&HParallax.entryCount, 1); + for (int i = 0; i < HParallax.entryCount; ++i) { FileRead(&fileBuffer, 1); - hParallax.parallaxFactor[i] = fileBuffer; + HParallax.parallaxFactor[i] = fileBuffer; FileRead(&fileBuffer, 1); - hParallax.scrollSpeed[i] = fileBuffer << 10; + HParallax.scrollSpeed[i] = fileBuffer << 10; - hParallax.scrollPos[i] = 0; + HParallax.scrollPos[i] = 0; - FileRead(&hParallax.deform[i], 1); + FileRead(&HParallax.deform[i], 1); } - FileRead(&vParallax.entryCount, 1); - for (int i = 0; i < vParallax.entryCount; ++i) { + FileRead(&VParallax.entryCount, 1); + for (int i = 0; i < VParallax.entryCount; ++i) { FileRead(&fileBuffer, 1); - vParallax.parallaxFactor[i] = fileBuffer; + VParallax.parallaxFactor[i] = fileBuffer; FileRead(&fileBuffer, 1); - vParallax.scrollSpeed[i] = fileBuffer << 10; + VParallax.scrollSpeed[i] = fileBuffer << 10; - vParallax.scrollPos[i] = 0; + VParallax.scrollPos[i] = 0; - FileRead(&vParallax.deform[i], 1); + FileRead(&VParallax.deform[i], 1); } for (int i = 1; i < layerCount + 1; ++i) { FileRead(&fileBuffer, 1); - stageLayouts[i].xsize = fileBuffer; + StageLayouts[i].xsize = fileBuffer; FileRead(&fileBuffer, 1); - stageLayouts[i].ysize = fileBuffer; + StageLayouts[i].ysize = fileBuffer; FileRead(&fileBuffer, 1); - stageLayouts[i].type = fileBuffer; + StageLayouts[i].type = fileBuffer; FileRead(&fileBuffer, 1); - stageLayouts[i].parallaxFactor = fileBuffer; + StageLayouts[i].parallaxFactor = fileBuffer; FileRead(&fileBuffer, 1); - stageLayouts[i].scrollSpeed = fileBuffer << 10; - stageLayouts[i].scrollPos = 0; + StageLayouts[i].scrollSpeed = fileBuffer << 10; + StageLayouts[i].scrollPos = 0; - - memset(stageLayouts[i].tiles, 0, TILELAYER_CHUNK_MAX * sizeof(ushort)); - byte *lineScrollPtr = stageLayouts[i].lineScroll; - memset(stageLayouts[i].lineScroll, 0, 0x7FFF); + memset(StageLayouts[i].tiles, 0, TILELAYER_CHUNK_MAX * sizeof(ushort)); + byte *lineScrollPtr = StageLayouts[i].lineScroll; + memset(StageLayouts[i].lineScroll, 0, 0x7FFF); // Read Line Scroll byte buf[3]; @@ -496,23 +501,21 @@ void LoadStageBackground() FileRead(&buf[1], 1); if (buf[1] == 0xFF) { break; - } - else { + } else { FileRead(&buf[2], 1); int val = buf[1]; int cnt = buf[2] - 1; for (int c = 0; c < cnt; ++c) *lineScrollPtr++ = val; } - } - else { + } else { *lineScrollPtr++ = buf[0]; } } // Read Layout - for (int y = 0; y < stageLayouts[i].ysize; ++y) { - ushort *chunks = &stageLayouts[i].tiles[y * 0x100]; - for (int x = 0; x < stageLayouts[i].xsize; ++x) { + for (int y = 0; y < StageLayouts[i].ysize; ++y) { + ushort *chunks = &StageLayouts[i].tiles[y * 0x100]; + for (int x = 0; x < StageLayouts[i].xsize; ++x) { FileRead(&fileBuffer, 1); *chunks += fileBuffer; ++chunks; @@ -523,58 +526,56 @@ void LoadStageBackground() CloseFile(); } } -void LoadStageChunks() -{ +void Load128x128Mappings() { FileInfo info; byte entry[3]; - if (LoadStageFile("128x128Tiles.bin", stageListPosition, &info)) { + if (LoadStageFile("128x128Tiles.bin", StageListPosition, &info)) { for (int i = 0; i < CHUNKTILE_COUNT; ++i) { FileRead(&entry, 3); entry[0] -= (byte)((entry[0] >> 6) << 6); - tiles128x128.visualPlane[i] = (byte)(entry[0] >> 4); + StageTiles.visualPlane[i] = (byte)(entry[0] >> 4); entry[0] -= 16 * (entry[0] >> 4); - tiles128x128.direction[i] = (byte)(entry[0] >> 2); + StageTiles.direction[i] = (byte)(entry[0] >> 2); entry[0] -= 4 * (entry[0] >> 2); - tiles128x128.tileIndex[i] = entry[1] + (entry[0] << 8); - tiles128x128.gfxDataPos[i] = tiles128x128.tileIndex[i] << 8; + StageTiles.tileIndex[i] = entry[1] + (entry[0] << 8); + StageTiles.gfxDataPos[i] = StageTiles.tileIndex[i] << 8; - tiles128x128.collisionFlags[0][i] = entry[2] >> 4; - tiles128x128.collisionFlags[1][i] = entry[2] - ((entry[2] >> 4) << 4); + StageTiles.collisionFlags[0][i] = entry[2] >> 4; + StageTiles.collisionFlags[1][i] = entry[2] - ((entry[2] >> 4) << 4); } CloseFile(); } } -void LoadStageCollisions() -{ +void LoadStageCollisions() { FileInfo info; - if (LoadStageFile("CollisionMasks.bin", stageListPosition, &info)) { + if (LoadStageFile("CollisionMasks.bin", StageListPosition, &info)) { byte fileBuffer = 0; - int tileIndex = 0; + int tileIndex = 0; for (int t = 0; t < 1024; ++t) { for (int p = 0; p < 2; ++p) { FileRead(&fileBuffer, 1); bool isCeiling = fileBuffer >> 4; - collisionMasks[p].flags[t] = fileBuffer & 0xF; + TileCollisions[p].flags[t] = fileBuffer & 0xF; FileRead(&fileBuffer, 1); - collisionMasks[p].angles[t] = fileBuffer; + TileCollisions[p].angles[t] = fileBuffer; FileRead(&fileBuffer, 1); - collisionMasks[p].angles[t] += fileBuffer << 8; + TileCollisions[p].angles[t] += fileBuffer << 8; FileRead(&fileBuffer, 1); - collisionMasks[p].angles[t] += fileBuffer << 16; + TileCollisions[p].angles[t] += fileBuffer << 16; FileRead(&fileBuffer, 1); - collisionMasks[p].angles[t] += fileBuffer << 24; + TileCollisions[p].angles[t] += fileBuffer << 24; if (isCeiling) // Ceiling Tile { for (int c = 0; c < TILE_SIZE; c += 2) { FileRead(&fileBuffer, 1); - collisionMasks[p].roofMasks[c + tileIndex] = fileBuffer >> 4; - collisionMasks[p].roofMasks[c + tileIndex + 1] = fileBuffer & 0xF; + TileCollisions[p].roofMasks[c + tileIndex] = fileBuffer >> 4; + TileCollisions[p].roofMasks[c + tileIndex + 1] = fileBuffer & 0xF; } // Has Collision (Pt 1) @@ -582,11 +583,10 @@ void LoadStageCollisions() int id = 1; for (int c = 0; c < TILE_SIZE / 2; ++c) { if (fileBuffer & id) { - collisionMasks[p].floorMasks[c + tileIndex + 8] = 0; - } - else { - collisionMasks[p].floorMasks[c + tileIndex + 8] = 0x40; - collisionMasks[p].roofMasks[c + tileIndex + 8] = -0x40; + TileCollisions[p].floorMasks[c + tileIndex + 8] = 0; + } else { + TileCollisions[p].floorMasks[c + tileIndex + 8] = 0x40; + TileCollisions[p].roofMasks[c + tileIndex + 8] = -0x40; } id <<= 1; } @@ -596,11 +596,10 @@ void LoadStageCollisions() id = 1; for (int c = 0; c < TILE_SIZE / 2; ++c) { if (fileBuffer & id) { - collisionMasks[p].floorMasks[c + tileIndex] = 0; - } - else { - collisionMasks[p].floorMasks[c + tileIndex] = 0x40; - collisionMasks[p].roofMasks[c + tileIndex] = -0x40; + TileCollisions[p].floorMasks[c + tileIndex] = 0; + } else { + TileCollisions[p].floorMasks[c + tileIndex] = 0x40; + TileCollisions[p].roofMasks[c + tileIndex] = -0x40; } id <<= 1; } @@ -610,14 +609,12 @@ void LoadStageCollisions() int h = 0; while (h > -1) { if (h >= TILE_SIZE) { - collisionMasks[p].lWallMasks[c + tileIndex] = 0x40; + TileCollisions[p].lWallMasks[c + tileIndex] = 0x40; h = -1; - } - else if (c > collisionMasks[p].roofMasks[h + tileIndex]) { + } else if (c > TileCollisions[p].roofMasks[h + tileIndex]) { ++h; - } - else { - collisionMasks[p].lWallMasks[c + tileIndex] = h; + } else { + TileCollisions[p].lWallMasks[c + tileIndex] = h; h = -1; } } @@ -628,36 +625,32 @@ void LoadStageCollisions() int h = TILE_SIZE - 1; while (h < TILE_SIZE) { if (h <= -1) { - collisionMasks[p].rWallMasks[c + tileIndex] = -0x40; + TileCollisions[p].rWallMasks[c + tileIndex] = -0x40; h = TILE_SIZE; - } - else if (c > collisionMasks[p].roofMasks[h + tileIndex]) { + } else if (c > TileCollisions[p].roofMasks[h + tileIndex]) { --h; - } - else { - collisionMasks[p].rWallMasks[c + tileIndex] = h; + } else { + TileCollisions[p].rWallMasks[c + tileIndex] = h; h = TILE_SIZE; } } } - } - else // Regular Tile + } else // Regular Tile { for (int c = 0; c < TILE_SIZE; c += 2) { FileRead(&fileBuffer, 1); - collisionMasks[p].floorMasks[c + tileIndex] = fileBuffer >> 4; - collisionMasks[p].floorMasks[c + tileIndex + 1] = fileBuffer & 0xF; + TileCollisions[p].floorMasks[c + tileIndex] = fileBuffer >> 4; + TileCollisions[p].floorMasks[c + tileIndex + 1] = fileBuffer & 0xF; } FileRead(&fileBuffer, 1); int id = 1; for (int c = 0; c < TILE_SIZE / 2; ++c) // HasCollision { if (fileBuffer & id) { - collisionMasks[p].roofMasks[c + tileIndex + 8] = 0xF; - } - else { - collisionMasks[p].floorMasks[c + tileIndex + 8] = 0x40; - collisionMasks[p].roofMasks[c + tileIndex + 8] = -0x40; + TileCollisions[p].roofMasks[c + tileIndex + 8] = 0xF; + } else { + TileCollisions[p].floorMasks[c + tileIndex + 8] = 0x40; + TileCollisions[p].roofMasks[c + tileIndex + 8] = -0x40; } id <<= 1; } @@ -667,46 +660,41 @@ void LoadStageCollisions() for (int c = 0; c < TILE_SIZE / 2; ++c) // HasCollision (pt 2) { if (fileBuffer & id) { - collisionMasks[p].roofMasks[c + tileIndex] = 0xF; - } - else { - collisionMasks[p].floorMasks[c + tileIndex] = 0x40; - collisionMasks[p].roofMasks[c + tileIndex] = -0x40; + TileCollisions[p].roofMasks[c + tileIndex] = 0xF; + } else { + TileCollisions[p].floorMasks[c + tileIndex] = 0x40; + TileCollisions[p].roofMasks[c + tileIndex] = -0x40; } id <<= 1; } - //LWall rotations + // LWall rotations for (int c = 0; c < TILE_SIZE; ++c) { int h = 0; while (h > -1) { if (h >= TILE_SIZE) { - collisionMasks[p].lWallMasks[c + tileIndex] = 0x40; + TileCollisions[p].lWallMasks[c + tileIndex] = 0x40; h = -1; - } - else if (c < collisionMasks[p].floorMasks[h + tileIndex]) { + } else if (c < TileCollisions[p].floorMasks[h + tileIndex]) { ++h; - } - else { - collisionMasks[p].lWallMasks[c + tileIndex] = h; + } else { + TileCollisions[p].lWallMasks[c + tileIndex] = h; h = -1; } } } - //RWall rotations + // RWall rotations for (int c = 0; c < TILE_SIZE; ++c) { int h = TILE_SIZE - 1; while (h < TILE_SIZE) { if (h <= -1) { - collisionMasks[p].rWallMasks[c + tileIndex] = -0x40; + TileCollisions[p].rWallMasks[c + tileIndex] = -0x40; h = TILE_SIZE; - } - else if (c < collisionMasks[p].floorMasks[h + tileIndex]) { + } else if (c < TileCollisions[p].floorMasks[h + tileIndex]) { --h; - } - else { - collisionMasks[p].rWallMasks[c + tileIndex] = h; + } else { + TileCollisions[p].rWallMasks[c + tileIndex] = h; h = TILE_SIZE; } } @@ -718,8 +706,7 @@ void LoadStageCollisions() CloseFile(); } } -void LoadStageGIFFile(int stageID) -{ +void LoadStageGIFFile(int stageID) { FileInfo info; if (LoadStageFile("16x16Tiles.gif", stageID, &info)) { byte fileBuffer = 0; @@ -736,8 +723,8 @@ void LoadStageGIFFile(int stageID) height += (fileBuffer << 8); FileRead(&fileBuffer, 1); // Palette Size - int has_pallete = (fileBuffer & 0x80) >> 7; - int colors = ((fileBuffer & 0x70) >> 4) + 1; + int has_pallete = (fileBuffer & 0x80) >> 7; + int colors = ((fileBuffer & 0x70) >> 4) + 1; int palette_size = (fileBuffer & 0x7) + 1; if (palette_size > 0) palette_size = 1 << palette_size; @@ -745,8 +732,7 @@ void LoadStageGIFFile(int stageID) FileRead(&fileBuffer, 1); // BG Colour index (thrown away) FileRead(&fileBuffer, 1); // Pixel aspect ratio (thrown away) - if (palette_size == 256) - { + if (palette_size == 256) { byte clr[3]; for (int c = 0; c < 0x80; ++c) FileRead(clr, 3); @@ -773,19 +759,18 @@ void LoadStageGIFFile(int stageID) } while (c != 256); } - ReadGifPictureData(width, height, interlaced, tilesetGFXData, 0); + ReadGifPictureData(width, height, interlaced, TileGfx, 0); - byte transparent = tilesetGFXData[0]; + byte transparent = TileGfx[0]; for (int i = 0; i < 0x40000; ++i) { - if (tilesetGFXData[i] == transparent) - tilesetGFXData[i] = 0; + if (TileGfx[i] == transparent) + TileGfx[i] = 0; } CloseFile(); } } -void LoadStageGFXFile(int stageID) -{ +void LoadStageGFXFile(int stageID) { FileInfo info; if (LoadStageFile("16x16Tiles.gfx", stageID, &info)) { byte fileBuffer = 0; @@ -805,7 +790,7 @@ void LoadStageGFXFile(int stageID) SetPaletteEntry(c, clr[0], clr[1], clr[2]); } - byte *gfxData = tilesetGFXData; + byte *gfxData = TileGfx; byte buf[3]; while (true) { FileRead(&buf[0], 1); @@ -813,103 +798,98 @@ void LoadStageGFXFile(int stageID) FileRead(&buf[1], 1); if (buf[1] == 0xFF) { break; - } - else { + } else { FileRead(&buf[2], 1); for (int i = 0; i < buf[2]; ++i) *gfxData++ = buf[1]; } - } - else { + } else { *gfxData++ = buf[0]; } } - byte transparent = tilesetGFXData[0]; + byte transparent = TileGfx[0]; for (int i = 0; i < 0x40000; ++i) { - if (tilesetGFXData[i] == transparent) - tilesetGFXData[i] = 0; + if (TileGfx[i] == transparent) + TileGfx[i] = 0; } CloseFile(); } } -void ResetBackgroundSettings() -{ +void ResetBackgroundSettings() { for (int i = 0; i < LAYER_COUNT; ++i) { - stageLayouts[i].scrollPos = 0; + StageLayouts[i].scrollPos = 0; } for (int i = 0; i < PARALLAX_COUNT; ++i) { - hParallax.scrollPos[i] = 0; - vParallax.scrollPos[i] = 0; + HParallax.scrollPos[i] = 0; + VParallax.scrollPos[i] = 0; } } -void SetPlayerScreenPosition(Player* player) -{ - PlayerScript* script = &playerScriptList[player->type]; - int playerXPos = player->XPos >> 16; - int playerYPos = player->YPos >> 16; - if (newYBoundary1 > yBoundary1) { - if (yScrollOffset <= newYBoundary1) - yBoundary1 = yScrollOffset; +void SetPlayerScreenPosition(Player *player) { + PlayerScript *script = &PlayerScriptList[player->type]; + int playerXPos = player->XPos >> 16; + int playerYPos = player->YPos >> 16; + if (NewYBoundary1 > YBoundary1) { + if (YScrollOffset <= NewYBoundary1) + YBoundary1 = YScrollOffset; else - yBoundary1 = newYBoundary1; + YBoundary1 = NewYBoundary1; } - if (newYBoundary1 < yBoundary1) { - if (yScrollOffset <= yBoundary1) - --yBoundary1; + if (NewYBoundary1 < YBoundary1) { + if (YScrollOffset <= YBoundary1) + --YBoundary1; else - yBoundary1 = newYBoundary1; + YBoundary1 = NewYBoundary1; } - if (newYBoundary2 < yBoundary2) { - if (yScrollOffset + SCREEN_YSIZE >= yBoundary2 || yScrollOffset + SCREEN_YSIZE <= newYBoundary2) - --yBoundary2; + if (NewYBoundary2 < YBoundary2) { + if (YScrollOffset + SCREEN_YSIZE >= YBoundary2 || YScrollOffset + SCREEN_YSIZE <= NewYBoundary2) + --YBoundary2; else - yBoundary2 = yScrollOffset + SCREEN_YSIZE; + YBoundary2 = YScrollOffset + SCREEN_YSIZE; } - if (newYBoundary2 > yBoundary2) { - if (yScrollOffset + SCREEN_YSIZE >= yBoundary2) - ++yBoundary2; + if (NewYBoundary2 > YBoundary2) { + if (YScrollOffset + SCREEN_YSIZE >= YBoundary2) + ++YBoundary2; else - yBoundary2 = newYBoundary2; + YBoundary2 = NewYBoundary2; } - if (newXBoundary1 > xBoundary1) { - if (xScrollOffset <= newXBoundary1) - xBoundary1 = xScrollOffset; + if (NewXBoundary1 > XBoundary1) { + if (XScrollOffset <= NewXBoundary1) + XBoundary1 = XScrollOffset; else - xBoundary1 = newXBoundary1; + XBoundary1 = NewXBoundary1; } - if (newXBoundary1 < xBoundary1) { - if (xScrollOffset <= xBoundary1) - --xBoundary1; + if (NewXBoundary1 < XBoundary1) { + if (XScrollOffset <= XBoundary1) + --XBoundary1; else - xBoundary1 = newXBoundary1; + XBoundary1 = NewXBoundary1; } - if (newXBoundary2 < xBoundary2) { - if (xScrollOffset + SCREEN_XSIZE >= xBoundary2) - xBoundary2 = xScrollOffset + SCREEN_XSIZE; + if (NewXBoundary2 < XBoundary2) { + if (XScrollOffset + SCREEN_XSIZE >= XBoundary2) + XBoundary2 = XScrollOffset + SCREEN_XSIZE; else - xBoundary2 = newXBoundary2; + XBoundary2 = NewXBoundary2; } - if (newXBoundary2 > xBoundary2) { - if (xScrollOffset + SCREEN_XSIZE >= xBoundary2) - ++xBoundary2; + if (NewXBoundary2 > XBoundary2) { + if (XScrollOffset + SCREEN_XSIZE >= XBoundary2) + ++XBoundary2; else - xBoundary2 = newXBoundary2; + XBoundary2 = NewXBoundary2; } - int xscrollA = xScrollA; - int xscrollB = xScrollB; - int scrollAmount = playerXPos - (xScrollA + SCREEN_CENTERX); + int xscrollA = XScrollA; + int xscrollB = XScrollB; + int scrollAmount = playerXPos - (XScrollA + SCREEN_CENTERX); if (abs(scrollAmount) >= 25) { if (scrollAmount <= 0) xscrollA -= 16; else xscrollA += 16; xscrollB = xscrollA + SCREEN_XSIZE; - } - else { + } else { if (playerXPos > xscrollA + SCREEN_SCROLL_RIGHT) { xscrollA = playerXPos - SCREEN_SCROLL_RIGHT; xscrollB = playerXPos - SCREEN_SCROLL_RIGHT + SCREEN_XSIZE; @@ -919,329 +899,316 @@ void SetPlayerScreenPosition(Player* player) xscrollB = playerXPos - SCREEN_SCROLL_LEFT + SCREEN_XSIZE; } } - if (xscrollA < xBoundary1) { - xscrollA = xBoundary1; - xscrollB = xBoundary1 + SCREEN_XSIZE; + if (xscrollA < XBoundary1) { + xscrollA = XBoundary1; + xscrollB = XBoundary1 + SCREEN_XSIZE; } - if (xscrollB > xBoundary2) { - xscrollB = xBoundary2; - xscrollA = xBoundary2 - SCREEN_XSIZE; + if (xscrollB > XBoundary2) { + xscrollB = XBoundary2; + xscrollA = XBoundary2 - SCREEN_XSIZE; } - xScrollA = xscrollA; - xScrollB = xscrollB; + XScrollA = xscrollA; + XScrollB = xscrollB; if (playerXPos <= xscrollA + SCREEN_CENTERX) { - player->screenXPos = earthquakeX + playerXPos - xscrollA; - xScrollOffset = xscrollA - earthquakeX; - } - else { - xScrollOffset = playerXPos + earthquakeX - SCREEN_CENTERX; - player->screenXPos = SCREEN_CENTERX - earthquakeX; + player->screenXPos = EarthquakeX + playerXPos - xscrollA; + XScrollOffset = xscrollA - EarthquakeX; + } else { + XScrollOffset = playerXPos + EarthquakeX - SCREEN_CENTERX; + player->screenXPos = SCREEN_CENTERX - EarthquakeX; if (playerXPos > xscrollB - SCREEN_CENTERX) { - player->screenXPos = playerXPos - (xscrollB - SCREEN_CENTERX) + earthquakeX + SCREEN_CENTERX; - xScrollOffset = xscrollB - SCREEN_XSIZE - earthquakeX; + player->screenXPos = playerXPos - (xscrollB - SCREEN_CENTERX) + EarthquakeX + SCREEN_CENTERX; + XScrollOffset = xscrollB - SCREEN_XSIZE - EarthquakeX; } } - int yscrollA = yScrollA; - int yscrollB = yScrollB; - int hitboxDiff = hitboxList[0].left[0] - getPlayerHitbox(script)->left[0]; - int adjustYPos = playerYPos - hitboxDiff; - int adjustAmount = player->lookPos + adjustYPos - (yScrollA + SCREEN_SCROLL_UP); + int yscrollA = YScrollA; + int yscrollB = YScrollB; + int hitboxDiff = PlayerCBoxes[0].bottom[0] - GetPlayerCBoxInstance(player, script)->bottom[0]; + int adjustYPos = playerYPos - hitboxDiff; + int adjustAmount = player->lookPos + adjustYPos - (YScrollA + SCREEN_SCROLL_UP); if (player->trackScroll) { - yScrollMove = 32; - } - else { - if (yScrollMove == 32) { - yScrollMove = 2 * ((hitboxDiff + SCREEN_SCROLL_UP - player->screenYPos - player->lookPos) >> 1); - if (yScrollMove > 32) - yScrollMove = 32; - if (yScrollMove < -32) - yScrollMove = -32; + YScrollMove = 32; + } else { + if (YScrollMove == 32) { + YScrollMove = 2 * ((hitboxDiff + SCREEN_SCROLL_UP - player->screenYPos - player->lookPos) >> 1); + if (YScrollMove > 32) + YScrollMove = 32; + if (YScrollMove < -32) + YScrollMove = -32; } - if (yScrollMove > 0) - yScrollMove -= 6; - yScrollMove += yScrollMove < 0 ? 6 : 0; + if (YScrollMove > 0) + YScrollMove -= 6; + YScrollMove += YScrollMove < 0 ? 6 : 0; } int absAdjust = abs(adjustAmount); - if (absAdjust >= abs(yScrollMove) + 17) { + if (absAdjust >= abs(YScrollMove) + 17) { if (adjustAmount <= 0) yscrollA -= 16; else yscrollA += 16; yscrollB = yscrollA + SCREEN_YSIZE; - } - else if (yScrollMove == 32) { - if (player->lookPos + adjustYPos > yscrollA + yScrollMove + SCREEN_SCROLL_UP) { - yscrollA = player->lookPos + adjustYPos - (yScrollMove + SCREEN_SCROLL_UP); + } else if (YScrollMove == 32) { + if (player->lookPos + adjustYPos > yscrollA + YScrollMove + SCREEN_SCROLL_UP) { + yscrollA = player->lookPos + adjustYPos - (YScrollMove + SCREEN_SCROLL_UP); yscrollB = yscrollA + SCREEN_YSIZE; } - if (player->lookPos + adjustYPos < yscrollA + SCREEN_SCROLL_UP - yScrollMove) { - yscrollA = player->lookPos + adjustYPos - (SCREEN_SCROLL_UP - yScrollMove); + if (player->lookPos + adjustYPos < yscrollA + SCREEN_SCROLL_UP - YScrollMove) { + yscrollA = player->lookPos + adjustYPos - (SCREEN_SCROLL_UP - YScrollMove); yscrollB = yscrollA + SCREEN_YSIZE; } - } - else { - yscrollA = player->lookPos + adjustYPos + yScrollMove - SCREEN_SCROLL_UP; + } else { + yscrollA = player->lookPos + adjustYPos + YScrollMove - SCREEN_SCROLL_UP; yscrollB = yscrollA + SCREEN_YSIZE; } - if (yscrollA < yBoundary1) { - yscrollA = yBoundary1; - yscrollB = yBoundary1 + SCREEN_YSIZE; + if (yscrollA < YBoundary1) { + yscrollA = YBoundary1; + yscrollB = YBoundary1 + SCREEN_YSIZE; } - if (yscrollB > yBoundary2) { - yscrollB = yBoundary2; - yscrollA = yBoundary2 - SCREEN_YSIZE; + if (yscrollB > YBoundary2) { + yscrollB = YBoundary2; + yscrollA = YBoundary2 - SCREEN_YSIZE; } - yScrollA = yscrollA; - yScrollB = yscrollB; + YScrollA = yscrollA; + YScrollB = yscrollB; - if (earthquakeY) { - if (earthquakeY <= 0) - earthquakeY = ~earthquakeY; + if (EarthquakeY) { + if (EarthquakeY <= 0) + EarthquakeY = ~EarthquakeY; else - earthquakeY = -earthquakeY; + EarthquakeY = -EarthquakeY; } if (player->lookPos + adjustYPos <= yscrollA + SCREEN_SCROLL_UP) { - player->screenYPos = adjustYPos - yscrollA - earthquakeY; - yScrollOffset = earthquakeY + yscrollA; - } - else { - yScrollOffset = earthquakeY + adjustYPos + player->lookPos - SCREEN_SCROLL_UP; - player->screenYPos = SCREEN_SCROLL_UP - player->lookPos - earthquakeY; + player->screenYPos = adjustYPos - yscrollA - EarthquakeY; + YScrollOffset = EarthquakeY + yscrollA; + } else { + YScrollOffset = EarthquakeY + adjustYPos + player->lookPos - SCREEN_SCROLL_UP; + player->screenYPos = SCREEN_SCROLL_UP - player->lookPos - EarthquakeY; if (player->lookPos + adjustYPos > yscrollB - SCREEN_SCROLL_DOWN) { - player->screenYPos = adjustYPos - (yscrollB - SCREEN_SCROLL_DOWN) + earthquakeY + SCREEN_SCROLL_UP; - yScrollOffset = yscrollB - SCREEN_YSIZE - earthquakeY; + player->screenYPos = adjustYPos - (yscrollB - SCREEN_SCROLL_DOWN) + EarthquakeY + SCREEN_SCROLL_UP; + YScrollOffset = yscrollB - SCREEN_YSIZE - EarthquakeY; } } player->screenYPos += hitboxDiff; } -void SetPlayerScreenPositionCDStyle(Player* player) -{ - PlayerScript* script = &playerScriptList[player->type]; - int playerXPos = player->XPos >> 16; - int playerYPos = player->YPos >> 16; - if (newYBoundary1 > yBoundary1) { - if (yScrollOffset <= newYBoundary1) - yBoundary1 = yScrollOffset; +void SetPlayerScreenPositionCDStyle(Player *player) { + PlayerScript *script = &PlayerScriptList[player->type]; + int playerXPos = player->XPos >> 16; + int playerYPos = player->YPos >> 16; + if (NewYBoundary1 > YBoundary1) { + if (YScrollOffset <= NewYBoundary1) + YBoundary1 = YScrollOffset; else - yBoundary1 = newYBoundary1; + YBoundary1 = NewYBoundary1; } - if (newYBoundary1 < yBoundary1) { - if (yScrollOffset <= yBoundary1) - --yBoundary1; + if (NewYBoundary1 < YBoundary1) { + if (YScrollOffset <= YBoundary1) + --YBoundary1; else - yBoundary1 = newYBoundary1; + YBoundary1 = NewYBoundary1; } - if (newYBoundary2 < yBoundary2) { - if (yScrollOffset + SCREEN_YSIZE >= yBoundary2 || yScrollOffset + SCREEN_YSIZE <= newYBoundary2) - --yBoundary2; + if (NewYBoundary2 < YBoundary2) { + if (YScrollOffset + SCREEN_YSIZE >= YBoundary2 || YScrollOffset + SCREEN_YSIZE <= NewYBoundary2) + --YBoundary2; else - yBoundary2 = yScrollOffset + SCREEN_YSIZE; + YBoundary2 = YScrollOffset + SCREEN_YSIZE; } - if (newYBoundary2 > yBoundary2) { - if (yScrollOffset + SCREEN_YSIZE >= yBoundary2) - ++yBoundary2; + if (NewYBoundary2 > YBoundary2) { + if (YScrollOffset + SCREEN_YSIZE >= YBoundary2) + ++YBoundary2; else - yBoundary2 = newYBoundary2; + YBoundary2 = NewYBoundary2; } - if (newXBoundary1 > xBoundary1) { - if (xScrollOffset <= newXBoundary1) - xBoundary1 = xScrollOffset; + if (NewXBoundary1 > XBoundary1) { + if (XScrollOffset <= NewXBoundary1) + XBoundary1 = XScrollOffset; else - xBoundary1 = newXBoundary1; + XBoundary1 = NewXBoundary1; } - if (newXBoundary1 < xBoundary1) { - if (xScrollOffset <= xBoundary1) - --xBoundary1; + if (NewXBoundary1 < XBoundary1) { + if (XScrollOffset <= XBoundary1) + --XBoundary1; else - xBoundary1 = newXBoundary1; + XBoundary1 = NewXBoundary1; } - if (newXBoundary2 < xBoundary2) { - if (xScrollOffset + SCREEN_XSIZE >= xBoundary2) - xBoundary2 = xScrollOffset + SCREEN_XSIZE; + if (NewXBoundary2 < XBoundary2) { + if (XScrollOffset + SCREEN_XSIZE >= XBoundary2) + XBoundary2 = XScrollOffset + SCREEN_XSIZE; else - xBoundary2 = newXBoundary2; + XBoundary2 = NewXBoundary2; } - if (newXBoundary2 > xBoundary2) { - if (xScrollOffset + SCREEN_XSIZE >= xBoundary2) - ++xBoundary2; + if (NewXBoundary2 > XBoundary2) { + if (XScrollOffset + SCREEN_XSIZE >= XBoundary2) + ++XBoundary2; else - xBoundary2 = newXBoundary2; + XBoundary2 = NewXBoundary2; } + if (!player->gravity) { if (player->direction) { if (player->animation == ANI_PEELOUT || player->animation == ANI_SPINDASH || player->speed < -0x5F5C2) { - if (cameraLag < 64) - cameraLag += 2; + if (XScrollMove < 64) + XScrollMove += 2; + } else { + XScrollMove += XScrollMove < 0 ? 2 : 0; + if (XScrollMove > 0) + XScrollMove -= 2; } - else { - cameraLag += cameraLag < 0 ? 2 : 0; - if (cameraLag > 0) - cameraLag -= 2; - } - } - else if (player->animation == ANI_PEELOUT || player->animation == ANI_SPINDASH || player->speed > 0x5F5C2) { - if (cameraLag > -64) - cameraLag -= 2; - } - else { - cameraLag += cameraLag < 0 ? 2 : 0; - if (cameraLag > 0) - cameraLag -= 2; + } else if (player->animation == ANI_PEELOUT || player->animation == ANI_SPINDASH || player->speed > 0x5F5C2) { + if (XScrollMove > -64) + XScrollMove -= 2; + } else { + XScrollMove += XScrollMove < 0 ? 2 : 0; + if (XScrollMove > 0) + XScrollMove -= 2; } } - if (playerXPos <= xBoundary1 + cameraLag + SCREEN_CENTERX) { - player->screenXPos = earthquakeX + playerXPos - xBoundary1; - xScrollOffset = xBoundary1 - earthquakeX; - } - else { - xScrollOffset = playerXPos + earthquakeX - SCREEN_CENTERX - cameraLag; - player->screenXPos = cameraLag + SCREEN_CENTERX - earthquakeX; - if (playerXPos - cameraLag > xBoundary2 - SCREEN_CENTERX) { - player->screenXPos = playerXPos - (xBoundary2 - SCREEN_CENTERX) + earthquakeX + SCREEN_CENTERX; - xScrollOffset = xBoundary2 - SCREEN_XSIZE - earthquakeX; + if (playerXPos <= XBoundary1 + XScrollMove + SCREEN_CENTERX) { + player->screenXPos = EarthquakeX + playerXPos - XBoundary1; + XScrollOffset = XBoundary1 - EarthquakeX; + } else { + XScrollOffset = playerXPos + EarthquakeX - XScrollMove - SCREEN_CENTERX; + player->screenXPos = XScrollMove - EarthquakeX + SCREEN_CENTERX; + if (playerXPos - XScrollMove > XBoundary2 - SCREEN_CENTERX) { + player->screenXPos = EarthquakeX + playerXPos - XBoundary2 + SCREEN_XSIZE; + XScrollOffset = XBoundary2 - SCREEN_XSIZE - EarthquakeX; } } - int yscrollA = yScrollA; - int yscrollB = yScrollB; - int hitboxDiff = hitboxList[0].left[0] - getPlayerHitbox(script)->left[0]; - int adjustY = playerYPos - hitboxDiff; - int adjustOffset = player->lookPos + adjustY - (yScrollA + SCREEN_SCROLL_UP); + + XScrollA = XScrollOffset; + XScrollB = (XScrollA + SCREEN_XSIZE); + + int yscrollA = YScrollA; + int yscrollB = YScrollB; + int hitboxDiff = PlayerCBoxes[0].bottom[0] - GetPlayerCBoxInstance(player, script)->bottom[0]; + int adjustY = playerYPos - hitboxDiff; + int adjustOffset = player->lookPos + adjustY - (YScrollA + SCREEN_SCROLL_UP); if (player->trackScroll) { - yScrollMove = 32; - } - else { - if (yScrollMove == 32) { - yScrollMove = 2 * ((hitboxDiff + SCREEN_SCROLL_UP - player->screenYPos - player->lookPos) >> 1); - if (yScrollMove > 32) - yScrollMove = 32; - if (yScrollMove < -32) - yScrollMove = -32; + YScrollMove = 32; + } else { + if (YScrollMove == 32) { + YScrollMove = ((hitboxDiff + SCREEN_SCROLL_UP - player->screenYPos - player->lookPos) >> 1) << 1; + if (YScrollMove > 32) + YScrollMove = 32; + if (YScrollMove < -32) + YScrollMove = -32; } - if (yScrollMove > 0) - yScrollMove -= 6; - yScrollMove += yScrollMove < 0 ? 6 : 0; + if (YScrollMove > 0) + YScrollMove -= 6; + YScrollMove += YScrollMove < 0 ? 6 : 0; } int absAdjust = abs(adjustOffset); - if (absAdjust >= abs(yScrollMove) + 17) { + if (absAdjust >= abs(YScrollMove) + 17) { if (adjustOffset <= 0) yscrollA -= 16; else yscrollA += 16; yscrollB = yscrollA + SCREEN_YSIZE; - } - else if (yScrollMove == 32) { - if (player->lookPos + adjustY > yscrollA + yScrollMove + SCREEN_SCROLL_UP) { - yscrollA = player->lookPos + adjustY - (yScrollMove + SCREEN_SCROLL_UP); + } else if (YScrollMove == 32) { + if (player->lookPos + adjustY > yscrollA + YScrollMove + SCREEN_SCROLL_UP) { + yscrollA = player->lookPos + adjustY - (YScrollMove + SCREEN_SCROLL_UP); yscrollB = yscrollA + SCREEN_YSIZE; } - if (player->lookPos + adjustY < yscrollA + SCREEN_SCROLL_UP - yScrollMove) { - yscrollA = player->lookPos + adjustY - (SCREEN_SCROLL_UP - yScrollMove); + if (player->lookPos + adjustY < yscrollA + SCREEN_SCROLL_UP - YScrollMove) { + yscrollA = player->lookPos + adjustY - (SCREEN_SCROLL_UP - YScrollMove); yscrollB = yscrollA + SCREEN_YSIZE; } - } - else { - yscrollA = player->lookPos + adjustY + yScrollMove - SCREEN_SCROLL_UP; + } else { + yscrollA = player->lookPos + adjustY + YScrollMove - SCREEN_SCROLL_UP; yscrollB = yscrollA + SCREEN_YSIZE; } - if (yscrollA < yBoundary1) { - yscrollA = yBoundary1; - yscrollB = yBoundary1 + SCREEN_YSIZE; + if (yscrollA < YBoundary1) { + yscrollA = YBoundary1; + yscrollB = YBoundary1 + SCREEN_YSIZE; } - if (yscrollB > yBoundary2) { - yscrollB = yBoundary2; - yscrollA = yBoundary2 - SCREEN_YSIZE; + if (yscrollB > YBoundary2) { + yscrollB = YBoundary2; + yscrollA = YBoundary2 - SCREEN_YSIZE; } - yScrollA = yscrollA; - yScrollB = yscrollB; - if (earthquakeY) { - if (earthquakeY <= 0) - earthquakeY = ~earthquakeY; + YScrollA = yscrollA; + YScrollB = yscrollB; + + if (EarthquakeY) { + if (EarthquakeY <= 0) + EarthquakeY = ~EarthquakeY; else - earthquakeY = -earthquakeY; + EarthquakeY = -EarthquakeY; } if (player->lookPos + adjustY <= yscrollA + SCREEN_SCROLL_UP) { - player->screenYPos = adjustY - yscrollA - earthquakeY; - yScrollOffset = earthquakeY + yscrollA; - } - else { - yScrollOffset = earthquakeY + adjustY + player->lookPos - SCREEN_SCROLL_UP; - player->screenYPos = SCREEN_SCROLL_UP - player->lookPos - earthquakeY; + player->screenYPos = adjustY - yscrollA - EarthquakeY; + YScrollOffset = EarthquakeY + yscrollA; + } else { + YScrollOffset = EarthquakeY + adjustY + player->lookPos - SCREEN_SCROLL_UP; + player->screenYPos = SCREEN_SCROLL_UP - player->lookPos - EarthquakeY; if (player->lookPos + adjustY > yscrollB - SCREEN_SCROLL_DOWN) { - player->screenYPos = adjustY - (yscrollB - SCREEN_SCROLL_DOWN) + earthquakeY + SCREEN_SCROLL_UP; - yScrollOffset = yscrollB - SCREEN_YSIZE - earthquakeY; + player->screenYPos = adjustY - (yscrollB - SCREEN_SCROLL_DOWN) + EarthquakeY + SCREEN_SCROLL_UP; + YScrollOffset = yscrollB - SCREEN_YSIZE - EarthquakeY; } } + player->screenYPos += hitboxDiff; } -void SetPlayerLockedScreenPosition(Player* player) -{ - PlayerScript* script = &playerScriptList[player->type]; - int playerXPos = player->XPos >> 16; - int playerYPos = player->YPos >> 16; - switch (cameraStyle) { - case CAMERASTYLE_FOLLOW: - { - if (playerXPos <= xBoundary1 + cameraLag + SCREEN_CENTERX) { - player->screenXPos = earthquakeX + playerXPos - xBoundary1; - xScrollOffset = xBoundary1 - earthquakeX; - } - else { - xScrollOffset = playerXPos + earthquakeX - SCREEN_CENTERX - cameraLag; - player->screenXPos = cameraLag + SCREEN_CENTERX - earthquakeX; - if (playerXPos > xBoundary2 + cameraLag - SCREEN_CENTERX) { - player->screenXPos = cameraLag + playerXPos - (xBoundary2 - SCREEN_CENTERX) + earthquakeX + SCREEN_CENTERX; - xScrollOffset = xBoundary2 - SCREEN_XSIZE - earthquakeX - cameraLag; +void SetPlayerLockedScreenPosition(Player *player) { + PlayerScript *script = &PlayerScriptList[player->type]; + int playerXPos = player->XPos >> 16; + int playerYPos = player->YPos >> 16; + switch (CameraStyle) { + case CAMERASTYLE_FOLLOW: { + if (playerXPos <= XBoundary1 + XScrollMove + SCREEN_CENTERX) { + player->screenXPos = EarthquakeX + playerXPos - XBoundary1; + XScrollOffset = XBoundary1 - EarthquakeX; + } else { + XScrollOffset = playerXPos + EarthquakeX - SCREEN_CENTERX - XScrollMove; + player->screenXPos = XScrollMove + SCREEN_CENTERX - EarthquakeX; + if (playerXPos > XBoundary2 + XScrollMove - SCREEN_CENTERX) { + player->screenXPos = XScrollMove + playerXPos - (XBoundary2 - SCREEN_CENTERX) + EarthquakeX + SCREEN_CENTERX; + XScrollOffset = XBoundary2 - SCREEN_XSIZE - EarthquakeX - XScrollMove; } } break; } - case CAMERASTYLE_EXTENDED: - { - int xscrollA = xScrollA; - int xscrollB = xScrollB; - if (playerXPos <= xScrollA + SCREEN_CENTERX) { - player->screenXPos = earthquakeX + playerXPos - xScrollA; - xScrollOffset = xscrollA - earthquakeX; - } - else { - xScrollOffset = playerXPos + earthquakeX - SCREEN_CENTERX; - player->screenXPos = SCREEN_CENTERX - earthquakeX; + case CAMERASTYLE_EXTENDED: { + int xscrollA = XScrollA; + int xscrollB = XScrollB; + if (playerXPos <= XScrollA + SCREEN_CENTERX) { + player->screenXPos = EarthquakeX + playerXPos - XScrollA; + XScrollOffset = xscrollA - EarthquakeX; + } else { + XScrollOffset = playerXPos + EarthquakeX - SCREEN_CENTERX; + player->screenXPos = SCREEN_CENTERX - EarthquakeX; if (playerXPos > xscrollB - SCREEN_CENTERX) { - player->screenXPos = playerXPos - (xscrollB - SCREEN_CENTERX) + earthquakeX + SCREEN_CENTERX; - xScrollOffset = xscrollB - SCREEN_XSIZE - earthquakeX; + player->screenXPos = playerXPos - (xscrollB - SCREEN_CENTERX) + EarthquakeX + SCREEN_CENTERX; + XScrollOffset = xscrollB - SCREEN_XSIZE - EarthquakeX; } } break; } default: break; } - int yscrollA = yScrollA; - int yscrollB = yScrollB; - int hitboxDiff = hitboxList[0].left[0] - getPlayerHitbox(script)->left[0]; - int adjustY = playerYPos - hitboxDiff; - - if (earthquakeY) { - if (earthquakeY <= 0) - earthquakeY = ~earthquakeY; + int yscrollA = YScrollA; + int yscrollB = YScrollB; + int hitboxDiff = PlayerCBoxes[0].bottom[0] - GetPlayerCBoxInstance(player, script)->bottom[0]; + int adjustY = playerYPos - hitboxDiff; + + if (EarthquakeY) { + if (EarthquakeY <= 0) + EarthquakeY = ~EarthquakeY; else - earthquakeY = -earthquakeY; + EarthquakeY = -EarthquakeY; } - if (player->lookPos + adjustY <= yScrollA + SCREEN_SCROLL_UP) { - player->screenYPos = adjustY - yScrollA - earthquakeY; - yScrollOffset = earthquakeY + yscrollA; - } - else { - yScrollOffset = earthquakeY + adjustY + player->lookPos - SCREEN_SCROLL_UP; - player->screenYPos = SCREEN_SCROLL_UP - player->lookPos - earthquakeY; + if (player->lookPos + adjustY <= YScrollA + SCREEN_SCROLL_UP) { + player->screenYPos = adjustY - YScrollA - EarthquakeY; + YScrollOffset = EarthquakeY + yscrollA; + } else { + YScrollOffset = EarthquakeY + adjustY + player->lookPos - SCREEN_SCROLL_UP; + player->screenYPos = SCREEN_SCROLL_UP - player->lookPos - EarthquakeY; if (player->lookPos + adjustY > yscrollB - SCREEN_SCROLL_DOWN) { - player->screenYPos = adjustY - (yscrollB - SCREEN_SCROLL_DOWN) + earthquakeY + SCREEN_SCROLL_UP; - yScrollOffset = yscrollB - SCREEN_YSIZE - earthquakeY; + player->screenYPos = adjustY - (yscrollB - SCREEN_SCROLL_DOWN) + EarthquakeY + SCREEN_SCROLL_UP; + YScrollOffset = yscrollB - SCREEN_YSIZE - EarthquakeY; } } player->screenYPos += hitboxDiff; diff --git a/Nexus/Scene.hpp b/Nexus/Scene.hpp index 8115529..de97c32 100644 --- a/Nexus/Scene.hpp +++ b/Nexus/Scene.hpp @@ -120,91 +120,91 @@ extern int stageListCount[STAGELIST_MAX]; extern char stageListNames[STAGELIST_MAX][0x20]; extern SceneInfo stageList[STAGELIST_MAX][0x100]; -extern int stageMode; +extern int StageMode; -extern int cameraStyle; -extern int cameraEnabled; +extern int CameraStyle; +extern int CameraEnabled; extern int cameraAdjustY; -extern int xScrollOffset; -extern int yScrollOffset; -extern int yScrollA; -extern int yScrollB; -extern int xScrollA; -extern int xScrollB; -extern int yScrollMove; -extern int earthquakeX; -extern int earthquakeY; -extern int cameraLag; - -extern int xBoundary1; -extern int newXBoundary1; -extern int yBoundary1; -extern int newYBoundary1; -extern int xBoundary2; -extern int yBoundary2; -extern int waterLevel; +extern int XScrollOffset; +extern int YScrollOffset; +extern int YScrollA; +extern int YScrollB; +extern int XScrollA; +extern int XScrollB; +extern int YScrollMove; +extern int EarthquakeX; +extern int EarthquakeY; +extern int XScrollMove; + +extern int XBoundary1; +extern int NewXBoundary1; +extern int YBoundary1; +extern int NewYBoundary1; +extern int XBoundary2; +extern int YBoundary2; +extern int WaterLevel; extern int waterDrawPos; -extern int newXBoundary2; -extern int newYBoundary2; +extern int NewXBoundary2; +extern int NewYBoundary2; extern int SCREEN_SCROLL_LEFT; extern int SCREEN_SCROLL_RIGHT; #define SCREEN_SCROLL_UP ((SCREEN_YSIZE / 2) - 16) #define SCREEN_SCROLL_DOWN ((SCREEN_YSIZE / 2) + 16) -extern int lastXSize; -extern int lastYSize; +extern int LastXSize; +extern int LastYSize; -extern bool pauseEnabled; -extern bool timeEnabled; +extern bool PauseEnabled; +extern bool TimeEnabled; extern bool debugMode; -extern int frameCounter; -extern int stageMilliseconds; -extern int stageSeconds; -extern int stageMinutes; +extern int FrameCounter; +extern int MilliSeconds; +extern int Seconds; +extern int Minutes; // Category and Scene IDs -extern int activeStageList; -extern int stageListPosition; -extern char currentStageFolder[0x100]; -extern int actID; +extern int ActiveStageList; +extern int StageListPosition; +extern char CurrentStageFolder[0x100]; +extern int ActNumber; extern char titleCardText[0x100]; extern byte titleCardWord2; extern byte activeTileLayers[4]; extern byte tLayerMidPoint; -extern TileLayer stageLayouts[LAYER_COUNT]; +extern TileLayer StageLayouts[LAYER_COUNT]; -extern int bgDeformationData0[DEFORM_COUNT]; -extern int bgDeformationData1[DEFORM_COUNT]; -extern int bgDeformationData2[DEFORM_COUNT]; -extern int bgDeformationData3[DEFORM_COUNT]; +extern int BGDeformationData1[DEFORM_COUNT]; +extern int BGDeformationData2[DEFORM_COUNT]; +extern int BGDeformationData3[DEFORM_COUNT]; +extern int BGDeformationData4[DEFORM_COUNT]; -extern int fgDeformationOffset; -extern int fgDeformationOffsetW; -extern int bgDeformationOffset; -extern int bgDeformationOffsetW; +extern int DeformationPos1; +extern int DeformationPos2; +extern int DeformationPos3; +extern int DeformationPos4; -extern LineScroll hParallax; -extern LineScroll vParallax; +extern LineScroll HParallax; +extern LineScroll VParallax; -extern Tiles128x128 tiles128x128; -extern CollisionMasks collisionMasks[2]; +extern Tiles128x128 StageTiles; +extern CollisionMasks TileCollisions[2]; -extern byte tilesetGFXData[TILESET_SIZE]; +extern byte TileGfx[TILESET_SIZE]; void ProcessStage(); void ResetBackgroundSettings(); -inline void ResetCurrentStageFolder() { strcpy(currentStageFolder, ""); } +inline void ResetCurrentStageFolder() { strcpy(CurrentStageFolder, ""); } inline bool CheckCurrentStageFolder(int stage) { - if (strcmp(currentStageFolder, stageList[activeStageList][stage].folder) == 0) { + if (strcmp(CurrentStageFolder, stageList[ActiveStageList][stage].folder) == 0) { return true; } else { - strcpy(currentStageFolder, stageList[activeStageList][stage].folder); + strcpy(CurrentStageFolder, stageList[ActiveStageList][stage].folder); return false; } } @@ -215,19 +215,10 @@ int LoadStageFile(const char *filePath, int stageID, FileInfo *info); void LoadActLayout(); void LoadStageBackground(); -void LoadStageChunks(); +void Load128x128Mappings(); void LoadStageCollisions(); void LoadStageGIFFile(int stageID); void LoadStageGFXFile(int stageID); - -inline void Copy16x16Tile(ushort dest, ushort src) -{ - byte *destPtr = &tilesetGFXData[TILELAYER_CHUNK_W * dest]; - byte *srcPtr = &tilesetGFXData[TILELAYER_CHUNK_W * src]; - int cnt = TILE_DATASIZE; - while (cnt--) *destPtr++ = *srcPtr++; -} - void SetPlayerScreenPosition(Player *player); void SetPlayerScreenPositionCDStyle(Player *player); void SetPlayerLockedScreenPosition(Player *player); diff --git a/Nexus/Script.cpp b/Nexus/Script.cpp index 356d6fb..da7c8be 100644 --- a/Nexus/Script.cpp +++ b/Nexus/Script.cpp @@ -1,44 +1,38 @@ #include "RetroEngine.hpp" #include -ObjectScript objectScriptList[OBJECT_COUNT]; -ScriptPtr functionScriptList[FUNCTION_COUNT]; +ObjectScript ObjectScriptList[OBJECT_COUNT]; -int scriptData[SCRIPTDATA_COUNT]; -int jumpTableData[JUMPTABLE_COUNT]; -int jumpTableStack[JUMPSTACK_COUNT]; -int functionStack[FUNCSTACK_COUNT]; +int ScriptData[SCRIPTDATA_COUNT]; +int JumpTableData[JUMPTABLE_COUNT]; +int JumpTableStack[JUMPSTACK_COUNT]; -int scriptCodePos = 0; -int jumpTablePos = 0; -int jumpTableStackPos = 0; -int functionStackPos = 0; +int JumpTablePos = 0; +int JumpTableStackPos = 0; -ScriptEngine scriptEng = ScriptEngine(); -char scriptText[0x100]; +ScriptEngine ScriptEng = ScriptEngine(); +char ScriptText[0x100]; -int scriptDataPos = 0; -int scriptDataOffset = 0; -int jumpTableDataPos = 0; -int jumpTableDataOffset = 0; +int ScriptDataPos = 0; +int scriptDataOffset = 0; +int JumpTableDataPos = 0; +int JumpTableOffset = 0; -#define ALIAS_COUNT (0x80) +#define ALIAS_COUNT (0x80) #if !RETRO_USE_ORIGINAL_CODE #define COMMONALIAS_COUNT (22) #else #define COMMONALIAS_COUNT (14) #endif -int aliasCount = 0; +int NO_ALIASES = 0; int lineID = 0; struct AliasInfo { - AliasInfo() - { + AliasInfo() { StrCopy(name, ""); StrCopy(value, ""); } - AliasInfo(const char *aliasName, const char *aliasVal) - { + AliasInfo(const char *aliasName, const char *aliasVal) { StrCopy(name, aliasName); StrCopy(value, aliasVal); } @@ -48,13 +42,11 @@ struct AliasInfo { }; struct FunctionInfo { - FunctionInfo() - { + FunctionInfo() { StrCopy(name, ""); opcodeSize = 0; } - FunctionInfo(const char *functionName, int opSize) - { + FunctionInfo(const char *functionName, int opSize) { StrCopy(name, functionName); opcodeSize = opSize; } @@ -292,20 +284,12 @@ const FunctionInfo functions[] = { FunctionInfo("End", 0), FunctionInfo("PlayStageSfx", 2), FunctionInfo("StopStageSfx", 1) }; -AliasInfo aliases[0x80] = { AliasInfo("true", "1"), - AliasInfo("false", "0"), - AliasInfo("FX_SCALE", "0"), - AliasInfo("FX_ROTATE", "1"), - AliasInfo("FX_INK", "2"), - AliasInfo("PRESENTATION_STAGE", "0"), - AliasInfo("REGULAR_STAGE", "1"), - AliasInfo("BONUS_STAGE", "2"), - AliasInfo("SPECIAL_STAGE", "3"), - AliasInfo("MENU_1", "0"), - AliasInfo("MENU_2", "1"), - AliasInfo("C_TOUCH", "0"), - AliasInfo("C_BOX", "1"), - AliasInfo("C_PLATFORM", "2"), +AliasInfo aliases[0x80] = { + AliasInfo("true", "1"), AliasInfo("false", "0"), AliasInfo("FX_SCALE", "0"), + AliasInfo("FX_ROTATE", "1"), AliasInfo("FX_INK", "2"), AliasInfo("PRESENTATION_STAGE", "0"), + AliasInfo("REGULAR_STAGE", "1"), AliasInfo("BONUS_STAGE", "2"), AliasInfo("SPECIAL_STAGE", "3"), + AliasInfo("MENU_1", "0"), AliasInfo("MENU_2", "1"), AliasInfo("C_TOUCH", "0"), + AliasInfo("C_BOX", "1"), AliasInfo("C_PLATFORM", "2"), #if !RETRO_USE_ORIGINAL_CODE AliasInfo("INK_NONE", "0"), AliasInfo("INK_BLEND", "1"), AliasInfo("INK_TINT", "2"), AliasInfo("FX_TINT", "3"), AliasInfo("FLIP_NONE", "0"), AliasInfo("FLIP_X", "1"), @@ -313,13 +297,18 @@ AliasInfo aliases[0x80] = { AliasInfo("true", "1"), #endif }; - const char scriptEvaluationTokens[][0x4] = { "=", "+=", "-=", "++", "--", "*=", "/=", ">>=", "<<=", "&=", "|=", "^=", "==", ">", ">=", "<", "<=", "!=" }; enum ScriptReadModes { READMODE_NORMAL = 0, READMODE_STRING = 1, READMODE_COMMENTLINE = 2, READMODE_ENDLINE = 3, READMODE_EOF = 4 }; -enum ScriptParseModes { PARSEMODE_SCOPELESS = 0, PARSEMODE_PLATFORMSKIP = 1, PARSEMODE_FUNCTION = 2, PARSEMODE_SWITCHREAD = 3, PARSEMODE_ERROR = 0xFF }; +enum ScriptParseModes { + PARSEMODE_SCOPELESS = 0, + PARSEMODE_PLATFORMSKIP = 1, + PARSEMODE_FUNCTION = 2, + PARSEMODE_SWITCHREAD = 3, + PARSEMODE_ERROR = 0xFF +}; enum ScriptVarTypes { SCRIPTVAR_VAR = 1, SCRIPTVAR_INTCONST = 2, SCRIPTVAR_STRCONST = 3 }; enum ScriptVarArrTypes { VARARR_NONE = 0, VARARR_ARRAY = 1, VARARR_ENTNOPLUS1 = 2, VARARR_ENTNOMINUS1 = 3 }; @@ -557,8 +546,7 @@ enum ScrFunction { FUNC_MAX_CNT }; -void CheckAliasText(char *text) -{ +void CheckAliasText(char *text) { if (FindStringToken(text, "#alias", 1)) return; int textPos = 6; @@ -567,30 +555,26 @@ void CheckAliasText(char *text) while (aliasMatch < 2) { if (aliasMatch) { if (aliasMatch == 1) { - aliases[aliasCount].name[aliasStrPos] = text[textPos]; + aliases[NO_ALIASES].name[aliasStrPos] = text[textPos]; if (text[textPos]) { aliasStrPos++; - } - else { + } else { aliasStrPos = 0; ++aliasMatch; } } - } - else if (text[textPos] == ':') { - aliases[aliasCount].value[aliasStrPos] = 0; - aliasStrPos = 0; - aliasMatch = 1; - } - else { - aliases[aliasCount].value[aliasStrPos++] = text[textPos]; + } else if (text[textPos] == ':') { + aliases[NO_ALIASES].value[aliasStrPos] = 0; + aliasStrPos = 0; + aliasMatch = 1; + } else { + aliases[NO_ALIASES].value[aliasStrPos++] = text[textPos]; } ++textPos; } - ++aliasCount; + ++NO_ALIASES; } -void ConvertArithmaticSyntax(char *text) -{ +void ConvertArithmaticSyntax(char *text) { int token = 0; int offset = 0; int findID = 0; @@ -620,18 +604,17 @@ void ConvertArithmaticSyntax(char *text) StrCopy(text, dest); } } -void ConvertIfWhileStatement(char *text) -{ +void ConvertIfWhileStatement(char *text) { char dest[260]; int compareOp = -1; int strPos = 0; int destStrPos = 0; if (FindStringToken(text, "if", 1)) { - if (!FindStringToken(text, "while", 1)) { //if no "if" but there is "while" + if (!FindStringToken(text, "while", 1)) { // if no "if" but there is "while" for (int i = 0; i < 6; ++i) { destStrPos = FindStringToken(text, scriptEvaluationTokens[i + (FUNC_NOT - 1)], 1); if (destStrPos > -1) { - strPos = destStrPos; + strPos = destStrPos; compareOp = i; } } @@ -639,7 +622,7 @@ void ConvertIfWhileStatement(char *text) text[strPos] = ','; StrCopy(dest, functions[compareOp + FUNC_WEQUAL].name); StrAdd(dest, "("); - AppendIntegerToString(dest, jumpTableDataPos - jumpTableDataOffset); + AppendIntegerToString(dest, JumpTableDataPos - JumpTableOffset); StrAdd(dest, ","); destStrPos = StrLength(dest); for (int i = 5; text[i]; ++i) { @@ -649,17 +632,16 @@ void ConvertIfWhileStatement(char *text) dest[destStrPos] = 0; StrAdd(dest, ")"); StrCopy(text, dest); - jumpTableStack[++jumpTableStackPos] = jumpTableDataPos; - jumpTableData[jumpTableDataPos++] = scriptDataPos - scriptDataOffset; - jumpTableData[jumpTableDataPos++] = 0; + JumpTableStack[++JumpTableStackPos] = JumpTableDataPos; + JumpTableData[JumpTableDataPos++] = ScriptDataPos - scriptDataOffset; + JumpTableData[JumpTableDataPos++] = 0; } } - } - else { + } else { for (int i = 0; i < 6; ++i) { destStrPos = FindStringToken(text, scriptEvaluationTokens[i + (FUNC_NOT - 1)], 1); if (destStrPos > -1) { - strPos = destStrPos; + strPos = destStrPos; compareOp = i; } } @@ -667,7 +649,7 @@ void ConvertIfWhileStatement(char *text) text[strPos] = ','; StrCopy(dest, functions[compareOp + FUNC_IFEQUAL].name); StrAdd(dest, "("); - AppendIntegerToString(dest, jumpTableDataPos - jumpTableDataOffset); + AppendIntegerToString(dest, JumpTableDataPos - JumpTableOffset); StrAdd(dest, ","); destStrPos = StrLength(dest); for (int i = 2; text[i]; ++i) { @@ -677,20 +659,19 @@ void ConvertIfWhileStatement(char *text) dest[destStrPos] = 0; StrAdd(dest, ")"); StrCopy(text, dest); - jumpTableStack[++jumpTableStackPos] = jumpTableDataPos; - jumpTableData[jumpTableDataPos++] = -1; - jumpTableData[jumpTableDataPos++] = 0; + JumpTableStack[++JumpTableStackPos] = JumpTableDataPos; + JumpTableData[JumpTableDataPos++] = -1; + JumpTableData[JumpTableDataPos++] = 0; } } } -bool ConvertSwitchStatement(char *text) -{ +bool ConvertSwitchStatement(char *text) { if (FindStringToken(text, "switch", 1)) return false; char switchText[260]; StrCopy(switchText, "switch"); StrAdd(switchText, "("); - AppendIntegerToString(switchText, jumpTableDataPos - jumpTableDataOffset); + AppendIntegerToString(switchText, JumpTableDataPos - JumpTableOffset); StrAdd(switchText, ","); int pos = StrLength(switchText); for (int i = 6; text[i]; ++i) { @@ -700,15 +681,14 @@ bool ConvertSwitchStatement(char *text) switchText[pos] = 0; StrAdd(switchText, ")"); StrCopy(text, switchText); - jumpTableStack[++jumpTableStackPos] = jumpTableDataPos; - jumpTableData[jumpTableDataPos++] = 0x10000; - jumpTableData[jumpTableDataPos++] = -0x10000; - jumpTableData[jumpTableDataPos++] = -1; - jumpTableData[jumpTableDataPos++] = 0; + JumpTableStack[++JumpTableStackPos] = JumpTableDataPos; + JumpTableData[JumpTableDataPos++] = 0x10000; + JumpTableData[JumpTableDataPos++] = -0x10000; + JumpTableData[JumpTableDataPos++] = -1; + JumpTableData[JumpTableDataPos++] = 0; return true; } -void ConvertFunctionText(char *text) -{ +void ConvertFunctionText(char *text) { char strBuffer[128]; char funcName[132]; int opcode = 0; @@ -726,39 +706,38 @@ void ConvertFunctionText(char *text) } } if (opcode <= 0) { - //error lol - } - else { - scriptData[scriptDataPos++] = opcode; + // error lol + } else { + ScriptData[ScriptDataPos++] = opcode; if (StrComp("else", functions[opcode].name)) - jumpTableData[jumpTableStack[jumpTableStackPos]] = scriptDataPos - scriptDataOffset; + JumpTableData[JumpTableStack[JumpTableStackPos]] = ScriptDataPos - scriptDataOffset; if (StrComp("endif", functions[opcode].name) == 1) { - int jPos = jumpTableStack[jumpTableStackPos]; - jumpTableData[jPos + 1] = scriptDataPos - scriptDataOffset; - if (jumpTableData[jPos] == -1) - jumpTableData[jPos] = (scriptDataPos - scriptDataOffset) - 1; - --jumpTableStackPos; + int jPos = JumpTableStack[JumpTableStackPos]; + JumpTableData[jPos + 1] = ScriptDataPos - scriptDataOffset; + if (JumpTableData[jPos] == -1) + JumpTableData[jPos] = (ScriptDataPos - scriptDataOffset) - 1; + --JumpTableStackPos; } if (StrComp("endswitch", functions[opcode].name)) { - int jPos = jumpTableStack[jumpTableStackPos]; - jumpTableData[jPos + 3] = scriptDataPos - scriptDataOffset; - if (jumpTableData[jPos + 2] == -1) { - jumpTableData[jPos + 2] = (scriptDataPos - scriptDataOffset) - 1; - int caseCnt = abs(jumpTableData[jPos + 1] - jumpTableData[jPos]) + 1; + int jPos = JumpTableStack[JumpTableStackPos]; + JumpTableData[jPos + 3] = ScriptDataPos - scriptDataOffset; + if (JumpTableData[jPos + 2] == -1) { + JumpTableData[jPos + 2] = (ScriptDataPos - scriptDataOffset) - 1; + int caseCnt = abs(JumpTableData[jPos + 1] - JumpTableData[jPos]) + 1; int jOffset = jPos + 4; for (int c = 0; c < caseCnt; ++c) { - if (jumpTableData[jOffset + c] < 0) - jumpTableData[jOffset + c] = jumpTableData[jPos + 2]; + if (JumpTableData[jOffset + c] < 0) + JumpTableData[jOffset + c] = JumpTableData[jPos + 2]; } } - --jumpTableStackPos; + --JumpTableStackPos; } if (StrComp("loop", functions[opcode].name)) { - jumpTableData[jumpTableStack[jumpTableStackPos--] + 1] = scriptDataPos - scriptDataOffset; + JumpTableData[JumpTableStack[JumpTableStackPos--] + 1] = ScriptDataPos - scriptDataOffset; } for (int i = 0; i < opcodeSize; ++i) { @@ -773,8 +752,7 @@ void ConvertFunctionText(char *text) else strBuffer[scriptTextByteID++] = text[textPos]; ++textPos; - } - else { + } else { if (text[textPos] == '[') value = 1; else @@ -785,7 +763,7 @@ void ConvertFunctionText(char *text) funcName[funcNamePos] = 0; strBuffer[scriptTextByteID] = 0; // Eg: TempValue0 = FX_SCALE - for (int a = 0; a < aliasCount; ++a) { + for (int a = 0; a < NO_ALIASES; ++a) { if (StrComp(funcName, aliases[a].name)) { CopyAliasStr(funcName, aliases[a].value, 0); if (FindStringToken(aliases[a].value, "[", 1) > -1) @@ -793,81 +771,76 @@ void ConvertFunctionText(char *text) } } // Eg: TempValue0 = Game.Variable - for (int v = 0; v < globalVariablesCount; ++v) { - if (StrComp(funcName, globalVariableNames[v])) { + for (int v = 0; v < NO_GLOBALVARIABLES; ++v) { + if (StrComp(funcName, GlobalVariableNames[v])) { StrCopy(funcName, "Global"); strBuffer[0] = 0; AppendIntegerToString(strBuffer, v); } } if (ConvertStringToInteger(funcName, &value)) { - scriptData[scriptDataPos++] = SCRIPTVAR_INTCONST; - scriptData[scriptDataPos++] = value; - } - else if (funcName[0] == '"') { - scriptData[scriptDataPos++] = SCRIPTVAR_STRCONST; - scriptData[scriptDataPos++] = StrLength(funcName) - 2; + ScriptData[ScriptDataPos++] = SCRIPTVAR_INTCONST; + ScriptData[ScriptDataPos++] = value; + } else if (funcName[0] == '"') { + ScriptData[ScriptDataPos++] = SCRIPTVAR_STRCONST; + ScriptData[ScriptDataPos++] = StrLength(funcName) - 2; int scriptTextPos = 1; scriptTextByteID = 0; while (scriptTextPos > -1) { switch (scriptTextByteID) { case 0: - scriptData[scriptDataPos] = funcName[scriptTextPos] << 24; + ScriptData[ScriptDataPos] = funcName[scriptTextPos] << 24; ++scriptTextByteID; break; case 1: - scriptData[scriptDataPos] += funcName[scriptTextPos] << 16; + ScriptData[ScriptDataPos] += funcName[scriptTextPos] << 16; ++scriptTextByteID; break; case 2: - scriptData[scriptDataPos] += funcName[scriptTextPos] << 8; + ScriptData[ScriptDataPos] += funcName[scriptTextPos] << 8; ++scriptTextByteID; break; case 3: - scriptData[scriptDataPos++] += funcName[scriptTextPos]; + ScriptData[ScriptDataPos++] += funcName[scriptTextPos]; scriptTextByteID = 0; break; default: break; } if (funcName[scriptTextPos] == '"') { if (scriptTextByteID > 0) - ++scriptDataPos; + ++ScriptDataPos; scriptTextPos = -1; - } - else { + } else { scriptTextPos++; } } - } - else { - scriptData[scriptDataPos++] = SCRIPTVAR_VAR; + } else { + ScriptData[ScriptDataPos++] = SCRIPTVAR_VAR; if (strBuffer[0]) { - scriptData[scriptDataPos] = VARARR_ARRAY; + ScriptData[ScriptDataPos] = VARARR_ARRAY; if (strBuffer[0] == '+') - scriptData[scriptDataPos] = VARARR_ENTNOPLUS1; + ScriptData[ScriptDataPos] = VARARR_ENTNOPLUS1; if (strBuffer[0] == '-') - scriptData[scriptDataPos] = VARARR_ENTNOMINUS1; - ++scriptDataPos; + ScriptData[ScriptDataPos] = VARARR_ENTNOMINUS1; + ++ScriptDataPos; if (strBuffer[0] == '-' || strBuffer[0] == '+') { for (int i = 0; i < StrLength(strBuffer); ++i) strBuffer[i] = strBuffer[i + 1]; } if (ConvertStringToInteger(strBuffer, &value) == 1) { - scriptData[scriptDataPos++] = 0; - scriptData[scriptDataPos++] = value; - } - else { + ScriptData[ScriptDataPos++] = 0; + ScriptData[ScriptDataPos++] = value; + } else { if (StrComp(strBuffer, "ArrayPos0")) value = 0; if (StrComp(strBuffer, "ArrayPos1")) value = 1; if (StrComp(strBuffer, "TempObjectPos")) value = 2; - scriptData[scriptDataPos++] = 1; - scriptData[scriptDataPos++] = value; + ScriptData[ScriptDataPos++] = 1; + ScriptData[ScriptDataPos++] = value; } - } - else { - scriptData[scriptDataPos++] = VARARR_NONE; + } else { + ScriptData[ScriptDataPos++] = VARARR_NONE; } value = -1; for (int i = 0; i < VAR_MAX_CNT; ++i) { @@ -876,16 +849,15 @@ void ConvertFunctionText(char *text) } if (value == -1) { - //error - value = 0; + // error + value = 0; } - scriptData[scriptDataPos++] = value; + ScriptData[ScriptDataPos++] = value; } } } } -void CheckCaseNumber(char *text) -{ +void CheckCaseNumber(char *text) { if (FindStringToken(text, "case", 1)) return; @@ -899,13 +871,12 @@ void CheckCaseNumber(char *text) caseString[caseStrPos++] = caseChar; caseChar = text[textPos++]; } while (caseChar); - } - else { + } else { caseStrPos = 0; } caseString[caseStrPos] = 0; - for (int a = 0; a < aliasCount; ++a) { + for (int a = 0; a < NO_ALIASES; ++a) { if (StrComp(aliases[a].name, caseString)) { StrCopy(caseString, aliases[a].value); break; @@ -914,39 +885,35 @@ void CheckCaseNumber(char *text) int caseID = 0; if (ConvertStringToInteger(caseString, &caseID)) { - int stackValue = jumpTableStack[jumpTableStackPos]; - if (caseID < jumpTableData[stackValue]) - jumpTableData[stackValue] = caseID; + int stackValue = JumpTableStack[JumpTableStackPos]; + if (caseID < JumpTableData[stackValue]) + JumpTableData[stackValue] = caseID; stackValue++; - if (caseID > jumpTableData[stackValue]) - jumpTableData[stackValue] = caseID; - } - else { - printLog("WARNING: unable to convert case string \"%s\" to int, on line %d", caseString, lineID); + if (caseID > JumpTableData[stackValue]) + JumpTableData[stackValue] = caseID; + } else { + PrintLog("WARNING: unable to convert case string \"%s\" to int, on line %d", caseString, lineID); } } -bool ReadSwitchCase(char *text) -{ +bool ReadSwitchCase(char *text) { char caseText[0x80]; if (FindStringToken(text, "case", 1)) { if (FindStringToken(text, "default", 1)) { return false; - } - else { - int jumpTablepos = jumpTableStack[jumpTableStackPos]; - jumpTableData[jumpTablepos + 2] = scriptDataPos - scriptDataOffset; - int cnt = abs(jumpTableData[jumpTablepos + 1] - jumpTableData[jumpTablepos]) + 1; + } else { + int jumpTablepos = JumpTableStack[JumpTableStackPos]; + JumpTableData[jumpTablepos + 2] = ScriptDataPos - scriptDataOffset; + int cnt = abs(JumpTableData[jumpTablepos + 1] - JumpTableData[jumpTablepos]) + 1; int jOffset = jumpTablepos + 4; for (int i = 0; i < cnt; ++i) { - if (jumpTableData[jOffset + i] < 0) - jumpTableData[jOffset + i] = scriptDataPos - scriptDataOffset; + if (JumpTableData[jOffset + i] < 0) + JumpTableData[jOffset + i] = ScriptDataPos - scriptDataOffset; } return true; } - } - else { - int textPos = 4; + } else { + int textPos = 4; int caseStringPos = 0; while (text[textPos]) { if (text[textPos] != ':') @@ -954,23 +921,22 @@ bool ReadSwitchCase(char *text) ++textPos; } caseText[caseStringPos] = 0; - for (int a = 0; a < aliasCount; ++a) { + for (int a = 0; a < NO_ALIASES; ++a) { if (StrComp(caseText, aliases[a].name)) StrCopy(caseText, aliases[a].value); } int val = 0; - int jPos = jumpTableStack[jumpTableStackPos]; + int jPos = JumpTableStack[JumpTableStackPos]; int jOffset = jPos + 4; if (ConvertStringToInteger(caseText, &val)) - jumpTableData[val - jumpTableData[jPos] + jOffset] = scriptDataPos - scriptDataOffset; + JumpTableData[val - JumpTableData[jPos] + jOffset] = ScriptDataPos - scriptDataOffset; return true; } return false; } -void AppendIntegerToString(char *text, int value) -{ +void AppendIntegerToString(char *text, int value) { int textPos = 0; while (true) { if (!text[textPos]) @@ -983,7 +949,7 @@ void AppendIntegerToString(char *text, int value) while (v != 0) { v /= 10; cnt++; - } + } v = 0; for (int i = cnt - 1; i >= 0; --i) { @@ -992,7 +958,7 @@ void AppendIntegerToString(char *text, int value) int strValue = v + '0'; if (strValue < '0' || strValue > '9') { - //what + // what } text[textPos++] = strValue; } @@ -1000,8 +966,7 @@ void AppendIntegerToString(char *text, int value) text[textPos++] = '0'; text[textPos] = 0; } -bool ConvertStringToInteger(char *text, int *value) -{ +bool ConvertStringToInteger(char *text, int *value) { int charID = 0; bool negative = false; int base = 10; @@ -1014,8 +979,7 @@ bool ConvertStringToInteger(char *text, int *value) negative = true; charID = 1; --strLength; - } - else if (*text == '+') { + } else if (*text == '+') { charID = 1; --strLength; } @@ -1051,34 +1015,28 @@ bool ConvertStringToInteger(char *text, int *value) if (strLength <= 0) { if (text[charID] >= '0' && text[charID] <= '9') { *value = text[charID] + *value - '0'; - } - else if (text[charID] >= 'a' && text[charID] <= 'f') { + } else if (text[charID] >= 'a' && text[charID] <= 'f') { charVal = text[charID] - 'a'; charVal += 10; *value += charVal; - } - else if (text[charID] >= 'A' && text[charID] <= 'F') { + } else if (text[charID] >= 'A' && text[charID] <= 'F') { charVal = text[charID] - 'A'; charVal += 10; *value += charVal; } - } - else { + } else { int strlen = strLength + 1; charVal = 0; if (text[charID] >= '0' && text[charID] <= '9') { charVal = text[charID] - '0'; - } - else if (text[charID] >= 'a' && text[charID] <= 'f') { + } else if (text[charID] >= 'a' && text[charID] <= 'f') { charVal = text[charID] - 'a'; charVal += 10; - } - else if (text[charID] >= 'A' && text[charID] <= 'F') { + } else if (text[charID] >= 'A' && text[charID] <= 'F') { charVal = text[charID] - 'A'; charVal += 10; } - for (; --strlen; charVal *= base) - ; + for (; --strlen; charVal *= base); *value += charVal; } --strLength; @@ -1088,8 +1046,7 @@ bool ConvertStringToInteger(char *text, int *value) *value = -*value; return true; } -void CopyAliasStr(char *dest, char *text, bool arrayIndex) -{ +void CopyAliasStr(char *dest, char *text, bool arrayIndex) { int textPos = 0; int destPos = 0; bool arrayValue = false; @@ -1101,22 +1058,19 @@ void CopyAliasStr(char *dest, char *text, bool arrayIndex) else dest[destPos++] = text[textPos]; ++textPos; - } - else { + } else { if (text[textPos] == '[') arrayValue = true; ++textPos; } } - } - else { + } else { while (text[textPos]) { if (arrayValue) { if (text[textPos] == ']') arrayValue = false; ++textPos; - } - else { + } else { if (text[textPos] == '[') arrayValue = true; else @@ -1127,8 +1081,7 @@ void CopyAliasStr(char *dest, char *text, bool arrayIndex) } dest[destPos] = 0; } -bool CheckOpcodeType(char *text) -{ +bool CheckOpcodeType(char *text) { while (true) { int c = *text; if (!*text) @@ -1140,12 +1093,11 @@ bool CheckOpcodeType(char *text) return true; } -void ParseScriptFile(char *scriptName, int scriptID) -{ +void ParseScriptFile(char *scriptName, int scriptID) { int currentSub = -1; - jumpTableStackPos = 0; + JumpTableStackPos = 0; lineID = 0; - aliasCount = COMMONALIAS_COUNT; + NO_ALIASES = COMMONALIAS_COUNT; for (int i = COMMONALIAS_COUNT; i < ALIAS_COUNT; ++i) { StrCopy(aliases[i].name, ""); StrCopy(aliases[i].value, ""); @@ -1156,11 +1108,11 @@ void ParseScriptFile(char *scriptName, int scriptID) StrAdd(scriptPath, scriptName); FileInfo info; if (LoadFile(scriptPath, &info)) { - int readMode = READMODE_NORMAL; - int parseMode = PARSEMODE_SCOPELESS; - char prevChar = 0; - char curChar = 0; - int switchDeep = 0; + int readMode = READMODE_NORMAL; + int parseMode = PARSEMODE_SCOPELESS; + char prevChar = 0; + char curChar = 0; + int switchDeep = 0; while (readMode < READMODE_EOF) { int textPos = 0; readMode = READMODE_NORMAL; @@ -1171,43 +1123,36 @@ void ParseScriptFile(char *scriptName, int scriptID) if (curChar == '\t' || curChar == '\r' || curChar == '\n' || curChar == ';' || readMode >= READMODE_COMMENTLINE) { if ((curChar == '\n' && prevChar != '\r') || (curChar == '\n' && prevChar == '\r') || curChar == ';') { readMode = READMODE_ENDLINE; - scriptText[textPos] = 0; + ScriptText[textPos] = 0; } - } - else if (curChar != '/' || textPos <= 0) { - scriptText[textPos++] = curChar; + } else if (curChar != '/' || textPos <= 0) { + ScriptText[textPos++] = curChar; if (curChar == '"') readMode = READMODE_NORMAL; - } - else if (curChar == '/' && prevChar == '/') { + } else if (curChar == '/' && prevChar == '/') { readMode = READMODE_COMMENTLINE; - scriptText[--textPos] = 0; + ScriptText[--textPos] = 0; + } else { + ScriptText[textPos++] = curChar; } - else { - scriptText[textPos++] = curChar; - } - } - else if (curChar == ' ' || curChar == '\t' || curChar == '\r' || curChar == '\n' || curChar == ';' - || readMode >= READMODE_COMMENTLINE) { + } else if (curChar == ' ' || curChar == '\t' || curChar == '\r' || curChar == '\n' || curChar == ';' + || readMode >= READMODE_COMMENTLINE) { if ((curChar == '\n' && prevChar != '\r') || (curChar == '\n' && prevChar == '\r') || curChar == ';') { readMode = READMODE_ENDLINE; - scriptText[textPos] = 0; + ScriptText[textPos] = 0; } - } - else if (curChar != '/' || textPos <= 0) { - scriptText[textPos++] = curChar; + } else if (curChar != '/' || textPos <= 0) { + ScriptText[textPos++] = curChar; if (curChar == '"' && !readMode) readMode = READMODE_STRING; - } - else if (curChar == '/' && prevChar == '/') { + } else if (curChar == '/' && prevChar == '/') { readMode = READMODE_COMMENTLINE; - scriptText[--textPos] = 0; - } - else { - scriptText[textPos++] = curChar; + ScriptText[--textPos] = 0; + } else { + ScriptText[textPos++] = curChar; } if (ReachedEndOfFile()) { - scriptText[textPos] = 0; + ScriptText[textPos] = 0; readMode = READMODE_EOF; } } @@ -1215,104 +1160,103 @@ void ParseScriptFile(char *scriptName, int scriptID) switch (parseMode) { case PARSEMODE_SCOPELESS: ++lineID; - CheckAliasText(scriptText); - if (StrComp(scriptText, "subObjectMain")) { + CheckAliasText(ScriptText); + if (StrComp(ScriptText, "subObjectMain")) { parseMode = PARSEMODE_FUNCTION; - objectScriptList[scriptID].subMain.scriptCodePtr = scriptDataPos; - objectScriptList[scriptID].subMain.jumpTablePtr = jumpTableDataPos; - scriptDataOffset = scriptDataPos; - jumpTableDataOffset = jumpTableDataPos; + ObjectScriptList[scriptID].subMain.scriptCodePtr = ScriptDataPos; + ObjectScriptList[scriptID].subMain.jumpTablePtr = JumpTableDataPos; + scriptDataOffset = ScriptDataPos; + JumpTableOffset = JumpTableDataPos; currentSub = SUB_MAIN; } - if (StrComp(scriptText, "subObjectPlayerInteraction")) { + if (StrComp(ScriptText, "subObjectPlayerInteraction")) { parseMode = PARSEMODE_FUNCTION; - objectScriptList[scriptID].subPlayerInteraction.scriptCodePtr = scriptDataPos; - objectScriptList[scriptID].subPlayerInteraction.jumpTablePtr = jumpTableDataPos; - scriptDataOffset = scriptDataPos; - jumpTableDataOffset = jumpTableDataPos; + ObjectScriptList[scriptID].subPlayerInteraction.scriptCodePtr = ScriptDataPos; + ObjectScriptList[scriptID].subPlayerInteraction.jumpTablePtr = JumpTableDataPos; + scriptDataOffset = ScriptDataPos; + JumpTableOffset = JumpTableDataPos; currentSub = SUB_PLAYERINTERACTION; } - if (StrComp(scriptText, "subObjectDraw")) { + if (StrComp(ScriptText, "subObjectDraw")) { parseMode = PARSEMODE_FUNCTION; - objectScriptList[scriptID].subDraw.scriptCodePtr = scriptDataPos; - objectScriptList[scriptID].subDraw.jumpTablePtr = jumpTableDataPos; - scriptDataOffset = scriptDataPos; - jumpTableDataOffset = jumpTableDataPos; + ObjectScriptList[scriptID].subDraw.scriptCodePtr = ScriptDataPos; + ObjectScriptList[scriptID].subDraw.jumpTablePtr = JumpTableDataPos; + scriptDataOffset = ScriptDataPos; + JumpTableOffset = JumpTableDataPos; currentSub = SUB_DRAW; } - if (StrComp(scriptText, "subObjectStartup")) { + if (StrComp(ScriptText, "subObjectStartup")) { parseMode = PARSEMODE_FUNCTION; - objectScriptList[scriptID].subStartup.scriptCodePtr = scriptDataPos; - objectScriptList[scriptID].subStartup.jumpTablePtr = jumpTableDataPos; - scriptDataOffset = scriptDataPos; - jumpTableDataOffset = jumpTableDataPos; + ObjectScriptList[scriptID].subStartup.scriptCodePtr = ScriptDataPos; + ObjectScriptList[scriptID].subStartup.jumpTablePtr = JumpTableDataPos; + scriptDataOffset = ScriptDataPos; + JumpTableOffset = JumpTableDataPos; currentSub = SUB_SETUP; } - if (StrComp(scriptText, "subPlayerMain")) { + if (StrComp(ScriptText, "subPlayerMain")) { parseMode = PARSEMODE_FUNCTION; - playerScriptList[scriptID].scriptCodePtr_PlayerMain = scriptDataPos; - playerScriptList[scriptID].jumpTablePtr_PlayerMain = jumpTableDataPos; - scriptDataOffset = scriptDataPos; - jumpTableDataOffset = jumpTableDataPos; + PlayerScriptList[scriptID].scriptCodePtr_PlayerMain = ScriptDataPos; + PlayerScriptList[scriptID].jumpTablePtr_PlayerMain = JumpTableDataPos; + scriptDataOffset = ScriptDataPos; + JumpTableOffset = JumpTableDataPos; currentSub = SUB_PLAYERMAIN; } - if (!FindStringToken(scriptText, "subPlayerState", 1)) { + if (!FindStringToken(ScriptText, "subPlayerState", 1)) { char stateName[0x20]; - for (textPos = 14; scriptText[textPos]; ++textPos) stateName[textPos - 14] = scriptText[textPos]; + for (textPos = 14; ScriptText[textPos]; ++textPos) stateName[textPos - 14] = ScriptText[textPos]; stateName[textPos - 14] = 0; - for (int a = 0; a < aliasCount; ++a) { + for (int a = 0; a < NO_ALIASES; ++a) { if (StrComp(stateName, aliases[a].name)) StrCopy(stateName, aliases[a].value); } int val = 0; if (ConvertStringToInteger(stateName, &val) == 1) { - playerScriptList[scriptID].scriptCodePtr_PlayerState[val] = scriptDataPos; - playerScriptList[scriptID].jumpTablePtr_PlayerState[val] = jumpTablePos; - scriptDataOffset = scriptDataPos; - jumpTableDataOffset = jumpTablePos; + PlayerScriptList[scriptID].scriptCodePtr_PlayerState[val] = ScriptDataPos; + PlayerScriptList[scriptID].jumpTablePtr_PlayerState[val] = JumpTablePos; + scriptDataOffset = ScriptDataPos; + JumpTableOffset = JumpTablePos; parseMode = PARSEMODE_FUNCTION; currentSub = SUB_PLAYERSTATE; - } - else { + } else { parseMode = PARSEMODE_SCOPELESS; } } break; case PARSEMODE_PLATFORMSKIP: ++lineID; - if (!FindStringToken(scriptText, "{", 1)) + if (!FindStringToken(ScriptText, "{", 1)) parseMode = PARSEMODE_FUNCTION; break; case PARSEMODE_FUNCTION: ++lineID; - if (scriptText[0]) { - if (StrComp(scriptText, "endsub")) { - scriptData[scriptDataPos++] = FUNC_END; + if (ScriptText[0]) { + if (StrComp(ScriptText, "endsub")) { + ScriptData[ScriptDataPos++] = FUNC_END; parseMode = PARSEMODE_SCOPELESS; - } - else { - ConvertIfWhileStatement(scriptText); - if (ConvertSwitchStatement(scriptText)) { + } else { + ConvertIfWhileStatement(ScriptText); + if (ConvertSwitchStatement(ScriptText)) { parseMode = PARSEMODE_SWITCHREAD; info.readPos = (int)GetFilePosition(); switchDeep = 0; } - ConvertArithmaticSyntax(scriptText); - if (!ReadSwitchCase(scriptText)) { - ConvertFunctionText(scriptText); - if (!scriptText[0]) { + ConvertArithmaticSyntax(ScriptText); + if (!ReadSwitchCase(ScriptText)) { + ConvertFunctionText(ScriptText); + if (!ScriptText[0]) { parseMode = PARSEMODE_SCOPELESS; switch (currentSub) { - case SUB_MAIN: scriptData[objectScriptList[scriptID].subMain.scriptCodePtr] = FUNC_END; break; + case SUB_MAIN: ScriptData[ObjectScriptList[scriptID].subMain.scriptCodePtr] = FUNC_END; break; case SUB_PLAYERINTERACTION: - scriptData[objectScriptList[scriptID].subPlayerInteraction.scriptCodePtr] = FUNC_END; + ScriptData[ObjectScriptList[scriptID].subPlayerInteraction.scriptCodePtr] = FUNC_END; break; - case SUB_DRAW: scriptData[objectScriptList[scriptID].subDraw.scriptCodePtr] = FUNC_END; break; - case SUB_SETUP: scriptData[objectScriptList[scriptID].subStartup.scriptCodePtr] = FUNC_END; break; - case SUB_PLAYERMAIN: scriptData[playerScriptList[scriptID].scriptCodePtr_PlayerMain] = FUNC_END; break; + case SUB_DRAW: ScriptData[ObjectScriptList[scriptID].subDraw.scriptCodePtr] = FUNC_END; break; + case SUB_SETUP: ScriptData[ObjectScriptList[scriptID].subStartup.scriptCodePtr] = FUNC_END; break; + case SUB_PLAYERMAIN: ScriptData[PlayerScriptList[scriptID].scriptCodePtr_PlayerMain] = FUNC_END; break; case SUB_PLAYERSTATE: - for (int i = 0; i < 256; ++i) scriptData[playerScriptList[scriptID].scriptCodePtr_PlayerState[i]] = FUNC_END; + for (int i = 0; i < 256; ++i) + ScriptData[PlayerScriptList[scriptID].scriptCodePtr_PlayerState[i]] = FUNC_END; break; default: break; } @@ -1322,21 +1266,19 @@ void ParseScriptFile(char *scriptName, int scriptID) } break; case PARSEMODE_SWITCHREAD: - if (!FindStringToken(scriptText, "switch", 1)) + if (!FindStringToken(ScriptText, "switch", 1)) ++switchDeep; if (switchDeep) { - if (!FindStringToken(scriptText, "endswitch", 1)) + if (!FindStringToken(ScriptText, "endswitch", 1)) --switchDeep; - } - else if (FindStringToken(scriptText, "endswitch", 1)) { - CheckCaseNumber(scriptText); - } - else { + } else if (FindStringToken(ScriptText, "endswitch", 1)) { + CheckCaseNumber(ScriptText); + } else { SetFilePosition(info.readPos); parseMode = PARSEMODE_FUNCTION; - int jPos = jumpTableStack[jumpTableStackPos]; - switchDeep = abs(jumpTableData[jPos + 1] - jumpTableData[jPos]) + 1; - for (textPos = 0; textPos < switchDeep; ++textPos) jumpTableData[jumpTableDataPos++] = -1; + int jPos = JumpTableStack[JumpTableStackPos]; + switchDeep = abs(JumpTableData[jPos + 1] - JumpTableData[jPos]) + 1; + for (textPos = 0; textPos < switchDeep; ++textPos) JumpTableData[JumpTableDataPos++] = -1; } break; default: break; @@ -1347,37 +1289,34 @@ void ParseScriptFile(char *scriptName, int scriptID) } } -void ClearScriptData() -{ - memset(scriptData, 0, SCRIPTDATA_COUNT * sizeof(int)); - memset(jumpTableData, 0, JUMPTABLE_COUNT * sizeof(int)); +void ClearScriptData() { + memset(ScriptData, 0, SCRIPTDATA_COUNT * sizeof(int)); + memset(JumpTableData, 0, JUMPTABLE_COUNT * sizeof(int)); + + ScriptFramesNo = 0; - scriptFrameCount = 0; - - scriptCodePos = 0; - jumpTablePos = 0; - jumpTableStackPos = 0; - functionStackPos = 0; + JumpTablePos = 0; + JumpTableStackPos = 0; - scriptDataPos = 0; - scriptDataOffset = 0; - jumpTableDataPos = 0; - jumpTableDataOffset = 0; + ScriptDataPos = 0; + scriptDataOffset = 0; + JumpTableDataPos = 0; + JumpTableOffset = 0; - aliasCount = COMMONALIAS_COUNT; - lineID = 0; + NO_ALIASES = COMMONALIAS_COUNT; + lineID = 0; for (int p = 0; p < PLAYER_COUNT; ++p) { for (int s = 0; s < 256; ++s) { - playerScriptList[p].scriptCodePtr_PlayerState[s] = SCRIPTDATA_COUNT - 1; - playerScriptList[p].jumpTablePtr_PlayerState[s] = JUMPTABLE_COUNT - 1; + PlayerScriptList[p].scriptCodePtr_PlayerState[s] = SCRIPTDATA_COUNT - 1; + PlayerScriptList[p].jumpTablePtr_PlayerState[s] = JUMPTABLE_COUNT - 1; } - playerScriptList[p].scriptCodePtr_PlayerMain = SCRIPTDATA_COUNT - 1; - playerScriptList[p].jumpTablePtr_PlayerMain = JUMPTABLE_COUNT - 1; + PlayerScriptList[p].scriptCodePtr_PlayerMain = SCRIPTDATA_COUNT - 1; + PlayerScriptList[p].jumpTablePtr_PlayerMain = JUMPTABLE_COUNT - 1; } for (int o = 0; o < OBJECT_COUNT; ++o) { - ObjectScript *scriptInfo = &objectScriptList[o]; + ObjectScript *scriptInfo = &ObjectScriptList[o]; scriptInfo->subMain.scriptCodePtr = SCRIPTDATA_COUNT - 1; scriptInfo->subMain.jumpTablePtr = JUMPTABLE_COUNT - 1; scriptInfo->subPlayerInteraction.scriptCodePtr = SCRIPTDATA_COUNT - 1; @@ -1386,469 +1325,442 @@ void ClearScriptData() scriptInfo->subDraw.jumpTablePtr = JUMPTABLE_COUNT - 1; scriptInfo->subStartup.scriptCodePtr = SCRIPTDATA_COUNT - 1; scriptInfo->subStartup.jumpTablePtr = JUMPTABLE_COUNT - 1; - scriptInfo->frameStartPtr = scriptFrames; + scriptInfo->frameStartPtr = ScriptFrames; scriptInfo->spriteSheetID = 0; } - - for (int f = 0; f < FUNCTION_COUNT; ++f) { - functionScriptList[f].scriptCodePtr = SCRIPTDATA_COUNT - 1; - functionScriptList[f].jumpTablePtr = JUMPTABLE_COUNT - 1; - } } -void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) -{ - bool running = true; - int scriptDataPtr = scriptCodePtr; - //int jumpTableDataPtr = jumpTablePtr; - jumpTableStackPos = 0; - functionStackPos = 0; +void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) { + bool running = true; + int scriptDataPtr = scriptCodePtr; + JumpTableStackPos = 0; while (running) { - int opcode = scriptData[scriptDataPtr++]; + int opcode = ScriptData[scriptDataPtr++]; int opcodeSize = functions[opcode].opcodeSize; int scriptCodeOffset = scriptDataPtr; // Get Valuess for (int i = 0; i < opcodeSize; ++i) { - int opcodeType = scriptData[scriptDataPtr++]; + int opcodeType = ScriptData[scriptDataPtr++]; if (opcodeType == SCRIPTVAR_VAR) { int arrayVal = 0; - switch (scriptData[scriptDataPtr++]) { - case VARARR_NONE: arrayVal = objectLoop; break; + switch (ScriptData[scriptDataPtr++]) { + case VARARR_NONE: arrayVal = ObjectLoop; break; case VARARR_ARRAY: - if (scriptData[scriptDataPtr++] == 1) - arrayVal = scriptEng.arrayPosition[scriptData[scriptDataPtr++]]; + if (ScriptData[scriptDataPtr++] == 1) + arrayVal = ScriptEng.arrayPosition[ScriptData[scriptDataPtr++]]; else - arrayVal = scriptData[scriptDataPtr++]; + arrayVal = ScriptData[scriptDataPtr++]; break; case VARARR_ENTNOPLUS1: - if (scriptData[scriptDataPtr++] == 1) - arrayVal = scriptEng.arrayPosition[scriptData[scriptDataPtr++]] + objectLoop; + if (ScriptData[scriptDataPtr++] == 1) + arrayVal = ScriptEng.arrayPosition[ScriptData[scriptDataPtr++]] + ObjectLoop; else - arrayVal = scriptData[scriptDataPtr++] + objectLoop; + arrayVal = ScriptData[scriptDataPtr++] + ObjectLoop; break; case VARARR_ENTNOMINUS1: - if (scriptData[scriptDataPtr++] == 1) - arrayVal = objectLoop - scriptEng.arrayPosition[scriptData[scriptDataPtr++]]; + if (ScriptData[scriptDataPtr++] == 1) + arrayVal = ObjectLoop - ScriptEng.arrayPosition[ScriptData[scriptDataPtr++]]; else - arrayVal = objectLoop - scriptData[scriptDataPtr++]; + arrayVal = ObjectLoop - ScriptData[scriptDataPtr++]; break; default: break; } // Variables - switch (scriptData[scriptDataPtr++]) { + switch (ScriptData[scriptDataPtr++]) { default: break; case VAR_OBJECTTYPE: { - scriptEng.operands[i] = objectEntityList[arrayVal].type; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].type; break; } case VAR_OBJECTPROPERTYVALUE: { - scriptEng.operands[i] = objectEntityList[arrayVal].propertyValue; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].propertyValue; break; } case VAR_OBJECTXPOS: { - scriptEng.operands[i] = objectEntityList[arrayVal].XPos; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].XPos; break; } case VAR_OBJECTYPOS: { - scriptEng.operands[i] = objectEntityList[arrayVal].YPos; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].YPos; break; } case VAR_OBJECTIXPOS: { - scriptEng.operands[i] = objectEntityList[arrayVal].XPos >> 16; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].XPos >> 16; break; } case VAR_OBJECTIYPOS: { - scriptEng.operands[i] = objectEntityList[arrayVal].YPos >> 16; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].YPos >> 16; break; } case VAR_OBJECTSTATE: { - scriptEng.operands[i] = objectEntityList[arrayVal].state; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].state; break; } case VAR_OBJECTROTATION: { - scriptEng.operands[i] = objectEntityList[arrayVal].rotation; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].rotation; break; } case VAR_OBJECTSCALE: { - scriptEng.operands[i] = objectEntityList[arrayVal].scale; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].scale; break; } case VAR_OBJECTPRIORITY: { - scriptEng.operands[i] = objectEntityList[arrayVal].priority; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].priority; break; } case VAR_OBJECTDRAWORDER: { - scriptEng.operands[i] = objectEntityList[arrayVal].drawOrder; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].drawOrder; break; } case VAR_OBJECTDIRECTION: { - scriptEng.operands[i] = objectEntityList[arrayVal].direction; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].direction; break; } case VAR_OBJECTINKEFFECT: { - scriptEng.operands[i] = objectEntityList[arrayVal].inkEffect; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].inkEffect; break; } case VAR_OBJECTFRAME: { - scriptEng.operands[i] = objectEntityList[arrayVal].frame; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].frame; break; } case VAR_OBJECTVALUE0: { - scriptEng.operands[i] = objectEntityList[arrayVal].values[0]; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].values[0]; break; } case VAR_OBJECTVALUE1: { - scriptEng.operands[i] = objectEntityList[arrayVal].values[1]; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].values[1]; break; } case VAR_OBJECTVALUE2: { - scriptEng.operands[i] = objectEntityList[arrayVal].values[2]; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].values[2]; break; } case VAR_OBJECTVALUE3: { - scriptEng.operands[i] = objectEntityList[arrayVal].values[3]; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].values[3]; break; } case VAR_OBJECTVALUE4: { - scriptEng.operands[i] = objectEntityList[arrayVal].values[4]; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].values[4]; break; } case VAR_OBJECTVALUE5: { - scriptEng.operands[i] = objectEntityList[arrayVal].values[5]; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].values[5]; break; } case VAR_OBJECTVALUE6: { - scriptEng.operands[i] = objectEntityList[arrayVal].values[6]; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].values[6]; break; } case VAR_OBJECTVALUE7: { - scriptEng.operands[i] = objectEntityList[arrayVal].values[7]; - break; - } - case VAR_TEMPVALUE0: scriptEng.operands[i] = scriptEng.tempValue[0]; break; - case VAR_TEMPVALUE1: scriptEng.operands[i] = scriptEng.tempValue[1]; break; - case VAR_TEMPVALUE2: scriptEng.operands[i] = scriptEng.tempValue[2]; break; - case VAR_TEMPVALUE3: scriptEng.operands[i] = scriptEng.tempValue[3]; break; - case VAR_TEMPVALUE4: scriptEng.operands[i] = scriptEng.tempValue[4]; break; - case VAR_TEMPVALUE5: scriptEng.operands[i] = scriptEng.tempValue[5]; break; - case VAR_TEMPVALUE6: scriptEng.operands[i] = scriptEng.tempValue[6]; break; - case VAR_TEMPVALUE7: scriptEng.operands[i] = scriptEng.tempValue[7]; break; - case VAR_CHECKRESULT: scriptEng.operands[i] = scriptEng.checkResult; break; - case VAR_ARRAYPOS0: scriptEng.operands[i] = scriptEng.arrayPosition[0]; break; - case VAR_ARRAYPOS1: scriptEng.operands[i] = scriptEng.arrayPosition[1]; break; - case VAR_KEYDOWNUP: scriptEng.operands[i] = keyDown.up; break; - case VAR_KEYDOWNDOWN: scriptEng.operands[i] = keyDown.down; break; - case VAR_KEYDOWNLEFT: scriptEng.operands[i] = keyDown.left; break; - case VAR_KEYDOWNRIGHT: scriptEng.operands[i] = keyDown.right; break; - case VAR_KEYDOWNBUTTONA: scriptEng.operands[i] = keyDown.A; break; - case VAR_KEYDOWNBUTTONB: scriptEng.operands[i] = keyDown.B; break; - case VAR_KEYDOWNBUTTONC: scriptEng.operands[i] = keyDown.C; break; - case VAR_KEYDOWNSTART: scriptEng.operands[i] = keyDown.start; break; - case VAR_KEYPRESSUP: scriptEng.operands[i] = keyPress.up; break; - case VAR_KEYPRESSDOWN: scriptEng.operands[i] = keyPress.down; break; - case VAR_KEYPRESSLEFT: scriptEng.operands[i] = keyPress.left; break; - case VAR_KEYPRESSRIGHT: scriptEng.operands[i] = keyPress.right; break; - case VAR_KEYPRESSBUTTONA: scriptEng.operands[i] = keyPress.A; break; - case VAR_KEYPRESSBUTTONB: scriptEng.operands[i] = keyPress.B; break; - case VAR_KEYPRESSBUTTONC: scriptEng.operands[i] = keyPress.C; break; - case VAR_KEYPRESSSTART: scriptEng.operands[i] = keyPress.start; break; - case VAR_MENU1SELECTION: scriptEng.operands[i] = gameMenu[0].selection1; break; - case VAR_MENU2SELECTION: scriptEng.operands[i] = gameMenu[1].selection1; break; - case VAR_STAGEACTIVELIST: scriptEng.operands[i] = activeStageList; break; - case VAR_STAGELISTPOS: scriptEng.operands[i] = stageListPosition; break; - case VAR_GLOBAL: scriptEng.operands[i] = globalVariables[arrayVal]; break; - case VAR_XSCROLLOFFSET: scriptEng.operands[i] = xScrollOffset; break; - case VAR_YSCROLLOFFSET: scriptEng.operands[i] = yScrollOffset; break; - case VAR_STAGETIMEENABLED: scriptEng.operands[i] = timeEnabled; break; - case VAR_STAGEMILLISECONDS: scriptEng.operands[i] = stageMilliseconds; break; - case VAR_STAGESECONDS: scriptEng.operands[i] = stageSeconds; break; - case VAR_STAGEMINUTES: scriptEng.operands[i] = stageMinutes; break; - case VAR_STAGEACTNO: scriptEng.operands[i] = actID; break; - case VAR_OBJECTENTITYNO: scriptEng.operands[i] = arrayVal; break; + ScriptEng.operands[i] = ObjectEntityList[arrayVal].values[7]; + break; + } + case VAR_TEMPVALUE0: ScriptEng.operands[i] = ScriptEng.tempValue[0]; break; + case VAR_TEMPVALUE1: ScriptEng.operands[i] = ScriptEng.tempValue[1]; break; + case VAR_TEMPVALUE2: ScriptEng.operands[i] = ScriptEng.tempValue[2]; break; + case VAR_TEMPVALUE3: ScriptEng.operands[i] = ScriptEng.tempValue[3]; break; + case VAR_TEMPVALUE4: ScriptEng.operands[i] = ScriptEng.tempValue[4]; break; + case VAR_TEMPVALUE5: ScriptEng.operands[i] = ScriptEng.tempValue[5]; break; + case VAR_TEMPVALUE6: ScriptEng.operands[i] = ScriptEng.tempValue[6]; break; + case VAR_TEMPVALUE7: ScriptEng.operands[i] = ScriptEng.tempValue[7]; break; + case VAR_CHECKRESULT: ScriptEng.operands[i] = ScriptEng.checkResult; break; + case VAR_ARRAYPOS0: ScriptEng.operands[i] = ScriptEng.arrayPosition[0]; break; + case VAR_ARRAYPOS1: ScriptEng.operands[i] = ScriptEng.arrayPosition[1]; break; + case VAR_KEYDOWNUP: ScriptEng.operands[i] = GKeyDown.up; break; + case VAR_KEYDOWNDOWN: ScriptEng.operands[i] = GKeyDown.down; break; + case VAR_KEYDOWNLEFT: ScriptEng.operands[i] = GKeyDown.left; break; + case VAR_KEYDOWNRIGHT: ScriptEng.operands[i] = GKeyDown.right; break; + case VAR_KEYDOWNBUTTONA: ScriptEng.operands[i] = GKeyDown.A; break; + case VAR_KEYDOWNBUTTONB: ScriptEng.operands[i] = GKeyDown.B; break; + case VAR_KEYDOWNBUTTONC: ScriptEng.operands[i] = GKeyDown.C; break; + case VAR_KEYDOWNSTART: ScriptEng.operands[i] = GKeyDown.start; break; + case VAR_KEYPRESSUP: ScriptEng.operands[i] = GKeyPress.up; break; + case VAR_KEYPRESSDOWN: ScriptEng.operands[i] = GKeyPress.down; break; + case VAR_KEYPRESSLEFT: ScriptEng.operands[i] = GKeyPress.left; break; + case VAR_KEYPRESSRIGHT: ScriptEng.operands[i] = GKeyPress.right; break; + case VAR_KEYPRESSBUTTONA: ScriptEng.operands[i] = GKeyPress.A; break; + case VAR_KEYPRESSBUTTONB: ScriptEng.operands[i] = GKeyPress.B; break; + case VAR_KEYPRESSBUTTONC: ScriptEng.operands[i] = GKeyPress.C; break; + case VAR_KEYPRESSSTART: ScriptEng.operands[i] = GKeyPress.start; break; + case VAR_MENU1SELECTION: ScriptEng.operands[i] = GameMenu[0].selection1; break; + case VAR_MENU2SELECTION: ScriptEng.operands[i] = GameMenu[1].selection1; break; + case VAR_STAGEACTIVELIST: ScriptEng.operands[i] = ActiveStageList; break; + case VAR_STAGELISTPOS: ScriptEng.operands[i] = StageListPosition; break; + case VAR_XSCROLLOFFSET: ScriptEng.operands[i] = XScrollOffset; break; + case VAR_YSCROLLOFFSET: ScriptEng.operands[i] = YScrollOffset; break; + case VAR_GLOBAL: ScriptEng.operands[i] = GlobalVariables[arrayVal]; break; + case VAR_STAGETIMEENABLED: ScriptEng.operands[i] = TimeEnabled; break; + case VAR_STAGEMILLISECONDS: ScriptEng.operands[i] = MilliSeconds; break; + case VAR_STAGESECONDS: ScriptEng.operands[i] = Seconds; break; + case VAR_STAGEMINUTES: ScriptEng.operands[i] = Minutes; break; + case VAR_STAGEACTNO: ScriptEng.operands[i] = ActNumber; break; + case VAR_OBJECTENTITYNO: ScriptEng.operands[i] = arrayVal; break; case VAR_PLAYERTYPE: { - scriptEng.operands[i] = playerList[activePlayer].type; + ScriptEng.operands[i] = PlayerList[PlayerNo].type; break; } case VAR_PLAYERSTATE: { - scriptEng.operands[i] = playerList[activePlayer].state; + ScriptEng.operands[i] = PlayerList[PlayerNo].state; break; } case VAR_PLAYERCONTROLMODE: { - scriptEng.operands[i] = playerList[activePlayer].controlMode; + ScriptEng.operands[i] = PlayerList[PlayerNo].controlMode; break; } case VAR_PLAYERCOLLISIONMODE: { - scriptEng.operands[i] = playerList[activePlayer].collisionMode; + ScriptEng.operands[i] = PlayerList[PlayerNo].collisionMode; break; } case VAR_PLAYERCOLLISIONPLANE: { - scriptEng.operands[i] = playerList[activePlayer].collisionPlane; + ScriptEng.operands[i] = PlayerList[PlayerNo].collisionPlane; break; } case VAR_PLAYERXPOS: { - scriptEng.operands[i] = playerList[activePlayer].XPos; + ScriptEng.operands[i] = PlayerList[PlayerNo].XPos; break; } case VAR_PLAYERYPOS: { - scriptEng.operands[i] = playerList[activePlayer].YPos; + ScriptEng.operands[i] = PlayerList[PlayerNo].YPos; break; } case VAR_PLAYERSCREENXPOS: { - scriptEng.operands[i] = playerList[activePlayer].screenXPos; + ScriptEng.operands[i] = PlayerList[PlayerNo].screenXPos; break; } case VAR_PLAYERSCREENYPOS: { - scriptEng.operands[i] = playerList[activePlayer].screenYPos; + ScriptEng.operands[i] = PlayerList[PlayerNo].screenYPos; break; } case VAR_PLAYERSPEED: { - scriptEng.operands[i] = playerList[activePlayer].speed; + ScriptEng.operands[i] = PlayerList[PlayerNo].speed; break; } case VAR_PLAYERXVELOCITY: { - scriptEng.operands[i] = playerList[activePlayer].XVelocity; + ScriptEng.operands[i] = PlayerList[PlayerNo].XVelocity; break; } case VAR_PLAYERYVELOCITY: { - scriptEng.operands[i] = playerList[activePlayer].YVelocity; + ScriptEng.operands[i] = PlayerList[PlayerNo].YVelocity; break; } case VAR_PLAYERGRAVITY: { - scriptEng.operands[i] = playerList[activePlayer].gravity; + ScriptEng.operands[i] = PlayerList[PlayerNo].gravity; break; } case VAR_PLAYERANGLE: { - scriptEng.operands[i] = playerList[activePlayer].angle; + ScriptEng.operands[i] = PlayerList[PlayerNo].angle; break; } case VAR_PLAYERSKIDDING: { - scriptEng.operands[i] = playerList[activePlayer].skidding; + ScriptEng.operands[i] = PlayerList[PlayerNo].skidding; break; } case VAR_PLAYERPUSHING: { - scriptEng.operands[i] = playerList[activePlayer].pushing; + ScriptEng.operands[i] = PlayerList[PlayerNo].pushing; break; } case VAR_PLAYERFRICTIONLOSS: { - scriptEng.operands[i] = playerList[activePlayer].frictionLoss; + ScriptEng.operands[i] = PlayerList[PlayerNo].frictionLoss; break; } case VAR_PLAYERWALKINGSPEED: { - scriptEng.operands[i] = playerList[activePlayer].walkingSpeed; + ScriptEng.operands[i] = PlayerList[PlayerNo].walkingSpeed; break; } case VAR_PLAYERRUNNINGSPEED: { - scriptEng.operands[i] = playerList[activePlayer].runningSpeed; + ScriptEng.operands[i] = PlayerList[PlayerNo].runningSpeed; break; } case VAR_PLAYERJUMPINGSPEED: { - scriptEng.operands[i] = playerList[activePlayer].jumpingSpeed; + ScriptEng.operands[i] = PlayerList[PlayerNo].jumpingSpeed; break; } case VAR_PLAYERTRACKSCROLL: { - scriptEng.operands[i] = playerList[activePlayer].trackScroll; + ScriptEng.operands[i] = PlayerList[PlayerNo].trackScroll; break; } case VAR_PLAYERUP: { - scriptEng.operands[i] = playerList[activePlayer].up; + ScriptEng.operands[i] = PlayerList[PlayerNo].up; break; } case VAR_PLAYERDOWN: { - scriptEng.operands[i] = playerList[activePlayer].down; + ScriptEng.operands[i] = PlayerList[PlayerNo].down; break; } case VAR_PLAYERLEFT: { - scriptEng.operands[i] = playerList[activePlayer].left; + ScriptEng.operands[i] = PlayerList[PlayerNo].left; break; } case VAR_PLAYERRIGHT: { - scriptEng.operands[i] = playerList[activePlayer].right; + ScriptEng.operands[i] = PlayerList[PlayerNo].right; break; } case VAR_PLAYERJUMPPRESS: { - scriptEng.operands[i] = playerList[activePlayer].jumpPress; + ScriptEng.operands[i] = PlayerList[PlayerNo].jumpPress; break; } case VAR_PLAYERJUMPHOLD: { - scriptEng.operands[i] = playerList[activePlayer].jumpHold; + ScriptEng.operands[i] = PlayerList[PlayerNo].jumpHold; break; } case VAR_PLAYERFOLLOWPLAYER1: { - scriptEng.operands[i] = playerList[activePlayer].followPlayer1; + ScriptEng.operands[i] = PlayerList[PlayerNo].followPlayer1; break; } case VAR_PLAYERLOOKPOS: { - scriptEng.operands[i] = playerList[activePlayer].lookPos; + ScriptEng.operands[i] = PlayerList[PlayerNo].lookPos; break; } case VAR_PLAYERWATER: { - scriptEng.operands[i] = playerList[activePlayer].water; + ScriptEng.operands[i] = PlayerList[PlayerNo].water; break; } case VAR_PLAYERTOPSPEED: { - scriptEng.operands[i] = playerList[activePlayer].stats.topSpeed; + ScriptEng.operands[i] = PlayerList[PlayerNo].stats.topSpeed; break; } case VAR_PLAYERACCELERATION: { - scriptEng.operands[i] = playerList[activePlayer].stats.acceleration; + ScriptEng.operands[i] = PlayerList[PlayerNo].stats.acceleration; break; } case VAR_PLAYERDECELERATION: { - scriptEng.operands[i] = playerList[activePlayer].stats.deceleration; + ScriptEng.operands[i] = PlayerList[PlayerNo].stats.deceleration; break; } case VAR_PLAYERAIRACCELERATION: { - scriptEng.operands[i] = playerList[activePlayer].stats.airAcceleration; + ScriptEng.operands[i] = PlayerList[PlayerNo].stats.airAcceleration; break; } case VAR_PLAYERAIRDECELERATION: { - scriptEng.operands[i] = playerList[activePlayer].stats.airDeceleration; + ScriptEng.operands[i] = PlayerList[PlayerNo].stats.airDeceleration; break; } case VAR_PLAYERGRAVITYSTRENGTH: { - scriptEng.operands[i] = playerList[activePlayer].stats.gravityStrength; + ScriptEng.operands[i] = PlayerList[PlayerNo].stats.gravityStrength; break; } case VAR_PLAYERJUMPSTRENGTH: { - scriptEng.operands[i] = playerList[activePlayer].stats.jumpStrength; + ScriptEng.operands[i] = PlayerList[PlayerNo].stats.jumpStrength; break; } case VAR_PLAYERROLLINGACCELERATION: { - scriptEng.operands[i] = playerList[activePlayer].stats.rollingAcceleration; + ScriptEng.operands[i] = PlayerList[PlayerNo].stats.rollingAcceleration; break; } case VAR_PLAYERROLLINGDECELERATION: { - scriptEng.operands[i] = playerList[activePlayer].stats.rollingDeceleration; + ScriptEng.operands[i] = PlayerList[PlayerNo].stats.rollingDeceleration; break; } case VAR_PLAYERENTITYNO: { - scriptEng.operands[i] = activePlayer; + ScriptEng.operands[i] = PlayerNo; break; } case VAR_PLAYERCOLLISIONLEFT: { - Hitbox *hitbox = &hitboxList[playerScriptList[activePlayer] - .animations[playerList[activePlayer].animation] - .frames[playerList[activePlayer].frame] - .hitboxID]; - scriptEng.operands[i] = hitbox->left[0]; + ScriptEng.operands[i] = GetPlayerCBox(&PlayerScriptList[PlayerNo])->left[0]; break; } case VAR_PLAYERCOLLISIONTOP: { - Hitbox *hitbox = &hitboxList[playerScriptList[activePlayer] - .animations[playerList[activePlayer].animation] - .frames[playerList[activePlayer].frame] - .hitboxID]; - scriptEng.operands[i] = hitbox->top[0]; + ScriptEng.operands[i] = GetPlayerCBox(&PlayerScriptList[PlayerNo])->top[0]; break; } case VAR_PLAYERCOLLISIONRIGHT: { - Hitbox *hitbox = &hitboxList[playerScriptList[activePlayer] - .animations[playerList[activePlayer].animation] - .frames[playerList[activePlayer].frame] - .hitboxID]; - scriptEng.operands[i] = hitbox->right[0]; + ScriptEng.operands[i] = GetPlayerCBox(&PlayerScriptList[PlayerNo])->right[0]; break; } case VAR_PLAYERCOLLISIONBOTTOM: { - Hitbox *hitbox = &hitboxList[playerScriptList[activePlayer] - .animations[playerList[activePlayer].animation] - .frames[playerList[activePlayer].frame] - .hitboxID]; - scriptEng.operands[i] = hitbox->bottom[0]; + ScriptEng.operands[i] = GetPlayerCBox(&PlayerScriptList[PlayerNo])->bottom[0]; break; } case VAR_PLAYERFLAILING: { - scriptEng.operands[i] = playerList[activePlayer].flailing[arrayVal]; + ScriptEng.operands[i] = PlayerList[PlayerNo].flailing[arrayVal]; break; } case VAR_PLAYERTIMER: { - scriptEng.operands[i] = playerList[activePlayer].timer; + ScriptEng.operands[i] = PlayerList[PlayerNo].timer; break; } case VAR_PLAYERTILECOLLISIONS: { - scriptEng.operands[i] = playerList[activePlayer].tileCollisions; + ScriptEng.operands[i] = PlayerList[PlayerNo].tileCollisions; break; } case VAR_PLAYEROBJECTINTERACTION: { - scriptEng.operands[i] = playerList[activePlayer].objectInteraction; - break; - } - case VAR_PLAYERVISIBLE: { - scriptEng.operands[i] = playerList[activePlayer].visible; + ScriptEng.operands[i] = PlayerList[PlayerNo].objectInteraction; break; } case VAR_PLAYERROTATION: { - scriptEng.operands[i] = playerList[activePlayer].rotation; + ScriptEng.operands[i] = PlayerList[PlayerNo].rotation; break; } case VAR_PLAYERDIRECTION: { - scriptEng.operands[i] = playerList[activePlayer].direction; + ScriptEng.operands[i] = PlayerList[PlayerNo].direction; break; } case VAR_PLAYERFRAME: { - scriptEng.operands[i] = playerList[activePlayer].frame; + ScriptEng.operands[i] = PlayerList[PlayerNo].frame; break; } case VAR_PLAYERANIMATION: { - scriptEng.operands[i] = playerList[activePlayer].animation; + ScriptEng.operands[i] = PlayerList[PlayerNo].animation; break; } case VAR_PLAYERANIMATIONSPEED: { - scriptEng.operands[i] = playerList[activePlayer].animationSpeed; - break; - } - case VAR_STAGEPAUSEENABLED: scriptEng.operands[i] = pauseEnabled; break; - case VAR_STAGELISTSIZE: scriptEng.operands[i] = stageListCount[activeStageList]; break; - case VAR_SCREENCAMERAENABLED: scriptEng.operands[i] = cameraEnabled; break; - case VAR_SCREENCAMERASTYLE: scriptEng.operands[i] = cameraStyle; break; - case VAR_MUSICVOLUME: scriptEng.operands[i] = masterVolume; break; - case VAR_MUSICCURRENTTRACK: scriptEng.operands[i] = trackID; break; - case VAR_STAGENEWXBOUNDARY1: scriptEng.operands[i] = newXBoundary1; break; - case VAR_STAGENEWXBOUNDARY2: scriptEng.operands[i] = newXBoundary2; break; - case VAR_STAGENEWYBOUNDARY1: scriptEng.operands[i] = newYBoundary1; break; - case VAR_STAGENEWYBOUNDARY2: scriptEng.operands[i] = newYBoundary2; break; - case VAR_STAGEXBOUNDARY1: scriptEng.operands[i] = xBoundary1; break; - case VAR_STAGEXBOUNDARY2: scriptEng.operands[i] = xBoundary2; break; - case VAR_STAGEYBOUNDARY1: scriptEng.operands[i] = yBoundary1; break; - case VAR_STAGEYBOUNDARY2: scriptEng.operands[i] = yBoundary2; break; + ScriptEng.operands[i] = PlayerList[PlayerNo].animationSpeed; + break; + } + case VAR_STAGEPAUSEENABLED: ScriptEng.operands[i] = PauseEnabled; break; + case VAR_STAGELISTSIZE: ScriptEng.operands[i] = stageListCount[ActiveStageList]; break; + case VAR_SCREENCAMERAENABLED: ScriptEng.operands[i] = CameraEnabled; break; + case VAR_SCREENCAMERASTYLE: ScriptEng.operands[i] = CameraStyle; break; + case VAR_MUSICVOLUME: ScriptEng.operands[i] = MusicVolume; break; + case VAR_MUSICCURRENTTRACK: ScriptEng.operands[i] = CurrentMusicTrack; break; + case VAR_PLAYERVISIBLE: { + ScriptEng.operands[i] = PlayerList[PlayerNo].visible; + break; + } + case VAR_STAGENEWXBOUNDARY1: ScriptEng.operands[i] = NewXBoundary1; break; + case VAR_STAGENEWXBOUNDARY2: ScriptEng.operands[i] = NewXBoundary2; break; + case VAR_STAGENEWYBOUNDARY1: ScriptEng.operands[i] = NewYBoundary1; break; + case VAR_STAGENEWYBOUNDARY2: ScriptEng.operands[i] = NewYBoundary2; break; + case VAR_STAGEXBOUNDARY1: ScriptEng.operands[i] = XBoundary1; break; + case VAR_STAGEXBOUNDARY2: ScriptEng.operands[i] = XBoundary2; break; + case VAR_STAGEYBOUNDARY1: ScriptEng.operands[i] = YBoundary1; break; + case VAR_STAGEYBOUNDARY2: ScriptEng.operands[i] = YBoundary2; break; case VAR_OBJECTOUTOFBOUNDS: { - int pos = objectEntityList[arrayVal].XPos >> 16; - if (pos <= xScrollOffset - OBJECT_BORDER_X1 || pos >= OBJECT_BORDER_X2 + xScrollOffset) { - scriptEng.operands[i] = 1; - } - else { - int pos = objectEntityList[arrayVal].YPos >> 16; - scriptEng.operands[i] = pos <= yScrollOffset - OBJECT_BORDER_Y1 || pos >= yScrollOffset + OBJECT_BORDER_Y2; + int pos = ObjectEntityList[arrayVal].XPos >> 16; + if (pos <= XScrollOffset - OBJECT_BORDER_X1 || pos >= OBJECT_BORDER_X2 + XScrollOffset) { + ScriptEng.operands[i] = 1; + } else { + int pos = ObjectEntityList[arrayVal].YPos >> 16; + ScriptEng.operands[i] = pos <= YScrollOffset - OBJECT_BORDER_Y1 || pos >= YScrollOffset + OBJECT_BORDER_Y2; } break; } } - } - else if (opcodeType == SCRIPTVAR_INTCONST) { // int constant - scriptEng.operands[i] = scriptData[scriptDataPtr++]; - } - else if (opcodeType == SCRIPTVAR_STRCONST) { // string constant - int strLen = scriptData[scriptDataPtr++]; - scriptText[strLen] = 0; + } else if (opcodeType == SCRIPTVAR_INTCONST) { // int constant + ScriptEng.operands[i] = ScriptData[scriptDataPtr++]; + } else if (opcodeType == SCRIPTVAR_STRCONST) { // string constant + int strLen = ScriptData[scriptDataPtr++]; + ScriptText[strLen] = 0; for (int c = 0; c < strLen; ++c) { switch (c % 4) { case 0: { - scriptText[c] = scriptData[scriptDataPtr] >> 24; + ScriptText[c] = ScriptData[scriptDataPtr] >> 24; break; } case 1: { - scriptText[c] = (0x00FFFFFF & scriptData[scriptDataPtr]) >> 16; + ScriptText[c] = (0x00FFFFFF & ScriptData[scriptDataPtr]) >> 16; break; } case 2: { - scriptText[c] = (0x0000FFFF & scriptData[scriptDataPtr]) >> 8; + ScriptText[c] = (0x0000FFFF & ScriptData[scriptDataPtr]) >> 8; break; } case 3: { - scriptText[c] = (0x000000FF & scriptData[scriptDataPtr++]) >> 0; + ScriptText[c] = (0x000000FF & ScriptData[scriptDataPtr++]) >> 0; break; } default: break; @@ -1858,219 +1770,219 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) } } - ObjectScript *scriptInfo = &objectScriptList[objectEntityList[objectLoop].type]; - Entity *entity = &objectEntityList[objectLoop]; - Player *player = &playerList[activePlayer]; + ObjectScript *scriptInfo = &ObjectScriptList[ObjectEntityList[ObjectLoop].type]; + Entity *entity = &ObjectEntityList[ObjectLoop]; + Player *player = &PlayerList[PlayerNo]; SpriteFrame *spriteFrame = nullptr; // Functions switch (opcode) { default: break; case FUNC_END: running = false; break; - case FUNC_EQUAL: scriptEng.operands[0] = scriptEng.operands[1]; break; - case FUNC_ADD: scriptEng.operands[0] += scriptEng.operands[1]; break; - case FUNC_SUB: scriptEng.operands[0] -= scriptEng.operands[1]; break; - case FUNC_INC: ++scriptEng.operands[0]; break; - case FUNC_DEC: --scriptEng.operands[0]; break; - case FUNC_MUL: scriptEng.operands[0] *= scriptEng.operands[1]; break; - case FUNC_DIV: scriptEng.operands[0] /= scriptEng.operands[1]; break; - case FUNC_SHR: scriptEng.operands[0] >>= scriptEng.operands[1]; break; - case FUNC_SHL: scriptEng.operands[0] <<= scriptEng.operands[1]; break; - case FUNC_AND: scriptEng.operands[0] &= scriptEng.operands[1]; break; - case FUNC_OR: scriptEng.operands[0] |= scriptEng.operands[1]; break; - case FUNC_XOR: scriptEng.operands[0] ^= scriptEng.operands[1]; break; - case FUNC_NOT: scriptEng.operands[0] = ~scriptEng.operands[0]; break; - case FUNC_FLIPSIGN: scriptEng.operands[0] = -scriptEng.operands[0]; break; + case FUNC_EQUAL: ScriptEng.operands[0] = ScriptEng.operands[1]; break; + case FUNC_ADD: ScriptEng.operands[0] += ScriptEng.operands[1]; break; + case FUNC_SUB: ScriptEng.operands[0] -= ScriptEng.operands[1]; break; + case FUNC_INC: ++ScriptEng.operands[0]; break; + case FUNC_DEC: --ScriptEng.operands[0]; break; + case FUNC_MUL: ScriptEng.operands[0] *= ScriptEng.operands[1]; break; + case FUNC_DIV: ScriptEng.operands[0] /= ScriptEng.operands[1]; break; + case FUNC_SHR: ScriptEng.operands[0] >>= ScriptEng.operands[1]; break; + case FUNC_SHL: ScriptEng.operands[0] <<= ScriptEng.operands[1]; break; + case FUNC_AND: ScriptEng.operands[0] &= ScriptEng.operands[1]; break; + case FUNC_OR: ScriptEng.operands[0] |= ScriptEng.operands[1]; break; + case FUNC_XOR: ScriptEng.operands[0] ^= ScriptEng.operands[1]; break; + case FUNC_NOT: ScriptEng.operands[0] = ~ScriptEng.operands[0]; break; + case FUNC_FLIPSIGN: ScriptEng.operands[0] = -ScriptEng.operands[0]; break; case FUNC_CHECKEQUAL: - scriptEng.checkResult = scriptEng.operands[0] == scriptEng.operands[1]; + ScriptEng.checkResult = ScriptEng.operands[0] == ScriptEng.operands[1]; opcodeSize = 0; break; case FUNC_CHECKGREATER: - scriptEng.checkResult = scriptEng.operands[0] > scriptEng.operands[1]; + ScriptEng.checkResult = ScriptEng.operands[0] > ScriptEng.operands[1]; opcodeSize = 0; break; case FUNC_CHECKLOWER: - scriptEng.checkResult = scriptEng.operands[0] < scriptEng.operands[1]; + ScriptEng.checkResult = ScriptEng.operands[0] < ScriptEng.operands[1]; opcodeSize = 0; break; case FUNC_CHECKNOTEQUAL: - scriptEng.checkResult = scriptEng.operands[0] != scriptEng.operands[1]; + ScriptEng.checkResult = ScriptEng.operands[0] != ScriptEng.operands[1]; opcodeSize = 0; break; case FUNC_IFEQUAL: - if (scriptEng.operands[1] != scriptEng.operands[2]) - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + scriptEng.operands[0]]; - jumpTableStack[++jumpTableStackPos] = scriptEng.operands[0]; + if (ScriptEng.operands[1] != ScriptEng.operands[2]) + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + ScriptEng.operands[0]]; + JumpTableStack[++JumpTableStackPos] = ScriptEng.operands[0]; opcodeSize = 0; break; case FUNC_IFGREATER: - if (scriptEng.operands[1] <= scriptEng.operands[2]) - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + scriptEng.operands[0]]; - jumpTableStack[++jumpTableStackPos] = scriptEng.operands[0]; + if (ScriptEng.operands[1] <= ScriptEng.operands[2]) + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + ScriptEng.operands[0]]; + JumpTableStack[++JumpTableStackPos] = ScriptEng.operands[0]; opcodeSize = 0; break; case FUNC_IFGREATEROREQUAL: - if (scriptEng.operands[1] < scriptEng.operands[2]) - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + scriptEng.operands[0]]; - jumpTableStack[++jumpTableStackPos] = scriptEng.operands[0]; + if (ScriptEng.operands[1] < ScriptEng.operands[2]) + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + ScriptEng.operands[0]]; + JumpTableStack[++JumpTableStackPos] = ScriptEng.operands[0]; opcodeSize = 0; break; case FUNC_IFLOWER: - if (scriptEng.operands[1] >= scriptEng.operands[2]) - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + scriptEng.operands[0]]; - jumpTableStack[++jumpTableStackPos] = scriptEng.operands[0]; + if (ScriptEng.operands[1] >= ScriptEng.operands[2]) + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + ScriptEng.operands[0]]; + JumpTableStack[++JumpTableStackPos] = ScriptEng.operands[0]; opcodeSize = 0; break; case FUNC_IFLOWEROREQUAL: - if (scriptEng.operands[1] > scriptEng.operands[2]) - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + scriptEng.operands[0]]; - jumpTableStack[++jumpTableStackPos] = scriptEng.operands[0]; + if (ScriptEng.operands[1] > ScriptEng.operands[2]) + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + ScriptEng.operands[0]]; + JumpTableStack[++JumpTableStackPos] = ScriptEng.operands[0]; opcodeSize = 0; break; case FUNC_IFNOTEQUAL: - if (scriptEng.operands[1] == scriptEng.operands[2]) - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + scriptEng.operands[0]]; - jumpTableStack[++jumpTableStackPos] = scriptEng.operands[0]; + if (ScriptEng.operands[1] == ScriptEng.operands[2]) + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + ScriptEng.operands[0]]; + JumpTableStack[++JumpTableStackPos] = ScriptEng.operands[0]; opcodeSize = 0; break; case FUNC_ELSE: opcodeSize = 0; - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + jumpTableStack[jumpTableStackPos--] + 1]; + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + JumpTableStack[JumpTableStackPos--] + 1]; break; case FUNC_ENDIF: opcodeSize = 0; - --jumpTableStackPos; + --JumpTableStackPos; break; case FUNC_WEQUAL: - if (scriptEng.operands[1] != scriptEng.operands[2]) - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + scriptEng.operands[0] + 1]; + if (ScriptEng.operands[1] != ScriptEng.operands[2]) + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + ScriptEng.operands[0] + 1]; else - jumpTableStack[++jumpTableStackPos] = scriptEng.operands[0]; + JumpTableStack[++JumpTableStackPos] = ScriptEng.operands[0]; opcodeSize = 0; break; case FUNC_WGREATER: - if (scriptEng.operands[1] <= scriptEng.operands[2]) - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + scriptEng.operands[0] + 1]; + if (ScriptEng.operands[1] <= ScriptEng.operands[2]) + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + ScriptEng.operands[0] + 1]; else - jumpTableStack[++jumpTableStackPos] = scriptEng.operands[0]; + JumpTableStack[++JumpTableStackPos] = ScriptEng.operands[0]; opcodeSize = 0; break; case FUNC_WGREATEROREQUAL: - if (scriptEng.operands[1] < scriptEng.operands[2]) - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + scriptEng.operands[0] + 1]; + if (ScriptEng.operands[1] < ScriptEng.operands[2]) + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + ScriptEng.operands[0] + 1]; else - jumpTableStack[++jumpTableStackPos] = scriptEng.operands[0]; + JumpTableStack[++JumpTableStackPos] = ScriptEng.operands[0]; opcodeSize = 0; break; case FUNC_WLOWER: - if (scriptEng.operands[1] >= scriptEng.operands[2]) - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + scriptEng.operands[0] + 1]; + if (ScriptEng.operands[1] >= ScriptEng.operands[2]) + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + ScriptEng.operands[0] + 1]; else - jumpTableStack[++jumpTableStackPos] = scriptEng.operands[0]; + JumpTableStack[++JumpTableStackPos] = ScriptEng.operands[0]; opcodeSize = 0; break; case FUNC_WLOWEROREQUAL: - if (scriptEng.operands[1] > scriptEng.operands[2]) - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + scriptEng.operands[0] + 1]; + if (ScriptEng.operands[1] > ScriptEng.operands[2]) + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + ScriptEng.operands[0] + 1]; else - jumpTableStack[++jumpTableStackPos] = scriptEng.operands[0]; + JumpTableStack[++JumpTableStackPos] = ScriptEng.operands[0]; opcodeSize = 0; break; case FUNC_WNOTEQUAL: - if (scriptEng.operands[1] == scriptEng.operands[2]) - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + scriptEng.operands[0] + 1]; + if (ScriptEng.operands[1] == ScriptEng.operands[2]) + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + ScriptEng.operands[0] + 1]; else - jumpTableStack[++jumpTableStackPos] = scriptEng.operands[0]; + JumpTableStack[++JumpTableStackPos] = ScriptEng.operands[0]; opcodeSize = 0; break; case FUNC_LOOP: opcodeSize = 0; - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + jumpTableStack[jumpTableStackPos--]]; + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + JumpTableStack[JumpTableStackPos--]]; break; case FUNC_SWITCH: - jumpTableStack[++jumpTableStackPos] = scriptEng.operands[0]; - if (scriptEng.operands[1] < jumpTableData[jumpTablePtr + scriptEng.operands[0]] - || scriptEng.operands[1] > jumpTableData[jumpTablePtr + scriptEng.operands[0] + 1]) - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + scriptEng.operands[0] + 2]; + JumpTableStack[++JumpTableStackPos] = ScriptEng.operands[0]; + if (ScriptEng.operands[1] < JumpTableData[jumpTablePtr + ScriptEng.operands[0]] + || ScriptEng.operands[1] > JumpTableData[jumpTablePtr + ScriptEng.operands[0] + 1]) + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + ScriptEng.operands[0] + 2]; else scriptDataPtr = scriptCodePtr - + jumpTableData[jumpTablePtr + scriptEng.operands[0] + 4 - + (scriptEng.operands[1] - jumpTableData[jumpTablePtr + scriptEng.operands[0]])]; + + JumpTableData[jumpTablePtr + ScriptEng.operands[0] + 4 + + (ScriptEng.operands[1] - JumpTableData[jumpTablePtr + ScriptEng.operands[0]])]; opcodeSize = 0; break; case FUNC_BREAK: opcodeSize = 0; - scriptDataPtr = scriptCodePtr + jumpTableData[jumpTablePtr + jumpTableStack[jumpTableStackPos--] + 3]; + scriptDataPtr = scriptCodePtr + JumpTableData[jumpTablePtr + JumpTableStack[JumpTableStackPos--] + 3]; break; case FUNC_ENDSWITCH: opcodeSize = 0; - --jumpTableStackPos; + --JumpTableStackPos; break; - case FUNC_RAND: scriptEng.operands[0] = rand() % scriptEng.operands[1]; break; + case FUNC_RAND: ScriptEng.operands[0] = rand() % ScriptEng.operands[1]; break; case FUNC_SIN: { - scriptEng.operands[0] = sin512(scriptEng.operands[1]); + ScriptEng.operands[0] = Sin512(ScriptEng.operands[1]); break; } case FUNC_COS: { - scriptEng.operands[0] = cos512(scriptEng.operands[1]); + ScriptEng.operands[0] = Cos512(ScriptEng.operands[1]); break; } case FUNC_SIN256: { - scriptEng.operands[0] = sin256(scriptEng.operands[1]); + ScriptEng.operands[0] = Sin256(ScriptEng.operands[1]); break; } case FUNC_COS256: { - scriptEng.operands[0] = cos256(scriptEng.operands[1]); + ScriptEng.operands[0] = Cos256(ScriptEng.operands[1]); break; } case FUNC_SINCHANGE: { - scriptEng.operands[0] = scriptEng.operands[3] + (sin512(scriptEng.operands[1]) >> scriptEng.operands[2]) - scriptEng.operands[4]; + ScriptEng.operands[0] = ScriptEng.operands[3] + (Sin512(ScriptEng.operands[1]) >> ScriptEng.operands[2]) - ScriptEng.operands[4]; break; } case FUNC_COSCHANGE: { - scriptEng.operands[0] = scriptEng.operands[3] + (cos512(scriptEng.operands[1]) >> scriptEng.operands[2]) - scriptEng.operands[4]; + ScriptEng.operands[0] = ScriptEng.operands[3] + (Cos512(ScriptEng.operands[1]) >> ScriptEng.operands[2]) - ScriptEng.operands[4]; break; } case FUNC_ATAN2: { opcodeSize = 0; - //doesn't exist + // doesn't exist break; } case FUNC_INTERPOLATE: - scriptEng.operands[0] = - (scriptEng.operands[2] * (0x100 - scriptEng.operands[3]) + scriptEng.operands[3] * scriptEng.operands[1]) >> 8; + ScriptEng.operands[0] = + (ScriptEng.operands[2] * (0x100 - ScriptEng.operands[3]) + ScriptEng.operands[3] * ScriptEng.operands[1]) >> 8; break; case FUNC_INTERPOLATEXY: - scriptEng.operands[0] = - (scriptEng.operands[3] * (0x100 - scriptEng.operands[6]) >> 8) + ((scriptEng.operands[6] * scriptEng.operands[2]) >> 8); - scriptEng.operands[1] = - (scriptEng.operands[5] * (0x100 - scriptEng.operands[6]) >> 8) + (scriptEng.operands[6] * scriptEng.operands[4] >> 8); + ScriptEng.operands[0] = + (ScriptEng.operands[3] * (0x100 - ScriptEng.operands[6]) >> 8) + ((ScriptEng.operands[6] * ScriptEng.operands[2]) >> 8); + ScriptEng.operands[1] = + (ScriptEng.operands[5] * (0x100 - ScriptEng.operands[6]) >> 8) + (ScriptEng.operands[6] * ScriptEng.operands[4] >> 8); break; case FUNC_LOADSPRITESHEET: opcodeSize = 0; - scriptInfo->spriteSheetID = AddGraphicsFile(scriptText); + scriptInfo->spriteSheetID = AddGraphicsFile(ScriptText); break; case FUNC_REMOVESPRITESHEET: opcodeSize = 0; - RemoveGraphicsFile(scriptText, -1); + RemoveGraphicsFile(ScriptText, -1); break; case FUNC_DRAWSPRITE: opcodeSize = 0; - spriteFrame = &scriptInfo->frameStartPtr[scriptEng.operands[0]]; - DrawSprite((entity->XPos >> 16) - xScrollOffset + spriteFrame->pivotX, (entity->YPos >> 16) - yScrollOffset + spriteFrame->pivotY, + spriteFrame = &scriptInfo->frameStartPtr[ScriptEng.operands[0]]; + DrawSprite((entity->XPos >> 16) - XScrollOffset + spriteFrame->pivotX, (entity->YPos >> 16) - YScrollOffset + spriteFrame->pivotY, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); break; case FUNC_DRAWSPRITEXY: opcodeSize = 0; - spriteFrame = &scriptInfo->frameStartPtr[scriptEng.operands[0]]; - DrawSprite((scriptEng.operands[1] >> 16) - xScrollOffset + spriteFrame->pivotX, - (scriptEng.operands[2] >> 16) - yScrollOffset + spriteFrame->pivotY, spriteFrame->width, spriteFrame->height, + spriteFrame = &scriptInfo->frameStartPtr[ScriptEng.operands[0]]; + DrawSprite((ScriptEng.operands[1] >> 16) - XScrollOffset + spriteFrame->pivotX, + (ScriptEng.operands[2] >> 16) - YScrollOffset + spriteFrame->pivotY, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); break; case FUNC_DRAWSPRITESCREENXY: opcodeSize = 0; - spriteFrame = &scriptInfo->frameStartPtr[scriptEng.operands[0]]; - DrawSprite(scriptEng.operands[1] + spriteFrame->pivotX, scriptEng.operands[2] + spriteFrame->pivotY, spriteFrame->width, + spriteFrame = &scriptInfo->frameStartPtr[ScriptEng.operands[0]]; + DrawSprite(ScriptEng.operands[1] + spriteFrame->pivotX, ScriptEng.operands[2] + spriteFrame->pivotY, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); break; case FUNC_DRAWSPRITE3D: @@ -2080,31 +1992,30 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) case FUNC_DRAWNUMBERS: { opcodeSize = 0; int i = 10; - if (scriptEng.operands[6]) { - while (scriptEng.operands[4] > 0) { - int frameID = scriptEng.operands[3] % i / (i / 10) + scriptEng.operands[0]; + if (ScriptEng.operands[6]) { + while (ScriptEng.operands[4] > 0) { + int frameID = ScriptEng.operands[3] % i / (i / 10) + ScriptEng.operands[0]; spriteFrame = &scriptInfo->frameStartPtr[frameID]; - DrawSprite(spriteFrame->pivotX + scriptEng.operands[1], spriteFrame->pivotY + scriptEng.operands[2], spriteFrame->width, + DrawSprite(spriteFrame->pivotX + ScriptEng.operands[1], spriteFrame->pivotY + ScriptEng.operands[2], spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); - scriptEng.operands[1] -= scriptEng.operands[5]; + ScriptEng.operands[1] -= ScriptEng.operands[5]; i *= 10; - --scriptEng.operands[4]; + --ScriptEng.operands[4]; } - } - else { + } else { int extra = 10; - if (scriptEng.operands[3]) - extra = 10 * scriptEng.operands[3]; - while (scriptEng.operands[4] > 0) { + if (ScriptEng.operands[3]) + extra = 10 * ScriptEng.operands[3]; + while (ScriptEng.operands[4] > 0) { if (extra >= i) { - int frameID = scriptEng.operands[3] % i / (i / 10) + scriptEng.operands[0]; + int frameID = ScriptEng.operands[3] % i / (i / 10) + ScriptEng.operands[0]; spriteFrame = &scriptInfo->frameStartPtr[frameID]; - DrawSprite(spriteFrame->pivotX + scriptEng.operands[1], spriteFrame->pivotY + scriptEng.operands[2], spriteFrame->width, + DrawSprite(spriteFrame->pivotX + ScriptEng.operands[1], spriteFrame->pivotY + ScriptEng.operands[2], spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); } - scriptEng.operands[1] -= scriptEng.operands[5]; + ScriptEng.operands[1] -= ScriptEng.operands[5]; i *= 10; - --scriptEng.operands[4]; + --ScriptEng.operands[4]; } } break; @@ -2113,15 +2024,15 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) opcodeSize = 0; int charID = 0; - switch (scriptEng.operands[3]) { + switch (ScriptEng.operands[3]) { default: break; case 1: // Draw Word 1 charID = 0; - // Draw the first letter as a capital letter, the rest are lowercase (if scriptEng.operands[4] is true, otherwise they're all + // Draw the first letter as a capital letter, the rest are lowercase (if ScriptEng.operands[4] is true, otherwise they're all // uppercase) - if (scriptEng.operands[4] == 1 && titleCardText[charID] != 0) { + if (ScriptEng.operands[4] == 1 && titleCardText[charID] != 0) { int character = titleCardText[charID]; if (character == ' ') character = 0; @@ -2133,17 +2044,16 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) character -= 'A'; if (character <= -1) { - scriptEng.operands[1] += scriptEng.operands[5] + scriptEng.operands[6]; - } - else { - character += scriptEng.operands[0]; + ScriptEng.operands[1] += ScriptEng.operands[5] + ScriptEng.operands[6]; + } else { + character += ScriptEng.operands[0]; spriteFrame = &scriptInfo->frameStartPtr[character]; - DrawSprite(scriptEng.operands[1] + spriteFrame->pivotX, scriptEng.operands[2] + spriteFrame->pivotY, + DrawSprite(ScriptEng.operands[1] + spriteFrame->pivotX, ScriptEng.operands[2] + spriteFrame->pivotY, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); - scriptEng.operands[1] += spriteFrame->width + scriptEng.operands[6]; + ScriptEng.operands[1] += spriteFrame->width + ScriptEng.operands[6]; } - scriptEng.operands[0] += 26; + ScriptEng.operands[0] += 26; charID++; } @@ -2158,14 +2068,13 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) if (character > '9' && character < 'f') character -= 'A'; if (character <= -1) { - scriptEng.operands[1] += scriptEng.operands[5] + scriptEng.operands[6]; - } - else { - character += scriptEng.operands[0]; + ScriptEng.operands[1] += ScriptEng.operands[5] + ScriptEng.operands[6]; + } else { + character += ScriptEng.operands[0]; spriteFrame = &scriptInfo->frameStartPtr[character]; - DrawSprite(scriptEng.operands[1] + spriteFrame->pivotX, scriptEng.operands[2] + spriteFrame->pivotY, + DrawSprite(ScriptEng.operands[1] + spriteFrame->pivotX, ScriptEng.operands[2] + spriteFrame->pivotY, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); - scriptEng.operands[1] += spriteFrame->width + scriptEng.operands[6]; + ScriptEng.operands[1] += spriteFrame->width + ScriptEng.operands[6]; } charID++; } @@ -2174,9 +2083,9 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) case 2: // Draw Word 2 charID = titleCardWord2; - // Draw the first letter as a capital letter, the rest are lowercase (if scriptEng.operands[4] is true, otherwise they're all + // Draw the first letter as a capital letter, the rest are lowercase (if ScriptEng.operands[4] is true, otherwise they're all // uppercase) - if (scriptEng.operands[4] == 1 && titleCardText[charID] != 0) { + if (ScriptEng.operands[4] == 1 && titleCardText[charID] != 0) { int character = titleCardText[charID]; if (character == ' ') character = 0; @@ -2187,16 +2096,15 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) if (character > '9' && character < 'f') character -= 'A'; if (character <= -1) { - scriptEng.operands[1] += scriptEng.operands[5] + scriptEng.operands[6]; - } - else { - character += scriptEng.operands[0]; + ScriptEng.operands[1] += ScriptEng.operands[5] + ScriptEng.operands[6]; + } else { + character += ScriptEng.operands[0]; spriteFrame = &scriptInfo->frameStartPtr[character]; - DrawSprite(scriptEng.operands[1] + spriteFrame->pivotX, scriptEng.operands[2] + spriteFrame->pivotY, + DrawSprite(ScriptEng.operands[1] + spriteFrame->pivotX, ScriptEng.operands[2] + spriteFrame->pivotY, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); - scriptEng.operands[1] += spriteFrame->width + scriptEng.operands[6]; + ScriptEng.operands[1] += spriteFrame->width + ScriptEng.operands[6]; } - scriptEng.operands[0] += 26; + ScriptEng.operands[0] += 26; charID++; } @@ -2211,14 +2119,13 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) if (character > '9' && character < 'f') character -= 'A'; if (character <= -1) { - scriptEng.operands[1] += scriptEng.operands[5] + scriptEng.operands[6]; - } - else { - character += scriptEng.operands[0]; + ScriptEng.operands[1] += ScriptEng.operands[5] + ScriptEng.operands[6]; + } else { + character += ScriptEng.operands[0]; spriteFrame = &scriptInfo->frameStartPtr[character]; - DrawSprite(scriptEng.operands[1] + spriteFrame->pivotX, scriptEng.operands[2] + spriteFrame->pivotY, + DrawSprite(ScriptEng.operands[1] + spriteFrame->pivotX, ScriptEng.operands[2] + spriteFrame->pivotY, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); - scriptEng.operands[1] += spriteFrame->width + scriptEng.operands[6]; + ScriptEng.operands[1] += spriteFrame->width + ScriptEng.operands[6]; } charID++; } @@ -2228,34 +2135,34 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) } case FUNC_DRAWMENU: opcodeSize = 0; - textMenuSurfaceNo = scriptInfo->spriteSheetID; - DrawTextMenu(&gameMenu[scriptEng.operands[0]], scriptEng.operands[1], scriptEng.operands[2]); + TextMenuSurfaceNo = scriptInfo->spriteSheetID; + DrawTextMenu(&GameMenu[ScriptEng.operands[0]], ScriptEng.operands[1], ScriptEng.operands[2]); break; case FUNC_SPRITEFRAME: opcodeSize = 0; - if (scriptSub == SUB_SETUP && scriptFrameCount < SPRITEFRAME_COUNT) { - scriptFrames[scriptFrameCount].pivotX = scriptEng.operands[0]; - scriptFrames[scriptFrameCount].pivotY = scriptEng.operands[1]; - scriptFrames[scriptFrameCount].width = scriptEng.operands[2]; - scriptFrames[scriptFrameCount].height = scriptEng.operands[3]; - scriptFrames[scriptFrameCount].sprX = scriptEng.operands[4]; - scriptFrames[scriptFrameCount].sprY = scriptEng.operands[5]; - ++scriptFrameCount; + if (scriptSub == SUB_SETUP && ScriptFramesNo < SPRITEFRAME_COUNT) { + ScriptFrames[ScriptFramesNo].pivotX = ScriptEng.operands[0]; + ScriptFrames[ScriptFramesNo].pivotY = ScriptEng.operands[1]; + ScriptFrames[ScriptFramesNo].width = ScriptEng.operands[2]; + ScriptFrames[ScriptFramesNo].height = ScriptEng.operands[3]; + ScriptFrames[ScriptFramesNo].sprX = ScriptEng.operands[4]; + ScriptFrames[ScriptFramesNo].sprY = ScriptEng.operands[5]; + ++ScriptFramesNo; } break; case FUNC_SETDEBUGICON: opcodeSize = 0; break; case FUNC_LOADPALETTE: opcodeSize = 0; - LoadPalette(scriptText, scriptEng.operands[1], scriptEng.operands[2]); + LoadPalette(ScriptText, ScriptEng.operands[1], ScriptEng.operands[2]); break; case FUNC_ROTATEPALETTE: opcodeSize = 0; - RotatePalette(scriptEng.operands[0], scriptEng.operands[1], scriptEng.operands[2]); + RotatePalette(ScriptEng.operands[0], ScriptEng.operands[1], ScriptEng.operands[2]); break; case FUNC_SETFADE: opcodeSize = 0; - SetFade(scriptEng.operands[0], scriptEng.operands[1], scriptEng.operands[2], scriptEng.operands[3], scriptEng.operands[4], - scriptEng.operands[5]); + SetFade(ScriptEng.operands[0], ScriptEng.operands[1], ScriptEng.operands[2], ScriptEng.operands[3], ScriptEng.operands[4], + ScriptEng.operands[5]); break; case FUNC_SETWATERCOLOR: opcodeSize = 0; @@ -2263,58 +2170,57 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) break; case FUNC_SETBLENDTABLE: opcodeSize = 0; - SetBlendTable(scriptEng.operands[0], scriptEng.operands[1], scriptEng.operands[2], scriptEng.operands[3]); + GenerateBlendTable(ScriptEng.operands[0], ScriptEng.operands[1], ScriptEng.operands[2], ScriptEng.operands[3]); break; case FUNC_SETTINTTABLE: opcodeSize = 0; - SetTintTable(scriptEng.operands[0], scriptEng.operands[1], scriptEng.operands[2], scriptEng.operands[3], scriptEng.operands[4], - scriptEng.operands[5]); + GenerateTintTable(ScriptEng.operands[0], ScriptEng.operands[1], ScriptEng.operands[2], ScriptEng.operands[3], ScriptEng.operands[4], + ScriptEng.operands[5]); break; case FUNC_CLEARSCREEN: opcodeSize = 0; - ClearScreen(scriptEng.operands[0]); + ClearScreen(ScriptEng.operands[0]); break; case FUNC_DRAWSPRITEFX: opcodeSize = 0; - spriteFrame = &scriptInfo->frameStartPtr[scriptEng.operands[0]]; - switch (scriptEng.operands[1]) { + spriteFrame = &scriptInfo->frameStartPtr[ScriptEng.operands[0]]; + switch (ScriptEng.operands[1]) { default: break; case FX_SCALE: - DrawSpriteScaled(entity->direction, (scriptEng.operands[2] >> 16) - xScrollOffset, - (scriptEng.operands[3] >> 16) - yScrollOffset, -spriteFrame->pivotX, -spriteFrame->pivotY, entity->scale, + DrawScaledSprite(entity->direction, (ScriptEng.operands[2] >> 16) - XScrollOffset, + (ScriptEng.operands[3] >> 16) - YScrollOffset, -spriteFrame->pivotX, -spriteFrame->pivotY, entity->scale, entity->scale, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); break; case FX_ROTATE: - DrawSpriteRotated(entity->direction, (scriptEng.operands[2] >> 16) - xScrollOffset, - (scriptEng.operands[3] >> 16) - yScrollOffset, -spriteFrame->pivotX, -spriteFrame->pivotY, + DrawRotatedSprite(entity->direction, (ScriptEng.operands[2] >> 16) - XScrollOffset, + (ScriptEng.operands[3] >> 16) - YScrollOffset, -spriteFrame->pivotX, -spriteFrame->pivotY, spriteFrame->sprX, spriteFrame->sprY, spriteFrame->width, spriteFrame->height, entity->rotation, scriptInfo->spriteSheetID); break; case FX_INK: switch (entity->inkEffect) { case INK_NONE: - DrawSprite((scriptEng.operands[2] >> 16) - xScrollOffset + spriteFrame->pivotX, - (scriptEng.operands[3] >> 16) - yScrollOffset + spriteFrame->pivotY, spriteFrame->width, + DrawSprite((ScriptEng.operands[2] >> 16) - XScrollOffset + spriteFrame->pivotX, + (ScriptEng.operands[3] >> 16) - YScrollOffset + spriteFrame->pivotY, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); break; case INK_BLEND: - DrawBlendedSprite((scriptEng.operands[2] >> 16) - xScrollOffset + spriteFrame->pivotX, - (scriptEng.operands[3] >> 16) - yScrollOffset + spriteFrame->pivotY, spriteFrame->width, + DrawBlendedSprite((ScriptEng.operands[2] >> 16) - XScrollOffset + spriteFrame->pivotX, + (ScriptEng.operands[3] >> 16) - YScrollOffset + spriteFrame->pivotY, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); break; } break; case FX_TINT: if (entity->inkEffect == INK_TINT) { - DrawScaledTintMask(entity->direction, (scriptEng.operands[2] >> 16) - xScrollOffset, - (scriptEng.operands[3] >> 16) - yScrollOffset, -spriteFrame->pivotX, -spriteFrame->pivotY, + DrawScaledTintMask(entity->direction, (ScriptEng.operands[2] >> 16) - XScrollOffset, + (ScriptEng.operands[3] >> 16) - YScrollOffset, -spriteFrame->pivotX, -spriteFrame->pivotY, entity->scale, entity->scale, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, 0, scriptInfo->spriteSheetID); - } - else { - DrawSpriteScaled(entity->direction, (scriptEng.operands[2] >> 16) - xScrollOffset, - (scriptEng.operands[3] >> 16) - yScrollOffset, -spriteFrame->pivotX, -spriteFrame->pivotY, entity->scale, + } else { + DrawScaledSprite(entity->direction, (ScriptEng.operands[2] >> 16) - XScrollOffset, + (ScriptEng.operands[3] >> 16) - YScrollOffset, -spriteFrame->pivotX, -spriteFrame->pivotY, entity->scale, entity->scale, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); } @@ -2323,27 +2229,27 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) break; case FUNC_DRAWSPRITESCREENFX: opcodeSize = 0; - spriteFrame = &scriptInfo->frameStartPtr[scriptEng.operands[0]]; - switch (scriptEng.operands[1]) { + spriteFrame = &scriptInfo->frameStartPtr[ScriptEng.operands[0]]; + switch (ScriptEng.operands[1]) { default: break; case FX_SCALE: - DrawSpriteScaled(entity->direction, scriptEng.operands[2], scriptEng.operands[3], -spriteFrame->pivotX, -spriteFrame->pivotY, + DrawScaledSprite(entity->direction, ScriptEng.operands[2], ScriptEng.operands[3], -spriteFrame->pivotX, -spriteFrame->pivotY, entity->scale, entity->scale, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); break; case FX_ROTATE: - DrawSpriteRotated(entity->direction, scriptEng.operands[2], scriptEng.operands[3], -spriteFrame->pivotX, -spriteFrame->pivotY, + DrawRotatedSprite(entity->direction, ScriptEng.operands[2], ScriptEng.operands[3], -spriteFrame->pivotX, -spriteFrame->pivotY, spriteFrame->sprX, spriteFrame->sprY, spriteFrame->width, spriteFrame->height, entity->rotation, scriptInfo->spriteSheetID); break; case FX_INK: switch (entity->inkEffect) { case INK_NONE: - DrawSprite(scriptEng.operands[2] + spriteFrame->pivotX, scriptEng.operands[3] + spriteFrame->pivotY, + DrawSprite(ScriptEng.operands[2] + spriteFrame->pivotX, ScriptEng.operands[3] + spriteFrame->pivotY, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); break; case INK_BLEND: - DrawBlendedSprite(scriptEng.operands[2] + spriteFrame->pivotX, scriptEng.operands[3] + spriteFrame->pivotY, + DrawBlendedSprite(ScriptEng.operands[2] + spriteFrame->pivotX, ScriptEng.operands[3] + spriteFrame->pivotY, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); break; @@ -2351,12 +2257,11 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) break; case FX_TINT: if (entity->inkEffect == INK_TINT) { - DrawScaledTintMask(entity->direction, scriptEng.operands[2], scriptEng.operands[3], -spriteFrame->pivotX, + DrawScaledTintMask(entity->direction, ScriptEng.operands[2], ScriptEng.operands[3], -spriteFrame->pivotX, -spriteFrame->pivotY, entity->scale, entity->scale, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, 0, scriptInfo->spriteSheetID); - } - else { - DrawSpriteScaled(entity->direction, scriptEng.operands[2], scriptEng.operands[3], -spriteFrame->pivotX, + } else { + DrawScaledSprite(entity->direction, ScriptEng.operands[2], ScriptEng.operands[3], -spriteFrame->pivotX, -spriteFrame->pivotY, entity->scale, entity->scale, spriteFrame->width, spriteFrame->height, spriteFrame->sprX, spriteFrame->sprY, scriptInfo->spriteSheetID); } @@ -2365,49 +2270,49 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) break; case FUNC_DRAWLIFEICON: { opcodeSize = 0; - SpriteAnimation *anim = &playerScriptList[playerList[0].type].animations[ANI_LIFEICON]; + SpriteAnimation *anim = &PlayerScriptList[PlayerList[0].type].animations[ANI_LIFEICON]; - DrawSprite(anim->frames[0].pivotX + scriptEng.operands[0], anim->frames[0].pivotY + scriptEng.operands[1], anim->frames[0].width, + DrawSprite(anim->frames[0].pivotX + ScriptEng.operands[0], anim->frames[0].pivotY + ScriptEng.operands[1], anim->frames[0].width, anim->frames[0].height, anim->frames[0].sprX, anim->frames[0].sprY, anim->frames[0].sheetID); break; } case FUNC_SETUPMENU: { opcodeSize = 0; - TextMenu *menu = &gameMenu[scriptEng.operands[0]]; - SetupTextMenu(menu, scriptEng.operands[1]); - menu->selectionCount = scriptEng.operands[2]; - menu->alignment = scriptEng.operands[3]; + TextMenu *menu = &GameMenu[ScriptEng.operands[0]]; + SetupTextMenu(menu, ScriptEng.operands[1]); + menu->selectionCount = ScriptEng.operands[2]; + menu->alignment = ScriptEng.operands[3]; break; } case FUNC_ADDMENUENTRY: { opcodeSize = 0; - TextMenu *menu = &gameMenu[scriptEng.operands[0]]; - menu->entryHighlight[menu->rowCount] = scriptEng.operands[2]; - AddTextMenuEntry(menu, scriptText); + TextMenu *menu = &GameMenu[ScriptEng.operands[0]]; + menu->entryHighlight[menu->rowCount] = ScriptEng.operands[2]; + AddTextMenuEntry(menu, ScriptText); break; } case FUNC_EDITMENUENTRY: { opcodeSize = 0; - TextMenu *menu = &gameMenu[scriptEng.operands[0]]; - EditTextMenuEntry(menu, scriptText, scriptEng.operands[2]); - menu->entryHighlight[scriptEng.operands[2]] = scriptEng.operands[3]; + TextMenu *menu = &GameMenu[ScriptEng.operands[0]]; + EditTextMenuEntry(menu, ScriptText, ScriptEng.operands[2]); + menu->entryHighlight[ScriptEng.operands[2]] = ScriptEng.operands[3]; break; } case FUNC_LOADSTAGE: opcodeSize = 0; - stageMode = STAGEMODE_LOAD; + StageMode = STAGEMODE_LOAD; break; case FUNC_DRAWTINTRECT: opcodeSize = 0; - DrawTintRectangle(scriptEng.operands[0], scriptEng.operands[1], scriptEng.operands[2], scriptEng.operands[3], scriptEng.operands[4]); + DrawTintRect(ScriptEng.operands[0], ScriptEng.operands[1], ScriptEng.operands[2], ScriptEng.operands[3], ScriptEng.operands[4]); break; case FUNC_RESETOBJECTENTITY: { opcodeSize = 0; - Entity *newEnt = &objectEntityList[scriptEng.operands[0]]; - newEnt->type = scriptEng.operands[1]; - newEnt->propertyValue = scriptEng.operands[2]; - newEnt->XPos = scriptEng.operands[3]; - newEnt->YPos = scriptEng.operands[4]; + Entity *newEnt = &ObjectEntityList[ScriptEng.operands[0]]; + newEnt->type = ScriptEng.operands[1]; + newEnt->propertyValue = ScriptEng.operands[2]; + newEnt->XPos = ScriptEng.operands[3]; + newEnt->YPos = ScriptEng.operands[4]; newEnt->direction = FLIP_NONE; newEnt->frame = 0; newEnt->priority = PRIORITY_BOUNDS; @@ -2428,33 +2333,33 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) } case FUNC_PLAYEROBJECTCOLLISION: opcodeSize = 0; - switch (scriptEng.operands[0]) { + switch (ScriptEng.operands[0]) { default: break; case C_TOUCH: - scriptEng.operands[5] = entity->XPos >> 16; - scriptEng.operands[6] = entity->YPos >> 16; - TouchCollision(scriptEng.operands[5] + scriptEng.operands[1], scriptEng.operands[6] + scriptEng.operands[2], - scriptEng.operands[5] + scriptEng.operands[3], scriptEng.operands[6] + scriptEng.operands[4]); + ScriptEng.operands[5] = entity->XPos >> 16; + ScriptEng.operands[6] = entity->YPos >> 16; + BasicCollision(ScriptEng.operands[5] + ScriptEng.operands[1], ScriptEng.operands[6] + ScriptEng.operands[2], + ScriptEng.operands[5] + ScriptEng.operands[3], ScriptEng.operands[6] + ScriptEng.operands[4]); break; case C_BOX: - BoxCollision(entity->XPos + (scriptEng.operands[1] << 16), entity->YPos + (scriptEng.operands[2] << 16), - entity->XPos + (scriptEng.operands[3] << 16), entity->YPos + (scriptEng.operands[4] << 16)); + BoxCollision(entity->XPos + (ScriptEng.operands[1] << 16), entity->YPos + (ScriptEng.operands[2] << 16), + entity->XPos + (ScriptEng.operands[3] << 16), entity->YPos + (ScriptEng.operands[4] << 16)); break; case C_PLATFORM: - PlatformCollision(entity->XPos + (scriptEng.operands[1] << 16), entity->YPos + (scriptEng.operands[2] << 16), - entity->XPos + (scriptEng.operands[3] << 16), entity->YPos + (scriptEng.operands[4] << 16)); + PlatformCollision(entity->XPos + (ScriptEng.operands[1] << 16), entity->YPos + (ScriptEng.operands[2] << 16), + entity->XPos + (ScriptEng.operands[3] << 16), entity->YPos + (ScriptEng.operands[4] << 16)); break; } break; case FUNC_CREATETEMPOBJECT: { opcodeSize = 0; - if (objectEntityList[scriptEng.arrayPosition[2]].type > 0 && ++scriptEng.arrayPosition[2] == ENTITY_COUNT) - scriptEng.arrayPosition[2] = TEMPENTITY_START; - Entity *temp = &objectEntityList[scriptEng.arrayPosition[2]]; - temp->type = scriptEng.operands[0]; - temp->propertyValue = scriptEng.operands[1]; - temp->XPos = scriptEng.operands[2]; - temp->YPos = scriptEng.operands[3]; + if (ObjectEntityList[ScriptEng.arrayPosition[2]].type > 0 && ++ScriptEng.arrayPosition[2] == ENTITY_COUNT) + ScriptEng.arrayPosition[2] = TEMPENTITY_START; + Entity *temp = &ObjectEntityList[ScriptEng.arrayPosition[2]]; + temp->type = ScriptEng.operands[0]; + temp->propertyValue = ScriptEng.operands[1]; + temp->XPos = ScriptEng.operands[2]; + temp->YPos = ScriptEng.operands[3]; temp->direction = FLIP_NONE; temp->frame = 0; temp->priority = PRIORITY_ALWAYS; @@ -2474,36 +2379,36 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) break; } case FUNC_DEFAULTGROUNDMOVEMENT: - opcodeSize = 0; - DefaultGroundMovement(&playerList[activePlayer]); + opcodeSize = 0; + ProcessDefaultGroundMovement(&PlayerList[PlayerNo]); break; case FUNC_DEFAULTAIRMOVEMENT: - opcodeSize = 0; - DefaultAirMovement(&playerList[activePlayer]); + opcodeSize = 0; + ProcessDefaultAirMovement(&PlayerList[PlayerNo]); break; case FUNC_DEFAULTROLLINGMOVEMENT: - opcodeSize = 0; - DefaultRollingMovement(&playerList[activePlayer]); + opcodeSize = 0; + ProcessDefaultRollingMovement(&PlayerList[PlayerNo]); break; - case FUNC_DEFAULTGRAVITYTRUE: + case FUNC_DEFAULTGRAVITYTRUE: opcodeSize = 0; - DefaultGravityTrue(&playerList[activePlayer]); + ProcessDefaultGravityTrue(&PlayerList[PlayerNo]); break; case FUNC_DEFAULTGRAVITYFALSE: - opcodeSize = 0; - DefaultGravityFalse(&playerList[activePlayer]); + opcodeSize = 0; + ProcessDefaultGravityFalse(&PlayerList[PlayerNo]); break; - case FUNC_DEFAULTJUMPACTION: + case FUNC_DEFAULTJUMPACTION: opcodeSize = 0; - DefaultJumpAction(&playerList[activePlayer]); + ProcessDefaultJumpAction(&PlayerList[PlayerNo]); break; case FUNC_SETMUSICTRACK: opcodeSize = 0; - SetMusicTrack(scriptText, scriptEng.operands[1], scriptEng.operands[2]); + SetMusicTrack(ScriptText, ScriptEng.operands[1], ScriptEng.operands[2]); break; case FUNC_PLAYMUSIC: opcodeSize = 0; - PlayMusic(scriptEng.operands[0]); + PlayMusic(ScriptEng.operands[0]); break; case FUNC_STOPMUSIC: opcodeSize = 0; @@ -2511,30 +2416,30 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) break; case FUNC_PLAYSFX: opcodeSize = 0; - PlaySfx(scriptEng.operands[0], scriptEng.operands[1]); + PlaySfx(ScriptEng.operands[0], ScriptEng.operands[1]); break; case FUNC_STOPSFX: opcodeSize = 0; - StopSfx(scriptEng.operands[0]); + StopSfx(ScriptEng.operands[0]); break; case FUNC_SETSFXATTRIBUTES: opcodeSize = 0; - SetSfxAttributes(scriptEng.operands[0], scriptEng.operands[1], scriptEng.operands[2]); + SetSfxAttributes(ScriptEng.operands[0], ScriptEng.operands[1], ScriptEng.operands[2]); break; case FUNC_OBJECTTILECOLLISION: opcodeSize = 0; - if (scriptEng.operands[0] == CSIDE_FLOOR) - ObjectFloorCollision(scriptEng.operands[1], scriptEng.operands[2], scriptEng.operands[3]); + if (ScriptEng.operands[0] == CSIDE_FLOOR) + ObjectFloorCollision(ScriptEng.operands[1], ScriptEng.operands[2], ScriptEng.operands[3]); break; case FUNC_OBJECTTILEGRIP: opcodeSize = 0; - if (scriptEng.operands[0] == CSIDE_FLOOR) - ObjectFloorGrip(scriptEng.operands[1], scriptEng.operands[2], scriptEng.operands[3]); + if (ScriptEng.operands[0] == CSIDE_FLOOR) + ObjectFloorGrip(ScriptEng.operands[1], ScriptEng.operands[2], ScriptEng.operands[3]); break; case FUNC_LOADVIDEO: opcodeSize = 0; PauseSound(); - scriptInfo->spriteSheetID = AddGraphicsFile(scriptText); + scriptInfo->spriteSheetID = AddGraphicsFile(ScriptText); ResumeSound(); break; case FUNC_NEXTVIDEOFRAME: @@ -2543,11 +2448,11 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) break; case FUNC_PLAYSTAGESFX: opcodeSize = 0; - PlaySfx(globalSFXCount + scriptEng.operands[0], scriptEng.operands[1]); + PlaySfx(NoGlobalSFX + ScriptEng.operands[0], ScriptEng.operands[1]); break; case FUNC_STOPSTAGESFX: opcodeSize = 0; - StopSfx(globalSFXCount + scriptEng.operands[0]); + StopSfx(NoGlobalSFX + ScriptEng.operands[0]); break; } @@ -2555,333 +2460,333 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) if (opcodeSize > 0) scriptDataPtr -= scriptDataPtr - scriptCodeOffset; for (int i = 0; i < opcodeSize; ++i) { - int opcodeType = scriptData[scriptDataPtr++]; + int opcodeType = ScriptData[scriptDataPtr++]; if (opcodeType == SCRIPTVAR_VAR) { int arrayVal = 0; - switch (scriptData[scriptDataPtr++]) { // variable - case VARARR_NONE: arrayVal = objectLoop; break; + switch (ScriptData[scriptDataPtr++]) { // variable + case VARARR_NONE: arrayVal = ObjectLoop; break; case VARARR_ARRAY: - if (scriptData[scriptDataPtr++] == 1) - arrayVal = scriptEng.arrayPosition[scriptData[scriptDataPtr++]]; + if (ScriptData[scriptDataPtr++] == 1) + arrayVal = ScriptEng.arrayPosition[ScriptData[scriptDataPtr++]]; else - arrayVal = scriptData[scriptDataPtr++]; + arrayVal = ScriptData[scriptDataPtr++]; break; case VARARR_ENTNOPLUS1: - if (scriptData[scriptDataPtr++] == 1) - arrayVal = scriptEng.arrayPosition[scriptData[scriptDataPtr++]] + objectLoop; + if (ScriptData[scriptDataPtr++] == 1) + arrayVal = ScriptEng.arrayPosition[ScriptData[scriptDataPtr++]] + ObjectLoop; else - arrayVal = scriptData[scriptDataPtr++] + objectLoop; + arrayVal = ScriptData[scriptDataPtr++] + ObjectLoop; break; case VARARR_ENTNOMINUS1: - if (scriptData[scriptDataPtr++] == 1) - arrayVal = objectLoop - scriptEng.arrayPosition[scriptData[scriptDataPtr++]]; + if (ScriptData[scriptDataPtr++] == 1) + arrayVal = ObjectLoop - ScriptEng.arrayPosition[ScriptData[scriptDataPtr++]]; else - arrayVal = objectLoop - scriptData[scriptDataPtr++]; + arrayVal = ObjectLoop - ScriptData[scriptDataPtr++]; break; default: break; } // Variables - switch (scriptData[scriptDataPtr++]) { + switch (ScriptData[scriptDataPtr++]) { default: break; case VAR_OBJECTTYPE: { - objectEntityList[arrayVal].type = scriptEng.operands[i]; + ObjectEntityList[arrayVal].type = ScriptEng.operands[i]; break; } case VAR_OBJECTPROPERTYVALUE: { - objectEntityList[arrayVal].propertyValue = scriptEng.operands[i]; + ObjectEntityList[arrayVal].propertyValue = ScriptEng.operands[i]; break; } case VAR_OBJECTXPOS: { - objectEntityList[arrayVal].XPos = scriptEng.operands[i]; + ObjectEntityList[arrayVal].XPos = ScriptEng.operands[i]; break; } case VAR_OBJECTYPOS: { - objectEntityList[arrayVal].YPos = scriptEng.operands[i]; + ObjectEntityList[arrayVal].YPos = ScriptEng.operands[i]; break; } case VAR_OBJECTIXPOS: { - objectEntityList[arrayVal].XPos = scriptEng.operands[i] << 16; + ObjectEntityList[arrayVal].XPos = ScriptEng.operands[i] << 16; break; } case VAR_OBJECTIYPOS: { - objectEntityList[arrayVal].YPos = scriptEng.operands[i] << 16; + ObjectEntityList[arrayVal].YPos = ScriptEng.operands[i] << 16; break; } case VAR_OBJECTSTATE: { - objectEntityList[arrayVal].state = scriptEng.operands[i]; + ObjectEntityList[arrayVal].state = ScriptEng.operands[i]; break; } case VAR_OBJECTROTATION: { - objectEntityList[arrayVal].rotation = scriptEng.operands[i]; + ObjectEntityList[arrayVal].rotation = ScriptEng.operands[i]; break; } case VAR_OBJECTSCALE: { - objectEntityList[arrayVal].scale = scriptEng.operands[i]; + ObjectEntityList[arrayVal].scale = ScriptEng.operands[i]; break; } case VAR_OBJECTPRIORITY: { - objectEntityList[arrayVal].priority = scriptEng.operands[i]; + ObjectEntityList[arrayVal].priority = ScriptEng.operands[i]; break; } case VAR_OBJECTDRAWORDER: { - objectEntityList[arrayVal].drawOrder = scriptEng.operands[i]; + ObjectEntityList[arrayVal].drawOrder = ScriptEng.operands[i]; break; } case VAR_OBJECTDIRECTION: { - objectEntityList[arrayVal].direction = scriptEng.operands[i]; + ObjectEntityList[arrayVal].direction = ScriptEng.operands[i]; break; } case VAR_OBJECTINKEFFECT: { - objectEntityList[arrayVal].inkEffect = scriptEng.operands[i]; + ObjectEntityList[arrayVal].inkEffect = ScriptEng.operands[i]; break; } case VAR_OBJECTFRAME: { - objectEntityList[arrayVal].frame = scriptEng.operands[i]; + ObjectEntityList[arrayVal].frame = ScriptEng.operands[i]; break; } case VAR_OBJECTVALUE0: { - objectEntityList[arrayVal].values[0] = scriptEng.operands[i]; + ObjectEntityList[arrayVal].values[0] = ScriptEng.operands[i]; break; } case VAR_OBJECTVALUE1: { - objectEntityList[arrayVal].values[1] = scriptEng.operands[i]; + ObjectEntityList[arrayVal].values[1] = ScriptEng.operands[i]; break; } case VAR_OBJECTVALUE2: { - objectEntityList[arrayVal].values[2] = scriptEng.operands[i]; + ObjectEntityList[arrayVal].values[2] = ScriptEng.operands[i]; break; } case VAR_OBJECTVALUE3: { - objectEntityList[arrayVal].values[3] = scriptEng.operands[i]; + ObjectEntityList[arrayVal].values[3] = ScriptEng.operands[i]; break; } case VAR_OBJECTVALUE4: { - objectEntityList[arrayVal].values[4] = scriptEng.operands[i]; + ObjectEntityList[arrayVal].values[4] = ScriptEng.operands[i]; break; } case VAR_OBJECTVALUE5: { - objectEntityList[arrayVal].values[5] = scriptEng.operands[i]; + ObjectEntityList[arrayVal].values[5] = ScriptEng.operands[i]; break; } case VAR_OBJECTVALUE6: { - objectEntityList[arrayVal].values[6] = scriptEng.operands[i]; + ObjectEntityList[arrayVal].values[6] = ScriptEng.operands[i]; break; } case VAR_OBJECTVALUE7: { - objectEntityList[arrayVal].values[7] = scriptEng.operands[i]; - break; - } - case VAR_TEMPVALUE0: scriptEng.tempValue[0] = scriptEng.operands[i]; break; - case VAR_TEMPVALUE1: scriptEng.tempValue[1] = scriptEng.operands[i]; break; - case VAR_TEMPVALUE2: scriptEng.tempValue[2] = scriptEng.operands[i]; break; - case VAR_TEMPVALUE3: scriptEng.tempValue[3] = scriptEng.operands[i]; break; - case VAR_TEMPVALUE4: scriptEng.tempValue[4] = scriptEng.operands[i]; break; - case VAR_TEMPVALUE5: scriptEng.tempValue[5] = scriptEng.operands[i]; break; - case VAR_TEMPVALUE6: scriptEng.tempValue[6] = scriptEng.operands[i]; break; - case VAR_TEMPVALUE7: scriptEng.tempValue[7] = scriptEng.operands[i]; break; - case VAR_CHECKRESULT: scriptEng.checkResult = scriptEng.operands[i]; break; - case VAR_ARRAYPOS0: scriptEng.arrayPosition[0] = scriptEng.operands[i]; break; - case VAR_ARRAYPOS1: scriptEng.arrayPosition[1] = scriptEng.operands[i]; break; - case VAR_KEYDOWNUP: keyDown.up = scriptEng.operands[i]; break; - case VAR_KEYDOWNDOWN: keyDown.down = scriptEng.operands[i]; break; - case VAR_KEYDOWNLEFT: keyDown.left = scriptEng.operands[i]; break; - case VAR_KEYDOWNRIGHT: keyDown.right = scriptEng.operands[i]; break; - case VAR_KEYDOWNBUTTONA: keyDown.A = scriptEng.operands[i]; break; - case VAR_KEYDOWNBUTTONB: keyDown.B = scriptEng.operands[i]; break; - case VAR_KEYDOWNBUTTONC: keyDown.C = scriptEng.operands[i]; break; - case VAR_KEYDOWNSTART: keyDown.start = scriptEng.operands[i]; break; - case VAR_KEYPRESSUP: keyPress.up = scriptEng.operands[i]; break; - case VAR_KEYPRESSDOWN: keyPress.down = scriptEng.operands[i]; break; - case VAR_KEYPRESSLEFT: keyPress.left = scriptEng.operands[i]; break; - case VAR_KEYPRESSRIGHT: keyPress.right = scriptEng.operands[i]; break; - case VAR_KEYPRESSBUTTONA: keyPress.A = scriptEng.operands[i]; break; - case VAR_KEYPRESSBUTTONB: keyPress.B = scriptEng.operands[i]; break; - case VAR_KEYPRESSBUTTONC: keyPress.C = scriptEng.operands[i]; break; - case VAR_KEYPRESSSTART: keyPress.start = scriptEng.operands[i]; break; - case VAR_MENU1SELECTION: gameMenu[0].selection1 = scriptEng.operands[i]; break; - case VAR_MENU2SELECTION: gameMenu[1].selection1 = scriptEng.operands[i]; break; - case VAR_STAGEACTIVELIST: activeStageList = scriptEng.operands[i]; break; - case VAR_STAGELISTPOS: stageListPosition = scriptEng.operands[i]; break; - case VAR_XSCROLLOFFSET: xScrollOffset = scriptEng.operands[i]; break; - case VAR_YSCROLLOFFSET: yScrollOffset = scriptEng.operands[i]; break; - case VAR_GLOBAL: globalVariables[arrayVal] = scriptEng.operands[i]; break; - case VAR_STAGETIMEENABLED: timeEnabled = scriptEng.operands[i]; break; - case VAR_STAGEMILLISECONDS: stageMilliseconds = scriptEng.operands[i]; break; - case VAR_STAGESECONDS: stageSeconds = scriptEng.operands[i]; break; - case VAR_STAGEMINUTES: stageMinutes = scriptEng.operands[i]; break; - case VAR_STAGEACTNO: actID = scriptEng.operands[i]; break; + ObjectEntityList[arrayVal].values[7] = ScriptEng.operands[i]; + break; + } + case VAR_TEMPVALUE0: ScriptEng.tempValue[0] = ScriptEng.operands[i]; break; + case VAR_TEMPVALUE1: ScriptEng.tempValue[1] = ScriptEng.operands[i]; break; + case VAR_TEMPVALUE2: ScriptEng.tempValue[2] = ScriptEng.operands[i]; break; + case VAR_TEMPVALUE3: ScriptEng.tempValue[3] = ScriptEng.operands[i]; break; + case VAR_TEMPVALUE4: ScriptEng.tempValue[4] = ScriptEng.operands[i]; break; + case VAR_TEMPVALUE5: ScriptEng.tempValue[5] = ScriptEng.operands[i]; break; + case VAR_TEMPVALUE6: ScriptEng.tempValue[6] = ScriptEng.operands[i]; break; + case VAR_TEMPVALUE7: ScriptEng.tempValue[7] = ScriptEng.operands[i]; break; + case VAR_CHECKRESULT: ScriptEng.checkResult = ScriptEng.operands[i]; break; + case VAR_ARRAYPOS0: ScriptEng.arrayPosition[0] = ScriptEng.operands[i]; break; + case VAR_ARRAYPOS1: ScriptEng.arrayPosition[1] = ScriptEng.operands[i]; break; + case VAR_KEYDOWNUP: GKeyDown.up = ScriptEng.operands[i]; break; + case VAR_KEYDOWNDOWN: GKeyDown.down = ScriptEng.operands[i]; break; + case VAR_KEYDOWNLEFT: GKeyDown.left = ScriptEng.operands[i]; break; + case VAR_KEYDOWNRIGHT: GKeyDown.right = ScriptEng.operands[i]; break; + case VAR_KEYDOWNBUTTONA: GKeyDown.A = ScriptEng.operands[i]; break; + case VAR_KEYDOWNBUTTONB: GKeyDown.B = ScriptEng.operands[i]; break; + case VAR_KEYDOWNBUTTONC: GKeyDown.C = ScriptEng.operands[i]; break; + case VAR_KEYDOWNSTART: GKeyDown.start = ScriptEng.operands[i]; break; + case VAR_KEYPRESSUP: GKeyPress.up = ScriptEng.operands[i]; break; + case VAR_KEYPRESSDOWN: GKeyPress.down = ScriptEng.operands[i]; break; + case VAR_KEYPRESSLEFT: GKeyPress.left = ScriptEng.operands[i]; break; + case VAR_KEYPRESSRIGHT: GKeyPress.right = ScriptEng.operands[i]; break; + case VAR_KEYPRESSBUTTONA: GKeyPress.A = ScriptEng.operands[i]; break; + case VAR_KEYPRESSBUTTONB: GKeyPress.B = ScriptEng.operands[i]; break; + case VAR_KEYPRESSBUTTONC: GKeyPress.C = ScriptEng.operands[i]; break; + case VAR_KEYPRESSSTART: GKeyPress.start = ScriptEng.operands[i]; break; + case VAR_MENU1SELECTION: GameMenu[0].selection1 = ScriptEng.operands[i]; break; + case VAR_MENU2SELECTION: GameMenu[1].selection1 = ScriptEng.operands[i]; break; + case VAR_STAGEACTIVELIST: ActiveStageList = ScriptEng.operands[i]; break; + case VAR_STAGELISTPOS: StageListPosition = ScriptEng.operands[i]; break; + case VAR_XSCROLLOFFSET: XScrollOffset = ScriptEng.operands[i]; break; + case VAR_YSCROLLOFFSET: YScrollOffset = ScriptEng.operands[i]; break; + case VAR_GLOBAL: GlobalVariables[arrayVal] = ScriptEng.operands[i]; break; + case VAR_STAGETIMEENABLED: TimeEnabled = ScriptEng.operands[i]; break; + case VAR_STAGEMILLISECONDS: MilliSeconds = ScriptEng.operands[i]; break; + case VAR_STAGESECONDS: Seconds = ScriptEng.operands[i]; break; + case VAR_STAGEMINUTES: Minutes = ScriptEng.operands[i]; break; + case VAR_STAGEACTNO: ActNumber = ScriptEng.operands[i]; break; case VAR_OBJECTENTITYNO: break; case VAR_PLAYERTYPE: { - playerList[activePlayer].type = scriptEng.operands[i]; + PlayerList[PlayerNo].type = ScriptEng.operands[i]; break; } case VAR_PLAYERSTATE: { - playerList[activePlayer].state = scriptEng.operands[i]; + PlayerList[PlayerNo].state = ScriptEng.operands[i]; break; } case VAR_PLAYERCONTROLMODE: { - playerList[activePlayer].controlMode = scriptEng.operands[i]; + PlayerList[PlayerNo].controlMode = ScriptEng.operands[i]; break; } case VAR_PLAYERCOLLISIONMODE: { - playerList[activePlayer].collisionMode = scriptEng.operands[i]; + PlayerList[PlayerNo].collisionMode = ScriptEng.operands[i]; break; } case VAR_PLAYERCOLLISIONPLANE: { - playerList[activePlayer].collisionPlane = scriptEng.operands[i]; + PlayerList[PlayerNo].collisionPlane = ScriptEng.operands[i]; break; } case VAR_PLAYERXPOS: { - playerList[activePlayer].XPos = scriptEng.operands[i]; + PlayerList[PlayerNo].XPos = ScriptEng.operands[i]; break; } case VAR_PLAYERYPOS: { - playerList[activePlayer].YPos = scriptEng.operands[i]; + PlayerList[PlayerNo].YPos = ScriptEng.operands[i]; break; } case VAR_PLAYERSCREENXPOS: { - playerList[activePlayer].screenXPos = scriptEng.operands[i]; + PlayerList[PlayerNo].screenXPos = ScriptEng.operands[i]; break; } case VAR_PLAYERSCREENYPOS: { - playerList[activePlayer].screenYPos = scriptEng.operands[i]; + PlayerList[PlayerNo].screenYPos = ScriptEng.operands[i]; break; } case VAR_PLAYERSPEED: { - playerList[activePlayer].speed = scriptEng.operands[i]; + PlayerList[PlayerNo].speed = ScriptEng.operands[i]; break; } case VAR_PLAYERXVELOCITY: { - playerList[activePlayer].XVelocity = scriptEng.operands[i]; + PlayerList[PlayerNo].XVelocity = ScriptEng.operands[i]; break; } case VAR_PLAYERYVELOCITY: { - playerList[activePlayer].YVelocity = scriptEng.operands[i]; + PlayerList[PlayerNo].YVelocity = ScriptEng.operands[i]; break; } case VAR_PLAYERGRAVITY: { - playerList[activePlayer].gravity = scriptEng.operands[i]; + PlayerList[PlayerNo].gravity = ScriptEng.operands[i]; break; } case VAR_PLAYERANGLE: { - playerList[activePlayer].angle = scriptEng.operands[i]; + PlayerList[PlayerNo].angle = ScriptEng.operands[i]; break; } case VAR_PLAYERROTATION: { - playerList[activePlayer].rotation = scriptEng.operands[i]; + PlayerList[PlayerNo].rotation = ScriptEng.operands[i]; break; } case VAR_PLAYERDIRECTION: { - playerList[activePlayer].direction = scriptEng.operands[i]; + PlayerList[PlayerNo].direction = ScriptEng.operands[i]; break; } case VAR_PLAYERANIMATION: { - playerList[activePlayer].animation = scriptEng.operands[i]; + PlayerList[PlayerNo].animation = ScriptEng.operands[i]; break; } case VAR_PLAYERFRAME: { - playerList[activePlayer].frame = scriptEng.operands[i]; + PlayerList[PlayerNo].frame = ScriptEng.operands[i]; break; } case VAR_PLAYERSKIDDING: { - playerList[activePlayer].skidding = scriptEng.operands[i]; + PlayerList[PlayerNo].skidding = ScriptEng.operands[i]; break; } case VAR_PLAYERPUSHING: { - playerList[activePlayer].pushing = scriptEng.operands[i]; + PlayerList[PlayerNo].pushing = ScriptEng.operands[i]; break; } case VAR_PLAYERFRICTIONLOSS: { - playerList[activePlayer].frictionLoss = scriptEng.operands[i]; + PlayerList[PlayerNo].frictionLoss = ScriptEng.operands[i]; break; } case VAR_PLAYERWALKINGSPEED: { - playerList[activePlayer].walkingSpeed = scriptEng.operands[i]; + PlayerList[PlayerNo].walkingSpeed = ScriptEng.operands[i]; break; } case VAR_PLAYERRUNNINGSPEED: { - playerList[activePlayer].runningSpeed = scriptEng.operands[i]; + PlayerList[PlayerNo].runningSpeed = ScriptEng.operands[i]; break; } case VAR_PLAYERJUMPINGSPEED: { - playerList[activePlayer].jumpingSpeed = scriptEng.operands[i]; + PlayerList[PlayerNo].jumpingSpeed = ScriptEng.operands[i]; break; } case VAR_PLAYERTRACKSCROLL: { - playerList[activePlayer].trackScroll = scriptEng.operands[i]; + PlayerList[PlayerNo].trackScroll = ScriptEng.operands[i]; break; } case VAR_PLAYERUP: { - playerList[activePlayer].up = scriptEng.operands[i]; + PlayerList[PlayerNo].up = ScriptEng.operands[i]; break; } case VAR_PLAYERDOWN: { - playerList[activePlayer].down = scriptEng.operands[i]; + PlayerList[PlayerNo].down = ScriptEng.operands[i]; break; } case VAR_PLAYERLEFT: { - playerList[activePlayer].left = scriptEng.operands[i]; + PlayerList[PlayerNo].left = ScriptEng.operands[i]; break; } case VAR_PLAYERRIGHT: { - playerList[activePlayer].right = scriptEng.operands[i]; + PlayerList[PlayerNo].right = ScriptEng.operands[i]; break; } case VAR_PLAYERJUMPPRESS: { - playerList[activePlayer].jumpPress = scriptEng.operands[i]; + PlayerList[PlayerNo].jumpPress = ScriptEng.operands[i]; break; } case VAR_PLAYERJUMPHOLD: { - playerList[activePlayer].jumpHold = scriptEng.operands[i]; + PlayerList[PlayerNo].jumpHold = ScriptEng.operands[i]; break; } case VAR_PLAYERFOLLOWPLAYER1: { - playerList[activePlayer].followPlayer1 = scriptEng.operands[i]; + PlayerList[PlayerNo].followPlayer1 = ScriptEng.operands[i]; break; } case VAR_PLAYERLOOKPOS: { - playerList[activePlayer].lookPos = scriptEng.operands[i]; + PlayerList[PlayerNo].lookPos = ScriptEng.operands[i]; break; } case VAR_PLAYERWATER: { - playerList[activePlayer].water = scriptEng.operands[i]; + PlayerList[PlayerNo].water = ScriptEng.operands[i]; break; } case VAR_PLAYERTOPSPEED: { - playerList[activePlayer].stats.topSpeed = scriptEng.operands[i]; + PlayerList[PlayerNo].stats.topSpeed = ScriptEng.operands[i]; break; } case VAR_PLAYERACCELERATION: { - playerList[activePlayer].stats.acceleration = scriptEng.operands[i]; + PlayerList[PlayerNo].stats.acceleration = ScriptEng.operands[i]; break; } case VAR_PLAYERDECELERATION: { - playerList[activePlayer].stats.deceleration = scriptEng.operands[i]; + PlayerList[PlayerNo].stats.deceleration = ScriptEng.operands[i]; break; } case VAR_PLAYERAIRACCELERATION: { - playerList[activePlayer].stats.airAcceleration = scriptEng.operands[i]; + PlayerList[PlayerNo].stats.airAcceleration = ScriptEng.operands[i]; break; } case VAR_PLAYERAIRDECELERATION: { - playerList[activePlayer].stats.airDeceleration = scriptEng.operands[i]; + PlayerList[PlayerNo].stats.airDeceleration = ScriptEng.operands[i]; break; } case VAR_PLAYERGRAVITYSTRENGTH: { - playerList[activePlayer].stats.gravityStrength = scriptEng.operands[i]; + PlayerList[PlayerNo].stats.gravityStrength = ScriptEng.operands[i]; break; } case VAR_PLAYERJUMPSTRENGTH: { - playerList[activePlayer].stats.jumpStrength = scriptEng.operands[i]; + PlayerList[PlayerNo].stats.jumpStrength = ScriptEng.operands[i]; break; } case VAR_PLAYERROLLINGACCELERATION: { - playerList[activePlayer].stats.rollingAcceleration = scriptEng.operands[i]; + PlayerList[PlayerNo].stats.rollingAcceleration = ScriptEng.operands[i]; break; } case VAR_PLAYERROLLINGDECELERATION: { - playerList[activePlayer].stats.rollingDeceleration = scriptEng.operands[i]; + PlayerList[PlayerNo].stats.rollingDeceleration = ScriptEng.operands[i]; break; } case VAR_PLAYERENTITYNO: break; @@ -2890,76 +2795,74 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub) case VAR_PLAYERCOLLISIONRIGHT: break; case VAR_PLAYERCOLLISIONBOTTOM: break; case VAR_PLAYERFLAILING: { - playerList[activePlayer].flailing[arrayVal] = scriptEng.operands[i]; + PlayerList[PlayerNo].flailing[arrayVal] = ScriptEng.operands[i]; break; } case VAR_STAGEPAUSEENABLED: { - pauseEnabled = scriptEng.operands[i]; + PauseEnabled = ScriptEng.operands[i]; break; } case VAR_STAGELISTSIZE: { break; } case VAR_PLAYERTIMER: { - playerList[activePlayer].timer = scriptEng.operands[i]; + PlayerList[PlayerNo].timer = ScriptEng.operands[i]; break; } case VAR_PLAYERANIMATIONSPEED: { - playerList[activePlayer].animationSpeed = scriptEng.operands[i]; + PlayerList[PlayerNo].animationSpeed = ScriptEng.operands[i]; break; } case VAR_PLAYERTILECOLLISIONS: { - playerList[activePlayer].tileCollisions = scriptEng.operands[i]; + PlayerList[PlayerNo].tileCollisions = ScriptEng.operands[i]; break; } case VAR_PLAYEROBJECTINTERACTION: { - playerList[activePlayer].objectInteraction = scriptEng.operands[i]; + PlayerList[PlayerNo].objectInteraction = ScriptEng.operands[i]; break; } - case VAR_SCREENCAMERAENABLED: cameraEnabled = scriptEng.operands[i]; break; - case VAR_SCREENCAMERASTYLE: cameraStyle = scriptEng.operands[i]; break; - case VAR_MUSICVOLUME: SetMusicVolume(scriptEng.operands[i]); break; - case VAR_MUSICCURRENTTRACK: trackID = scriptEng.operands[i]; break; + case VAR_SCREENCAMERAENABLED: CameraEnabled = ScriptEng.operands[i]; break; + case VAR_SCREENCAMERASTYLE: CameraStyle = ScriptEng.operands[i]; break; + case VAR_MUSICVOLUME: SetMusicVolume(ScriptEng.operands[i]); break; + case VAR_MUSICCURRENTTRACK: CurrentMusicTrack = ScriptEng.operands[i]; break; case VAR_PLAYERVISIBLE: { - playerList[activePlayer].visible = scriptEng.operands[i]; + PlayerList[PlayerNo].visible = ScriptEng.operands[i]; break; } - case VAR_STAGENEWXBOUNDARY1: newXBoundary1 = scriptEng.operands[i]; break; - case VAR_STAGENEWXBOUNDARY2: newXBoundary2 = scriptEng.operands[i]; break; - case VAR_STAGENEWYBOUNDARY1: newYBoundary1 = scriptEng.operands[i]; break; - case VAR_STAGENEWYBOUNDARY2: newYBoundary2 = scriptEng.operands[i]; break; + case VAR_STAGENEWXBOUNDARY1: NewXBoundary1 = ScriptEng.operands[i]; break; + case VAR_STAGENEWXBOUNDARY2: NewXBoundary2 = ScriptEng.operands[i]; break; + case VAR_STAGENEWYBOUNDARY1: NewYBoundary1 = ScriptEng.operands[i]; break; + case VAR_STAGENEWYBOUNDARY2: NewYBoundary2 = ScriptEng.operands[i]; break; case VAR_STAGEXBOUNDARY1: - if (xBoundary1 != scriptEng.operands[i]) { - xBoundary1 = scriptEng.operands[i]; - newXBoundary1 = scriptEng.operands[i]; + if (XBoundary1 != ScriptEng.operands[i]) { + XBoundary1 = ScriptEng.operands[i]; + NewXBoundary1 = ScriptEng.operands[i]; } break; case VAR_STAGEXBOUNDARY2: - if (xBoundary2 != scriptEng.operands[i]) { - xBoundary2 = scriptEng.operands[i]; - newXBoundary2 = scriptEng.operands[i]; + if (XBoundary2 != ScriptEng.operands[i]) { + XBoundary2 = ScriptEng.operands[i]; + NewXBoundary2 = ScriptEng.operands[i]; } break; case VAR_STAGEYBOUNDARY1: - if (yBoundary1 != scriptEng.operands[i]) { - yBoundary1 = scriptEng.operands[i]; - newYBoundary1 = scriptEng.operands[i]; + if (YBoundary1 != ScriptEng.operands[i]) { + YBoundary1 = ScriptEng.operands[i]; + NewYBoundary1 = ScriptEng.operands[i]; } break; case VAR_STAGEYBOUNDARY2: - if (yBoundary2 != scriptEng.operands[i]) { - yBoundary2 = scriptEng.operands[i]; - newYBoundary2 = scriptEng.operands[i]; + if (YBoundary2 != ScriptEng.operands[i]) { + YBoundary2 = ScriptEng.operands[i]; + NewYBoundary2 = ScriptEng.operands[i]; } break; case VAR_OBJECTOUTOFBOUNDS: break; } - } - else if (opcodeType == SCRIPTVAR_INTCONST) { // int constant + } else if (opcodeType == SCRIPTVAR_INTCONST) { // int constant scriptDataPtr++; - } - else if (opcodeType == SCRIPTVAR_STRCONST) { // string constant - int strLen = scriptData[scriptDataPtr++]; + } else if (opcodeType == SCRIPTVAR_STRCONST) { // string constant + int strLen = ScriptData[scriptDataPtr++]; for (int c = 0; c < strLen; ++c) { switch (c % 4) { case 0: break; diff --git a/Nexus/Script.hpp b/Nexus/Script.hpp index 0f3ef40..3172c1d 100644 --- a/Nexus/Script.hpp +++ b/Nexus/Script.hpp @@ -2,11 +2,8 @@ #define SCRIPT_H #define SCRIPTDATA_COUNT (0x40000) -#define JUMPTABLE_COUNT (0x4000) -#define FUNCTION_COUNT (0x200) - +#define JUMPTABLE_COUNT (0x4000) #define JUMPSTACK_COUNT (0x400) -#define FUNCSTACK_COUNT (0x400) struct ScriptPtr { int scriptCodePtr; @@ -20,7 +17,7 @@ struct ObjectScript { ScriptPtr subPlayerInteraction; ScriptPtr subDraw; ScriptPtr subStartup; - SpriteFrame* frameStartPtr; + SpriteFrame *frameStartPtr; }; struct ScriptEngine { @@ -32,27 +29,24 @@ struct ScriptEngine { enum ScriptSubs { SUB_MAIN = 0, SUB_PLAYERINTERACTION = 1, SUB_DRAW = 2, SUB_SETUP = 3, SUB_PLAYERMAIN = 4, SUB_PLAYERSTATE = 5 }; -extern ObjectScript objectScriptList[OBJECT_COUNT]; -extern ScriptPtr functionScriptList[FUNCTION_COUNT]; +extern ObjectScript ObjectScriptList[OBJECT_COUNT]; -extern int scriptData[SCRIPTDATA_COUNT]; -extern int jumpTableData[JUMPTABLE_COUNT]; +extern int ScriptData[SCRIPTDATA_COUNT]; +extern int JumpTableData[JUMPTABLE_COUNT]; -extern int jumpTableStack[JUMPSTACK_COUNT]; -extern int functionStack[FUNCSTACK_COUNT]; +extern int JumpTableStack[JUMPSTACK_COUNT]; -extern int jumpTableStackPos; -extern int functionStackPos; +extern int JumpTableStackPos; -extern ScriptEngine scriptEng; -extern char scriptText[0x100]; +extern ScriptEngine ScriptEng; +extern char ScriptText[0x100]; -extern int scriptDataPos; +extern int ScriptDataPos; extern int scriptDataOffset; -extern int jumpTableDataPos; -extern int jumpTableDataOffset; +extern int JumpTableDataPos; +extern int JumpTableOffset; -extern int aliasCount; +extern int NO_ALIASES; extern int lineID; void CheckAliasText(char *text); diff --git a/Nexus/Sprite.cpp b/Nexus/Sprite.cpp index 9d0041e..28ec08b 100644 --- a/Nexus/Sprite.cpp +++ b/Nexus/Sprite.cpp @@ -29,172 +29,160 @@ const int LZ_BITS = 12; const int FIRST_CODE = 4097; const int NO_SUCH_CODE = 4098; -struct GifDecoder gifDecoder; +struct GifDecoder GDecoder; int codeMasks[] = { 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095 }; int ReadGifCode(void); byte ReadGifByte(void); byte TraceGifPrefix(uint *prefix, int code, int clearCode); -void InitGifDecoder() -{ +void InitGifDecoder() { byte val = 0; FileRead(&val, 1); - gifDecoder.fileState = LOADING_IMAGE; - gifDecoder.position = 0; - gifDecoder.bufferSize = 0; - gifDecoder.buffer[0] = 0; - gifDecoder.depth = val; - gifDecoder.clearCode = 1 << val; - gifDecoder.eofCode = gifDecoder.clearCode + 1; - gifDecoder.runningCode = gifDecoder.eofCode + 1; - gifDecoder.runningBits = val + 1; - gifDecoder.maxCodePlusOne = 1 << gifDecoder.runningBits; - gifDecoder.stackPtr = 0; - gifDecoder.prevCode = NO_SUCH_CODE; - gifDecoder.shiftState = 0; - gifDecoder.shiftData = 0u; - for (int i = 0; i <= LZ_MAX_CODE; ++i) gifDecoder.prefix[i] = (byte)NO_SUCH_CODE; + GDecoder.fileState = LOADING_IMAGE; + GDecoder.position = 0; + GDecoder.bufferSize = 0; + GDecoder.buffer[0] = 0; + GDecoder.depth = val; + GDecoder.clearCode = 1 << val; + GDecoder.eofCode = GDecoder.clearCode + 1; + GDecoder.runningCode = GDecoder.eofCode + 1; + GDecoder.runningBits = val + 1; + GDecoder.maxCodePlusOne = 1 << GDecoder.runningBits; + GDecoder.stackPtr = 0; + GDecoder.prevCode = NO_SUCH_CODE; + GDecoder.shiftState = 0; + GDecoder.shiftData = 0u; + for (int i = 0; i <= LZ_MAX_CODE; ++i) GDecoder.prefix[i] = (byte)NO_SUCH_CODE; } -void ReadGifLine(byte *line, int length, int offset) -{ +void ReadGifLine(byte *line, int length, int offset) { int i = 0; - int stackPtr = gifDecoder.stackPtr; - int eofCode = gifDecoder.eofCode; - int clearCode = gifDecoder.clearCode; - int prevCode = gifDecoder.prevCode; + int stackPtr = GDecoder.stackPtr; + int eofCode = GDecoder.eofCode; + int clearCode = GDecoder.clearCode; + int prevCode = GDecoder.prevCode; if (stackPtr != 0) { while (stackPtr != 0) { if (i >= length) { break; } - line[offset++] = gifDecoder.stack[--stackPtr]; + line[offset++] = GDecoder.stack[--stackPtr]; i++; } } while (i < length) { int gifCode = ReadGifCode(); if (gifCode == eofCode) { - if (i != length - 1 | gifDecoder.pixelCount != 0u) { + if (i != length - 1 | GDecoder.pixelCount != 0u) { return; } i++; - } - else { + } else { if (gifCode == clearCode) { for (int j = 0; j <= LZ_MAX_CODE; j++) { - gifDecoder.prefix[j] = NO_SUCH_CODE; + GDecoder.prefix[j] = NO_SUCH_CODE; } - gifDecoder.runningCode = gifDecoder.eofCode + 1; - gifDecoder.runningBits = gifDecoder.depth + 1; - gifDecoder.maxCodePlusOne = 1 << gifDecoder.runningBits; - prevCode = (gifDecoder.prevCode = NO_SUCH_CODE); - } - else { + GDecoder.runningCode = GDecoder.eofCode + 1; + GDecoder.runningBits = GDecoder.depth + 1; + GDecoder.maxCodePlusOne = 1 << GDecoder.runningBits; + prevCode = (GDecoder.prevCode = NO_SUCH_CODE); + } else { if (gifCode < clearCode) { line[offset] = (byte)gifCode; offset++; i++; - } - else { - if (gifCode<0 | gifCode> LZ_MAX_CODE) { + } else { + if (gifCode < 0 | gifCode > LZ_MAX_CODE) { return; } int code; - if (gifDecoder.prefix[gifCode] == NO_SUCH_CODE) { - if (gifCode != gifDecoder.runningCode - 2) { + if (GDecoder.prefix[gifCode] == NO_SUCH_CODE) { + if (gifCode != GDecoder.runningCode - 2) { return; } code = prevCode; - gifDecoder.suffix[gifDecoder.runningCode - 2] = - (gifDecoder.stack[stackPtr++] = TraceGifPrefix(gifDecoder.prefix, prevCode, clearCode)); - } - else { + GDecoder.suffix[GDecoder.runningCode - 2] = + (GDecoder.stack[stackPtr++] = TraceGifPrefix(GDecoder.prefix, prevCode, clearCode)); + } else { code = gifCode; } int c = 0; while (c++ <= LZ_MAX_CODE && code > clearCode && code <= LZ_MAX_CODE) { - gifDecoder.stack[stackPtr++] = gifDecoder.suffix[code]; - code = gifDecoder.prefix[code]; + GDecoder.stack[stackPtr++] = GDecoder.suffix[code]; + code = GDecoder.prefix[code]; } if (c >= LZ_MAX_CODE | code > LZ_MAX_CODE) { return; } - gifDecoder.stack[stackPtr++] = (byte)code; + GDecoder.stack[stackPtr++] = (byte)code; while (stackPtr != 0 && i++ < length) { - line[offset++] = gifDecoder.stack[--stackPtr]; + line[offset++] = GDecoder.stack[--stackPtr]; } } if (prevCode != NO_SUCH_CODE) { - if (gifDecoder.runningCode<2 | gifDecoder.runningCode> FIRST_CODE) { + if (GDecoder.runningCode < 2 | GDecoder.runningCode > FIRST_CODE) { return; } - gifDecoder.prefix[gifDecoder.runningCode - 2] = prevCode; - if (gifCode == gifDecoder.runningCode - 2) { - gifDecoder.suffix[gifDecoder.runningCode - 2] = TraceGifPrefix(gifDecoder.prefix, prevCode, clearCode); - } - else { - gifDecoder.suffix[gifDecoder.runningCode - 2] = TraceGifPrefix(gifDecoder.prefix, gifCode, clearCode); + GDecoder.prefix[GDecoder.runningCode - 2] = prevCode; + if (gifCode == GDecoder.runningCode - 2) { + GDecoder.suffix[GDecoder.runningCode - 2] = TraceGifPrefix(GDecoder.prefix, prevCode, clearCode); + } else { + GDecoder.suffix[GDecoder.runningCode - 2] = TraceGifPrefix(GDecoder.prefix, gifCode, clearCode); } } prevCode = gifCode; } } } - gifDecoder.prevCode = prevCode; - gifDecoder.stackPtr = stackPtr; + GDecoder.prevCode = prevCode; + GDecoder.stackPtr = stackPtr; } -int ReadGifCode() -{ - while (gifDecoder.shiftState < gifDecoder.runningBits) { +int ReadGifCode() { + while (GDecoder.shiftState < GDecoder.runningBits) { byte b = ReadGifByte(); - gifDecoder.shiftData |= (uint)((uint)b << gifDecoder.shiftState); - gifDecoder.shiftState += 8; + GDecoder.shiftData |= (uint)((uint)b << GDecoder.shiftState); + GDecoder.shiftState += 8; } - int result = (int)((unsigned long)gifDecoder.shiftData & (unsigned long)(codeMasks[gifDecoder.runningBits])); - gifDecoder.shiftData >>= gifDecoder.runningBits; - gifDecoder.shiftState -= gifDecoder.runningBits; - if (++gifDecoder.runningCode > gifDecoder.maxCodePlusOne && gifDecoder.runningBits < LZ_BITS) { - gifDecoder.maxCodePlusOne <<= 1; - gifDecoder.runningBits++; + int result = (int)((unsigned long)GDecoder.shiftData & (unsigned long)(codeMasks[GDecoder.runningBits])); + GDecoder.shiftData >>= GDecoder.runningBits; + GDecoder.shiftState -= GDecoder.runningBits; + if (++GDecoder.runningCode > GDecoder.maxCodePlusOne && GDecoder.runningBits < LZ_BITS) { + GDecoder.maxCodePlusOne <<= 1; + GDecoder.runningBits++; } return result; } -byte ReadGifByte() -{ +byte ReadGifByte() { char c = '\0'; - if (gifDecoder.fileState == LOAD_COMPLETE) + if (GDecoder.fileState == LOAD_COMPLETE) return c; byte b; - if (gifDecoder.position == gifDecoder.bufferSize) { + if (GDecoder.position == GDecoder.bufferSize) { FileRead(&b, 1); - gifDecoder.bufferSize = (int)b; - if (gifDecoder.bufferSize == 0) { - gifDecoder.fileState = LOAD_COMPLETE; + GDecoder.bufferSize = (int)b; + if (GDecoder.bufferSize == 0) { + GDecoder.fileState = LOAD_COMPLETE; return c; } - FileRead(gifDecoder.buffer, gifDecoder.bufferSize); - b = gifDecoder.buffer[0]; - gifDecoder.position = 1; - } - else { - b = gifDecoder.buffer[gifDecoder.position++]; + FileRead(GDecoder.buffer, GDecoder.bufferSize); + b = GDecoder.buffer[0]; + GDecoder.position = 1; + } else { + b = GDecoder.buffer[GDecoder.position++]; } return b; } -byte TraceGifPrefix(uint *prefix, int code, int clearCode) -{ +byte TraceGifPrefix(uint *prefix, int code, int clearCode) { int i = 0; while (code > clearCode && i++ <= LZ_MAX_CODE) code = prefix[code]; return code; } -void ReadGifPictureData(int width, int height, bool interlaced, byte *gfxData, int offset) -{ +void ReadGifPictureData(int width, int height, bool interlaced, byte *gfxData, int offset) { int array[] = { 0, 4, 2, 1 }; int array2[] = { 8, 8, 4, 2 }; InitGifDecoder(); @@ -209,18 +197,17 @@ void ReadGifPictureData(int width, int height, bool interlaced, byte *gfxData, i for (int h = 0; h < height; ++h) ReadGifLine(gfxData, width, h * width + offset); } -int AddGraphicsFile(const char *filePath) -{ +int AddGraphicsFile(const char *filePath) { char sheetPath[!RETRO_USE_ORIGINAL_CODE ? 0x100 : 0x40]; StrCopy(sheetPath, "Data/Sprites/"); StrAdd(sheetPath, filePath); int sheetID = 0; - while (StrLength(gfxSurface[sheetID].fileName) > 0) { - if (StrComp(gfxSurface[sheetID].fileName, sheetPath)) + while (StrLength(GfxSurface[sheetID].fileName) > 0) { + if (StrComp(GfxSurface[sheetID].fileName, sheetPath)) return sheetID; - // NOTE - // This uses SPRITESHEETS_MAX (16), while RemoveGraphicsFile, uses SURFACE_MAX (24)... + // NOTE + // This uses SPRITESHEETS_MAX (16), while RemoveGraphicsFile, uses SURFACE_MAX (24)... if (++sheetID >= SPRITESHEETS_MAX) return 0; } @@ -234,33 +221,31 @@ int AddGraphicsFile(const char *filePath) return sheetID; } -void RemoveGraphicsFile(const char *filePath, int sheetID) -{ +void RemoveGraphicsFile(const char *filePath, int sheetID) { if (sheetID < 0) { for (int i = 0; i < SURFACE_MAX; ++i) { - if (StrLength(gfxSurface[i].fileName) > 0 && StrComp(gfxSurface[i].fileName, filePath)) + if (StrLength(GfxSurface[i].fileName) > 0 && StrComp(GfxSurface[i].fileName, filePath)) sheetID = i; } } - if (sheetID >= 0 && StrLength(gfxSurface[sheetID].fileName)) { - StrCopy(gfxSurface[sheetID].fileName, ""); - int dataPosStart = gfxSurface[sheetID].dataPosition; - int dataPosEnd = gfxSurface[sheetID].dataPosition + gfxSurface[sheetID].height * gfxSurface[sheetID].width; - for (int i = 0x200000 - dataPosEnd; i > 0; --i) graphicData[dataPosStart++] = graphicData[dataPosEnd++]; - gfxDataPosition -= gfxSurface[sheetID].height * gfxSurface[sheetID].width; + if (sheetID >= 0 && StrLength(GfxSurface[sheetID].fileName)) { + StrCopy(GfxSurface[sheetID].fileName, ""); + int dataPosStart = GfxSurface[sheetID].dataPosition; + int dataPosEnd = GfxSurface[sheetID].dataPosition + GfxSurface[sheetID].height * GfxSurface[sheetID].width; + for (int i = 0x200000 - dataPosEnd; i > 0; --i) GraphicData[dataPosStart++] = GraphicData[dataPosEnd++]; + GfxDataPosition -= GfxSurface[sheetID].height * GfxSurface[sheetID].width; for (int i = 0; i < SURFACE_MAX; ++i) { - if (gfxSurface[i].dataPosition > gfxSurface[sheetID].dataPosition) - gfxSurface[i].dataPosition -= gfxSurface[sheetID].height * gfxSurface[sheetID].width; + if (GfxSurface[i].dataPosition > GfxSurface[sheetID].dataPosition) + GfxSurface[i].dataPosition -= GfxSurface[sheetID].height * GfxSurface[sheetID].width; } } } -int LoadBMPFile(const char *filePath, byte sheetID) -{ +int LoadBMPFile(const char *filePath, byte sheetID) { FileInfo info; if (LoadFile(filePath, &info)) { - GFXSurface *surface = &gfxSurface[sheetID]; + GFXSurface *surface = &GfxSurface[sheetID]; StrCopy(surface->fileName, filePath); byte fileBuffer = 0; @@ -285,8 +270,8 @@ int LoadBMPFile(const char *filePath, byte sheetID) surface->height += fileBuffer << 24; SetFilePosition(info.fileSize - surface->height * surface->width); - surface->dataPosition = gfxDataPosition; - byte *gfxData = &graphicData[surface->dataPosition + surface->width * (surface->height - 1)]; + surface->dataPosition = GfxDataPosition; + byte *gfxData = &GraphicData[surface->dataPosition + surface->width * (surface->height - 1)]; for (int y = 0; y < surface->height; ++y) { for (int x = 0; x < surface->width; ++x) { FileRead(&fileBuffer, 1); @@ -294,11 +279,11 @@ int LoadBMPFile(const char *filePath, byte sheetID) } gfxData -= 2 * surface->width; } - gfxDataPosition += surface->height * surface->width; + GfxDataPosition += surface->height * surface->width; - if (gfxDataPosition >= GFXDATA_MAX) { - gfxDataPosition = 0; - printLog("WARNING: Exceeded max gfx size!"); + if (GfxDataPosition >= GFXDATA_MAX) { + GfxDataPosition = 0; + PrintLog("WARNING: Exceeded max gfx size!"); } CloseFile(); @@ -306,11 +291,10 @@ int LoadBMPFile(const char *filePath, byte sheetID) } return false; } -int LoadGIFFile(const char *filePath, byte sheetID) -{ +int LoadGIFFile(const char *filePath, byte sheetID) { FileInfo info; if (LoadFile(filePath, &info)) { - GFXSurface *surface = &gfxSurface[sheetID]; + GFXSurface *surface = &GfxSurface[sheetID]; StrCopy(surface->fileName, filePath); byte fileBuffer = 0; @@ -327,8 +311,8 @@ int LoadGIFFile(const char *filePath, byte sheetID) surface->height += (fileBuffer << 8); FileRead(&fileBuffer, 1); // Palette Size - int has_pallete = (fileBuffer & 0x80) >> 7; - int colors = ((fileBuffer & 0x70) >> 4) + 1; + int has_pallete = (fileBuffer & 0x80) >> 7; + int colors = ((fileBuffer & 0x70) >> 4) + 1; int palette_size = (fileBuffer & 0x7) + 1; if (palette_size > 0) palette_size = 1 << palette_size; @@ -360,15 +344,14 @@ int LoadGIFFile(const char *filePath, byte sheetID) } while (c != 256); } - surface->dataPosition = gfxDataPosition; + surface->dataPosition = GfxDataPosition; - gfxDataPosition += surface->width * surface->height; - if (gfxDataPosition < GFXDATA_MAX) { - ReadGifPictureData(surface->width, surface->height, interlaced, graphicData, surface->dataPosition); - } - else { - gfxDataPosition = 0; - printLog("WARNING: Exceeded max gfx surface size!"); + GfxDataPosition += surface->width * surface->height; + if (GfxDataPosition < GFXDATA_MAX) { + ReadGifPictureData(surface->width, surface->height, interlaced, GraphicData, surface->dataPosition); + } else { + GfxDataPosition = 0; + PrintLog("WARNING: Exceeded max gfx surface size!"); } CloseFile(); @@ -376,11 +359,10 @@ int LoadGIFFile(const char *filePath, byte sheetID) } return false; } -int LoadGFXFile(const char *filePath, byte sheetID) -{ +int LoadGFXFile(const char *filePath, byte sheetID) { FileInfo info; if (LoadFile(filePath, &info)) { - GFXSurface *surface = &gfxSurface[sheetID]; + GFXSurface *surface = &GfxSurface[sheetID]; StrCopy(surface->fileName, filePath); byte fileBuffer = 0; @@ -396,8 +378,8 @@ int LoadGFXFile(const char *filePath, byte sheetID) byte clr[3]; for (int i = 0; i < 0xFF; ++i) FileRead(&clr, 3); // Palette - surface->dataPosition = gfxDataPosition; - byte *gfxData = &graphicData[surface->dataPosition]; + surface->dataPosition = GfxDataPosition; + byte *gfxData = &GraphicData[surface->dataPosition]; byte buf[3]; while (true) { FileRead(&buf[0], 1); @@ -405,22 +387,20 @@ int LoadGFXFile(const char *filePath, byte sheetID) FileRead(&buf[1], 1); if (buf[1] == 0xFF) { break; - } - else { + } else { FileRead(&buf[2], 1); for (int i = 0; i < buf[2]; ++i) *gfxData++ = buf[1]; } - } - else { + } else { *gfxData++ = buf[0]; } } - gfxDataPosition += surface->height * surface->width; + GfxDataPosition += surface->height * surface->width; - if (gfxDataPosition >= GFXDATA_MAX) { - gfxDataPosition = 0; - printLog("WARNING: Exceeded max gfx size!"); + if (GfxDataPosition >= GFXDATA_MAX) { + GfxDataPosition = 0; + PrintLog("WARNING: Exceeded max gfx size!"); } CloseFile(); @@ -428,43 +408,42 @@ int LoadGFXFile(const char *filePath, byte sheetID) } return false; } -int LoadRSVFile(const char *filePath, byte sheetID) -{ +int LoadRSVFile(const char *filePath, byte sheetID) { FileInfo info; if (LoadFile(filePath, &info)) { - GFXSurface *surface = &gfxSurface[sheetID]; + GFXSurface *surface = &GfxSurface[sheetID]; StrCopy(surface->fileName, filePath); - videoSurface = sheetID; - currentVideoFrame = 0; + VideoSurface = sheetID; + CurrentVideoFrame = 0; byte fileBuffer = 0; FileRead(&fileBuffer, 1); - videoFrameCount = fileBuffer; + VideoFrameCount = fileBuffer; FileRead(&fileBuffer, 1); - videoFrameCount += fileBuffer << 8; + VideoFrameCount += fileBuffer << 8; FileRead(&fileBuffer, 1); - videoWidth = fileBuffer; + VideoWidth = fileBuffer; FileRead(&fileBuffer, 1); - videoWidth += fileBuffer << 8; + VideoWidth += fileBuffer << 8; FileRead(&fileBuffer, 1); - videoHeight = fileBuffer; + VideoHeight = fileBuffer; FileRead(&fileBuffer, 1); - videoHeight += fileBuffer << 8; - - videoFilePos = (int)GetFilePosition(); - videoPlaying = true; - surface->width = videoWidth; - surface->height = videoHeight; - surface->dataPosition = gfxDataPosition; - gfxDataPosition += surface->width * surface->height; - - if (gfxDataPosition >= GFXDATA_MAX) { - gfxDataPosition = 0; - printLog("WARNING: Exceeded max gfx size!"); + VideoHeight += fileBuffer << 8; + + VideoFilePos = (int)GetFilePosition(); + VideoPlaying = true; + surface->width = VideoWidth; + surface->height = VideoHeight; + surface->dataPosition = GfxDataPosition; + GfxDataPosition += surface->width * surface->height; + + if (GfxDataPosition >= GFXDATA_MAX) { + GfxDataPosition = 0; + PrintLog("WARNING: Exceeded max gfx size!"); } return true; diff --git a/Nexus/String.hpp b/Nexus/String.hpp index 7948fa8..c03d9cb 100644 --- a/Nexus/String.hpp +++ b/Nexus/String.hpp @@ -4,9 +4,7 @@ inline void StrCopy(char *dest, const char *src) { int i = 0; - for (; src[i]; ++i) dest[i] = src[i]; - dest[i] = 0; } diff --git a/Nexus/Text.cpp b/Nexus/Text.cpp index 2a55e8c..f21dc9b 100644 --- a/Nexus/Text.cpp +++ b/Nexus/Text.cpp @@ -1,7 +1,7 @@ #include "RetroEngine.hpp" -TextMenu gameMenu[TEXTMENU_COUNT]; -int textMenuSurfaceNo = 0; +TextMenu GameMenu[TEXTMENU_COUNT]; +int TextMenuSurfaceNo = 0; void SetupTextMenu(TextMenu *menu, int rowCount) { diff --git a/Nexus/Text.hpp b/Nexus/Text.hpp index 93e9807..d680e8c 100644 --- a/Nexus/Text.hpp +++ b/Nexus/Text.hpp @@ -23,8 +23,8 @@ struct TextMenu { sbyte selection2; }; -extern TextMenu gameMenu[TEXTMENU_COUNT]; -extern int textMenuSurfaceNo; +extern TextMenu GameMenu[TEXTMENU_COUNT]; +extern int TextMenuSurfaceNo; void LoadConfigListText(TextMenu *menu, int listNo); diff --git a/Nexus/Userdata.cpp b/Nexus/Userdata.cpp index 745168d..3fdf695 100644 --- a/Nexus/Userdata.cpp +++ b/Nexus/Userdata.cpp @@ -1,20 +1,11 @@ #include "RetroEngine.hpp" -int globalVariablesCount; -int globalVariables[GLOBALVAR_COUNT]; -char globalVariableNames[GLOBALVAR_COUNT][0x20]; +int NO_GLOBALVARIABLES; +int GlobalVariables[GLOBALVAR_COUNT]; +char GlobalVariableNames[GLOBALVAR_COUNT][0x20]; char gamePath[0x100]; - -#if RETRO_USE_MOD_LOADER -char modsPath[0x100]; - -std::vector modList; - -#include -#endif - void InitUserdata() { // userdata files are loaded from this directory @@ -55,7 +46,7 @@ void InitUserdata() ini.SetInteger("Window", "WindowScale", Engine.windowScale = 2); ini.SetInteger("Window", "ScreenWidth", SCREEN_XSIZE = DEFAULT_SCREEN_XSIZE); ini.SetInteger("Window", "RefreshRate", Engine.refreshRate = 60); - ini.SetInteger("Window", "ColourMode", Engine.colourMode = 0); + ini.SetInteger("Window", "ColourMode", Engine.ColourMode = 0); ini.SetFloat("Audio", "BGMVolume", bgmVolume / (float)MAX_VOLUME); ini.SetFloat("Audio", "SFXVolume", sfxVolume / (float)MAX_VOLUME); @@ -141,10 +132,10 @@ void InitUserdata() SCREEN_XSIZE = DEFAULT_SCREEN_XSIZE; if (!ini.GetInteger("Window", "RefreshRate", &Engine.refreshRate)) Engine.refreshRate = 60; - int cm = Engine.colourMode; + int cm = Engine.ColourMode; if (!ini.GetInteger("Window", "ColourMode", &cm)) cm = 1; - Engine.colourMode = cm; + Engine.ColourMode = cm; float bv = 0, sv = 0; if (!ini.GetFloat("Audio", "BGMVolume", &bv)) @@ -256,12 +247,12 @@ void InitUserdata() int nummaps = SDL_GameControllerAddMappingsFromFile(buffer); if (nummaps >= 0) - printLog("loaded %d controller mappings from '%s'\n", buffer, nummaps); + PrintLog("loaded %d controller mappings from '%s'\n", buffer, nummaps); } #endif } -void writeSettings() { +void WriteSettings() { IniParser ini; ini.SetComment("Dev", "DevMenuComment", "Enable this flag to activate dev menu via the ESC key"); @@ -296,7 +287,7 @@ void writeSettings() { ini.SetComment("Window", "RRComment", "Determines the target FPS"); ini.SetInteger("Window", "RefreshRate", Engine.refreshRate); ini.SetComment("Window", "CMComment", "Determines the output colour mode (0 = 8-bit, 1 = 16-bit, 2 = 32-bit)"); - ini.SetInteger("Window", "ColourMode", Engine.colourMode); + ini.SetInteger("Window", "ColourMode", Engine.ColourMode); ini.SetFloat("Audio", "BGMVolume", bgmVolume / (float)MAX_VOLUME); ini.SetFloat("Audio", "SFXVolume", sfxVolume / (float)MAX_VOLUME); @@ -341,239 +332,4 @@ void writeSettings() { ini.SetInteger("Controller 1", "Start", inputDevice[INPUT_START].contMappings); ini.Write(BASE_PATH"settings.ini"); -} - -#if RETRO_USE_MOD_LOADER -#include -#if RETRO_PLATFORM == RETRO_ANDROID -namespace fs = std::__fs::filesystem; -#else -namespace fs = std::filesystem; -#endif - -void initMods() -{ - modList.clear(); - - char modBuf[0x100]; - sprintf(modBuf, "%smods/", modsPath); - fs::path modPath(modBuf); - - if (fs::exists(modPath) && fs::is_directory(modPath)) { - std::string mod_config = modPath.string() + "/modconfig.ini"; - FileIO *configFile = fOpen(mod_config.c_str(), "r"); - if (configFile) { - fClose(configFile); - IniParser modConfig(mod_config.c_str(), false); - - for (int m = 0; m < modConfig.items.size(); ++m) { - bool active = false; - ModInfo info; - modConfig.GetBool("mods", modConfig.items[m].key, &active); - if (loadMod(&info, modPath.string(), modConfig.items[m].key, active)) - modList.push_back(info); - } - } - - try { - auto rdi = fs::directory_iterator(modPath); - for (auto de : rdi) { - if (de.is_directory()) { - fs::path modDirPath = de.path(); - - ModInfo info; - - std::string modDir = modDirPath.string().c_str(); - const std::string mod_inifile = modDir + "/mod.ini"; - std::string folder = modDirPath.filename().string(); - - bool flag = true; - for (int m = 0; m < modList.size(); ++m) { - if (modList[m].folder == folder) { - flag = false; - break; - } - } - - if (flag) { - if (loadMod(&info, modPath.string(), modDirPath.filename().string(), false)) - modList.push_back(info); - } - } - } - } catch (fs::filesystem_error fe) { - printLog("Mods Folder Scanning Error: "); - printLog(fe.what()); - } - } -} - -bool loadMod(ModInfo *info, std::string modsPath, std::string folder, bool active) -{ - if (!info) - return false; - - info->fileMap.clear(); - info->name = ""; - info->desc = ""; - info->author = ""; - info->version = ""; - info->folder = ""; - info->active = false; - - const std::string modDir = modsPath + "/" + folder; - - FileIO *f = fOpen((modDir + "/mod.ini").c_str(), "r"); - if (f) { - fClose(f); - IniParser modSettings((modDir + "/mod.ini").c_str(), false); - - info->name = "Unnamed Mod"; - info->desc = ""; - info->author = "Unknown Author"; - info->version = "1.0.0"; - info->folder = folder; - - char infoBuf[0x100]; - // Name - StrCopy(infoBuf, ""); - modSettings.GetString("", "Name", infoBuf); - if (!StrComp(infoBuf, "")) - info->name = infoBuf; - // Desc - StrCopy(infoBuf, ""); - modSettings.GetString("", "Description", infoBuf); - if (!StrComp(infoBuf, "")) - info->desc = infoBuf; - // Author - StrCopy(infoBuf, ""); - modSettings.GetString("", "Author", infoBuf); - if (!StrComp(infoBuf, "")) - info->author = infoBuf; - // Version - StrCopy(infoBuf, ""); - modSettings.GetString("", "Version", infoBuf); - if (!StrComp(infoBuf, "")) - info->version = infoBuf; - - info->active = active; - - // Check for Data/ replacements - fs::path dataPath(modDir + "/Data"); - - if (fs::exists(dataPath) && fs::is_directory(dataPath)) { - try { - auto data_rdi = fs::recursive_directory_iterator(dataPath); - for (auto data_de : data_rdi) { - if (data_de.is_regular_file()) { - char modBuf[0x100]; - StrCopy(modBuf, data_de.path().string().c_str()); - char folderTest[4][0x10] = { - "Data/", - "Data\\", - "data/", - "data\\", - }; - int tokenPos = -1; - for (int i = 0; i < 4; ++i) { - tokenPos = FindStringToken(modBuf, folderTest[i], 1); - if (tokenPos >= 0) - break; - } - - if (tokenPos >= 0) { - char buffer[0x80]; - for (int i = StrLength(modBuf); i >= tokenPos; --i) { - buffer[i - tokenPos] = modBuf[i] == '\\' ? '/' : modBuf[i]; - } - - // printLog(modBuf); - std::string path(buffer); - std::string modPath(modBuf); - char pathLower[0x100]; - memset(pathLower, 0, sizeof(char) * 0x100); - for (int c = 0; c < path.size(); ++c) { - pathLower[c] = tolower(path.c_str()[c]); - } - - info->fileMap.insert(std::pair(pathLower, modBuf)); - } - } - } - } catch (fs::filesystem_error fe) { - printLog("Data Folder Scanning Error: "); - printLog(fe.what()); - } - } - - // Check for Scripts/ replacements - fs::path scriptPath(modDir + "/Scripts"); - - if (fs::exists(scriptPath) && fs::is_directory(scriptPath)) { - try { - auto data_rdi = fs::recursive_directory_iterator(scriptPath); - for (auto data_de : data_rdi) { - if (data_de.is_regular_file()) { - char modBuf[0x100]; - StrCopy(modBuf, data_de.path().string().c_str()); - char folderTest[4][0x10] = { - "Scripts/", - "Scripts\\", - "scripts/", - "scripts\\", - }; - int tokenPos = -1; - for (int i = 0; i < 4; ++i) { - tokenPos = FindStringToken(modBuf, folderTest[i], 1); - if (tokenPos >= 0) - break; - } - - if (tokenPos >= 0) { - char buffer[0x80]; - for (int i = StrLength(modBuf); i >= tokenPos; --i) { - buffer[i - tokenPos] = modBuf[i] == '\\' ? '/' : modBuf[i]; - } - - // printLog(modBuf); - std::string path(buffer); - std::string modPath(modBuf); - char pathLower[0x100]; - memset(pathLower, 0, sizeof(char) * 0x100); - for (int c = 0; c < path.size(); ++c) { - pathLower[c] = tolower(path.c_str()[c]); - } - - info->fileMap.insert(std::pair(pathLower, modBuf)); - } - } - } - } catch (fs::filesystem_error fe) { - printLog("Script Folder Scanning Error: "); - printLog(fe.what()); - } - } - return true; - } - return false; -} -void saveMods() -{ - char modBuf[0x100]; - sprintf(modBuf, "%smods/", modsPath); - fs::path modPath(modBuf); - - if (fs::exists(modPath) && fs::is_directory(modPath)) { - std::string mod_config = modPath.string() + "/modconfig.ini"; - IniParser modConfig; - - for (int m = 0; m < modList.size(); ++m) { - ModInfo *info = &modList[m]; - - modConfig.SetBool("mods", info->folder.c_str(), info->active); - } - - modConfig.Write(mod_config.c_str(), false); - } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/Nexus/Userdata.hpp b/Nexus/Userdata.hpp index 1685f0c..9e3c396 100644 --- a/Nexus/Userdata.hpp +++ b/Nexus/Userdata.hpp @@ -3,65 +3,30 @@ #define GLOBALVAR_COUNT (0x100) -#define ACHIEVEMENT_MAX (0x40) -#define LEADERBOARD_MAX (0x80) - -#define MOD_MAX (0x100) - -#define SAVEDATA_MAX (0x2000) - -#include -#include -#include - -#if RETRO_USE_MOD_LOADER -struct ModInfo { - std::string name; - std::string desc; - std::string author; - std::string version; - std::map fileMap; - std::string folder; - bool active; -}; -#endif - -extern int globalVariablesCount; -extern int globalVariables[GLOBALVAR_COUNT]; -extern char globalVariableNames[GLOBALVAR_COUNT][0x20]; - -#if RETRO_USE_MOD_LOADER -extern char gamePath[0x100]; -extern char modsPath[0x100]; -extern std::vector modList; -#endif +extern int NO_GLOBALVARIABLES; +extern int GlobalVariables[GLOBALVAR_COUNT]; +extern char GlobalVariableNames[GLOBALVAR_COUNT][0x20]; inline int GetGlobalVariableByName(const char *name) { - for (int v = 0; v < globalVariablesCount; ++v) { - if (StrComp(name, globalVariableNames[v])) - return globalVariables[v]; + for (int v = 0; v < NO_GLOBALVARIABLES; ++v) { + if (StrComp(name, GlobalVariableNames[v])) + return GlobalVariables[v]; } return 0; } inline void SetGlobalVariableByName(const char *name, int value) { - for (int v = 0; v < globalVariablesCount; ++v) { - if (StrComp(name, globalVariableNames[v])) { - globalVariables[v] = value; + for (int v = 0; v < NO_GLOBALVARIABLES; ++v) { + if (StrComp(name, GlobalVariableNames[v])) { + GlobalVariables[v] = value; break; } } } void InitUserdata(); -void writeSettings(); - -#if RETRO_USE_MOD_LOADER -void initMods(); -bool loadMod(ModInfo *info, std::string modsPath, std::string folder, bool active); -void saveMods(); -#endif +void WriteSettings(); #endif //!USERDATA_H diff --git a/Nexus/Video.cpp b/Nexus/Video.cpp index 30ccbd5..d0a1537 100644 --- a/Nexus/Video.cpp +++ b/Nexus/Video.cpp @@ -1,28 +1,30 @@ #include "RetroEngine.hpp" -int currentVideoFrame = 0; -int videoFrameCount = 0; -int videoWidth = 0; -int videoHeight = 0; -int videoSurface = 0; -int videoFilePos = 0; -bool videoPlaying = false; +int CurrentVideoFrame = 0; +int VideoFrameCount = 0; +int VideoWidth = 0; +int VideoHeight = 0; +int VideoSurface = 0; +int VideoFilePos = 0; +bool VideoPlaying = false; -void UpdateVideoFrame() -{ - if (videoPlaying) { - if (currentVideoFrame < videoFrameCount) { - GFXSurface *surface = &gfxSurface[videoSurface]; +void UpdateVideoFrame() { + if (VideoPlaying) { + if (VideoFrameCount <= CurrentVideoFrame) { + VideoPlaying = false; + CloseFile(); + } else { + GFXSurface *surface = &GfxSurface[VideoSurface]; byte fileBuffer = 0; ushort fileBuffer2 = 0; FileRead(&fileBuffer, 1); - videoFilePos += fileBuffer; + VideoFilePos += fileBuffer; FileRead(&fileBuffer, 1); - videoFilePos += fileBuffer << 8; + VideoFilePos += fileBuffer << 8; FileRead(&fileBuffer, 1); - videoFilePos += fileBuffer << 16; + VideoFilePos += fileBuffer << 16; FileRead(&fileBuffer, 1); - videoFilePos += fileBuffer << 24; + VideoFilePos += fileBuffer << 24; byte clr[3]; for (int i = 0; i < 0x80; ++i) { @@ -49,14 +51,10 @@ void UpdateVideoFrame() FileRead(&fileBuffer, 1); } while (c != 0x100); } - ReadGifPictureData(surface->width, surface->height, interlaced, graphicData, surface->dataPosition); + ReadGifPictureData(surface->width, surface->height, interlaced, GraphicData, surface->dataPosition); - SetFilePosition(videoFilePos); - ++currentVideoFrame; - } - else { - videoPlaying = false; - CloseFile(); + SetFilePosition(VideoFilePos); + ++CurrentVideoFrame; } } } \ No newline at end of file diff --git a/Nexus/Video.hpp b/Nexus/Video.hpp index 670442d..01dd894 100644 --- a/Nexus/Video.hpp +++ b/Nexus/Video.hpp @@ -1,13 +1,13 @@ #ifndef VIDEO_H #define VIDEO_H -extern int currentVideoFrame; -extern int videoFrameCount; -extern int videoWidth; -extern int videoHeight; -extern int videoSurface; -extern int videoFilePos; -extern bool videoPlaying; +extern int CurrentVideoFrame; +extern int VideoFrameCount; +extern int VideoWidth; +extern int VideoHeight; +extern int VideoSurface; +extern int VideoFilePos; +extern bool VideoPlaying; void UpdateVideoFrame(); diff --git a/README.md b/README.md index 0082eda..695fd64 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,78 @@ # RSDKv2 Decompilation -A complete decompilation of Retro Engine v2. +A complete decompilation of the Retro-Sonic Engine v2. Without assets from the Sonic Nexus 2008 demo, this decompilation will not run. You can download the game [here](https://info.sonicretro.org/Sonic_Nexus). # Additional Tweaks * Added a built in mod loader, allowing to easily create and play mods. * There is now a `settings.ini` file that the game uses to load all settings, similar to Sonic Mania. -* Dev menu can now be accessed from anywhere by pressing the `ESC` key if enabled in the config. +* The dev menu can now be accessed from anywhere by pressing the `ESC` key if enabled in the config. * The `F12` pause, `F11` step over & fast forward debug features from Sonic Mania have all been ported and are enabled if `devMenu` is enabled in the config. -# How to build -## Windows -* Clone the repo, then follow the instructions in the [depencencies readme for Windows](./dependencies/windows/dependencies.txt) to setup dependencies, then build via the visual studio solution. -* Alternatively, you can grab a prebuilt executable from the releases section. +# How to Build -## Mac +This project uses [CMake](https://cmake.org/), a versatile building system that supports many different compilers and platforms. You can download CMake [here](https://cmake.org/download/). **(Make sure to enable the feature to add CMake to the system PATH during the installation!)** + +## Get the source code + +In order to clone the repository, you need to install Git, which you can get [here](https://git-scm.com/downloads). + +Clone the repo, using: +`git clone --recursive https://github.com/RSDKModding/RSDKv2-Decompilation` + +## Getting dependencies + +### Windows +To handle dependencies, you'll need to install [Visual Studio Community](https://visualstudio.microsoft.com/downloads/) (make sure to install the `Desktop development with C++` package during the installation) and [vcpkg](https://learn.microsoft.com/en-us/vcpkg/get_started/get-started?pivots=shell-cmd#1---set-up-vcpkg) (You only need to follow `1 - Set up vcpkg`). + +After installing those, run the following in Command Prompt (make sure to replace `[vcpkg root]` with the path to the vcpkg installation!): +- `[vcpkg root]\vcpkg.exe install sdl2 libogg libvorbis --triplet=x64-windows-static` (If you're compiling a 32-bit build, replace `x64-windows-static` with `x86-windows-static`.) + +Finally, follow the [compilation steps below](#compiling) using `-DCMAKE_TOOLCHAIN_FILE=[vcpkg root]/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_PREFIX_PATH=[vcpkg root]/installed/x64-windows-static/` as arguments for `cmake -B build`. + - Make sure to replace each instance of `[vcpkg root]` with the path to the vcpkg installation! + - If you're compiling a 32-bit build, replace each instance of `x64-windows-static` with `x86-windows-static`. + +### Mac * Clone the repo, follow the instructions in the [depencencies readme for Mac](./dependencies/mac/dependencies.txt) to setup dependencies, then build via the Xcode project. -## Linux -### Make -* To setup your build enviroment and library dependecies, run the following commands: - * Ubuntu (Mint, Pop!_OS, etc...): `sudo apt install build-essential git libsdl2-dev libvorbis-dev libogg-dev libtheora-dev` - * Arch Linux: `sudo pacman -S base-devel git sdl2 libvorbis libogg libtheora` -* Clone the repo with the following command: `git clone https://github.com/RSDKModding/RSDKv2-Decompilation.git` -* Go into the repo you just cloned with `cd Sonic-Nexus-Decompilation`. -* Then run `make CXXFLAGS=-O2 -j5`. - * If your distro is using gcc 8.x.x, then add the argument `LIBS=-lstdc++fs`. - * The `CXXFLAGS` option can be removed if you do not want optimizations. - * -j switch is optional, but will make building faster by running it parallel on multiple cores (8 cores would be -j9.) - -### CMake -* Install the following dependencies depending on your platform through your terminal: - * **pacman (Arch):** `sudo pacman -S base-devel cmake sdl2 libogg libtheora libvorbis` - * **apt (Debian/Ubuntu):** `sudo apt install build-essential cmake libsdl2-dev libogg-dev libtheora-dev libvorbis-dev` - * **rpm (Fedora):** `sudo dnf install make gcc cmake sdl2-devel libogg-devel libtheora-devel libvorbis-devel zlib-devel` - * **apk (Alpine/PostmarketOS)** `sudo apk add build-base cmake sdl2-dev libogg-dev libtheora-dev libvorbis-dev` - * Your favorite package manager here, [make a pull request](https://github.com/RSDKModding/RSDKv2-Decompilation/fork) - - -* Then just run the following in the root repository directory: - ``` - cmake -B build - cmake --build build --config release - ``` +### Linux +Install the following dependencies: then follow the [compilation steps below](#compiling): +- **pacman (Arch):** `sudo pacman -S base-devel cmake sdl2 libogg libvorbis` +- **apt (Debian/Ubuntu):** `sudo apt install build-essential cmake libsdl2-dev libogg-dev libvorbis-dev` +- **rpm (Fedora):** `sudo dnf install make gcc cmake sdl2-devel libogg-devel libvorbis-devel zlib-devel` +- **apk (Alpine/PostmarketOS)** `sudo apk add build-base cmake sdl2-dev libogg-dev libvorbis-dev` +- Your favorite package manager here, [make a pull request](https://github.com/RSDKModding/RSDKv2-Decompilation/fork) + +## Compiling + +Compiling is as simple as typing the following in the root repository directory: +``` +cmake -B build +cmake --build build --config release +``` + +The resulting build will be located somewhere in `build/` depending on your system. + +The following cmake arguments are available when compiling: +- Use these by adding `-D[flag-name]=[value]` to the end of the `cmake -B build` command. + +### RSDKv2 flags +- `FORCE_CASE_INSENSITIVE`: Forces case insensivity when loading files. Takes a boolean, defaults to `off`. +- `RETRO_MOD_LOADER`: Enables or disables the mod loader. Takes a boolean, defaults to `on`. +- `RETRO_ORIGINAL_CODE`: Removes any custom code. *A playable game will not be built with this enabled.* Takes a boolean, defaults to `off`. +- `RETRO_SDL_VERSION`: *Only change this if you know what you're doing.* Switches between using SDL1 or SDL2. Takes an integer of either `1` or `2`, defaults to `2`. ## Unofficial Branches Follow the installation instructions in the readme of each branch. * For the **Nintendo Switch**, go to [LittlePlanetCD's fork](https://github.com/LittlePlanetCD/Sonic-Nexus-Switch). - +* For **WebAssembly**, go to [Jdsle's fork](https://github.com/Jdsle/RSDKv2-Decompilation/tree/web). + Because these branches are unofficial, we can't provide support for them and they may not be up-to-date. ## Other Platforms -Currently the only supported platforms are the ones listed above, however the backend uses libogg, libvorbis, libtheora & SDL2 to power it, so the codebase is very multiplatform. If you're able to, you can clone this repo and port it to a platform not on the list. +Currently the only supported platforms are the ones listed above, however the backend uses libogg, libvorbis & SDL2 to power it, so the codebase is very multiplatform. +If you're able to, you can clone this repo and port it to a platform not on the list. # Contact: -Join the [Retro Engine Modding Discord Server](https://dc.railgun.works/retroengine) for any extra questions you may need to know about the decompilation or modding it. +Join the [Retro Engine Modding Discord Server](https://dc.railgun.works/retroengine) for any extra questions you may need to know about the decompilation or modding it. \ No newline at end of file diff --git a/platforms/Windows.cmake b/platforms/Windows.cmake new file mode 100644 index 0000000..fd3298e --- /dev/null +++ b/platforms/Windows.cmake @@ -0,0 +1,84 @@ +project(RetroEngine) + +add_executable(RetroEngine ${RETRO_FILES}) + +set(DEP_PATH windows) + +find_package(Ogg CONFIG) + +if(NOT ${Ogg_FOUND}) + set(COMPILE_OGG TRUE) + message(NOTICE "libogg not found, attempting to build from source") +else() + message("found libogg") + add_library(libogg ALIAS Ogg::ogg) + target_link_libraries(RetroEngine libogg) +endif() + +# i don't like this but it's what's on vcpkg so +find_package(unofficial-theora CONFIG) + +if(NOT unofficial-theora_FOUND) + message(NOTICE "could not find libtheora from unofficial-theora, attempting to find through Theora") + find_package(Theora CONFIG) + + if(NOT Theora_FOUND) + message("could not find libtheora, attempting to build manually") + set(COMPILE_THEORA TRUE) + else() + message("found libtheora") + add_library(libtheora ALIAS Theora::theora) # my best guess + target_link_libraries(RetroEngine libtheora) + endif() +else() + message("found libtheora") + add_library(libtheora ALIAS unofficial::theora::theora) + target_link_libraries(RetroEngine libtheora) +endif() + +find_package(Vorbis CONFIG) + +if(NOT ${Vorbis_FOUND}) + set(COMPILE_VORBIS TRUE) + message(NOTICE "libvorbis not found, attempting to build from source") +else() + message("found libvorbis") + add_library(libvorbis ALIAS Vorbis::vorbisfile) + target_link_libraries(RetroEngine libvorbis) +endif() + +if(RETRO_SDL_VERSION STREQUAL "2") + find_package(SDL2 CONFIG REQUIRED) + target_link_libraries(RetroEngine + $ + $,SDL2::SDL2,SDL2::SDL2-static> + ) +elseif(RETRO_SDL_VERSION STREQUAL "1") + find_package(SDL1 CONFIG REQUIRED) + target_link_libraries(RetroEngine + $ + $,SDL1::SDL1,SDL1::SDL1-static> + ) +else() + message(FATAL_ERROR "RETRO_SDL_VERSION must be 1 or 2") +endif() + +target_compile_definitions(RetroEngine PRIVATE _CRT_SECURE_NO_WARNINGS) +target_link_libraries(RetroEngine + winmm + comctl32 +) + +if(RETRO_MOD_LOADER) + set_target_properties(RetroEngine PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED ON + ) +endif() + +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(RetroEngine PRIVATE -Wno-microsoft-cast -Wno-microsoft-exception-spec) +endif() + +target_sources(RetroEngine PRIVATE ${RETRO_NAME}/${RETRO_NAME}.rc) +target_link_options(RetroEngine PRIVATE /subsystem:windows) \ No newline at end of file