Skip to content

Commit

Permalink
More dependency untangling
Browse files Browse the repository at this point in the history
1. Moves more assets-related stuff from `init` to `engine/assets`.
2. Removes `SDL_audiolib` dependency from `soundsample.h`.
3. Cleans up some unused/missing includes.
  • Loading branch information
glebm committed Jan 9, 2025
1 parent f601e13 commit 374cd33
Show file tree
Hide file tree
Showing 54 changed files with 363 additions and 328 deletions.
1 change: 1 addition & 0 deletions Source/DiabloUI/diabloui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "engine/render/clx_render.hpp"
#include "engine/ticks.hpp"
#include "hwcursor.hpp"
#include "init.h"
#include "utils/algorithm/container.hpp"
#include "utils/display.h"
#include "utils/is_of.hpp"
Expand Down
2 changes: 2 additions & 0 deletions Source/DiabloUI/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#include "engine/load_clx.hpp"
#include "engine/load_pcx.hpp"
#include "engine/palette.h"
#include "headless_mode.hpp"
#include "hwcursor.hpp"
#include "init.h"
#include "utils/display.h"
#include "utils/is_of.hpp"
#include "utils/language.h"
Expand Down
7 changes: 4 additions & 3 deletions Source/DiabloUI/hero/selhero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "DiabloUI/selyesno.h"
#include "control.h"
#include "controls/plrctrls.h"
#include "engine/assets.hpp"
#include "game_mode.hpp"
#include "menu.h"
#include "options.h"
Expand Down Expand Up @@ -161,10 +162,10 @@ void SelheroListSelect(size_t value)
vecSelHeroDlgItems.push_back(std::make_unique<UiListItem>(_("Sorcerer"), static_cast<int>(HeroClass::Sorcerer)));
if (gbIsHellfire) {
vecSelHeroDlgItems.push_back(std::make_unique<UiListItem>(_("Monk"), static_cast<int>(HeroClass::Monk)));
if (gbBard || *sgOptions.Gameplay.testBard) {
if (HaveBardAssets() || *sgOptions.Gameplay.testBard) {
vecSelHeroDlgItems.push_back(std::make_unique<UiListItem>(_("Bard"), static_cast<int>(HeroClass::Bard)));
}
if (gbBarbarian || *sgOptions.Gameplay.testBarbarian) {
if (HaveBarbarianAssets() || *sgOptions.Gameplay.testBarbarian) {
vecSelHeroDlgItems.push_back(std::make_unique<UiListItem>(_("Barbarian"), static_cast<int>(HeroClass::Barbarian)));
}
}
Expand Down Expand Up @@ -263,7 +264,7 @@ void AddSelHeroBackground()
void SelheroClassSelectorSelect(size_t value)
{
auto hClass = static_cast<HeroClass>(vecSelHeroDlgItems[value]->m_value);
if (gbIsSpawn && (hClass == HeroClass::Rogue || hClass == HeroClass::Sorcerer || (hClass == HeroClass::Bard && !gbBard))) {
if (gbIsSpawn && (hClass == HeroClass::Rogue || hClass == HeroClass::Sorcerer || (hClass == HeroClass::Bard && !HaveBardAssets()))) {
RemoveSelHeroBackground();
UiSelOkDialog(nullptr, _("The Rogue and Sorcerer are only available in the full retail version of Diablo. Visit https://www.gog.com/game/diablo to purchase.").data(), false);
AddSelHeroBackground();
Expand Down
1 change: 1 addition & 0 deletions Source/DiabloUI/mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "DiabloUI/diabloui.h"
#include "DiabloUI/selok.h"
#include "control.h"
#include "engine/assets.hpp"
#include "engine/load_clx.hpp"
#include "game_mode.hpp"
#include "utils/language.h"
Expand Down
2 changes: 2 additions & 0 deletions Source/DiabloUI/settingsmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdint>
#include <optional>
#include <vector>

#include <function_ref.hpp>

Expand All @@ -11,6 +12,7 @@
#include "controls/controller_motion.h"
#include "controls/plrctrls.h"
#include "controls/remap_keyboard.h"
#include "engine/assets.hpp"
#include "engine/render/text_render.hpp"
#include "hwcursor.hpp"
#include "options.h"
Expand Down
6 changes: 3 additions & 3 deletions Source/appfat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ void FreeDlg()
SNetDestroy();
}

[[noreturn]] void DisplayFatalErrorAndExit(std::string_view title, std::string_view body)
} // namespace

void DisplayFatalErrorAndExit(std::string_view title, std::string_view body)
{
FreeDlg();
UiErrorOkDialog(title, body);
diablo_quit(1);
}

} // namespace

void app_fatal(std::string_view str)
{
DisplayFatalErrorAndExit(_("Error"), str);
Expand Down
7 changes: 7 additions & 0 deletions Source/appfat.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ namespace devilution {
#define assert(exp) (void)((exp) || (assert_fail(__LINE__, __FILE__, #exp), 0))
#endif

/**
* @brief Terminates the game and displays an error message box.
* @param str Message box title.
* @param str Error message.
*/
[[noreturn]] void DisplayFatalErrorAndExit(std::string_view title, std::string_view body);

/**
* @brief Terminates the game and displays an error message box.
* @param str Error message.
Expand Down
2 changes: 1 addition & 1 deletion Source/capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ SDL_RWops *CaptureFile(std::string *dstPath)
const std::tm *tm = std::localtime(&tt);
const std::string filename = tm != nullptr
? fmt::format("Screenshot from {:04}-{:02}-{:02} {:02}-{:02}-{:02}",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec)
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec)
: "Screenshot";
*dstPath = StrCat(paths::PrefPath(), filename, ext);
int i = 0;
Expand Down
1 change: 0 additions & 1 deletion Source/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "engine/trn.hpp"
#include "gamemenu.h"
#include "headless_mode.hpp"
#include "init.h"
#include "inv.h"
#include "inv_iterators.hpp"
#include "levels/setmaps.h"
Expand Down
3 changes: 1 addition & 2 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <config.h>

#include "DiabloUI/selstart.h"
#include "appfat.h"
#include "automap.h"
#include "capture.h"
#include "control.h"
Expand Down Expand Up @@ -124,8 +125,6 @@ bool gbProcessPlayers;
bool gbLoadGame;
bool cineflag;
int PauseMode;
bool gbBard;
bool gbBarbarian;
clicktype sgbMouseDown;
uint16_t gnTickDelay = 50;
char gszProductName[64] = "DevilutionX vUnknown";
Expand Down
8 changes: 6 additions & 2 deletions Source/diablo.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

#include <cstdint>

#include <SDL.h>

#ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h"
#endif

#ifdef _DEBUG
#include "monstdat.h"
#endif
Expand Down Expand Up @@ -69,8 +75,6 @@ extern bool cineflag;
/* These are defined in fonts.h */
extern void FontsCleanup();
extern DVL_API_FOR_TEST int PauseMode;
extern bool gbBard;
extern bool gbBarbarian;
extern clicktype sgbMouseDown;
extern uint16_t gnTickDelay;
extern char gszProductName[64];
Expand Down
1 change: 1 addition & 0 deletions Source/dvlnet/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "appfat.h"
#include "dvlnet/abstract_net.h"
#include "utils/attributes.h"
#include "utils/endian_read.hpp"
#include "utils/endian_write.hpp"
#include "utils/str_cat.hpp"
#include "utils/stubs.h"
Expand Down
2 changes: 1 addition & 1 deletion Source/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "engine/sound.h"
#include "engine/sound_defs.hpp"
#include "engine/sound_position.hpp"
#include "init.h"
#include "game_mode.hpp"
#include "player.h"
#include "utils/is_of.hpp"

Expand Down
Loading

0 comments on commit 374cd33

Please sign in to comment.