OpenTTD Source 20260218-master-g2123fca5ea
gfxinit.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "stdafx.h"
11#include "fios.h"
12#include "newgrf.h"
13#include "3rdparty/md5/md5.h"
14#include "fontcache.h"
15#include "gfx_func.h"
16#include "transparency.h"
17#include "blitter/factory.hpp"
19#include "window_func.h"
20#include "palette_func.h"
21#include "base_media_func.h"
22#include "base_media_graphics.h"
23#include "base_media_sounds.h"
24
25#include "table/sprites.h"
26
27#include "safeguards.h"
28
30
32static constexpr std::span<const std::pair<SpriteID, SpriteID>> _landscape_spriteindexes[] = {
33 _landscape_spriteindexes_arctic,
34 _landscape_spriteindexes_tropic,
35 _landscape_spriteindexes_toyland,
36};
37
45static uint LoadGrfFile(const std::string &filename, SpriteID load_index, bool needs_palette_remap)
46{
47 SpriteID load_index_org = load_index;
48 SpriteID sprite_id = 0;
49
50 SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
51
52 Debug(sprite, 2, "Reading grf-file '{}'", filename);
53
54 uint8_t container_ver = file.GetContainerVersion();
55 if (container_ver == 0) UserError("Base grf '{}' is corrupt", filename);
57 if (container_ver >= 2) {
58 /* Read compression. */
59 uint8_t compression = file.ReadByte();
60 if (compression != 0) UserError("Unsupported compression format");
61 }
62
63 while (LoadNextSprite(load_index, file, sprite_id)) {
64 load_index++;
65 sprite_id++;
66 if (load_index >= MAX_SPRITES) {
67 UserError("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files.");
68 }
69 }
70 Debug(sprite, 2, "Currently {} sprites are loaded", load_index);
71
72 return load_index - load_index_org;
73}
74
81static void LoadGrfFileIndexed(const std::string &filename, std::span<const std::pair<SpriteID, SpriteID>> index_tbl, bool needs_palette_remap)
82{
83 uint sprite_id = 0;
84
85 SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
86
87 Debug(sprite, 2, "Reading indexed grf-file '{}'", filename);
88
89 uint8_t container_ver = file.GetContainerVersion();
90 if (container_ver == 0) UserError("Base grf '{}' is corrupt", filename);
92 if (container_ver >= 2) {
93 /* Read compression. */
94 uint8_t compression = file.ReadByte();
95 if (compression != 0) UserError("Unsupported compression format");
96 }
97
98 for (const auto &pair : index_tbl) {
99 for (SpriteID load_index = pair.first; load_index <= pair.second; ++load_index) {
100 [[maybe_unused]] bool b = LoadNextSprite(load_index, file, sprite_id);
101 assert(b);
102 sprite_id++;
103 }
104 }
105}
106
113{
114 if (BaseGraphics::GetUsedSet() == nullptr || BaseSounds::GetUsedSet() == nullptr) return;
115
116 const GraphicsSet *used_set = BaseGraphics::GetUsedSet();
117
118 Debug(grf, 1, "Using the {} base graphics set", used_set->name);
119
120 std::string error_msg;
121 auto output_iterator = std::back_inserter(error_msg);
122 if (used_set->GetNumInvalid() != 0) {
123 /* Not all files were loaded successfully, see which ones */
124 fmt::format_to(output_iterator, "Trying to load graphics set '{}', but it is incomplete. The game will probably not run correctly until you properly install this set or select another one. See section 1.4 of README.md.\n\nThe following files are corrupted or missing:\n", used_set->name);
125 for (const auto &file : used_set->files) {
127 if (res != MD5File::CR_MATCH) fmt::format_to(output_iterator, "\t{} is {} ({})\n", file.filename, res == MD5File::CR_MISMATCH ? "corrupt" : "missing", file.missing_warning);
128 }
129 fmt::format_to(output_iterator, "\n");
130 }
131
132 const SoundsSet *sounds_set = BaseSounds::GetUsedSet();
133 if (sounds_set->GetNumInvalid() != 0) {
134 fmt::format_to(output_iterator, "Trying to load sound set '{}', but it is incomplete. The game will probably not run correctly until you properly install this set or select another one. See section 1.4 of README.md.\n\nThe following files are corrupted or missing:\n", sounds_set->name);
135
136 static_assert(SoundsSet::NUM_FILES == 1);
137 /* No need to loop each file, as long as there is only a single
138 * sound file. */
139 fmt::format_to(output_iterator, "\t{} is {} ({})\n", sounds_set->files[0].filename, SoundsSet::CheckMD5(&sounds_set->files[0], BASESET_DIR) == MD5File::CR_MISMATCH ? "corrupt" : "missing", sounds_set->files[0].missing_warning);
140 }
141
142 if (!error_msg.empty()) ShowInfoI(error_msg);
143}
144
149static std::unique_ptr<GRFConfig> GetDefaultExtraGRFConfig()
150{
151 auto gc = std::make_unique<GRFConfig>("OPENTTD.GRF");
152 gc->palette |= GRFP_GRF_DOS;
153 FillGRFDetails(*gc, false, BASESET_DIR);
154 gc->flags.Reset(GRFConfigFlag::InitOnly);
155 return gc;
156}
157
162static std::unique_ptr<GRFConfig> GetBasesetExtraGRFConfig()
163{
164 auto gc = std::make_unique<GRFConfig>(BaseGraphics::GetUsedSet()->GetOrCreateExtraConfig());
165 if (gc->param.empty()) gc->SetParameterDefaults();
166 gc->flags.Reset(GRFConfigFlag::InitOnly);
167 return gc;
168}
169
171static void LoadSpriteTables()
172{
173 const GraphicsSet *used_set = BaseGraphics::GetUsedSet();
174
175 LoadGrfFile(used_set->files[GFT_BASE].filename, 0, PAL_DOS != used_set->palette);
176
177 /*
178 * The second basic file always starts at the given location and does
179 * contain a different amount of sprites depending on the "type"; DOS
180 * has a few sprites less. However, we do not care about those missing
181 * sprites as they are not shown anyway (logos in intro game).
182 */
183 LoadGrfFile(used_set->files[GFT_LOGOS].filename, 4793, PAL_DOS != used_set->palette);
184
185 /*
186 * Load additional sprites for climates other than temperate.
187 * This overwrites some of the temperate sprites, such as foundations
188 * and the ground sprites.
189 */
190 if (_settings_game.game_creation.landscape != LandscapeType::Temperate) {
192 used_set->files[GFT_ARCTIC + to_underlying(_settings_game.game_creation.landscape) - 1].filename,
193 _landscape_spriteindexes[to_underlying(_settings_game.game_creation.landscape) - 1],
194 PAL_DOS != used_set->palette
195 );
196 }
197
198 /* Initialize the unicode to sprite mapping table */
200
201 /*
202 * Load the base and extra NewGRF with OTTD required graphics as first NewGRF.
203 * However, we do not want it to show up in the list of used NewGRFs,
204 * so we have to manually add it, and then remove it later.
205 */
206
207 auto default_extra = GetDefaultExtraGRFConfig();
208 auto baseset_extra = GetBasesetExtraGRFConfig();
209 std::string default_filename = default_extra->filename;
210
211 _grfconfig.insert(std::begin(_grfconfig), std::move(default_extra));
212 _grfconfig.insert(std::next(std::begin(_grfconfig)), std::move(baseset_extra));
213
214 LoadNewGRF(SPR_NEWGRFS_BASE, 2);
215
216 uint total_extra_graphics = SPR_NEWGRFS_BASE - SPR_OPENTTD_BASE;
217 Debug(sprite, 4, "Checking sprites from fallback grf");
218 _missing_extra_graphics = GetSpriteCountForFile(default_filename, SPR_OPENTTD_BASE, SPR_NEWGRFS_BASE);
219 Debug(sprite, 1, "{} extra sprites, {} from baseset, {} from fallback", total_extra_graphics, total_extra_graphics - _missing_extra_graphics, _missing_extra_graphics);
220
221 /* The original baseset extra graphics intentionally make use of the fallback graphics.
222 * Let's say everything which provides less than 500 sprites misses the rest intentionally. */
223 if (500 + _missing_extra_graphics > total_extra_graphics) _missing_extra_graphics = 0;
224
225 /* Remove the default and baseset extra graphics from the config. */
226 _grfconfig.erase(std::begin(_grfconfig), std::next(std::begin(_grfconfig), 2));
227}
228
229
230static void RealChangeBlitter(std::string_view repl_blitter)
231{
232 std::string_view cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName();
233 if (cur_blitter == repl_blitter) return;
234
235 Debug(driver, 1, "Switching blitter from '{}' to '{}'... ", cur_blitter, repl_blitter);
236 Blitter *new_blitter = BlitterFactory::SelectBlitter(repl_blitter);
237 if (new_blitter == nullptr) NOT_REACHED();
238 Debug(driver, 1, "Successfully switched to {}.", repl_blitter);
239
240 if (!VideoDriver::GetInstance()->AfterBlitterChange()) {
241 /* Failed to switch blitter, let's hope we can return to the old one. */
242 if (BlitterFactory::SelectBlitter(cur_blitter) == nullptr || !VideoDriver::GetInstance()->AfterBlitterChange()) UserError("Failed to reinitialize video driver. Specify a fixed blitter in the config");
243 }
244
245 /* Clear caches that might have sprites for another blitter. */
249 ReInitAllWindows(false);
250}
251
257{
258 /* Never switch if the blitter was specified by the user. */
259 if (!_blitter_autodetected) return false;
260
261 /* Null driver => dedicated server => do nothing. */
262 if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) return false;
263
264 /* Get preferred depth.
265 * - depth_wanted_by_base: Depth required by the baseset, i.e. the majority of the sprites.
266 * - depth_wanted_by_grf: Depth required by some NewGRF.
267 * Both can force using a 32bpp blitter. depth_wanted_by_base is used to select
268 * between multiple 32bpp blitters, which perform differently with 8bpp sprites.
269 */
270 uint depth_wanted_by_base = BaseGraphics::GetUsedSet()->blitter == BLT_32BPP ? 32 : 8;
271 uint depth_wanted_by_grf = _support8bpp != S8BPP_NONE ? 8 : 32;
272 for (const auto &c : _grfconfig) {
273 if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND || c->flags.Test(GRFConfigFlag::InitOnly)) continue;
274 if (c->palette & GRFP_BLT_32BPP) depth_wanted_by_grf = 32;
275 }
276 /* We need a 32bpp blitter for font anti-alias. */
277 if (GetFontAAState()) depth_wanted_by_grf = 32;
278
279 /* Search the best blitter. */
280 static const struct {
281 const std::string_view name;
282 uint animation;
283 uint min_base_depth, max_base_depth, min_grf_depth, max_grf_depth;
284 } replacement_blitters[] = {
285 { "8bpp-optimized", 2, 8, 8, 8, 8 },
286 { "40bpp-anim", 2, 8, 32, 8, 32 },
287#ifdef WITH_SSE
288 { "32bpp-sse4", 0, 32, 32, 8, 32 },
289 { "32bpp-ssse3", 0, 32, 32, 8, 32 },
290 { "32bpp-sse2", 0, 32, 32, 8, 32 },
291 { "32bpp-sse4-anim", 1, 32, 32, 8, 32 },
292#endif
293 { "32bpp-optimized", 0, 8, 32, 8, 32 },
294#ifdef WITH_SSE
295 { "32bpp-sse2-anim", 1, 8, 32, 8, 32 },
296#endif
297 { "32bpp-anim", 1, 8, 32, 8, 32 },
298 };
299
300 const bool animation_wanted = HasBit(_display_opt, DO_FULL_ANIMATION);
301 std::string_view cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName();
302
303 for (const auto &replacement_blitter : replacement_blitters) {
304 if (animation_wanted && (replacement_blitter.animation == 0)) continue;
305 if (!animation_wanted && (replacement_blitter.animation == 1)) continue;
306
307 if (!IsInsideMM(depth_wanted_by_base, replacement_blitter.min_base_depth, replacement_blitter.max_base_depth + 1)) continue;
308 if (!IsInsideMM(depth_wanted_by_grf, replacement_blitter.min_grf_depth, replacement_blitter.max_grf_depth + 1)) continue;
309
310 if (replacement_blitter.name == cur_blitter) {
311 return false;
312 }
313 if (BlitterFactory::GetBlitterFactory(replacement_blitter.name) == nullptr) continue;
314
315 /* Inform the video driver we want to switch blitter as soon as possible. */
316 VideoDriver::GetInstance()->QueueOnMainThread(std::bind(&RealChangeBlitter, replacement_blitter.name));
317 break;
318 }
319
320 return true;
321}
322
332
335{
336 Debug(sprite, 2, "Loading sprite set {}", _settings_game.game_creation.landscape);
337
341 GfxInitSpriteMem();
343 GfxInitPalettes();
344
346}
347
348/* instantiate here, because unique_ptr needs a complete type */
349GraphicsSet::GraphicsSet() = default;
350
351/* instantiate here, because unique_ptr needs a complete type */
352GraphicsSet::~GraphicsSet() = default;
353
354bool GraphicsSet::FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename)
355{
356 if (!this->BaseSet<GraphicsSet>::FillSetDetails(ini, path, full_filename, false)) return false;
357
358 const IniGroup *metadata = ini.GetGroup("metadata");
359 assert(metadata != nullptr); /* already checked by the inherited FillSetDetails. */
360 const IniItem *item;
361
362 item = this->GetMandatoryItem(full_filename, *metadata, "palette");
363 if (item == nullptr) return false;
364 this->palette = ((*item->value)[0] == 'D' || (*item->value)[0] == 'd') ? PAL_DOS : PAL_WINDOWS;
365
366 /* Get optional blitter information. */
367 item = metadata->GetItem("blitter");
368 this->blitter = (item != nullptr && (*item->value)[0] == '3') ? BLT_32BPP : BLT_8BPP;
369
370 return true;
371}
372
378{
379 if (!this->extra_cfg) {
380 this->extra_cfg = std::make_unique<GRFConfig>(this->files[GFT_EXTRA].filename);
381
382 /* We know the palette of the base set, so if the base NewGRF is not
383 * setting one, use the palette of the base set and not the global
384 * one which might be the wrong palette for this base NewGRF.
385 * The value set here might be overridden via action14 later. */
386 switch (this->palette) {
387 case PAL_DOS: this->extra_cfg->palette |= GRFP_GRF_DOS; break;
388 case PAL_WINDOWS: this->extra_cfg->palette |= GRFP_GRF_WINDOWS; break;
389 default: break;
390 }
391 FillGRFDetails(*this->extra_cfg, false, BASESET_DIR);
392 }
393 return *this->extra_cfg;
394}
395
396bool GraphicsSet::IsConfigurable() const
397{
398 const GRFConfig &cfg = this->GetOrCreateExtraConfig();
399 /* This check is more strict than the one for NewGRF Settings.
400 * There are no legacy basesets with parameters, but without Action14 */
401 return !cfg.param_info.empty();
402}
403
404void GraphicsSet::CopyCompatibleConfig(const GraphicsSet &src)
405{
406 const GRFConfig *src_cfg = src.GetExtraConfig();
407 if (src_cfg == nullptr || src_cfg->param.empty()) return;
408 GRFConfig &dest_cfg = this->GetOrCreateExtraConfig();
409 if (dest_cfg.IsCompatible(src_cfg->version)) return;
410 dest_cfg.CopyParams(*src_cfg);
411}
412
423{
424 size_t size = 0;
425 auto f = FioFOpenFile(file->filename, "rb", subdir, &size);
426 if (!f.has_value()) return MD5File::CR_NO_FILE;
427
428 size_t max = GRFGetSizeOfDataSection(*f);
429
430 return file->CheckMD5(subdir, max);
431}
432
433
444{
445 size_t size;
446 auto f = FioFOpenFile(this->filename, "rb", subdir, &size);
447 if (!f.has_value()) return CR_NO_FILE;
448
449 size = std::min(size, max_size);
450
451 Md5 checksum;
452 uint8_t buffer[1024];
453 MD5Hash digest;
454 size_t len;
455
456 while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, *f)) != 0 && size != 0) {
457 size -= len;
458 checksum.Append(buffer, len);
459 }
460
461 checksum.Finish(digest);
462 return this->hash == digest ? CR_MATCH : CR_MISMATCH;
463}
464
466static const std::string_view _graphics_file_names[] = { "base", "logos", "arctic", "tropical", "toyland", "extra" };
467
468/* Implementation */
469
471template <>
472/* static */ std::span<const std::string_view> BaseSet<GraphicsSet>::GetFilenames()
473{
475}
476
477template <>
479{
480 if (BaseMedia<GraphicsSet>::used_set != nullptr) return true;
481
482 const GraphicsSet *best = nullptr;
483
484 auto IsBetter = [&best] (const GraphicsSet *current) {
485 /* Nothing chosen yet. */
486 if (best == nullptr) return true;
487 /* Not being a fallback is better. */
488 if (best->fallback && !current->fallback) return true;
489 /* Having more valid files is better. */
490 if (best->valid_files < current->valid_files) return true;
491 /* Having (essentially) fewer valid files is worse. */
492 if (best->valid_files != current->valid_files) return false;
493 /* Having a later version of the same base set is better. */
494 if (best->shortname == current->shortname && best->version < current->version) return true;
495 /* The DOS palette is the better palette. */
496 return best->palette != PAL_DOS && current->palette == PAL_DOS;
497 };
498
499 for (const auto &c : BaseMedia<GraphicsSet>::available_sets) {
500 /* Skip unusable sets */
501 if (c->GetNumMissing() != 0) continue;
502
503 if (IsBetter(c.get())) best = c.get();
504 }
505
507 return BaseMedia<GraphicsSet>::used_set != nullptr;
508}
509
510template <>
511/* static */ std::string_view BaseMedia<GraphicsSet>::GetExtension()
512{
513 return ".obg"; // OpenTTD Base Graphics
514}
515
516template class BaseMedia<GraphicsSet>;
Generic function implementations for base data (graphics, sounds).
Generic functions for replacing base graphics data.
@ BLT_32BPP
Base set has both 8 bpp and 32 bpp sprites.
@ BLT_8BPP
Base set has 8 bpp sprites only.
@ GFT_LOGOS
Logos, landscape icons and original terrain generator sprites.
@ GFT_EXTRA
Extra sprites that were not part of the original sprites.
@ GFT_ARCTIC
Landscape replacement sprites for arctic.
@ GFT_BASE
Base sprites for all climates.
Generic functions for replacing base sounds data.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Base for all base media (graphics, sounds).
static const GraphicsSet * GetUsedSet()
static std::vector< std::unique_ptr< Tbase_set > > available_sets
All available sets.
static const Tbase_set * used_set
The currently used set.
static bool DetermineBestSet()
Determine the graphics pack that has to be used.
static std::string_view GetExtension()
Get the extension that is used to identify this set.
static BlitterFactory * GetBlitterFactory(std::string_view name)
Get the blitter factory with the given name.
Definition factory.hpp:113
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition factory.hpp:138
static Blitter * SelectBlitter(std::string_view name)
Find the requested blitter and return its class.
Definition factory.hpp:97
How all blitters should look like.
Definition base.hpp:29
virtual std::string_view GetName()=0
Get the name of the blitter, the same as the Factory-instance returns.
static void ClearFontCaches(FontSizes fontsizes)
Clear cached information for the specified font caches.
uint8_t ReadByte()
Read a byte from the file.
RandomAccessFile with some extra information specific for sprite files.
uint8_t GetContainerVersion() const
Get the version number of container type used by the file.
void QueueOnMainThread(std::function< void()> &&func)
Queue a function to be called on the main thread with game state lock held and video buffer locked.
virtual void ClearSystemSprites()
Clear all cached sprites.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Definition debug.h:37
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
Factory to 'query' all available blitters.
bool _blitter_autodetected
Was the blitter autodetected or specified by the user?
Definition driver.cpp:37
std::optional< FileHandle > FioFOpenFile(std::string_view filename, std::string_view mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Definition fileio.cpp:244
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition fileio_type.h:88
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game).
Definition fileio_type.h:96
Declarations for savegames operations.
Functions to read fonts from files and cache them.
void InitializeUnicodeGlyphMap()
Initialize the glyph map.
void UpdateCursorSize()
Update cursor dimension.
Definition gfx.cpp:1623
Functions related to the gfx engine.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ S8BPP_NONE
No support for 8bpp by OS or hardware, force 32bpp blitters.
Definition gfx_type.h:381
constexpr FontSizes FONTSIZES_ALL
Mask of all possible font sizes.
Definition gfx_type.h:262
@ PAL_DOS
Use the DOS palette.
Definition gfx_type.h:352
@ PAL_WINDOWS
Use the Windows palette.
Definition gfx_type.h:353
static std::unique_ptr< GRFConfig > GetDefaultExtraGRFConfig()
Get GRFConfig for the default extra graphics.
Definition gfxinit.cpp:149
static std::unique_ptr< GRFConfig > GetBasesetExtraGRFConfig()
Get GRFConfig for the baseset extra graphics.
Definition gfxinit.cpp:162
static void LoadSpriteTables()
Actually load the sprite tables.
Definition gfxinit.cpp:171
static bool SwitchNewGRFBlitter()
Check blitter needed by NewGRF config and switch if needed.
Definition gfxinit.cpp:256
void CheckBlitter()
Check whether we still use the right blitter, or use another (better) one.
Definition gfxinit.cpp:324
static const std::string_view _graphics_file_names[]
Names corresponding to the GraphicsFileType.
Definition gfxinit.cpp:466
static constexpr std::span< const std::pair< SpriteID, SpriteID > > _landscape_spriteindexes[]
Offsets for loading the different "replacement" sprites in the files.
Definition gfxinit.cpp:32
static void LoadGrfFileIndexed(const std::string &filename, std::span< const std::pair< SpriteID, SpriteID > > index_tbl, bool needs_palette_remap)
Load an old fashioned GRF file to replace already loaded sprites.
Definition gfxinit.cpp:81
static uint LoadGrfFile(const std::string &filename, SpriteID load_index, bool needs_palette_remap)
Load an old fashioned GRF file.
Definition gfxinit.cpp:45
void CheckExternalFiles()
Checks whether the MD5 checksums of the files are correct.
Definition gfxinit.cpp:112
void GfxLoadSprites()
Initialise and load all the sprites.
Definition gfxinit.cpp:334
Offsets of sprites to replace for non-temperate landscapes.
@ Temperate
Base landscape.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
void LoadNewGRF(SpriteID load_index, uint num_baseset)
Load all the NewGRFs.
Definition newgrf.cpp:1758
Base for the NewGRF implementation.
GRFConfigList _grfconfig
First item in list of current GRF set up.
uint _missing_extra_graphics
Number of sprites provided by the fallback extra GRF, i.e. missing in the baseset.
bool FillGRFDetails(GRFConfig &config, bool is_static, Subdirectory subdir)
Find the GRFID of a given grf, and calculate its md5sum.
size_t GRFGetSizeOfDataSection(FileHandle &f)
Get the data section size of a GRF.
@ GCS_DISABLED
GRF file is disabled.
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
@ InitOnly
GRF file is processed up to GLS_INIT.
@ GRFP_GRF_WINDOWS
The NewGRF says the Windows palette can be used.
@ GRFP_GRF_DOS
The NewGRF says the DOS palette can be used.
@ GRFP_BLT_32BPP
The NewGRF prefers a 32 bpp blitter.
@ DO_FULL_ANIMATION
Perform palette animation.
Definition openttd.h:49
Functions related to palettes.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information.
uint GetSpriteCountForFile(const std::string &filename, SpriteID begin, SpriteID end)
Count the sprites which originate from a specific file in a range of SpriteIDs.
SpriteFile & OpenCachedSpriteFile(const std::string &filename, Subdirectory subdir, bool palette_remap)
Open/get the SpriteFile that is cached for use in the sprite cache.
bool LoadNextSprite(SpriteID load_index, SpriteFile &file, uint file_sprite_id)
Load a real or recolour sprite.
void ReadGRFSpriteOffsets(SpriteFile &file)
Parse the sprite section of GRFs.
This file contains all sprite-related enums and defines.
static constexpr uint32_t MAX_SPRITES
Masks needed for sprite operations.
Definition sprites.h:1569
static const SpriteID SPR_OPENTTD_BASE
Extra graphic spritenumbers.
Definition sprites.h:56
Definition of base types and functions in a cross-platform compatible way.
std::array< MD5File, BaseSet< T >::NUM_FILES > files
All files part of this set.
uint valid_files
Number of the files that could be found and are valid.
const IniItem * GetMandatoryItem(std::string_view full_filename, const IniGroup &group, std::string_view name) const
static constexpr size_t NUM_FILES
static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir)
static std::span< const std::string_view > GetFilenames()
Get the internal names of the files in this set.
std::string name
The name of the base set.
bool fallback
This set is a fallback set, i.e. it should be used only as last resort.
bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename, bool allow_empty_filename=true)
Read the set information from a loaded ini.
std::vector< uint32_t > version
The version of this base set.
uint32_t shortname
Four letter short variant of the name.
int GetNumInvalid() const
Get the number of invalid files.
Information about GRF, used in the game and (part of it) in savegames.
std::vector< std::optional< GRFParameterInfo > > param_info
NOSAVE: extra information about the parameters.
uint32_t version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
std::vector< uint32_t > param
GRF parameters.
bool IsCompatible(uint32_t old_version) const
Return whether this NewGRF can replace an older version of the same NewGRF.
void CopyParams(const GRFConfig &src)
Copy the parameter information from the src config.
All data of a graphics set.
std::unique_ptr< GRFConfig > extra_cfg
Parameters for extra GRF.
PaletteType palette
Palette of this graphics set.
static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir)
Calculate and check the MD5 hash of the supplied GRF.
Definition gfxinit.cpp:422
BlitterType blitter
Blitter of this graphics set.
GRFConfig & GetOrCreateExtraConfig() const
Return configuration for the extra GRF, or lazily create it.
Definition gfxinit.cpp:377
Ini file that supports both loading and saving.
Definition ini_type.h:86
const IniItem * GetItem(std::string_view name) const
Get the item with the given name.
Definition ini_load.cpp:50
std::optional< std::string > value
The value of this item.
Definition ini_type.h:25
const IniGroup * GetGroup(std::string_view name) const
Get the group with the given name.
Definition ini_load.cpp:117
Structure holding filename and MD5 information about a single file.
ChecksumResult CheckMD5(Subdirectory subdir, size_t max_size) const
Calculate and check the MD5 hash of the supplied filename.
Definition gfxinit.cpp:443
ChecksumResult
The result of a checksum check.
@ CR_MATCH
The file did exist and the md5 checksum did match.
@ CR_MISMATCH
The file did exist, just the md5 checksum did not match.
@ CR_NO_FILE
The file did not exist.
MD5Hash hash
md5 sum of the file
std::string filename
filename
All data of a sounds set.
Functions related to transparency.
uint8_t _display_opt
What do we want to draw/do?
Base of all video drivers.
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
Definition window.cpp:3424
Window functions not directly related to making/drawing windows.