diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml index 5e16bc1475d..24602f973a6 100644 --- a/.github/workflows/clang-format-check.yml +++ b/.github/workflows/clang-format-check.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - dreamcast paths-ignore: - '*.md' - 'docs/**' diff --git a/Source/DiabloUI/mainmenu.cpp b/Source/DiabloUI/mainmenu.cpp index ba240932266..5b1449b7320 100644 --- a/Source/DiabloUI/mainmenu.cpp +++ b/Source/DiabloUI/mainmenu.cpp @@ -36,8 +36,8 @@ void MainmenuEsc() void MainmenuLoad(const char *name) { #ifndef __DREAMCAST__ - //single player save files are too big for the VMU - //todo reactivate when SD card saving is implemented + // single player save files are too big for the VMU + // todo reactivate when SD card saving is implemented vecMenuItems.push_back(std::make_unique(_("Single Player"), MAINMENU_SINGLE_PLAYER)); #endif vecMenuItems.push_back(std::make_unique(_("Multi Player"), MAINMENU_MULTIPLAYER)); diff --git a/Source/controls/devices/joystick.cpp b/Source/controls/devices/joystick.cpp index f1ac60bcfc4..af62cb395ea 100644 --- a/Source/controls/devices/joystick.cpp +++ b/Source/controls/devices/joystick.cpp @@ -104,18 +104,18 @@ StaticVector Joystick::ToControllerButtonEvents(const case SDL_JOYAXISMOTION: case SDL_JOYBALLMOTION: #ifdef __DREAMCAST__ - if(event.jaxis.axis == 3) { - Log("BUTTON_LEFTSHOULDER detected"); - Log("event.jbutton.button = {}", event.jbutton.button); - Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED); - return { ControllerButtonEvent { ControllerButton_BUTTON_LEFTSHOULDER, event.jaxis.value < 255 } }; - } - if(event.jaxis.axis == 2) { - Log("BUTTON_RIGHTSHOULDER detected"); - Log("event.jbutton.button = {}", event.jbutton.button); - Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED); - return { ControllerButtonEvent { ControllerButton_BUTTON_RIGHTSHOULDER, event.jaxis.value < 255 } }; - } + if (event.jaxis.axis == 3) { + Log("BUTTON_LEFTSHOULDER detected"); + Log("event.jbutton.button = {}", event.jbutton.button); + Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED); + return { ControllerButtonEvent { ControllerButton_BUTTON_LEFTSHOULDER, event.jaxis.value < 255 } }; + } + if (event.jaxis.axis == 2) { + Log("BUTTON_RIGHTSHOULDER detected"); + Log("event.jbutton.button = {}", event.jbutton.button); + Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED); + return { ControllerButtonEvent { ControllerButton_BUTTON_RIGHTSHOULDER, event.jaxis.value < 255 } }; + } #endif // ProcessAxisMotion() requires a ControllerButtonEvent parameter // so provide one here using ControllerButton_NONE @@ -322,11 +322,11 @@ bool Joystick::ProcessAxisMotion(const SDL_Event &event) Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED); switch (event.jaxis.axis) { - case 0: //horizontal + case 0: // horizontal leftStickXUnscaled = event.jaxis.value; leftStickNeedsScaling = true; return true; - case 1: //vertical + case 1: // vertical leftStickYUnscaled = event.jaxis.value; leftStickNeedsScaling = true; return true; @@ -334,7 +334,7 @@ bool Joystick::ProcessAxisMotion(const SDL_Event &event) return false; } } -#else //!ifdef __DREAMCAST__ +#else //! ifdef __DREAMCAST__ bool Joystick::ProcessAxisMotion(const SDL_Event &event) { if (event.type != SDL_JOYAXISMOTION) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index f91726e6bf7..e50b62433bd 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -789,11 +789,7 @@ void GameEventHandler(const SDL_Event &event, uint16_t modState) default: if (IsCustomEvent(event.type)) { if (gbIsMultiplayer) - { - Log("IsCustomEvent({}) = true", event.type); - Log("pfile_write_hero"); pfile_write_hero(); - } nthread_ignore_mutex(true); PaletteFadeOut(8); sound_stop(); @@ -913,7 +909,6 @@ void RunGameLoop(interface_mode uMsg) demo::NotifyGameLoopEnd(); if (gbIsMultiplayer) { - Log("gbRunGame = {}, pfile_write_hero(/*writeGameData=*/false)", gbRunGame); pfile_write_hero(/*writeGameData=*/false); sfile_write_stash(); } @@ -2850,7 +2845,6 @@ void DisableInputEventHandler(const SDL_Event &event, uint16_t modState) void LoadGameLevel(bool firstflag, lvl_entry lvldir) { - Log("LoadGameLevel(firstflag = {}, lvldir = {})", firstflag, static_cast(lvldir)); _music_id neededTrack = GetLevelMusic(leveltype); ClearFloatingNumbers(); diff --git a/Source/init.cpp b/Source/init.cpp index edd92a344d2..57357ae06e8 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -220,10 +220,10 @@ bool IsDevilutionXMpqOutOfDate(MpqArchive &archive) bool AreExtraFontsOutOfDate(const std::string &path) { #ifdef __DREAMCAST__ - //handle ISO 9660 trailing period - const std::string versionPath = path + "fonts" DIRECTORY_SEPARATOR_STR "VERSION."; + // handle ISO 9660 trailing period + const std::string versionPath = path + "fonts" DIRECTORY_SEPARATOR_STR "VERSION."; #else - const std::string versionPath = path + "fonts" DIRECTORY_SEPARATOR_STR "VERSION"; + const std::string versionPath = path + "fonts" DIRECTORY_SEPARATOR_STR "VERSION"; #endif if (versionPath.size() + 1 > AssetRef::PathBufSize) diff --git a/Source/interfac.cpp b/Source/interfac.cpp index 51ed9b1f7b7..601473e5d2b 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -73,7 +73,6 @@ Cutscenes GetCutSceneFromLevelType(dungeon_type type) Cutscenes PickCutscene(interface_mode uMsg) { - Log("MyPlayer->plrlevel = {}", MyPlayer->plrlevel); switch (uMsg) { case WM_DIABLOADGAME: case WM_DIABNEWGAME: @@ -352,7 +351,6 @@ void ShowProgress(interface_mode uMsg) case WM_DIABNEXTLVL: IncProgress(); if (!gbIsMultiplayer) { - Log("pfile_save_level()"); pfile_save_level(); } else { DeltaSaveLevel(); @@ -363,14 +361,12 @@ void ShowProgress(interface_mode uMsg) currlevel = myPlayer.plrlevel; leveltype = GetLevelType(currlevel); IncProgress(); - Log("LoadGameLevel(false, ENTRY_MAIN)"); LoadGameLevel(false, ENTRY_MAIN); IncProgress(); break; case WM_DIABPREVLVL: IncProgress(); if (!gbIsMultiplayer) { - Log("pfile_save_level()"); pfile_save_level(); } else { DeltaSaveLevel(); @@ -381,7 +377,6 @@ void ShowProgress(interface_mode uMsg) leveltype = GetLevelType(currlevel); assert(myPlayer.isOnActiveLevel()); IncProgress(); - Log("LoadGameLevel(false, ENTRY_PREV)"); LoadGameLevel(false, ENTRY_PREV); IncProgress(); break; diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index a3f3c8b2849..71a811f89c8 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -179,8 +179,6 @@ class SaveHelper { , m_buffer_(new std::byte[codec_get_encoded_len(bufferLen)]) , m_capacity_(bufferLen) { - Log("SaveHelper instantiated: this(mpqWriter, \"{}\", {})", szFileName, bufferLen); - Log("SaveHelper allocated byte array of {} bytes", codec_get_encoded_len(bufferLen)); } bool IsValid(size_t len = 1) @@ -226,12 +224,9 @@ class SaveHelper { ~SaveHelper() { - //const auto encodedLen = m_cur_; const auto encodedLen = codec_get_encoded_len(m_cur_); const char *const password = pfile_get_password(); - Log("codec_encode(m_buffer_.get(), {}, {}, \"{}\")", m_cur_, encodedLen, password); codec_encode(m_buffer_.get(), m_cur_, encodedLen, password); - Log("~SaveHelper WriteFile(\"{}\", m_buffer_.get(), {})", m_szFileName_, encodedLen); m_mpqWriter.WriteFile(m_szFileName_, m_buffer_.get(), encodedLen); } }; @@ -1839,7 +1834,6 @@ void LoadLevelSeeds() void SaveLevel(SaveWriter &saveWriter, LevelConversionData *levelConversionData) { - Log("SaveLevel(SaveWriter &saveWriter, LevelConversionData *levelConversionData)"); Player &myPlayer = *MyPlayer; DoUnVision(myPlayer.position.tile, myPlayer._pLightRad); // fix for vision staying on the level @@ -1849,7 +1843,6 @@ void SaveLevel(SaveWriter &saveWriter, LevelConversionData *levelConversionData) char szName[MaxMpqPathSize]; GetTempLevelNames(szName); - Log("SaveHelper file(saveWriter, \"{}\", 256 * 1024)", szName); SaveHelper file(saveWriter, szName, 256 * 1024); if (leveltype != DTYPE_TOWN) { @@ -1920,18 +1913,11 @@ void SaveLevel(SaveWriter &saveWriter, LevelConversionData *levelConversionData) void LoadLevel(LevelConversionData *levelConversionData) { - Log("LoadLevel"); char szName[MaxMpqPathSize]; std::optional archive = OpenSaveArchive(gSaveNumber); - Log("OpenSaveArchive({})", gSaveNumber); GetTempLevelNames(szName); - Log("szName = '{}'", szName); - Log("!archive = {}", !archive); - Log("!archive->HasFile(\"{}\") = {}", szName, !archive->HasFile(szName)); - if (!archive || !archive->HasFile(szName)) { - Log("{} not found in archive, calling GetPermLevelNames(\"{}\")", szName, szName); + if (!archive || !archive->HasFile(szName)) GetPermLevelNames(szName); - } LoadHelper file(std::move(archive), szName); if (!file.IsValid()) app_fatal(_("Unable to open save file archive")); @@ -2237,8 +2223,12 @@ size_t HotkeysSize(size_t nHotkeys = NumHotkeys) void LoadHotkeys() { - //hotkeys => htks to get around VMU filename size limits +#ifdef __DREAMCAST____ + // hotkeys => htks to get around VMU filename size limits LoadHelper file(OpenSaveArchive(gSaveNumber), "htks"); +#else + LoadHelper file(OpenSaveArchive(gSaveNumber), "hotkeys"); +#endif if (!file.IsValid()) return; @@ -2280,8 +2270,12 @@ void LoadHotkeys() void SaveHotkeys(SaveWriter &saveWriter, const Player &player) { - //hotkeys => htks to get around VMU filename size limits +#ifdef __DREAMCAST____ + // hotkeys => htks to get around VMU filename size limits SaveHelper file(saveWriter, "htks", HotkeysSize()); +#else + SaveHelper file(saveWriter, "hotkeys", HotkeysSize()); +#endif // Write the number of spell hotkeys file.WriteLE(static_cast(NumHotkeys)); @@ -2301,8 +2295,12 @@ void SaveHotkeys(SaveWriter &saveWriter, const Player &player) void LoadHeroItems(Player &player) { - //heroitems => hitms to get around VMU filename size limits +#ifdef __DREAMCAST____ + // heroitems => hitms to get around VMU filename size limits LoadHelper file(OpenSaveArchive(gSaveNumber), "hitms"); +#else + LoadHelper file(OpenSaveArchive(gSaveNumber), "heroitems"); +#endif if (!file.IsValid()) return; @@ -2368,7 +2366,6 @@ void RemoveEmptyInventory(Player &player) void LoadGame(bool firstflag) { - Log("LoadGame(firstflag = {})", firstflag); FreeGameMem(); LoadHelper file(OpenSaveArchive(gSaveNumber), "game"); @@ -2389,7 +2386,6 @@ void LoadGame(bool firstflag) giNumberOfSmithPremiumItems = 6; } - Log("pfile_remove_temp_files"); pfile_remove_temp_files(); setlevel = file.NextBool8(); @@ -2419,16 +2415,13 @@ void LoadGame(bool firstflag) Player &myPlayer = *MyPlayer; - Log("LoadPlayer(file, myPlayer);"); LoadPlayer(file, myPlayer); if (sgGameInitInfo.nDifficulty < DIFF_NORMAL || sgGameInitInfo.nDifficulty > DIFF_HELL) sgGameInitInfo.nDifficulty = DIFF_NORMAL; - Log("LoadQuests {}", giNumberQuests); for (int i = 0; i < giNumberQuests; i++) LoadQuest(&file, i); - Log("LoadPortals", MAXPORTAL); for (int i = 0; i < MAXPORTAL; i++) LoadPortal(&file, i); @@ -2437,7 +2430,6 @@ void LoadGame(bool firstflag) RemoveEmptyInventory(myPlayer); } - Log("LoadGameLevel"); LoadGameLevel(firstflag, ENTRY_LOAD); SetPlrAnims(myPlayer); SyncPlrAnim(myPlayer); @@ -2454,7 +2446,6 @@ void LoadGame(bool firstflag) if (leveltype != DTYPE_TOWN) { for (unsigned &monsterId : ActiveMonsters) monsterId = file.NextBE(); - Log("LoadMonsters {}", ActiveMonsterCount); for (size_t i = 0; i < ActiveMonsterCount; i++) LoadMonster(&file, Monsters[ActiveMonsters[i]]); for (size_t i = 0; i < ActiveMonsterCount; i++) @@ -2463,7 +2454,6 @@ void LoadGame(bool firstflag) file.Skip(MaxMissilesForSaveGame); // Skip AvailableMissiles file.Skip(MaxMissilesForSaveGame); - Log("LoadMissiles {}", tmpNummissiles); for (int i = 0; i < tmpNummissiles; i++) LoadMissile(&file); // For petrified monsters, the data in missile.var1 must be used to @@ -2587,12 +2577,15 @@ void LoadGame(bool firstflag) gbIsHellfireSaveGame = gbIsHellfire; } -//todo restore saving of inventory body void SaveHeroItems(SaveWriter &saveWriter, Player &player) { - size_t itemCount = static_cast(NUM_INVLOC) + InventoryGridCells + MaxBeltItems; //7 + 40 + 8 = 55 - //heroitems => hitms to get around VMU filename size limits - SaveHelper file(saveWriter, "hitms", itemCount * (gbIsHellfire ? HellfireItemSaveSize : DiabloItemSaveSize) + sizeof(uint8_t)); //55 * 368 + 1 = 20241 bytes + size_t itemCount = static_cast(NUM_INVLOC) + InventoryGridCells + MaxBeltItems; // 7 + 40 + 8 = 55 +#ifdef __DREAMCAST____ + // heroitems => hitms to get around VMU filename size limits + SaveHelper file(saveWriter, "hitms", itemCount * (gbIsHellfire ? HellfireItemSaveSize : DiabloItemSaveSize) + sizeof(uint8_t)); // 55 * 368 + 1 = 20241 bytes +#else + SaveHelper file(saveWriter, "heroitems", itemCount * (gbIsHellfire ? HellfireItemSaveSize : DiabloItemSaveSize) + sizeof(uint8_t)); +#endif file.WriteLE(gbIsHellfire ? 1 : 0); @@ -2641,7 +2634,6 @@ void SaveStash(SaveWriter &stashWriter) } }; - Log("Saving {} pages of stash", pagesToSave.size()); // Current stash size is 100 pages. Will definitely fit in a 32 bit value. file.WriteLE(static_cast(pagesToSave.size())); for (const auto &page : pagesToSave) { @@ -2649,7 +2641,6 @@ void SaveStash(SaveWriter &stashWriter) for (const auto &row : Stash.stashGrids[page]) { for (uint16_t cell : row) { file.WriteLE(cell); - Log("\t\tSaving stash item {}", cell); } } } @@ -2657,7 +2648,6 @@ void SaveStash(SaveWriter &stashWriter) // 100 pages of 100 items is still only 10 000, as with the page count will definitely fit in 32 bits even in the worst case. file.WriteLE(static_cast(Stash.stashList.size())); for (const Item &item : Stash.stashList) { - Log("SaveItem(file, item)"); SaveItem(file, item); } @@ -2666,7 +2656,6 @@ void SaveStash(SaveWriter &stashWriter) void SaveGameData(SaveWriter &saveWriter) { - Log("SaveHelper file(saveWriter, \"game\", 320 * 1024)"); SaveHelper file(saveWriter, "game", 320 * 1024); if (gbIsSpawn && !gbIsHellfire) @@ -2832,7 +2821,6 @@ void SaveGameData(SaveWriter &saveWriter) void SaveGame() { - Log("SaveGame()"); gbValidSaveFile = true; pfile_write_hero(/*writeGameData=*/true); sfile_write_stash(); diff --git a/Source/main.cpp b/Source/main.cpp index a248f4bde02..9fedd1b8c41 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -23,9 +23,10 @@ #include "diablo.h" #ifdef __DREAMCAST__ -//fchmod fails to link on the dreamcast, this stub is provided as a workaround -extern "C" int fchmod(int fd, mode_t mode) { - return 0; +// fchmod fails to link on the dreamcast, this stub is provided as a workaround +extern "C" int fchmod(int fd, mode_t mode) +{ + return 0; } #endif diff --git a/Source/pfile.cpp b/Source/pfile.cpp index b036c56ae26..0cd66dcadbf 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -33,10 +33,10 @@ #include "utils/utf8.hpp" #ifdef __DREAMCAST__ -#include +#include #include +#include #include -#include #endif #ifdef UNPACKED_SAVES @@ -54,19 +54,20 @@ namespace devilution { bool gbValidSaveFile; - -void listdir(const char *dir, int depth) { +#ifdef __DREAMCAST__ +void listdir(const char *dir, int depth) +{ file_t d = fs_open(dir, O_RDONLY | O_DIR); dirent_t *entry; printf("============ %s ============\n", dir); - while(NULL != (entry = fs_readdir(d))) { + while (NULL != (entry = fs_readdir(d))) { char absolutePath[1024]; strcpy(absolutePath, dir); strcat(absolutePath, "/"); strcat(absolutePath, entry->name); bool isDir = entry->size == -1; printf("[%s]\t%.2f kB\t%s\n", isDir ? "DIR" : "FIL", entry->size / 1024.0, entry->name); - if(isDir) { + if (isDir) { printf("absolutePath = %s, depth = %d\n", absolutePath, depth); listdir(absolutePath, depth + 1); } @@ -74,6 +75,7 @@ void listdir(const char *dir, int depth) { fs_close(d); printf("============ %s ============\n\n\n", dir); } +#endif namespace { /** List of character names for the character selection screen. */ @@ -81,20 +83,25 @@ char hero_names[MAX_CHARACTERS][PlayerNameLength]; std::string GetSavePath(uint32_t saveNum, std::string_view savePrefix = {}) { - //shorter names to get around VMU filename size limits + // shorter names to get around VMU filename size limits return StrCat(paths::PrefPath(), savePrefix, gbIsSpawn +#ifdef __DREAMCAST__ ? (gbIsMultiplayer ? "M" : "S") : (gbIsMultiplayer ? "m" : "s"), +#else + ? (gbIsMultiplayer ? "share_" : "spawn_") + : (gbIsMultiplayer ? "multi_" : "single_"), +#endif saveNum, #ifdef UNPACKED_SAVES #ifdef __DREAMCAST__ - //flatten directory structure for easier fs_ramdisk_* usage - //for example, /ram/spawn_sv/hero would become /ram/spawn_sv_hero + // flatten directory structure for VMU filesystem compatibility + // for example, /vmu/spawn_sv/hero would become /vmu/spawn_sv_hero - gbIsHellfire ? "_hsv" DIRECTORY_SEPARATOR_STR : "_sv_" + gbIsHellfire ? "_hsv" DIRECTORY_SEPARATOR_STR : "_sv_" #else - gbIsHellfire ? "_hsv" DIRECTORY_SEPARATOR_STR : "_sv" DIRECTORY_SEPARATOR_STR + gbIsHellfire ? "_hsv" DIRECTORY_SEPARATOR_STR : "_sv" DIRECTORY_SEPARATOR_STR #endif #else gbIsHellfire ? ".hsv" : ".sv" @@ -108,7 +115,7 @@ std::string GetStashSavePath() gbIsSpawn ? "stash_spawn" : "stash", #ifdef UNPACKED_SAVES #ifdef __DREAMCAST__ - //same as above + // same as above gbIsHellfire ? "_hsv" DIRECTORY_SEPARATOR_STR : "_sv_" #else gbIsHellfire ? "_hsv" DIRECTORY_SEPARATOR_STR : "_sv" DIRECTORY_SEPARATOR_STR @@ -156,14 +163,9 @@ void RenameTempToPerm(SaveWriter &saveWriter) [[maybe_unused]] bool result = GetPermSaveNames(dwIndex, szPerm); // DO NOT PUT DIRECTLY INTO ASSERT! assert(result); dwIndex++; - Log("GetPermSaveNames({}, \"{}\")", dwIndex, szTemp); if (saveWriter.HasFile(szTemp)) { - Log("saveWriter.HasFile(\"{}\") = true", szTemp); - if (saveWriter.HasFile(szPerm)) { - Log("saveWriter.HasFile(\"{}\") = true => RemoveHashEntry", szPerm); + if (saveWriter.HasFile(szPerm)) saveWriter.RemoveHashEntry(szPerm); - } - Log("saveWriter.RenameFile(\"{}\", {})", szTemp, szPerm); saveWriter.RenameFile(szTemp, szPerm); } } @@ -176,7 +178,6 @@ bool ReadHero(SaveReader &archive, PlayerPack *pPack) auto buf = ReadArchive(archive, "hero", &read); if (buf == nullptr) { - Log("ReadArchive(archive, \"hero\", {}) = false", read); return false; } @@ -185,12 +186,14 @@ bool ReadHero(SaveReader &archive, PlayerPack *pPack) memcpy(pPack, buf.get(), sizeof(*pPack)); ret = true; } + +#ifdef __DREAMCAST__ Log("{} == sizeof(*pPack) ({}) = {}", read, sizeof(*pPack), read == sizeof(*pPack)); Log("Read player {}", pPack->pName); - //Log("\tpHPBase = {}", pPack->pHPBase); - + // Log("\tpHPBase = {}", pPack->pHPBase); listdir("/ram", 0); - listdir("/vmu/a1", 0); + listdir("/vmu/a1", 0); +#endif return ret; } @@ -200,13 +203,9 @@ void EncodeHero(SaveWriter &saveWriter, const PlayerPack *pack) size_t packedLen = codec_get_encoded_len(sizeof(*pack)); std::unique_ptr packed { new std::byte[packedLen] }; - Log("memcpy(packed.get(), pack, {})", sizeof(*pack)); memcpy(packed.get(), pack, sizeof(*pack)); codec_encode(packed.get(), sizeof(*pack), packedLen, pfile_get_password()); - Log("Saving player {}", pack->pName); - //Log("\tpHPBase = {}", pack->pHPBase); - bool result = saveWriter.WriteFile("hero", packed.get(), packedLen /* sizeof(*pack) */); - Log("saveWriter.WriteFile(\"hero\", packed.get(), {}) = {}", packedLen, result); + saveWriter.WriteFile("hero", packed.get(), packedLen); } SaveWriter GetSaveWriter(uint32_t saveNum) @@ -292,8 +291,8 @@ std::optional CreateSaveReader(std::string &&path) #ifdef UNPACKED_SAVES #ifdef __DREAMCAST__ Log("\tAttempting to load save file {}", path); - //no notion of directories in ramdisk, so /ram/spawn_0_sv/ doesn't exist - //instead, we check for /ram/spawn_0_sv_hero which was previously created + // no notion of directories in vmu, so /vmu/spawn_0_sv/ doesn't exist + // instead, we check for /vmu/spawn_0_sv_hero which was previously created std::string heroFile = path + "hero"; if (!FileExists(heroFile)) { Log("\tFailed ):"); @@ -613,16 +612,14 @@ std::unique_ptr SaveReader::ReadFile(const char *filename, std::siz Log("path = \"{}\"", path); size_t size = 0; uint8 *contents; - if(fs_load(path.c_str(), &contents) == -1) - { + if (fs_load(path.c_str(), &contents) == -1) { error = 1; LogError("fs_load(\"{}\", &contents) = -1", path); app_fatal("SaveReader::ReadFile " + path + " KO"); return nullptr; } vmu_pkg_t package; - if(vmu_pkg_parse(contents, &package) < 0) - { + if (vmu_pkg_parse(contents, &package) < 0) { error = 1; free(contents); LogError("vmu_pkg_parse = -1"); @@ -634,7 +631,7 @@ std::unique_ptr SaveReader::ReadFile(const char *filename, std::siz std::unique_ptr result; result.reset(new std::byte[fileSize]); memcpy(result.get(), package.data, fileSize); - //free(package.data); + // free(package.data); free(contents); return result; } @@ -670,10 +667,9 @@ bool SaveWriter::WriteFile(const char *filename, const std::byte *data, size_t s const std::string path = dir_ + filename; Log("dir_ = {}", dir_); Log("path = {}", path); - const char* baseName = basename(path.c_str()); - //vmu code - if(dir_.starts_with("/vmu")) - { + const char *baseName = basename(path.c_str()); + // vmu code + if (dir_.starts_with("/vmu")) { vmu_pkg_t package; strcpy(package.app_id, "DevilutionX"); strncpy(package.desc_short, filename, 20); @@ -687,16 +683,14 @@ bool SaveWriter::WriteFile(const char *filename, const std::byte *data, size_t s uint8 *contents; size_t packageSize; - if(vmu_pkg_build(&package, &contents, &packageSize) < 0) - { + if (vmu_pkg_build(&package, &contents, &packageSize) < 0) { delete[] package.data; LogError("vmu_pkg_build failed"); app_fatal("vmu_pkg_build failed"); return false; } - FILE* file = OpenFile(path.c_str(), "wb"); - if(file == nullptr) - { + FILE *file = OpenFile(path.c_str(), "wb"); + if (file == nullptr) { delete[] package.data; free(contents); LogError("fopen(\"{}\", \"wb\") = nullptr", path); @@ -704,8 +698,7 @@ bool SaveWriter::WriteFile(const char *filename, const std::byte *data, size_t s return false; } size_t written = std::fwrite(contents, sizeof(uint8), packageSize, file); - if(written != packageSize) - { + if (written != packageSize) { delete[] package.data; free(contents); std::fclose(file); @@ -713,8 +706,7 @@ bool SaveWriter::WriteFile(const char *filename, const std::byte *data, size_t s app_fatal("vmu fwrite call failed"); return false; } - if(std::fclose(file) != 0) - { + if (std::fclose(file) != 0) { delete[] package.data; free(contents); LogError("fclose(file) = 0"); @@ -727,23 +719,21 @@ bool SaveWriter::WriteFile(const char *filename, const std::byte *data, size_t s return true; } - //ramdisk code + // ramdisk code bool exists = FileExists(baseName); - if(exists) - { + if (exists) { Log("{} exists, removing it", path); void *toFree; size_t ignore; int detach_result = fs_ramdisk_detach(baseName, &toFree, &ignore); free(toFree); Log("fs_ramdisk_detach result = {}", detach_result); - if(detach_result == -1) - { + if (detach_result == -1) { return false; } } Log("\tAllocating {} bytes for path {}", size, baseName); - void* buffer = malloc(size); + void *buffer = malloc(size); memcpy(buffer, data, size); Log("\tMallocation succeeded ? {}", buffer != NULL); int attach_result = fs_ramdisk_attach(baseName, buffer, size); @@ -793,7 +783,7 @@ bool SaveWriter::WriteFile(const char *filename, const std::byte *data, size_t s std::fclose(file); return true; } -#endif //def __DREAMCAST__ +#endif // def __DREAMCAST__ void SaveWriter::RemoveHashEntries(bool (*fnGetName)(uint8_t, char *)) { char pszFileName[MaxMpqPathSize]; @@ -803,7 +793,7 @@ void SaveWriter::RemoveHashEntries(bool (*fnGetName)(uint8_t, char *)) RemoveHashEntry(pszFileName); } } -#endif //def UNPACKED_SAVES +#endif // def UNPACKED_SAVES std::optional OpenSaveArchive(uint32_t saveNum) { @@ -820,12 +810,9 @@ std::unique_ptr ReadArchive(SaveReader &archive, const char *pszNam int32_t error; std::size_t length; - Log("ReadArchive(archive, \"{}\", {})", pszName, *pdwLen); - Log("ReadArchive 0"); std::unique_ptr result = archive.ReadFile(pszName, length, error); if (error != 0) { Log("ReadArchive 0 error = {}", error); - app_fatal("ReadArchive 0 = " + error); return nullptr; } @@ -833,16 +820,8 @@ std::unique_ptr ReadArchive(SaveReader &archive, const char *pszNam std::size_t decodedLength = codec_decode(result.get(), length, pfile_get_password()); if (decodedLength == 0) { Log("ReadArchive nullptr"); - app_fatal("decodedLength = 0"); return nullptr; } - if(strcmp(pszName, "hero") == 0) - { - PlayerPack pPack; - memcpy(&pPack, result.get(), decodedLength); - Log("ReadArchive player {}", pPack.pName); - //Log("\tpHPBase = {}", pPack.pHPBase); - } Log("ReadArchive 2"); if (pdwLen != nullptr) @@ -877,7 +856,6 @@ void pfile_write_hero_demo(int demo) HeroCompareResult pfile_compare_hero_demo(int demo, bool logDetails) { - Log("pfile_compare_hero_demo({}, {})", demo, logDetails); std::string referenceSavePath = GetSavePath(gSaveNumber, StrCat("demo_", demo, "_reference_")); if (!FileExists(referenceSavePath.c_str())) @@ -916,13 +894,9 @@ bool pfile_ui_set_hero_infos(bool (*uiAddHeroInfo)(_uiheroinfo *)) if (archive) { PlayerPack pkplr; if (ReadHero(*archive, &pkplr)) { - Log("ReadHero OK"); - Log("Player {}", pkplr.pName); - //Log("Player {}, HP = {}", pkplr.pName, pkplr.pHPBase); _uiheroinfo uihero; uihero.saveNumber = i; strcpy(hero_names[i], pkplr.pName); - Log("hero_names[{}] = {}", i, pkplr.pName); bool hasSaveGame = ArchiveContainsGame(*archive); if (hasSaveGame) pkplr.bIsHellfire = gbIsHellfireSaveGame ? 1 : 0; @@ -937,10 +911,6 @@ bool pfile_ui_set_hero_infos(bool (*uiAddHeroInfo)(_uiheroinfo *)) Game2UiPlayer(player, &uihero, hasSaveGame); uiAddHeroInfo(&uihero); } - else { - Log("ReadHero(*archive, &pkplr) failed"); - app_fatal("ReadHero(*archive, &pkplr) failed"); - } } } @@ -1014,13 +984,17 @@ void pfile_read_player_from_save(uint32_t saveNum, Player &player) { std::optional archive = OpenSaveArchive(saveNum); if (!archive) { +#ifdef __DREAMCAST__ listdir("/ram", 0); - listdir("/vmu/a1", 0); + listdir("/vmu/a1", 0); +#endif app_fatal(_("Unable to open archive")); } if (!ReadHero(*archive, &pkplr)) { +#ifdef __DREAMCAST__ listdir("/ram", 0); - listdir("/vmu/a1", 0); + listdir("/vmu/a1", 0); +#endif app_fatal(_("Unable to load character")); } @@ -1066,10 +1040,15 @@ void pfile_update(bool forceSave) return; Uint32 tick = SDL_GetTicks(); - //600000 instead of 60000 - //60000 ms is too frequent for the VMU, the game hangs too often and too long +#ifdef __DREAMCAST__ + // 600000 instead of 60000 + // 60000 ms is too frequent for the VMU, the game hangs too often and too long if (!forceSave && tick - prevTick <= 600000) return; +#else + if (!forceSave && tick - prevTick <= 60000) + return; +#endif Log("pfile_update({})", forceSave); prevTick = tick; diff --git a/Source/pfile.h b/Source/pfile.h index 0ee7f0496f2..da520a00d2b 100644 --- a/Source/pfile.h +++ b/Source/pfile.h @@ -19,7 +19,11 @@ namespace devilution { -#define MAX_CHARACTERS 1 //todo restore me to 99 +#ifdef __DREAMCAST____ +#define MAX_CHARACTERS 1 // todo restore me to 99 +#else +#define MAX_CHARACTERS 99 +#endif extern bool gbValidSaveFile; @@ -28,7 +32,6 @@ struct SaveReader { explicit SaveReader(std::string &&dir) : dir_(std::move(dir)) { - Log("new SaveReader(\"{}\");", dir); } const std::string &dir() const @@ -51,7 +54,6 @@ struct SaveWriter { explicit SaveWriter(std::string &&dir) : dir_(std::move(dir)) { - Log("new SaveWriter(\"{}\");", dir); } bool WriteFile(const char *filename, const std::byte *data, size_t size); diff --git a/Source/utils/file_util.cpp b/Source/utils/file_util.cpp index cd09a7bc5ea..0a0114ed976 100644 --- a/Source/utils/file_util.cpp +++ b/Source/utils/file_util.cpp @@ -107,14 +107,15 @@ bool FileExists(const char *path) } return true; #elif defined(__DREAMCAST__) - //ramdisk access doesn't work with SDL_RWFromFile or std::filesystem::exists + // ramdisk access doesn't work with SDL_RWFromFile or std::filesystem::exists + // todo check to see if this is needed with vmu fs int file = fs_open(path, O_RDONLY); - if(file != -1) { + if (file != -1) { fs_close(file); return true; } file = fs_open(path, O_RDONLY | O_DIR); - if(file != -1) { + if (file != -1) { fs_close(file); return true; } @@ -317,19 +318,19 @@ void RecursivelyCreateDir(const char *path) #ifdef __DREAMCAST__ bool TruncateFile(const char *path, off_t size) { - Log("TruncateFile(\"{}\", {})", path, size); - void *contents; - size_t read = fs_load(path, &contents); - if(read == -1) - { - return false; - } + Log("TruncateFile(\"{}\", {})", path, size); + void *contents; + size_t read = fs_load(path, &contents); + if (read == -1) { + return false; + } - fs_unlink(path); - file_t fh = fs_open(path, O_WRONLY); - int result = fs_write(fh, contents, size); - free(contents); - return result != -1; + fs_unlink(path); + file_t fh = fs_open(path, O_WRONLY); + int result = fs_write(fh, contents, size); + fs_close(fh); + free(contents); + return result != -1; } #endif diff --git a/Source/utils/sdl2_to_1_2_backports.cpp b/Source/utils/sdl2_to_1_2_backports.cpp index a41addb89a2..8081b1c460f 100644 --- a/Source/utils/sdl2_to_1_2_backports.cpp +++ b/Source/utils/sdl2_to_1_2_backports.cpp @@ -883,7 +883,7 @@ char *SDL_GetPrefPath(const char *org, const char *app) return retval; #elif defined(__DREAMCAST__) retval = SDL_strdup("/vmu/a1/"); - return retval; + return retval; #endif if (!app) { diff --git a/Source/utils/sdl_compat.h b/Source/utils/sdl_compat.h index 56c1c6aebfa..7c5da623487 100644 --- a/Source/utils/sdl_compat.h +++ b/Source/utils/sdl_compat.h @@ -85,7 +85,7 @@ inline int SDLC_SetSurfaceAndPaletteColors(SDL_Surface *surface, SDL_Palette *pa // In SDL1, the surface always has its own distinct palette, so we need to // update it as well. return SDL_SetPalette(surface, SDL_LOGPAL, colors, firstcolor, ncolors) - 1; -#endif //defined(__DREAMCAST__) +#endif // defined(__DREAMCAST__) #else // !USE_SDL1 if (SDL_SetPaletteColors(palette, colors, firstcolor, ncolors) < 0)