Skip to content

Commit

Permalink
Extract HeadlessMode from diablo.h
Browse files Browse the repository at this point in the history
Untangles some dependencies.
Many places that use `HeadlessMode` do not need all of `diablo.h`.
  • Loading branch information
glebm committed Jan 9, 2025
1 parent b76feb2 commit cccc28d
Show file tree
Hide file tree
Showing 30 changed files with 52 additions and 9 deletions.
1 change: 1 addition & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(libdevilutionx_SRCS
game_mode.cpp
gamemenu.cpp
gmenu.cpp
headless_mode.cpp
help.cpp
hwcursor.cpp
init.cpp
Expand Down
1 change: 1 addition & 0 deletions Source/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "engine/render/text_render.hpp"
#include "engine/trn.hpp"
#include "gamemenu.h"
#include "headless_mode.hpp"
#include "init.h"
#include "inv.h"
#include "inv_iterators.hpp"
Expand Down
1 change: 1 addition & 0 deletions Source/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "engine/render/clx_render.hpp"
#include "engine/render/primitive_render.hpp"
#include "engine/trn.hpp"
#include "headless_mode.hpp"
#include "hwcursor.hpp"
#include "inv.h"
#include "levels/trigs.h"
Expand Down
7 changes: 7 additions & 0 deletions Source/data/file.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#include "file.hpp"

#include <bitset>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <memory>

#include <expected.hpp>
#include <fmt/format.h>

#include "engine/assets.hpp"
Expand Down
1 change: 1 addition & 0 deletions Source/dead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cstdint>

#include "diablo.h"
#include "headless_mode.hpp"
#include "levels/gendung.h"
#include "lighting.h"
#include "misdat.h"
Expand Down
2 changes: 1 addition & 1 deletion Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "game_mode.hpp"
#include "gamemenu.h"
#include "gmenu.h"
#include "headless_mode.hpp"
#include "help.h"
#include "hwcursor.hpp"
#include "init.h"
Expand Down Expand Up @@ -125,7 +126,6 @@ bool cineflag;
int PauseMode;
bool gbBard;
bool gbBarbarian;
bool HeadlessMode = false;
clicktype sgbMouseDown;
uint16_t gnTickDelay = 50;
char gszProductName[64] = "DevilutionX vUnknown";
Expand Down
4 changes: 0 additions & 4 deletions Source/diablo.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ extern void FontsCleanup();
extern DVL_API_FOR_TEST int PauseMode;
extern bool gbBard;
extern bool gbBarbarian;
/**
* @brief Don't load UI or show Messageboxes or other user-interaction. Needed for UnitTests.
*/
extern DVL_API_FOR_TEST bool HeadlessMode;
extern clicktype sgbMouseDown;
extern uint16_t gnTickDelay;
extern char gszProductName[64];
Expand Down
2 changes: 1 addition & 1 deletion Source/engine/assets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <fmt/format.h>

#include "appfat.h"
#include "diablo.h"
#include "game_mode.hpp"
#include "headless_mode.hpp"
#include "utils/file_util.h"
#include "utils/language.h"
#include "utils/str_cat.hpp"
Expand Down
1 change: 1 addition & 0 deletions Source/engine/demomode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "controls/plrctrls.h"
#include "engine/events.hpp"
#include "gmenu.h"
#include "headless_mode.hpp"
#include "menu.h"
#include "nthread.h"
#include "options.h"
Expand Down
1 change: 1 addition & 0 deletions Source/engine/dx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "controls/plrctrls.h"
#include "engine/render/primitive_render.hpp"
#include "headless_mode.hpp"
#include "options.h"
#include "utils/display.h"
#include "utils/log.hpp"
Expand Down
3 changes: 1 addition & 2 deletions Source/engine/load_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
#include <memory>

#include <expected.hpp>
#include <fmt/core.h>

#include "appfat.h"
#include "diablo.h"
#include "engine/assets.hpp"
#include "headless_mode.hpp"
#include "mpq/mpq_common.hpp"
#include "utils/static_vector.hpp"
#include "utils/str_cat.hpp"
Expand Down
1 change: 1 addition & 0 deletions Source/engine/palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "engine/dx.h"
#include "engine/load_file.hpp"
#include "engine/random.hpp"
#include "headless_mode.hpp"
#include "hwcursor.hpp"
#include "options.h"
#include "utils/display.h"
Expand Down
1 change: 1 addition & 0 deletions Source/engine/render/scrollrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "engine/trn.hpp"
#include "engine/world_tile.hpp"
#include "gmenu.h"
#include "headless_mode.hpp"
#include "help.h"
#include "hwcursor.hpp"
#include "init.h"
Expand Down
1 change: 1 addition & 0 deletions Source/gamemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "engine/sound.h"
#include "engine/sound_defs.hpp"
#include "gmenu.h"
#include "headless_mode.hpp"
#include "init.h"
#include "loadsave.h"
#include "options.h"
Expand Down
1 change: 1 addition & 0 deletions Source/gmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "engine/render/clx_render.hpp"
#include "engine/render/primitive_render.hpp"
#include "engine/render/text_render.hpp"
#include "headless_mode.hpp"
#include "options.h"
#include "stores.h"
#include "utils/language.h"
Expand Down
7 changes: 7 additions & 0 deletions Source/headless_mode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "headless_mode.hpp"

namespace devilution {

bool HeadlessMode;

} // namespace devilution
12 changes: 12 additions & 0 deletions Source/headless_mode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "utils/attributes.h"

namespace devilution {

/**
* @brief Don't load UI or show Messageboxes or other user-interaction. Needed for unit tests.
*/
extern DVL_API_FOR_TEST bool HeadlessMode;

} // namespace devilution
1 change: 1 addition & 0 deletions Source/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "engine/dx.h"
#include "engine/events.hpp"
#include "game_mode.hpp"
#include "headless_mode.hpp"
#include "hwcursor.hpp"
#include "options.h"
#include "pfile.h"
Expand Down
1 change: 1 addition & 0 deletions Source/interfac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "engine/palette.h"
#include "engine/render/clx_render.hpp"
#include "engine/render/primitive_render.hpp"
#include "headless_mode.hpp"
#include "hwcursor.hpp"
#include "init.h"
#include "loadsave.h"
Expand Down
1 change: 1 addition & 0 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "engine/render/clx_render.hpp"
#include "engine/render/primitive_render.hpp"
#include "engine/render/text_render.hpp"
#include "headless_mode.hpp"
#include "init.h"
#include "inv_iterators.hpp"
#include "levels/town.h"
Expand Down
1 change: 1 addition & 0 deletions Source/misdat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "data/file.hpp"
#include "data/iterators.hpp"
#include "data/record_reader.hpp"
#include "headless_mode.hpp"
#include "missiles.h"
#include "mpq/mpq_common.hpp"
#include "utils/file_name_generator.hpp"
Expand Down
1 change: 1 addition & 0 deletions Source/missiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "engine/points_in_rectangle_range.hpp"
#include "engine/random.hpp"
#include "engine/render/primitive_render.hpp"
#include "headless_mode.hpp"
#include "init.h"
#include "inv.h"
#include "levels/dun_tile.hpp"
Expand Down
1 change: 1 addition & 0 deletions Source/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "engine/sound_position.hpp"
#include "engine/world_tile.hpp"
#include "game_mode.hpp"
#include "headless_mode.hpp"
#include "init.h"
#include "levels/crypt.h"
#include "levels/drlg_l4.h"
Expand Down
1 change: 1 addition & 0 deletions Source/objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "engine/load_file.hpp"
#include "engine/points_in_rectangle_range.hpp"
#include "engine/random.hpp"
#include "headless_mode.hpp"
#include "init.h"
#include "inv.h"
#include "inv_iterators.hpp"
Expand Down
1 change: 1 addition & 0 deletions Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "engine/world_tile.hpp"
#include "game_mode.hpp"
#include "gamemenu.h"
#include "headless_mode.hpp"
#include "help.h"
#include "init.h"
#include "inv_iterators.hpp"
Expand Down
1 change: 1 addition & 0 deletions Source/qol/stash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "engine/render/clx_render.hpp"
#include "engine/render/text_render.hpp"
#include "engine/size.hpp"
#include "headless_mode.hpp"
#include "hwcursor.hpp"
#include "inv.h"
#include "minitext.h"
Expand Down
1 change: 1 addition & 0 deletions Source/storm/storm_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "dvlnet/abstract_net.h"
#include "engine/demomode.h"
#include "headless_mode.hpp"
#include "menu.h"
#include "options.h"
#include "utils/stubs.h"
Expand Down
1 change: 1 addition & 0 deletions Source/utils/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "controls/touch/gamepad.h"
#include "engine/backbuffer_state.hpp"
#include "engine/dx.h"
#include "headless_mode.hpp"
#include "options.h"
#include "utils/log.hpp"
#include "utils/sdl_geometry.h"
Expand Down
2 changes: 1 addition & 1 deletion test/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>

#include "diablo.h"
#include "headless_mode.hpp"
#include "options.h"
#include "utils/paths.h"

Expand Down
1 change: 1 addition & 0 deletions test/timedemo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "diablo.h"
#include "engine/demomode.h"
#include "game_mode.hpp"
#include "headless_mode.hpp"
#include "lua/lua.hpp"
#include "monstdat.h"
#include "options.h"
Expand Down

0 comments on commit cccc28d

Please sign in to comment.