From f078bac265c0392861528bd06d94fb095607d220 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Tue, 7 Jan 2025 20:18:07 +0000 Subject: [PATCH] Move MPQs from init to engine/assets Untangles some of the dependencies. --- Source/diablo.h | 1 - Source/engine/assets.cpp | 20 ++++++++++++++++++++ Source/engine/assets.hpp | 33 ++++++++++++++++++++++++++++++++- Source/init.cpp | 20 -------------------- Source/init.h | 27 ++------------------------- 5 files changed, 54 insertions(+), 47 deletions(-) diff --git a/Source/diablo.h b/Source/diablo.h index f2b5146410a..6e868067e20 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -10,7 +10,6 @@ #ifdef _DEBUG #include "monstdat.h" #endif -#include "init.h" #include "levels/gendung.h" #include "utils/attributes.h" #include "utils/endian.hpp" diff --git a/Source/engine/assets.cpp b/Source/engine/assets.cpp index 3647ab2bb6f..bbb2c4f69f7 100644 --- a/Source/engine/assets.cpp +++ b/Source/engine/assets.cpp @@ -17,6 +17,26 @@ namespace devilution { +#ifdef UNPACKED_MPQS +std::optional spawn_data_path; +std::optional diabdat_data_path; +std::optional hellfire_data_path; +std::optional font_data_path; +std::optional lang_data_path; +#else +std::optional spawn_mpq; +std::optional diabdat_mpq; +std::optional hellfire_mpq; +std::optional hfmonk_mpq; +std::optional hfbard_mpq; +std::optional hfbarb_mpq; +std::optional hfmusic_mpq; +std::optional hfvoice_mpq; +std::optional devilutionx_mpq; +std::optional lang_mpq; +std::optional font_mpq; +#endif + namespace { #ifdef UNPACKED_MPQS diff --git a/Source/engine/assets.hpp b/Source/engine/assets.hpp index a0e5a41b6cf..203d296aa30 100644 --- a/Source/engine/assets.hpp +++ b/Source/engine/assets.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -13,12 +14,19 @@ #include "appfat.h" #include "diablo.h" -#include "mpq/mpq_reader.hpp" #include "utils/file_util.h" #include "utils/language.h" #include "utils/str_cat.hpp" #include "utils/string_or_view.hpp" +#ifndef UNPACKED_MPQS +#include "mpq/mpq_reader.hpp" +#endif + +#ifdef USE_SDL1 +#include "utils/sdl2_to_1_2_backports.h" +#endif + namespace devilution { #ifdef UNPACKED_MPQS @@ -268,4 +276,27 @@ struct AssetData { tl::expected LoadAsset(std::string_view path); +#ifdef UNPACKED_MPQS +extern DVL_API_FOR_TEST std::optional spawn_data_path; +extern DVL_API_FOR_TEST std::optional diabdat_data_path; +extern std::optional hellfire_data_path; +extern std::optional font_data_path; +extern std::optional lang_data_path; +#else +/** A handle to the spawn.mpq archive. */ +extern DVL_API_FOR_TEST std::optional spawn_mpq; +/** A handle to the diabdat.mpq archive. */ +extern DVL_API_FOR_TEST std::optional diabdat_mpq; +/** A handle to an hellfire.mpq archive. */ +extern std::optional hellfire_mpq; +extern std::optional hfmonk_mpq; +extern std::optional hfbard_mpq; +extern std::optional hfbarb_mpq; +extern std::optional hfmusic_mpq; +extern std::optional hfvoice_mpq; +extern std::optional font_mpq; +extern std::optional lang_mpq; +extern std::optional devilutionx_mpq; +#endif + } // namespace devilution diff --git a/Source/init.cpp b/Source/init.cpp index 02eafbc9d5c..fc429e100fb 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -55,26 +55,6 @@ bool gbVanilla; /** Whether the Hellfire mode is required (forced). */ bool forceHellfire; -#ifdef UNPACKED_MPQS -std::optional spawn_data_path; -std::optional diabdat_data_path; -std::optional hellfire_data_path; -std::optional font_data_path; -std::optional lang_data_path; -#else -std::optional spawn_mpq; -std::optional diabdat_mpq; -std::optional hellfire_mpq; -std::optional hfmonk_mpq; -std::optional hfbard_mpq; -std::optional hfbarb_mpq; -std::optional hfmusic_mpq; -std::optional hfvoice_mpq; -std::optional devilutionx_mpq; -std::optional lang_mpq; -std::optional font_mpq; -#endif - namespace { constexpr char DevilutionXMpqVersion[] = "1\n"; diff --git a/Source/init.h b/Source/init.h index 538a5f66308..30d7ac54501 100644 --- a/Source/init.h +++ b/Source/init.h @@ -7,6 +7,7 @@ #include +#include "engine/assets.hpp" #include "utils/attributes.h" #ifdef UNPACKED_MPQS @@ -15,39 +16,15 @@ #include "mpq/mpq_reader.hpp" #endif -#include - namespace devilution { +/** True if the game is the current active window */ extern bool gbActive; extern DVL_API_FOR_TEST bool gbIsSpawn; extern DVL_API_FOR_TEST bool gbIsHellfire; extern DVL_API_FOR_TEST bool gbVanilla; extern bool forceHellfire; -#ifdef UNPACKED_MPQS -extern DVL_API_FOR_TEST std::optional spawn_data_path; -extern DVL_API_FOR_TEST std::optional diabdat_data_path; -extern std::optional hellfire_data_path; -extern std::optional font_data_path; -extern std::optional lang_data_path; -#else -/** A handle to the spawn.mpq archive. */ -extern DVL_API_FOR_TEST std::optional spawn_mpq; -/** A handle to the diabdat.mpq archive. */ -extern DVL_API_FOR_TEST std::optional diabdat_mpq; -/** A handle to an hellfire.mpq archive. */ -extern std::optional hellfire_mpq; -extern std::optional hfmonk_mpq; -extern std::optional hfbard_mpq; -extern std::optional hfbarb_mpq; -extern std::optional hfmusic_mpq; -extern std::optional hfvoice_mpq; -extern std::optional font_mpq; -extern std::optional lang_mpq; -extern std::optional devilutionx_mpq; -#endif - inline bool HaveSpawn() { #ifdef UNPACKED_MPQS