OpenTTD Source  20241120-master-g6d3adc6169
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 <http://www.gnu.org/licenses/>.
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 
22 /* The type of set we're replacing */
23 #define SET_TYPE "graphics"
24 #include "base_media_func.h"
25 
26 #include "table/sprites.h"
27 
28 #include "safeguards.h"
29 
30 #include "table/landscape_sprite.h"
31 
33 static constexpr std::span<const std::pair<SpriteID, SpriteID>> _landscape_spriteindexes[] = {
34  _landscape_spriteindexes_arctic,
35  _landscape_spriteindexes_tropic,
36  _landscape_spriteindexes_toyland,
37 };
38 
46 static uint LoadGrfFile(const std::string &filename, SpriteID load_index, bool needs_palette_remap)
47 {
48  SpriteID load_index_org = load_index;
49  SpriteID sprite_id = 0;
50 
51  SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
52 
53  Debug(sprite, 2, "Reading grf-file '{}'", filename);
54 
55  uint8_t container_ver = file.GetContainerVersion();
56  if (container_ver == 0) UserError("Base grf '{}' is corrupt", filename);
58  if (container_ver >= 2) {
59  /* Read compression. */
60  uint8_t compression = file.ReadByte();
61  if (compression != 0) UserError("Unsupported compression format");
62  }
63 
64  while (LoadNextSprite(load_index, file, sprite_id)) {
65  load_index++;
66  sprite_id++;
67  if (load_index >= MAX_SPRITES) {
68  UserError("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files.");
69  }
70  }
71  Debug(sprite, 2, "Currently {} sprites are loaded", load_index);
72 
73  return load_index - load_index_org;
74 }
75 
83 static void LoadGrfFileIndexed(const std::string &filename, std::span<const std::pair<SpriteID, SpriteID>> index_tbl, bool needs_palette_remap)
84 {
85  uint sprite_id = 0;
86 
87  SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
88 
89  Debug(sprite, 2, "Reading indexed grf-file '{}'", filename);
90 
91  uint8_t container_ver = file.GetContainerVersion();
92  if (container_ver == 0) UserError("Base grf '{}' is corrupt", filename);
94  if (container_ver >= 2) {
95  /* Read compression. */
96  uint8_t compression = file.ReadByte();
97  if (compression != 0) UserError("Unsupported compression format");
98  }
99 
100  for (const auto &pair : index_tbl) {
101  for (SpriteID load_index = pair.first; load_index <= pair.second; ++load_index) {
102  [[maybe_unused]] bool b = LoadNextSprite(load_index, file, sprite_id);
103  assert(b);
104  sprite_id++;
105  }
106  }
107 }
108 
115 {
116  if (BaseGraphics::GetUsedSet() == nullptr || BaseSounds::GetUsedSet() == nullptr) return;
117 
118  const GraphicsSet *used_set = BaseGraphics::GetUsedSet();
119 
120  Debug(grf, 1, "Using the {} base graphics set", used_set->name);
121 
122  std::string error_msg;
123  auto output_iterator = std::back_inserter(error_msg);
124  if (used_set->GetNumInvalid() != 0) {
125  /* Not all files were loaded successfully, see which ones */
126  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 4.1 of README.md.\n\nThe following files are corrupted or missing:\n", used_set->name);
127  for (const auto &file : used_set->files) {
129  if (res != MD5File::CR_MATCH) fmt::format_to(output_iterator, "\t{} is {} ({})\n", file.filename, res == MD5File::CR_MISMATCH ? "corrupt" : "missing", file.missing_warning);
130  }
131  fmt::format_to(output_iterator, "\n");
132  }
133 
134  const SoundsSet *sounds_set = BaseSounds::GetUsedSet();
135  if (sounds_set->GetNumInvalid() != 0) {
136  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 4.1 of README.md.\n\nThe following files are corrupted or missing:\n", sounds_set->name);
137 
138  static_assert(SoundsSet::NUM_FILES == 1);
139  /* No need to loop each file, as long as there is only a single
140  * sound file. */
141  fmt::format_to(output_iterator, "\t{} is {} ({})\n", sounds_set->files->filename, SoundsSet::CheckMD5(sounds_set->files, BASESET_DIR) == MD5File::CR_MISMATCH ? "corrupt" : "missing", sounds_set->files->missing_warning);
142  }
143 
144  if (!error_msg.empty()) ShowInfoI(error_msg);
145 }
146 
148 static void LoadSpriteTables()
149 {
150  const GraphicsSet *used_set = BaseGraphics::GetUsedSet();
151 
152  LoadGrfFile(used_set->files[GFT_BASE].filename, 0, PAL_DOS != used_set->palette);
153 
154  /*
155  * The second basic file always starts at the given location and does
156  * contain a different amount of sprites depending on the "type"; DOS
157  * has a few sprites less. However, we do not care about those missing
158  * sprites as they are not shown anyway (logos in intro game).
159  */
160  LoadGrfFile(used_set->files[GFT_LOGOS].filename, 4793, PAL_DOS != used_set->palette);
161 
162  /*
163  * Load additional sprites for climates other than temperate.
164  * This overwrites some of the temperate sprites, such as foundations
165  * and the ground sprites.
166  */
167  if (_settings_game.game_creation.landscape != LT_TEMPERATE) {
171  PAL_DOS != used_set->palette
172  );
173  }
174 
175  /* Initialize the unicode to sprite mapping table */
177 
178  /*
179  * Load the base and extra NewGRF with OTTD required graphics as first NewGRF.
180  * However, we do not want it to show up in the list of used NewGRFs,
181  * so we have to manually add it, and then remove it later.
182  */
183  GRFConfig *top = _grfconfig;
184 
185  /* Default extra graphics */
186  static const char *master_filename = "OPENTTD.GRF";
187  GRFConfig *master = new GRFConfig(master_filename);
188  master->palette |= GRFP_GRF_DOS;
189  FillGRFDetails(master, false, BASESET_DIR);
190  ClrBit(master->flags, GCF_INIT_ONLY);
191 
192  /* Baseset extra graphics */
193  GRFConfig *extra = new GRFConfig(used_set->GetOrCreateExtraConfig());
194  if (extra->num_params == 0) extra->SetParameterDefaults();
196 
197  extra->next = top;
198  master->next = extra;
199  _grfconfig = master;
200 
201  LoadNewGRF(SPR_NEWGRFS_BASE, 2);
202 
203  uint total_extra_graphics = SPR_NEWGRFS_BASE - SPR_OPENTTD_BASE;
204  Debug(sprite, 4, "Checking sprites from fallback grf");
205  _missing_extra_graphics = GetSpriteCountForFile(master_filename, SPR_OPENTTD_BASE, SPR_NEWGRFS_BASE);
206  Debug(sprite, 1, "{} extra sprites, {} from baseset, {} from fallback", total_extra_graphics, total_extra_graphics - _missing_extra_graphics, _missing_extra_graphics);
207 
208  /* The original baseset extra graphics intentionally make use of the fallback graphics.
209  * Let's say everything which provides less than 500 sprites misses the rest intentionally. */
210  if (500 + _missing_extra_graphics > total_extra_graphics) _missing_extra_graphics = 0;
211 
212  /* Free and remove the top element. */
213  delete extra;
214  delete master;
215  _grfconfig = top;
216 }
217 
218 
219 static void RealChangeBlitter(const std::string_view repl_blitter)
220 {
221  const std::string_view cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName();
222  if (cur_blitter == repl_blitter) return;
223 
224  Debug(driver, 1, "Switching blitter from '{}' to '{}'... ", cur_blitter, repl_blitter);
225  Blitter *new_blitter = BlitterFactory::SelectBlitter(repl_blitter);
226  if (new_blitter == nullptr) NOT_REACHED();
227  Debug(driver, 1, "Successfully switched to {}.", repl_blitter);
228 
229  if (!VideoDriver::GetInstance()->AfterBlitterChange()) {
230  /* Failed to switch blitter, let's hope we can return to the old one. */
231  if (BlitterFactory::SelectBlitter(cur_blitter) == nullptr || !VideoDriver::GetInstance()->AfterBlitterChange()) UserError("Failed to reinitialize video driver. Specify a fixed blitter in the config");
232  }
233 
234  /* Clear caches that might have sprites for another blitter. */
236  ClearFontCache();
238  ReInitAllWindows(false);
239 }
240 
245 static bool SwitchNewGRFBlitter()
246 {
247  /* Never switch if the blitter was specified by the user. */
248  if (!_blitter_autodetected) return false;
249 
250  /* Null driver => dedicated server => do nothing. */
251  if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) return false;
252 
253  /* Get preferred depth.
254  * - depth_wanted_by_base: Depth required by the baseset, i.e. the majority of the sprites.
255  * - depth_wanted_by_grf: Depth required by some NewGRF.
256  * Both can force using a 32bpp blitter. depth_wanted_by_base is used to select
257  * between multiple 32bpp blitters, which perform differently with 8bpp sprites.
258  */
259  uint depth_wanted_by_base = BaseGraphics::GetUsedSet()->blitter == BLT_32BPP ? 32 : 8;
260  uint depth_wanted_by_grf = _support8bpp != S8BPP_NONE ? 8 : 32;
261  for (GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
262  if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND || HasBit(c->flags, GCF_INIT_ONLY)) continue;
263  if (c->palette & GRFP_BLT_32BPP) depth_wanted_by_grf = 32;
264  }
265  /* We need a 32bpp blitter for font anti-alias. */
266  if (GetFontAAState()) depth_wanted_by_grf = 32;
267 
268  /* Search the best blitter. */
269  static const struct {
270  const std::string_view name;
271  uint animation;
272  uint min_base_depth, max_base_depth, min_grf_depth, max_grf_depth;
273  } replacement_blitters[] = {
274  { "8bpp-optimized", 2, 8, 8, 8, 8 },
275  { "40bpp-anim", 2, 8, 32, 8, 32 },
276 #ifdef WITH_SSE
277  { "32bpp-sse4", 0, 32, 32, 8, 32 },
278  { "32bpp-ssse3", 0, 32, 32, 8, 32 },
279  { "32bpp-sse2", 0, 32, 32, 8, 32 },
280  { "32bpp-sse4-anim", 1, 32, 32, 8, 32 },
281 #endif
282  { "32bpp-optimized", 0, 8, 32, 8, 32 },
283 #ifdef WITH_SSE
284  { "32bpp-sse2-anim", 1, 8, 32, 8, 32 },
285 #endif
286  { "32bpp-anim", 1, 8, 32, 8, 32 },
287  };
288 
289  const bool animation_wanted = HasBit(_display_opt, DO_FULL_ANIMATION);
290  const std::string_view cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName();
291 
292  for (const auto &replacement_blitter : replacement_blitters) {
293  if (animation_wanted && (replacement_blitter.animation == 0)) continue;
294  if (!animation_wanted && (replacement_blitter.animation == 1)) continue;
295 
296  if (!IsInsideMM(depth_wanted_by_base, replacement_blitter.min_base_depth, replacement_blitter.max_base_depth + 1)) continue;
297  if (!IsInsideMM(depth_wanted_by_grf, replacement_blitter.min_grf_depth, replacement_blitter.max_grf_depth + 1)) continue;
298 
299  if (replacement_blitter.name == cur_blitter) {
300  return false;
301  }
302  if (BlitterFactory::GetBlitterFactory(replacement_blitter.name) == nullptr) continue;
303 
304  /* Inform the video driver we want to switch blitter as soon as possible. */
305  VideoDriver::GetInstance()->QueueOnMainThread(std::bind(&RealChangeBlitter, replacement_blitter.name));
306  break;
307  }
308 
309  return true;
310 }
311 
314 {
315  if (!SwitchNewGRFBlitter()) return;
316 
317  ClearFontCache();
319  ReInitAllWindows(false);
320 }
321 
324 {
325  Debug(sprite, 2, "Loading sprite set {}", _settings_game.game_creation.landscape);
326 
329  ClearFontCache();
330  GfxInitSpriteMem();
332  GfxInitPalettes();
333 
335 }
336 
337 GraphicsSet::GraphicsSet()
338  : BaseSet<GraphicsSet, MAX_GFT, true>{}, palette{}, blitter{}
339 {
340  // instantiate here, because unique_ptr needs a complete type
341 }
342 
343 GraphicsSet::~GraphicsSet()
344 {
345  // instantiate here, because unique_ptr needs a complete type
346 }
347 
348 bool GraphicsSet::FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename)
349 {
350  bool ret = this->BaseSet<GraphicsSet, MAX_GFT, true>::FillSetDetails(ini, path, full_filename, false);
351  if (ret) {
352  const IniGroup *metadata = ini.GetGroup("metadata");
353  assert(metadata != nullptr); /* ret can't be true if metadata isn't present. */
354  const IniItem *item;
355 
356  fetch_metadata("palette");
357  this->palette = ((*item->value)[0] == 'D' || (*item->value)[0] == 'd') ? PAL_DOS : PAL_WINDOWS;
358 
359  /* Get optional blitter information. */
360  item = metadata->GetItem("blitter");
361  this->blitter = (item != nullptr && (*item->value)[0] == '3') ? BLT_32BPP : BLT_8BPP;
362  }
363  return ret;
364 }
365 
371 {
372  if (!this->extra_cfg) {
373  this->extra_cfg.reset(new GRFConfig(this->files[GFT_EXTRA].filename));
374 
375  /* We know the palette of the base set, so if the base NewGRF is not
376  * setting one, use the palette of the base set and not the global
377  * one which might be the wrong palette for this base NewGRF.
378  * The value set here might be overridden via action14 later. */
379  switch (this->palette) {
380  case PAL_DOS: this->extra_cfg->palette |= GRFP_GRF_DOS; break;
381  case PAL_WINDOWS: this->extra_cfg->palette |= GRFP_GRF_WINDOWS; break;
382  default: break;
383  }
384  FillGRFDetails(this->extra_cfg.get(), false, BASESET_DIR);
385  }
386  return *this->extra_cfg;
387 }
388 
389 bool GraphicsSet::IsConfigurable() const
390 {
391  const GRFConfig &cfg = this->GetOrCreateExtraConfig();
392  /* This check is more strict than the one for NewGRF Settings.
393  * There are no legacy basesets with parameters, but without Action14 */
394  return !cfg.param_info.empty();
395 }
396 
397 void GraphicsSet::CopyCompatibleConfig(const GraphicsSet &src)
398 {
399  const GRFConfig *src_cfg = src.GetExtraConfig();
400  if (src_cfg == nullptr || src_cfg->num_params == 0) return;
401  GRFConfig &dest_cfg = this->GetOrCreateExtraConfig();
402  if (dest_cfg.IsCompatible(src_cfg->version)) return;
403  dest_cfg.CopyParams(*src_cfg);
404 }
405 
416 {
417  size_t size = 0;
418  auto f = FioFOpenFile(file->filename, "rb", subdir, &size);
419  if (!f.has_value()) return MD5File::CR_NO_FILE;
420 
421  size_t max = GRFGetSizeOfDataSection(*f);
422 
423  return file->CheckMD5(subdir, max);
424 }
425 
426 
437 {
438  size_t size;
439  auto f = FioFOpenFile(this->filename, "rb", subdir, &size);
440  if (!f.has_value()) return CR_NO_FILE;
441 
442  size = std::min(size, max_size);
443 
444  Md5 checksum;
445  uint8_t buffer[1024];
446  MD5Hash digest;
447  size_t len;
448 
449  while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, *f)) != 0 && size != 0) {
450  size -= len;
451  checksum.Append(buffer, len);
452  }
453 
454  checksum.Finish(digest);
455  return this->hash == digest ? CR_MATCH : CR_MISMATCH;
456 }
457 
459 static const char * const _graphics_file_names[] = { "base", "logos", "arctic", "tropical", "toyland", "extra" };
460 
462 template <class T, size_t Tnum_files, bool Tsearch_in_tars>
464 
465 template <class Tbase_set>
467 {
468  if (BaseMedia<Tbase_set>::used_set != nullptr) return true;
469 
470  const Tbase_set *best = nullptr;
471  for (const Tbase_set *c = BaseMedia<Tbase_set>::available_sets; c != nullptr; c = c->next) {
472  /* Skip unusable sets */
473  if (c->GetNumMissing() != 0) continue;
474 
475  if (best == nullptr ||
476  (best->fallback && !c->fallback) ||
477  best->valid_files < c->valid_files ||
478  (best->valid_files == c->valid_files && (
479  (best->shortname == c->shortname && best->version < c->version) ||
480  (best->palette != PAL_DOS && c->palette == PAL_DOS)))) {
481  best = c;
482  }
483  }
484 
486  return BaseMedia<Tbase_set>::used_set != nullptr;
487 }
488 
489 template <class Tbase_set>
490 /* static */ const char *BaseMedia<Tbase_set>::GetExtension()
491 {
492  return ".obg"; // OpenTTD Base Graphics
493 }
494 
@ GFT_LOGOS
Logos, landscape icons and original terrain generator sprites.
@ MAX_GFT
We are looking for this amount of GRFs.
@ 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.
@ BLT_32BPP
Base set has both 8 bpp and 32 bpp sprites.
@ BLT_8BPP
Base set has 8 bpp sprites only.
Generic function implementations for base data (graphics, sounds).
#define INSTANTIATE_BASE_MEDIA_METHODS(repl_type, set_type)
Force instantiation of methods so we don't get linker errors.
#define fetch_metadata(name)
Try to read a single piece of metadata and return false if it doesn't exist.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Base for all base media (graphics, sounds)
static bool DetermineBestSet()
Determine the graphics pack that has to be used.
Definition: gfxinit.cpp:466
static const GraphicsSet * GetUsedSet()
Return the used set.
static const char * GetExtension()
Get the extension that is used to identify this set.
Definition: gfxinit.cpp:490
static Blitter * SelectBlitter(const std::string_view name)
Find the requested blitter and return its class.
Definition: factory.hpp:96
static BlitterFactory * GetBlitterFactory(const std::string_view name)
Get the blitter factory with the given name.
Definition: factory.hpp:114
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:138
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.
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,...)
Ouptut a line of debugging information.
Definition: debug.h:37
Factory to 'query' all available blitters.
bool _blitter_autodetected
Was the blitter autodetected or specified by the user?
Definition: driver.cpp:34
std::optional< FileHandle > FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Definition: fileio.cpp:242
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:115
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
Definition: fileio_type.h:123
Declarations for savegames operations.
Functions to read fonts from files and cache them.
void InitializeUnicodeGlyphMap()
Initialize the glyph map.
Definition: fontcache.h:158
void UpdateCursorSize()
Update cursor dimension.
Definition: gfx.cpp:1598
Functions related to the gfx engine.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:18
@ PAL_DOS
Use the DOS palette.
Definition: gfx_type.h:305
@ PAL_WINDOWS
Use the Windows palette.
Definition: gfx_type.h:306
@ S8BPP_NONE
No support for 8bpp by OS or hardware, force 32bpp blitters.
Definition: gfx_type.h:336
static const char *const _graphics_file_names[]
Names corresponding to the GraphicsFileType.
Definition: gfxinit.cpp:459
static void LoadSpriteTables()
Actually load the sprite tables.
Definition: gfxinit.cpp:148
static bool SwitchNewGRFBlitter()
Check blitter needed by NewGRF config and switch if needed.
Definition: gfxinit.cpp:245
void CheckBlitter()
Check whether we still use the right blitter, or use another (better) one.
Definition: gfxinit.cpp:313
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:83
static constexpr std::span< const std::pair< SpriteID, SpriteID > > _landscape_spriteindexes[]
Offsets for loading the different "replacement" sprites in the files.
Definition: gfxinit.cpp:33
static uint LoadGrfFile(const std::string &filename, SpriteID load_index, bool needs_palette_remap)
Load an old fashioned GRF file.
Definition: gfxinit.cpp:46
void CheckExternalFiles()
Checks whether the MD5 checksums of the files are correct.
Definition: gfxinit.cpp:114
void GfxLoadSprites()
Initialise and load all the sprites.
Definition: gfxinit.cpp:323
Offsets of sprites to replace for non-temperate landscapes.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:268
void LoadNewGRF(SpriteID load_index, uint num_baseset)
Load all the NewGRFs.
Definition: newgrf.cpp:10056
Base for the NewGRF implementation.
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.
GRFConfig * _grfconfig
First item in list of current GRF set up.
size_t GRFGetSizeOfDataSection(FileHandle &f)
Get the data section size of a GRF.
@ GRFP_GRF_WINDOWS
The NewGRF says the Windows palette can be used.
Definition: newgrf_config.h:71
@ GRFP_GRF_DOS
The NewGRF says the DOS palette can be used.
Definition: newgrf_config.h:70
@ GRFP_BLT_32BPP
The NewGRF prefers a 32 bpp blitter.
Definition: newgrf_config.h:76
@ GCF_INIT_ONLY
GRF file is processed up to GLS_INIT.
Definition: newgrf_config.h:27
@ GCS_DISABLED
GRF file is disabled.
Definition: newgrf_config.h:35
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
Definition: newgrf_config.h:36
@ 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:57
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.
Definition: spritecache.cpp:93
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:1555
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.
Information about a single base set.
static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir)
Calculate and check the MD5 hash of the supplied file.
int GetNumInvalid() const
Get the number of invalid files.
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.
static const size_t NUM_FILES
Number of files in this set.
std::string name
The name of the base set.
MD5File files[NUM_FILES]
All files part of this set.
Information about GRF, used in the game and (part of it) in savegames.
void SetParameterDefaults()
Set the default value for all parameters as specified by action14.
uint8_t palette
GRFPalette, bitset.
uint8_t flags
NOSAVE: GCF_Flags, bitset.
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.
uint8_t num_params
Number of used parameters.
struct GRFConfig * next
NOSAVE: Next item in the linked list.
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.
uint8_t landscape
the landscape we're currently in
GameCreationSettings game_creation
settings used during the creation of a game (map)
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:415
BlitterType blitter
Blitter of this graphics set.
GRFConfig & GetOrCreateExtraConfig() const
Return configuration for the extra GRF, or lazily create it.
Definition: gfxinit.cpp:370
Ini file that supports both loading and saving.
Definition: ini_type.h:88
A group within an ini file.
Definition: ini_type.h:34
const IniItem * GetItem(std::string_view name) const
Get the item with the given name.
Definition: ini_load.cpp:52
A single "line" in an ini file.
Definition: ini_type.h:23
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:119
Structure holding filename and MD5 information about a single file.
std::string missing_warning
warning when this file is missing
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.
ChecksumResult CheckMD5(Subdirectory subdir, size_t max_size) const
Calculate and check the MD5 hash of the supplied filename.
Definition: gfxinit.cpp:436
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:3327
Window functions not directly related to making/drawing windows.