From aa7eb089c6260ab96fcc2d2523f68e6242b14781 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Mon, 29 Sep 2025 21:16:42 +0200 Subject: [PATCH] Codechange: make all Providers fully const (Font/Screenshot/Sound) --- src/fontcache.h | 4 ++-- src/fontcache/freetypefontcache.cpp | 4 ++-- src/fontcache/spritefontcache.cpp | 4 ++-- src/os/macosx/font_osx.cpp | 4 ++-- src/os/windows/font_win32.cpp | 4 ++-- src/provider_manager.h | 8 ++++---- src/screenshot.cpp | 2 +- src/screenshot_bmp.cpp | 2 +- src/screenshot_pcx.cpp | 2 +- src/screenshot_png.cpp | 2 +- src/screenshot_type.h | 2 +- src/soundloader_opus.cpp | 2 +- src/soundloader_raw.cpp | 2 +- src/soundloader_type.h | 2 +- src/soundloader_wav.cpp | 2 +- 15 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/fontcache.h b/src/fontcache.h index a74e0a57b6..b03f84514d 100644 --- a/src/fontcache.h +++ b/src/fontcache.h @@ -229,8 +229,8 @@ public: ProviderManager::Unregister(*this); } - virtual std::unique_ptr LoadFont(FontSize fs, FontType fonttype) = 0; - virtual bool FindFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, class MissingGlyphSearcher *callback) = 0; + virtual std::unique_ptr LoadFont(FontSize fs, FontType fonttype) const = 0; + virtual bool FindFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, class MissingGlyphSearcher *callback) const = 0; }; class FontProviderManager : ProviderManager { diff --git a/src/fontcache/freetypefontcache.cpp b/src/fontcache/freetypefontcache.cpp index 9d52ab8f77..0e3de26877 100644 --- a/src/fontcache/freetypefontcache.cpp +++ b/src/fontcache/freetypefontcache.cpp @@ -225,7 +225,7 @@ public: * format is 'font family name' or 'font family name, font style'. * @param fs The font size to load. */ - std::unique_ptr LoadFont(FontSize fs, FontType fonttype) override + std::unique_ptr LoadFont(FontSize fs, FontType fonttype) const override { if (fonttype != FontType::TrueType) return nullptr; @@ -271,7 +271,7 @@ public: return LoadFont(fs, face, font, GetFontCacheFontSize(fs)); } - bool FindFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, class MissingGlyphSearcher *callback) override + bool FindFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, class MissingGlyphSearcher *callback) const override { #ifdef WITH_FONTCONFIG if (FontConfigFindFallbackFont(settings, language_isocode, callback)) return true; diff --git a/src/fontcache/spritefontcache.cpp b/src/fontcache/spritefontcache.cpp index a1c2f29770..0ed1cff34e 100644 --- a/src/fontcache/spritefontcache.cpp +++ b/src/fontcache/spritefontcache.cpp @@ -157,14 +157,14 @@ class SpriteFontCacheFactory : public FontCacheFactory { public: SpriteFontCacheFactory() : FontCacheFactory("sprite", "Sprite font provider") {} - std::unique_ptr LoadFont(FontSize fs, FontType fonttype) override + std::unique_ptr LoadFont(FontSize fs, FontType fonttype) const override { if (fonttype != FontType::Sprite) return nullptr; return std::make_unique(fs); } - bool FindFallbackFont(struct FontCacheSettings *, const std::string &, class MissingGlyphSearcher *) override + bool FindFallbackFont(struct FontCacheSettings *, const std::string &, class MissingGlyphSearcher *) const override { return false; } diff --git a/src/os/macosx/font_osx.cpp b/src/os/macosx/font_osx.cpp index 20c24f078a..e406a790b2 100644 --- a/src/os/macosx/font_osx.cpp +++ b/src/os/macosx/font_osx.cpp @@ -211,7 +211,7 @@ public: * fallback search, use it. Otherwise, try to resolve it by font name. * @param fs The font size to load. */ - std::unique_ptr LoadFont(FontSize fs, FontType fonttype) override + std::unique_ptr LoadFont(FontSize fs, FontType fonttype) const override { if (fonttype != FontType::TrueType) return nullptr; @@ -259,7 +259,7 @@ public: return std::make_unique(fs, std::move(font_ref), GetFontCacheFontSize(fs)); } - bool FindFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback) override + bool FindFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback) const override { /* Determine fallback font using CoreText. This uses the language isocode * to find a suitable font. CoreText is available from 10.5 onwards. */ diff --git a/src/os/windows/font_win32.cpp b/src/os/windows/font_win32.cpp index 7413eb70cb..da30507260 100644 --- a/src/os/windows/font_win32.cpp +++ b/src/os/windows/font_win32.cpp @@ -276,7 +276,7 @@ public: * fallback search, use it. Otherwise, try to resolve it by font name. * @param fs The font size to load. */ - std::unique_ptr LoadFont(FontSize fs, FontType fonttype) override + std::unique_ptr LoadFont(FontSize fs, FontType fonttype) const override { if (fonttype != FontType::TrueType) return nullptr; @@ -308,7 +308,7 @@ public: return LoadWin32Font(fs, logfont, GetFontCacheFontSize(fs), font); } - bool FindFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback) override + bool FindFallbackFont(FontCacheSettings *settings, const std::string &language_isocode, MissingGlyphSearcher *callback) const override { Debug(fontcache, 1, "Trying fallback fonts"); EFCParam langInfo; diff --git a/src/provider_manager.h b/src/provider_manager.h index 5ab398de34..377a17af28 100644 --- a/src/provider_manager.h +++ b/src/provider_manager.h @@ -25,7 +25,7 @@ public: ProviderManager &operator=(ProviderManager const &) = delete; - static void Register(TProviderType &instance) + static void Register(const TProviderType &instance) { /* Insert according to comparator. */ auto &providers = GetProviders(); @@ -33,7 +33,7 @@ public: providers.insert(it, &instance); } - static void Unregister(TProviderType &instance) + static void Unregister(const TProviderType &instance) { auto &providers = GetProviders(); providers.erase(std::find(std::begin(providers), std::end(providers), &instance)); @@ -43,9 +43,9 @@ public: * Get the currently known providers. * @return The known providers. */ - static std::vector &GetProviders() + static std::vector &GetProviders() { - static std::vector providers{}; + static std::vector providers{}; return providers; } }; diff --git a/src/screenshot.cpp b/src/screenshot.cpp index c12693c5a4..d06db8b154 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -46,7 +46,7 @@ uint _heightmap_highest_peak; ///< When saving a heightmap, this contain * If the selected provider is not found, then the first provider will be used instead. * @returns ScreenshotProvider, or null if none exist. */ -static ScreenshotProvider *GetScreenshotProvider() +static const ScreenshotProvider *GetScreenshotProvider() { const auto &providers = ProviderManager::GetProviders(); if (providers.empty()) return nullptr; diff --git a/src/screenshot_bmp.cpp b/src/screenshot_bmp.cpp index 6ad3c8dd98..260eefc6fa 100644 --- a/src/screenshot_bmp.cpp +++ b/src/screenshot_bmp.cpp @@ -43,7 +43,7 @@ class ScreenshotProvider_Bmp : public ScreenshotProvider { public: ScreenshotProvider_Bmp() : ScreenshotProvider("bmp", "BMP", 10) {} - bool MakeImage(std::string_view name, const ScreenshotCallback &callb, uint w, uint h, int pixelformat, const Colour *palette) override + bool MakeImage(std::string_view name, const ScreenshotCallback &callb, uint w, uint h, int pixelformat, const Colour *palette) const override { uint bpp; // bytes per pixel switch (pixelformat) { diff --git a/src/screenshot_pcx.cpp b/src/screenshot_pcx.cpp index e3c4c70441..024609a212 100644 --- a/src/screenshot_pcx.cpp +++ b/src/screenshot_pcx.cpp @@ -41,7 +41,7 @@ class ScreenshotProvider_Pcx : public ScreenshotProvider { public: ScreenshotProvider_Pcx() : ScreenshotProvider("pcx", "PCX", 20) {} - bool MakeImage(std::string_view name, const ScreenshotCallback &callb, uint w, uint h, int pixelformat, const Colour *palette) override + bool MakeImage(std::string_view name, const ScreenshotCallback &callb, uint w, uint h, int pixelformat, const Colour *palette) const override { uint maxlines; uint y; diff --git a/src/screenshot_png.cpp b/src/screenshot_png.cpp index c0c868bbe0..b636861b64 100644 --- a/src/screenshot_png.cpp +++ b/src/screenshot_png.cpp @@ -31,7 +31,7 @@ class ScreenshotProvider_Png : public ScreenshotProvider { public: ScreenshotProvider_Png() : ScreenshotProvider("png", "PNG", 0) {} - bool MakeImage(std::string_view name, const ScreenshotCallback &callb, uint w, uint h, int pixelformat, const Colour *palette) override + bool MakeImage(std::string_view name, const ScreenshotCallback &callb, uint w, uint h, int pixelformat, const Colour *palette) const override { png_color rq[256]; uint i, y, n; diff --git a/src/screenshot_type.h b/src/screenshot_type.h index d93f7c20bb..4859952899 100644 --- a/src/screenshot_type.h +++ b/src/screenshot_type.h @@ -36,7 +36,7 @@ public: ProviderManager::Unregister(*this); } - virtual bool MakeImage(std::string_view name, const ScreenshotCallback &callb, uint w, uint h, int pixelformat, const Colour *palette) = 0; + virtual bool MakeImage(std::string_view name, const ScreenshotCallback &callb, uint w, uint h, int pixelformat, const Colour *palette) const = 0; }; #endif /* SCREENSHOT_TYPE_H */ diff --git a/src/soundloader_opus.cpp b/src/soundloader_opus.cpp index 7bb924e9bc..79252641cf 100644 --- a/src/soundloader_opus.cpp +++ b/src/soundloader_opus.cpp @@ -34,7 +34,7 @@ public: static constexpr size_t DECODE_BUFFER_SAMPLES = 5760 * 2; static constexpr size_t DECODE_BUFFER_BYTES = DECODE_BUFFER_SAMPLES * sizeof(opus_int16); - bool Load(SoundEntry &sound, bool new_format, std::vector &data) override + bool Load(SoundEntry &sound, bool new_format, std::vector &data) const override { if (!new_format) return false; diff --git a/src/soundloader_raw.cpp b/src/soundloader_raw.cpp index 7caaf52905..2ac0efc1fb 100644 --- a/src/soundloader_raw.cpp +++ b/src/soundloader_raw.cpp @@ -22,7 +22,7 @@ public: static constexpr uint16_t RAW_SAMPLE_RATE = 11025; ///< Sample rate of raw pcm samples. static constexpr uint8_t RAW_SAMPLE_BITS = 8; ///< Bit depths of raw pcm samples. - bool Load(SoundEntry &sound, bool new_format, std::vector &data) override + bool Load(SoundEntry &sound, bool new_format, std::vector &data) const override { /* Raw sounds are apecial case for the jackhammer sound (name in Windows sample.cat is "Corrupt sound") * It's not a RIFF file, but raw PCM data. diff --git a/src/soundloader_type.h b/src/soundloader_type.h index 2f00cc8284..8c91052fd1 100644 --- a/src/soundloader_type.h +++ b/src/soundloader_type.h @@ -26,7 +26,7 @@ public: ProviderManager::Unregister(*this); } - virtual bool Load(SoundEntry &sound, bool new_format, std::vector &data) = 0; + virtual bool Load(SoundEntry &sound, bool new_format, std::vector &data) const = 0; }; #endif /* SOUNDLOADER_TYPE_H */ diff --git a/src/soundloader_wav.cpp b/src/soundloader_wav.cpp index 36897aab73..72dbf0a056 100644 --- a/src/soundloader_wav.cpp +++ b/src/soundloader_wav.cpp @@ -23,7 +23,7 @@ public: static constexpr uint16_t DEFAULT_SAMPLE_RATE = 11025; - bool Load(SoundEntry &sound, bool new_format, std::vector &data) override + bool Load(SoundEntry &sound, bool new_format, std::vector &data) const override { RandomAccessFile &file = *sound.file;