OpenTTD Source: src/gfxinit.cpp Source File

OpenTTD Source 15.3

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