From 6914d997786c684bcd0076eb269c83c1d4dfef07 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 26 Mar 2025 18:11:54 +0000 Subject: [PATCH] Codechange: Split baseset type definitions into separate files. --- src/CMakeLists.txt | 3 + src/base_media_base.h | 115 ---------------------------- src/base_media_graphics.h | 67 ++++++++++++++++ src/base_media_music.h | 63 +++++++++++++++ src/base_media_sounds.h | 27 +++++++ src/bootstrap_gui.cpp | 1 + src/gfxinit.cpp | 2 + src/music.cpp | 1 + src/music/dmusic.cpp | 1 + src/music/midifile.cpp | 1 + src/music/win32_m.cpp | 1 + src/music_gui.cpp | 1 + src/network/core/tcp_content.cpp | 3 + src/network/network_content.cpp | 3 + src/network/network_content_gui.cpp | 3 + src/openttd.cpp | 3 + src/screenshot_png.cpp | 1 + src/settings.cpp | 1 + src/settings_gui.cpp | 3 + src/settings_table.cpp | 2 + src/sound.cpp | 1 + src/survey.cpp | 3 + 22 files changed, 191 insertions(+), 115 deletions(-) create mode 100644 src/base_media_graphics.h create mode 100644 src/base_media_music.h create mode 100644 src/base_media_sounds.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b6a51a2efb..3e7160c4e2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -79,6 +79,9 @@ add_files( base_consist.h base_media_base.h base_media_func.h + base_media_graphics.h + base_media_music.h + base_media_sounds.h base_station_base.h bitmap_type.h bmp.cpp diff --git a/src/base_media_base.h b/src/base_media_base.h index 341e8b1941..e347006624 100644 --- a/src/base_media_base.h +++ b/src/base_media_base.h @@ -11,7 +11,6 @@ #define BASE_MEDIA_BASE_H #include "fileio_func.h" -#include "gfx_type.h" #include "textfile_type.h" #include "textfile_gui.h" #include "3rdparty/md5/md5.h" @@ -222,118 +221,4 @@ template /* static */ Tbase_set *BaseMedia::duplica template const char *TryGetBaseSetFile(const ContentInfo *ci, bool md5sum, const Tbase_set *s); -/** Types of graphics in the base graphics set */ -enum GraphicsFileType : uint8_t { - GFT_BASE, ///< Base sprites for all climates - GFT_LOGOS, ///< Logos, landscape icons and original terrain generator sprites - GFT_ARCTIC, ///< Landscape replacement sprites for arctic - GFT_TROPICAL, ///< Landscape replacement sprites for tropical - GFT_TOYLAND, ///< Landscape replacement sprites for toyland - GFT_EXTRA, ///< Extra sprites that were not part of the original sprites - MAX_GFT, ///< We are looking for this amount of GRFs -}; - -/** Blitter type for base graphics sets. */ -enum BlitterType : uint8_t { - BLT_8BPP, ///< Base set has 8 bpp sprites only. - BLT_32BPP, ///< Base set has both 8 bpp and 32 bpp sprites. -}; - -struct GRFConfig; - -/** All data of a graphics set. */ -struct GraphicsSet : BaseSet { -private: - mutable std::unique_ptr extra_cfg; ///< Parameters for extra GRF -public: - PaletteType palette; ///< Palette of this graphics set - BlitterType blitter; ///< Blitter of this graphics set - - GraphicsSet(); - ~GraphicsSet(); - - bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename); - GRFConfig *GetExtraConfig() const { return this->extra_cfg.get(); } - GRFConfig &GetOrCreateExtraConfig() const; - bool IsConfigurable() const; - void CopyCompatibleConfig(const GraphicsSet &src); - - static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir); -}; - -/** All data/functions related with replacing the base graphics. */ -class BaseGraphics : public BaseMedia { -public: - /** Values loaded from config file. */ - struct Ini { - std::string name; - uint32_t shortname; ///< unique key for base set - uint32_t extra_version; ///< version of the extra GRF - std::vector extra_params; ///< parameters for the extra GRF - }; - static inline Ini ini_data; - -}; - -/** All data of a sounds set. */ -struct SoundsSet : BaseSet { -}; - -/** All data/functions related with replacing the base sounds */ -class BaseSounds : public BaseMedia { -public: - /** The set as saved in the config file. */ - static inline std::string ini_set; - -}; - -/** Maximum number of songs in the 'class' playlists. */ -static const uint NUM_SONGS_CLASS = 10; -/** Number of classes for songs */ -static const uint NUM_SONG_CLASSES = 3; -/** Maximum number of songs in the full playlist; theme song + the classes */ -static const uint NUM_SONGS_AVAILABLE = 1 + NUM_SONG_CLASSES * NUM_SONGS_CLASS; - -/** Maximum number of songs in the (custom) playlist */ -static const uint NUM_SONGS_PLAYLIST = 32; - -/* Functions to read DOS music CAT files, similar to but not quite the same as sound effect CAT files */ -std::optional GetMusicCatEntryName(const std::string &filename, size_t entrynum); -std::optional> GetMusicCatEntryData(const std::string &filename, size_t entrynum); - -enum MusicTrackType : uint8_t { - MTT_STANDARDMIDI, ///< Standard MIDI file - MTT_MPSMIDI, ///< MPS GM driver MIDI format (contained in a CAT file) -}; - -/** Metadata about a music track. */ -struct MusicSongInfo { - std::string songname; ///< name of song displayed in UI - uint8_t tracknr; ///< track number of song displayed in UI - std::string filename; ///< file on disk containing song (when used in MusicSet class) - MusicTrackType filetype; ///< decoder required for song file - int cat_index; ///< entry index in CAT file, for filetype==MTT_MPSMIDI - bool loop; ///< song should play in a tight loop if possible, never ending - int override_start; ///< MIDI ticks to skip over in beginning - int override_end; ///< MIDI tick to end the song at (0 if no override) -}; - -/** All data of a music set. */ -struct MusicSet : BaseSet { - /** Data about individual songs in set. */ - MusicSongInfo songinfo[NUM_SONGS_AVAILABLE]; - /** Number of valid songs in set. */ - uint8_t num_available; - - bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename); -}; - -/** All data/functions related with replacing the base music */ -class BaseMusic : public BaseMedia { -public: - /** The set as saved in the config file. */ - static inline std::string ini_set; - -}; - #endif /* BASE_MEDIA_BASE_H */ diff --git a/src/base_media_graphics.h b/src/base_media_graphics.h new file mode 100644 index 0000000000..ada00a72dc --- /dev/null +++ b/src/base_media_graphics.h @@ -0,0 +1,67 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file base_media_graphics.h Generic functions for replacing base graphics data. */ + +#ifndef BASE_MEDIA_GRAPHICS_H +#define BASE_MEDIA_GRAPHICS_H + +#include "base_media_base.h" + +/** Types of graphics in the base graphics set */ +enum GraphicsFileType : uint8_t { + GFT_BASE, ///< Base sprites for all climates + GFT_LOGOS, ///< Logos, landscape icons and original terrain generator sprites + GFT_ARCTIC, ///< Landscape replacement sprites for arctic + GFT_TROPICAL, ///< Landscape replacement sprites for tropical + GFT_TOYLAND, ///< Landscape replacement sprites for toyland + GFT_EXTRA, ///< Extra sprites that were not part of the original sprites + MAX_GFT, ///< We are looking for this amount of GRFs +}; + +/** Blitter type for base graphics sets. */ +enum BlitterType : uint8_t { + BLT_8BPP, ///< Base set has 8 bpp sprites only. + BLT_32BPP, ///< Base set has both 8 bpp and 32 bpp sprites. +}; + +struct GRFConfig; + +/** All data of a graphics set. */ +struct GraphicsSet : BaseSet { +private: + mutable std::unique_ptr extra_cfg; ///< Parameters for extra GRF +public: + PaletteType palette; ///< Palette of this graphics set + BlitterType blitter; ///< Blitter of this graphics set + + GraphicsSet(); + ~GraphicsSet(); + + bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename); + GRFConfig *GetExtraConfig() const { return this->extra_cfg.get(); } + GRFConfig &GetOrCreateExtraConfig() const; + bool IsConfigurable() const; + void CopyCompatibleConfig(const GraphicsSet &src); + + static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir); +}; + +/** All data/functions related with replacing the base graphics. */ +class BaseGraphics : public BaseMedia { +public: + /** Values loaded from config file. */ + struct Ini { + std::string name; + uint32_t shortname; ///< unique key for base set + uint32_t extra_version; ///< version of the extra GRF + std::vector extra_params; ///< parameters for the extra GRF + }; + static inline Ini ini_data; +}; + +#endif /* BASE_MEDIA_BASE_H */ diff --git a/src/base_media_music.h b/src/base_media_music.h new file mode 100644 index 0000000000..3d6acf5a19 --- /dev/null +++ b/src/base_media_music.h @@ -0,0 +1,63 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file base_media_music.h Generic functions for replacing base music data. */ + +#ifndef BASE_MEDIA_MUSIC_H +#define BASE_MEDIA_MUSIC_H + +#include "base_media_base.h" + +/** Maximum number of songs in the 'class' playlists. */ +static const uint NUM_SONGS_CLASS = 10; +/** Number of classes for songs */ +static const uint NUM_SONG_CLASSES = 3; +/** Maximum number of songs in the full playlist; theme song + the classes */ +static const uint NUM_SONGS_AVAILABLE = 1 + NUM_SONG_CLASSES * NUM_SONGS_CLASS; + +/** Maximum number of songs in the (custom) playlist */ +static const uint NUM_SONGS_PLAYLIST = 32; + +/* Functions to read DOS music CAT files, similar to but not quite the same as sound effect CAT files */ +std::optional GetMusicCatEntryName(const std::string &filename, size_t entrynum); +std::optional> GetMusicCatEntryData(const std::string &filename, size_t entrynum); + +enum MusicTrackType : uint8_t { + MTT_STANDARDMIDI, ///< Standard MIDI file + MTT_MPSMIDI, ///< MPS GM driver MIDI format (contained in a CAT file) +}; + +/** Metadata about a music track. */ +struct MusicSongInfo { + std::string songname; ///< name of song displayed in UI + uint8_t tracknr; ///< track number of song displayed in UI + std::string filename; ///< file on disk containing song (when used in MusicSet class) + MusicTrackType filetype; ///< decoder required for song file + int cat_index; ///< entry index in CAT file, for filetype==MTT_MPSMIDI + bool loop; ///< song should play in a tight loop if possible, never ending + int override_start; ///< MIDI ticks to skip over in beginning + int override_end; ///< MIDI tick to end the song at (0 if no override) +}; + +/** All data of a music set. */ +struct MusicSet : BaseSet { + /** Data about individual songs in set. */ + MusicSongInfo songinfo[NUM_SONGS_AVAILABLE]; + /** Number of valid songs in set. */ + uint8_t num_available; + + bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename); +}; + +/** All data/functions related with replacing the base music */ +class BaseMusic : public BaseMedia { +public: + /** The set as saved in the config file. */ + static inline std::string ini_set; +}; + +#endif /* BASE_MEDIA_MUSIC_H */ diff --git a/src/base_media_sounds.h b/src/base_media_sounds.h new file mode 100644 index 0000000000..b089fdfa2d --- /dev/null +++ b/src/base_media_sounds.h @@ -0,0 +1,27 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file base_media_sounds.h Generic functions for replacing base sounds data. */ + +#ifndef BASE_MEDIA_SOUNDS_H +#define BASE_MEDIA_SOUNDS_H + +#include "base_media_base.h" + +/** All data of a sounds set. */ +struct SoundsSet : BaseSet { +}; + +/** All data/functions related with replacing the base sounds */ +class BaseSounds : public BaseMedia { +public: + /** The set as saved in the config file. */ + static inline std::string ini_set; + +}; + +#endif /* BASE_MEDIA_SOUNDS_H */ diff --git a/src/bootstrap_gui.cpp b/src/bootstrap_gui.cpp index 76533e1e11..41f4d88d91 100644 --- a/src/bootstrap_gui.cpp +++ b/src/bootstrap_gui.cpp @@ -9,6 +9,7 @@ #include "stdafx.h" #include "base_media_base.h" +#include "base_media_graphics.h" #include "blitter/factory.hpp" #include "error_func.h" diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index 2eb5135761..c3b014551d 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -22,6 +22,8 @@ /* The type of set we're replacing */ #define SET_TYPE "graphics" #include "base_media_func.h" +#include "base_media_graphics.h" +#include "base_media_sounds.h" #include "table/sprites.h" diff --git a/src/music.cpp b/src/music.cpp index 52a8ef259c..e10373949b 100644 --- a/src/music.cpp +++ b/src/music.cpp @@ -14,6 +14,7 @@ /** The type of set we're replacing */ #define SET_TYPE "music" #include "base_media_func.h" +#include "base_media_music.h" #include "random_access_file_type.h" #include "safeguards.h" diff --git a/src/music/dmusic.cpp b/src/music/dmusic.cpp index 18ee2655a5..724f00ba34 100644 --- a/src/music/dmusic.cpp +++ b/src/music/dmusic.cpp @@ -18,6 +18,7 @@ #include "../thread.h" #include "../fileio_func.h" #include "../base_media_base.h" +#include "../base_media_music.h" #include "dmusic.h" #include "midifile.hpp" #include "midi.h" diff --git a/src/music/midifile.cpp b/src/music/midifile.cpp index c246545563..d1124c0ff9 100644 --- a/src/music/midifile.cpp +++ b/src/music/midifile.cpp @@ -13,6 +13,7 @@ #include "../string_func.h" #include "../core/endian_func.hpp" #include "../base_media_base.h" +#include "../base_media_music.h" #include "midi.h" #include "../console_func.h" diff --git a/src/music/win32_m.cpp b/src/music/win32_m.cpp index 729af5d948..638a4210fd 100644 --- a/src/music/win32_m.cpp +++ b/src/music/win32_m.cpp @@ -17,6 +17,7 @@ #include "midifile.hpp" #include "midi.h" #include "../base_media_base.h" +#include "../base_media_music.h" #include "../core/mem_func.hpp" #include diff --git a/src/music_gui.cpp b/src/music_gui.cpp index 5a56fd8449..6b5907bf5a 100644 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -10,6 +10,7 @@ #include "stdafx.h" #include "openttd.h" #include "base_media_base.h" +#include "base_media_music.h" #include "music/music_driver.hpp" #include "window_gui.h" #include "strings_func.h" diff --git a/src/network/core/tcp_content.cpp b/src/network/core/tcp_content.cpp index c51f87ef8d..c8e24547db 100644 --- a/src/network/core/tcp_content.cpp +++ b/src/network/core/tcp_content.cpp @@ -13,6 +13,9 @@ #include "../../textfile_gui.h" #include "../../newgrf_config.h" #include "../../base_media_base.h" +#include "../../base_media_graphics.h" +#include "../../base_media_music.h" +#include "../../base_media_sounds.h" #include "../../ai/ai.hpp" #include "../../game/game.hpp" #include "../../fios.h" diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp index dafae1cd06..ac0f70d683 100644 --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -15,6 +15,9 @@ #include "../error.h" #include "../fileio_func.h" #include "../base_media_base.h" +#include "../base_media_graphics.h" +#include "../base_media_music.h" +#include "../base_media_sounds.h" #include "../settings_type.h" #include "../strings_func.h" #include "network_content.h" diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 0d556f4e39..7a9ff3d124 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -15,6 +15,9 @@ #include "../ai/ai.hpp" #include "../game/game.hpp" #include "../base_media_base.h" +#include "../base_media_graphics.h" +#include "../base_media_music.h" +#include "../base_media_sounds.h" #include "../openttd.h" #include "../sortlist_type.h" #include "../stringfilter_type.h" diff --git a/src/openttd.cpp b/src/openttd.cpp index e6c2b63cb1..e27339f0ea 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -21,6 +21,9 @@ #include "gui.h" #include "base_media_base.h" +#include "base_media_graphics.h" +#include "base_media_music.h" +#include "base_media_sounds.h" #include "saveload/saveload.h" #include "company_cmd.h" #include "company_func.h" diff --git a/src/screenshot_png.cpp b/src/screenshot_png.cpp index 1abc0fb198..116eed4883 100644 --- a/src/screenshot_png.cpp +++ b/src/screenshot_png.cpp @@ -21,6 +21,7 @@ #include "ai/ai_info.hpp" #include "company_base.h" #include "base_media_base.h" +#include "base_media_graphics.h" #endif /* PNG_TEXT_SUPPORTED */ #include "safeguards.h" diff --git a/src/settings.cpp b/src/settings.cpp index a39b82fdc9..cb75b27f1c 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -46,6 +46,7 @@ #include "newgrf_config.h" #include "picker_func.h" #include "base_media_base.h" +#include "base_media_graphics.h" #include "fios.h" #include "fileio_func.h" #include "settings_cmd.h" diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 4394d540de..f7b5bb8e41 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -25,6 +25,9 @@ #include "slider_func.h" #include "highscore.h" #include "base_media_base.h" +#include "base_media_graphics.h" +#include "base_media_music.h" +#include "base_media_sounds.h" #include "company_base.h" #include "company_func.h" #include "viewport_func.h" diff --git a/src/settings_table.cpp b/src/settings_table.cpp index 9df8ff8065..6412253fad 100644 --- a/src/settings_table.cpp +++ b/src/settings_table.cpp @@ -39,6 +39,8 @@ #include "music/music_driver.hpp" #include "blitter/factory.hpp" #include "base_media_base.h" +#include "base_media_music.h" +#include "base_media_sounds.h" #include "ai/ai_config.hpp" #include "ai/ai.hpp" #include "game/game_config.hpp" diff --git a/src/sound.cpp b/src/sound.cpp index 5960ee02d5..965fea6102 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -21,6 +21,7 @@ /* The type of set we're replacing */ #define SET_TYPE "sounds" #include "base_media_func.h" +#include "base_media_sounds.h" #include "safeguards.h" diff --git a/src/survey.cpp b/src/survey.cpp index b5e3aa9833..838a702fb1 100644 --- a/src/survey.cpp +++ b/src/survey.cpp @@ -32,6 +32,9 @@ #include "video/video_driver.hpp" #include "base_media_base.h" +#include "base_media_graphics.h" +#include "base_media_music.h" +#include "base_media_sounds.h" #include "blitter/factory.hpp" #include "social_integration.h"