1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2025-12-10 06:52:05 +01:00

Codechange: make all Providers fully const (Font/Screenshot/Sound)

This commit is contained in:
Rubidium
2025-09-29 21:16:42 +02:00
committed by rubidium42
parent dcc3a67752
commit aa7eb089c6
15 changed files with 23 additions and 23 deletions

View File

@@ -229,8 +229,8 @@ public:
ProviderManager<FontCacheFactory>::Unregister(*this); ProviderManager<FontCacheFactory>::Unregister(*this);
} }
virtual std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) = 0; virtual std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) const = 0;
virtual bool FindFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, class MissingGlyphSearcher *callback) = 0; virtual bool FindFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, class MissingGlyphSearcher *callback) const = 0;
}; };
class FontProviderManager : ProviderManager<FontCacheFactory> { class FontProviderManager : ProviderManager<FontCacheFactory> {

View File

@@ -225,7 +225,7 @@ public:
* format is 'font family name' or 'font family name, font style'. * format is 'font family name' or 'font family name, font style'.
* @param fs The font size to load. * @param fs The font size to load.
*/ */
std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) override std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) const override
{ {
if (fonttype != FontType::TrueType) return nullptr; if (fonttype != FontType::TrueType) return nullptr;
@@ -271,7 +271,7 @@ public:
return LoadFont(fs, face, font, GetFontCacheFontSize(fs)); 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 #ifdef WITH_FONTCONFIG
if (FontConfigFindFallbackFont(settings, language_isocode, callback)) return true; if (FontConfigFindFallbackFont(settings, language_isocode, callback)) return true;

View File

@@ -157,14 +157,14 @@ class SpriteFontCacheFactory : public FontCacheFactory {
public: public:
SpriteFontCacheFactory() : FontCacheFactory("sprite", "Sprite font provider") {} SpriteFontCacheFactory() : FontCacheFactory("sprite", "Sprite font provider") {}
std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) override std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) const override
{ {
if (fonttype != FontType::Sprite) return nullptr; if (fonttype != FontType::Sprite) return nullptr;
return std::make_unique<SpriteFontCache>(fs); return std::make_unique<SpriteFontCache>(fs);
} }
bool FindFallbackFont(struct FontCacheSettings *, const std::string &, class MissingGlyphSearcher *) override bool FindFallbackFont(struct FontCacheSettings *, const std::string &, class MissingGlyphSearcher *) const override
{ {
return false; return false;
} }

View File

@@ -211,7 +211,7 @@ public:
* fallback search, use it. Otherwise, try to resolve it by font name. * fallback search, use it. Otherwise, try to resolve it by font name.
* @param fs The font size to load. * @param fs The font size to load.
*/ */
std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) override std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) const override
{ {
if (fonttype != FontType::TrueType) return nullptr; if (fonttype != FontType::TrueType) return nullptr;
@@ -259,7 +259,7 @@ public:
return std::make_unique<CoreTextFontCache>(fs, std::move(font_ref), GetFontCacheFontSize(fs)); return std::make_unique<CoreTextFontCache>(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 /* Determine fallback font using CoreText. This uses the language isocode
* to find a suitable font. CoreText is available from 10.5 onwards. */ * to find a suitable font. CoreText is available from 10.5 onwards. */

View File

@@ -276,7 +276,7 @@ public:
* fallback search, use it. Otherwise, try to resolve it by font name. * fallback search, use it. Otherwise, try to resolve it by font name.
* @param fs The font size to load. * @param fs The font size to load.
*/ */
std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) override std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) const override
{ {
if (fonttype != FontType::TrueType) return nullptr; if (fonttype != FontType::TrueType) return nullptr;
@@ -308,7 +308,7 @@ public:
return LoadWin32Font(fs, logfont, GetFontCacheFontSize(fs), font); 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"); Debug(fontcache, 1, "Trying fallback fonts");
EFCParam langInfo; EFCParam langInfo;

View File

@@ -25,7 +25,7 @@ public:
ProviderManager &operator=(ProviderManager const &) = delete; ProviderManager &operator=(ProviderManager const &) = delete;
static void Register(TProviderType &instance) static void Register(const TProviderType &instance)
{ {
/* Insert according to comparator. */ /* Insert according to comparator. */
auto &providers = GetProviders(); auto &providers = GetProviders();
@@ -33,7 +33,7 @@ public:
providers.insert(it, &instance); providers.insert(it, &instance);
} }
static void Unregister(TProviderType &instance) static void Unregister(const TProviderType &instance)
{ {
auto &providers = GetProviders(); auto &providers = GetProviders();
providers.erase(std::find(std::begin(providers), std::end(providers), &instance)); providers.erase(std::find(std::begin(providers), std::end(providers), &instance));
@@ -43,9 +43,9 @@ public:
* Get the currently known providers. * Get the currently known providers.
* @return The known providers. * @return The known providers.
*/ */
static std::vector<TProviderType *> &GetProviders() static std::vector<const TProviderType *> &GetProviders()
{ {
static std::vector<TProviderType *> providers{}; static std::vector<const TProviderType *> providers{};
return providers; return providers;
} }
}; };

View File

@@ -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. * If the selected provider is not found, then the first provider will be used instead.
* @returns ScreenshotProvider, or null if none exist. * @returns ScreenshotProvider, or null if none exist.
*/ */
static ScreenshotProvider *GetScreenshotProvider() static const ScreenshotProvider *GetScreenshotProvider()
{ {
const auto &providers = ProviderManager<ScreenshotProvider>::GetProviders(); const auto &providers = ProviderManager<ScreenshotProvider>::GetProviders();
if (providers.empty()) return nullptr; if (providers.empty()) return nullptr;

View File

@@ -43,7 +43,7 @@ class ScreenshotProvider_Bmp : public ScreenshotProvider {
public: public:
ScreenshotProvider_Bmp() : ScreenshotProvider("bmp", "BMP", 10) {} 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 uint bpp; // bytes per pixel
switch (pixelformat) { switch (pixelformat) {

View File

@@ -41,7 +41,7 @@ class ScreenshotProvider_Pcx : public ScreenshotProvider {
public: public:
ScreenshotProvider_Pcx() : ScreenshotProvider("pcx", "PCX", 20) {} 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 maxlines;
uint y; uint y;

View File

@@ -31,7 +31,7 @@ class ScreenshotProvider_Png : public ScreenshotProvider {
public: public:
ScreenshotProvider_Png() : ScreenshotProvider("png", "PNG", 0) {} 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]; png_color rq[256];
uint i, y, n; uint i, y, n;

View File

@@ -36,7 +36,7 @@ public:
ProviderManager<ScreenshotProvider>::Unregister(*this); ProviderManager<ScreenshotProvider>::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 */ #endif /* SCREENSHOT_TYPE_H */

View File

@@ -34,7 +34,7 @@ public:
static constexpr size_t DECODE_BUFFER_SAMPLES = 5760 * 2; static constexpr size_t DECODE_BUFFER_SAMPLES = 5760 * 2;
static constexpr size_t DECODE_BUFFER_BYTES = DECODE_BUFFER_SAMPLES * sizeof(opus_int16); static constexpr size_t DECODE_BUFFER_BYTES = DECODE_BUFFER_SAMPLES * sizeof(opus_int16);
bool Load(SoundEntry &sound, bool new_format, std::vector<std::byte> &data) override bool Load(SoundEntry &sound, bool new_format, std::vector<std::byte> &data) const override
{ {
if (!new_format) return false; if (!new_format) return false;

View File

@@ -22,7 +22,7 @@ public:
static constexpr uint16_t RAW_SAMPLE_RATE = 11025; ///< Sample rate of raw pcm samples. 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. static constexpr uint8_t RAW_SAMPLE_BITS = 8; ///< Bit depths of raw pcm samples.
bool Load(SoundEntry &sound, bool new_format, std::vector<std::byte> &data) override bool Load(SoundEntry &sound, bool new_format, std::vector<std::byte> &data) const override
{ {
/* Raw sounds are apecial case for the jackhammer sound (name in Windows sample.cat is "Corrupt sound") /* 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. * It's not a RIFF file, but raw PCM data.

View File

@@ -26,7 +26,7 @@ public:
ProviderManager<SoundLoader>::Unregister(*this); ProviderManager<SoundLoader>::Unregister(*this);
} }
virtual bool Load(SoundEntry &sound, bool new_format, std::vector<std::byte> &data) = 0; virtual bool Load(SoundEntry &sound, bool new_format, std::vector<std::byte> &data) const = 0;
}; };
#endif /* SOUNDLOADER_TYPE_H */ #endif /* SOUNDLOADER_TYPE_H */

View File

@@ -23,7 +23,7 @@ public:
static constexpr uint16_t DEFAULT_SAMPLE_RATE = 11025; static constexpr uint16_t DEFAULT_SAMPLE_RATE = 11025;
bool Load(SoundEntry &sound, bool new_format, std::vector<std::byte> &data) override bool Load(SoundEntry &sound, bool new_format, std::vector<std::byte> &data) const override
{ {
RandomAccessFile &file = *sound.file; RandomAccessFile &file = *sound.file;