Skip to content

Commit

Permalink
Merge pull request #11 from azihassan/fix/ISSUE-10-formatting
Browse files Browse the repository at this point in the history
[ISSUE-10] Fix formatting
  • Loading branch information
azihassan authored Oct 6, 2024
2 parents 6eb3678 + 7dbeed9 commit 0f9e1a4
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 168 deletions.
1 change: 1 addition & 0 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- dreamcast
paths-ignore:
- '*.md'
- 'docs/**'
Expand Down
4 changes: 2 additions & 2 deletions Source/DiabloUI/mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UiListItem>(_("Single Player"), MAINMENU_SINGLE_PLAYER));
#endif
vecMenuItems.push_back(std::make_unique<UiListItem>(_("Multi Player"), MAINMENU_MULTIPLAYER));
Expand Down
30 changes: 15 additions & 15 deletions Source/controls/devices/joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ StaticVector<ControllerButtonEvent, 4> 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
Expand Down Expand Up @@ -322,19 +322,19 @@ 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;
default:
return false;
}
}
#else //!ifdef __DREAMCAST__
#else //! ifdef __DREAMCAST__
bool Joystick::ProcessAxisMotion(const SDL_Event &event)
{
if (event.type != SDL_JOYAXISMOTION)
Expand Down
6 changes: 0 additions & 6 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<uint8_t>(lvldir));
_music_id neededTrack = GetLevelMusic(leveltype);
ClearFloatingNumbers();

Expand Down
6 changes: 3 additions & 3 deletions Source/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions Source/interfac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -352,7 +351,6 @@ void ShowProgress(interface_mode uMsg)
case WM_DIABNEXTLVL:
IncProgress();
if (!gbIsMultiplayer) {
Log("pfile_save_level()");
pfile_save_level();
} else {
DeltaSaveLevel();
Expand All @@ -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();
Expand All @@ -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;
Expand Down
58 changes: 23 additions & 35 deletions Source/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -1920,18 +1913,11 @@ void SaveLevel(SaveWriter &saveWriter, LevelConversionData *levelConversionData)

void LoadLevel(LevelConversionData *levelConversionData)
{
Log("LoadLevel");
char szName[MaxMpqPathSize];
std::optional<SaveReader> 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"));
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<uint8_t>(static_cast<uint8_t>(NumHotkeys));
Expand All @@ -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;

Expand Down Expand Up @@ -2368,7 +2366,6 @@ void RemoveEmptyInventory(Player &player)

void LoadGame(bool firstflag)
{
Log("LoadGame(firstflag = {})", firstflag);
FreeGameMem();

LoadHelper file(OpenSaveArchive(gSaveNumber), "game");
Expand All @@ -2389,7 +2386,6 @@ void LoadGame(bool firstflag)
giNumberOfSmithPremiumItems = 6;
}

Log("pfile_remove_temp_files");
pfile_remove_temp_files();

setlevel = file.NextBool8();
Expand Down Expand Up @@ -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);

Expand All @@ -2437,7 +2430,6 @@ void LoadGame(bool firstflag)
RemoveEmptyInventory(myPlayer);
}

Log("LoadGameLevel");
LoadGameLevel(firstflag, ENTRY_LOAD);
SetPlrAnims(myPlayer);
SyncPlrAnim(myPlayer);
Expand All @@ -2454,7 +2446,6 @@ void LoadGame(bool firstflag)
if (leveltype != DTYPE_TOWN) {
for (unsigned &monsterId : ActiveMonsters)
monsterId = file.NextBE<uint32_t>();
Log("LoadMonsters {}", ActiveMonsterCount);
for (size_t i = 0; i < ActiveMonsterCount; i++)
LoadMonster(&file, Monsters[ActiveMonsters[i]]);
for (size_t i = 0; i < ActiveMonsterCount; i++)
Expand All @@ -2463,7 +2454,6 @@ void LoadGame(bool firstflag)
file.Skip<int8_t>(MaxMissilesForSaveGame);
// Skip AvailableMissiles
file.Skip<int8_t>(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
Expand Down Expand Up @@ -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<size_t>(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<size_t>(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<uint8_t>(gbIsHellfire ? 1 : 0);

Expand Down Expand Up @@ -2641,23 +2634,20 @@ 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<uint32_t>(static_cast<uint32_t>(pagesToSave.size()));
for (const auto &page : pagesToSave) {
file.WriteLE<uint32_t>(page);
for (const auto &row : Stash.stashGrids[page]) {
for (uint16_t cell : row) {
file.WriteLE<uint16_t>(cell);
Log("\t\tSaving stash item {}", cell);
}
}
}

// 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<uint32_t>(static_cast<uint32_t>(Stash.stashList.size()));
for (const Item &item : Stash.stashList) {
Log("SaveItem(file, item)");
SaveItem(file, item);
}

Expand All @@ -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)
Expand Down Expand Up @@ -2832,7 +2821,6 @@ void SaveGameData(SaveWriter &saveWriter)

void SaveGame()
{
Log("SaveGame()");
gbValidSaveFile = true;
pfile_write_hero(/*writeGameData=*/true);
sfile_write_stash();
Expand Down
7 changes: 4 additions & 3 deletions Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit 0f9e1a4

Please sign in to comment.