OpenTTD Source  14.0-beta3
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 const SpriteID * const _landscape_spriteindexes[] = {
34  _landscape_spriteindexes_arctic,
35  _landscape_spriteindexes_tropic,
36  _landscape_spriteindexes_toyland,
37 };
38 
46 static uint LoadGrfFile(const std::string &filename, uint load_index, bool needs_palette_remap)
47 {
48  uint load_index_org = load_index;
49  uint 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  byte container_ver = file.GetContainerVersion();
56  if (container_ver == 0) UserError("Base grf '{}' is corrupt", filename);
58  if (container_ver >= 2) {
59  /* Read compression. */
60  byte 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, const SpriteID *index_tbl, bool needs_palette_remap)
84 {
85  uint start;
86  uint sprite_id = 0;
87 
88  SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
89 
90  Debug(sprite, 2, "Reading indexed grf-file '{}'", filename);
91 
92  byte container_ver = file.GetContainerVersion();
93  if (container_ver == 0) UserError("Base grf '{}' is corrupt", filename);
95  if (container_ver >= 2) {
96  /* Read compression. */
97  byte compression = file.ReadByte();
98  if (compression != 0) UserError("Unsupported compression format");
99  }
100 
101  while ((start = *index_tbl++) != END) {
102  uint end = *index_tbl++;
103 
104  do {
105  [[maybe_unused]] bool b = LoadNextSprite(start, file, sprite_id);
106  assert(b);
107  sprite_id++;
108  } while (++start <= end);
109  }
110 }
111 
118 {
119  if (BaseGraphics::GetUsedSet() == nullptr || BaseSounds::GetUsedSet() == nullptr) return;
120 
121  const GraphicsSet *used_set = BaseGraphics::GetUsedSet();
122 
123  Debug(grf, 1, "Using the {} base graphics set", used_set->name);
124 
125  std::string error_msg;
126  auto output_iterator = std::back_inserter(error_msg);
127  if (used_set->GetNumInvalid() != 0) {
128  /* Not all files were loaded successfully, see which ones */
129  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);
130  for (uint i = 0; i < GraphicsSet::NUM_FILES; i++) {
132  if (res != MD5File::CR_MATCH) fmt::format_to(output_iterator, "\t{} is {} ({})\n", used_set->files[i].filename, res == MD5File::CR_MISMATCH ? "corrupt" : "missing", used_set->files[i].missing_warning);
133  }
134  fmt::format_to(output_iterator, "\n");
135  }
136 
137  const SoundsSet *sounds_set = BaseSounds::GetUsedSet();
138  if (sounds_set->GetNumInvalid() != 0) {
139  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);
140 
141  static_assert(SoundsSet::NUM_FILES == 1);
142  /* No need to loop each file, as long as there is only a single
143  * sound file. */
144  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);
145  }
146 
147  if (!error_msg.empty()) ShowInfoI(error_msg);
148 }
149 
151 static void LoadSpriteTables()
152 {
153  const GraphicsSet *used_set = BaseGraphics::GetUsedSet();
154 
155  LoadGrfFile(used_set->files[GFT_BASE].filename, 0, PAL_DOS != used_set->palette);
156 
157  /*
158  * The second basic file always starts at the given location and does
159  * contain a different amount of sprites depending on the "type"; DOS
160  * has a few sprites less. However, we do not care about those missing
161  * sprites as they are not shown anyway (logos in intro game).
162  */
163  LoadGrfFile(used_set->files[GFT_LOGOS].filename, 4793, PAL_DOS != used_set->palette);
164 
165  /*
166  * Load additional sprites for climates other than temperate.
167  * This overwrites some of the temperate sprites, such as foundations
168  * and the ground sprites.
169  */
170  if (_settings_game.game_creation.landscape != LT_TEMPERATE) {
174  PAL_DOS != used_set->palette
175  );
176  }
177 
178  /* Initialize the unicode to sprite mapping table */
180 
181  /*
182  * Load the base and extra NewGRF with OTTD required graphics as first NewGRF.
183  * However, we do not want it to show up in the list of used NewGRFs,
184  * so we have to manually add it, and then remove it later.
185  */
186  GRFConfig *top = _grfconfig;
187 
188  /* Default extra graphics */
189  static const char *master_filename = "OPENTTD.GRF";
190  GRFConfig *master = new GRFConfig(master_filename);
191  master->palette |= GRFP_GRF_DOS;
192  FillGRFDetails(master, false, BASESET_DIR);
193  ClrBit(master->flags, GCF_INIT_ONLY);
194 
195  /* Baseset extra graphics */
196  GRFConfig *extra = new GRFConfig(used_set->GetOrCreateExtraConfig());
197  if (extra->num_params == 0) extra->SetParameterDefaults();
198  ClrBit(extra->flags, GCF_INIT_ONLY);
199 
200  extra->next = top;
201  master->next = extra;
202  _grfconfig = master;
203 
204  LoadNewGRF(SPR_NEWGRFS_BASE, 2);
205 
206  uint total_extra_graphics = SPR_NEWGRFS_BASE - SPR_OPENTTD_BASE;
207  Debug(sprite, 4, "Checking sprites from fallback grf");
208  _missing_extra_graphics = GetSpriteCountForFile(master_filename, SPR_OPENTTD_BASE, SPR_NEWGRFS_BASE);
209  Debug(sprite, 1, "{} extra sprites, {} from baseset, {} from fallback", total_extra_graphics, total_extra_graphics - _missing_extra_graphics, _missing_extra_graphics);
210 
211  /* The original baseset extra graphics intentionally make use of the fallback graphics.
212  * Let's say everything which provides less than 500 sprites misses the rest intentionally. */
213  if (500 + _missing_extra_graphics > total_extra_graphics) _missing_extra_graphics = 0;
214 
215  /* Free and remove the top element. */
216  delete extra;
217  delete master;
218  _grfconfig = top;
219 }
220 
221 
222 static void RealChangeBlitter(const char *repl_blitter)
223 {
224  const char *cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName();
225  if (strcmp(cur_blitter, repl_blitter) == 0) return;
226 
227  Debug(driver, 1, "Switching blitter from '{}' to '{}'... ", cur_blitter, repl_blitter);
228  Blitter *new_blitter = BlitterFactory::SelectBlitter(repl_blitter);
229  if (new_blitter == nullptr) NOT_REACHED();
230  Debug(driver, 1, "Successfully switched to {}.", repl_blitter);
231 
232  if (!VideoDriver::GetInstance()->AfterBlitterChange()) {
233  /* Failed to switch blitter, let's hope we can return to the old one. */
234  if (BlitterFactory::SelectBlitter(cur_blitter) == nullptr || !VideoDriver::GetInstance()->AfterBlitterChange()) UserError("Failed to reinitialize video driver. Specify a fixed blitter in the config");
235  }
236 
237  /* Clear caches that might have sprites for another blitter. */
239  ClearFontCache();
241  ReInitAllWindows(false);
242 }
243 
248 static bool SwitchNewGRFBlitter()
249 {
250  /* Never switch if the blitter was specified by the user. */
251  if (!_blitter_autodetected) return false;
252 
253  /* Null driver => dedicated server => do nothing. */
254  if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) return false;
255 
256  /* Get preferred depth.
257  * - depth_wanted_by_base: Depth required by the baseset, i.e. the majority of the sprites.
258  * - depth_wanted_by_grf: Depth required by some NewGRF.
259  * Both can force using a 32bpp blitter. depth_wanted_by_base is used to select
260  * between multiple 32bpp blitters, which perform differently with 8bpp sprites.
261  */
262  uint depth_wanted_by_base = BaseGraphics::GetUsedSet()->blitter == BLT_32BPP ? 32 : 8;
263  uint depth_wanted_by_grf = _support8bpp != S8BPP_NONE ? 8 : 32;
264  for (GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
265  if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND || HasBit(c->flags, GCF_INIT_ONLY)) continue;
266  if (c->palette & GRFP_BLT_32BPP) depth_wanted_by_grf = 32;
267  }
268  /* We need a 32bpp blitter for font anti-alias. */
269  if (HasAntialiasedFonts()) depth_wanted_by_grf = 32;
270 
271  /* Search the best blitter. */
272  static const struct {
273  const char *name;
274  uint animation;
275  uint min_base_depth, max_base_depth, min_grf_depth, max_grf_depth;
276  } replacement_blitters[] = {
277  { "8bpp-optimized", 2, 8, 8, 8, 8 },
278  { "40bpp-anim", 2, 8, 32, 8, 32 },
279 #ifdef WITH_SSE
280  { "32bpp-sse4", 0, 32, 32, 8, 32 },
281  { "32bpp-ssse3", 0, 32, 32, 8, 32 },
282  { "32bpp-sse2", 0, 32, 32, 8, 32 },
283  { "32bpp-sse4-anim", 1, 32, 32, 8, 32 },
284 #endif
285  { "32bpp-optimized", 0, 8, 32, 8, 32 },
286 #ifdef WITH_SSE
287  { "32bpp-sse2-anim", 1, 8, 32, 8, 32 },
288 #endif
289  { "32bpp-anim", 1, 8, 32, 8, 32 },
290  };
291 
292  const bool animation_wanted = HasBit(_display_opt, DO_FULL_ANIMATION);
293  const char *cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName();
294 
295  for (uint i = 0; i < lengthof(replacement_blitters); i++) {
296  if (animation_wanted && (replacement_blitters[i].animation == 0)) continue;
297  if (!animation_wanted && (replacement_blitters[i].animation == 1)) continue;
298 
299  if (!IsInsideMM(depth_wanted_by_base, replacement_blitters[i].min_base_depth, replacement_blitters[i].max_base_depth + 1)) continue;
300  if (!IsInsideMM(depth_wanted_by_grf, replacement_blitters[i].min_grf_depth, replacement_blitters[i].max_grf_depth + 1)) continue;
301  const char *repl_blitter = replacement_blitters[i].name;
302 
303  if (strcmp(repl_blitter, cur_blitter) == 0) {
304  return false;
305  }
306  if (BlitterFactory::GetBlitterFactory(repl_blitter) == nullptr) continue;
307 
308  /* Inform the video driver we want to switch blitter as soon as possible. */
309  VideoDriver::GetInstance()->QueueOnMainThread(std::bind(&RealChangeBlitter, repl_blitter));
310  break;
311  }
312 
313  return true;
314 }
315 
318 {
319  if (!SwitchNewGRFBlitter()) return;
320 
321  ClearFontCache();
323  ReInitAllWindows(false);
324 }
325 
328 {
329  Debug(sprite, 2, "Loading sprite set {}", _settings_game.game_creation.landscape);
330 
333  ClearFontCache();
334  GfxInitSpriteMem();
336  GfxInitPalettes();
337 
339 }
340 
341 GraphicsSet::GraphicsSet()
342  : BaseSet<GraphicsSet, MAX_GFT, true>{}, palette{}, blitter{}
343 {
344  // instantiate here, because unique_ptr needs a complete type
345 }
346 
347 GraphicsSet::~GraphicsSet()
348 {
349  // instantiate here, because unique_ptr needs a complete type
350 }
351 
352 bool GraphicsSet::FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename)
353 {
354  bool ret = this->BaseSet<GraphicsSet, MAX_GFT, true>::FillSetDetails(ini, path, full_filename, false);
355  if (ret) {
356  const IniGroup *metadata = ini.GetGroup("metadata");
357  assert(metadata != nullptr); /* ret can't be true if metadata isn't present. */
358  const IniItem *item;
359 
360  fetch_metadata("palette");
361  this->palette = ((*item->value)[0] == 'D' || (*item->value)[0] == 'd') ? PAL_DOS : PAL_WINDOWS;
362 
363  /* Get optional blitter information. */
364  item = metadata->GetItem("blitter");
365  this->blitter = (item != nullptr && (*item->value)[0] == '3') ? BLT_32BPP : BLT_8BPP;
366  }
367  return ret;
368 }
369 
375 {
376  if (!this->extra_cfg) {
377  this->extra_cfg.reset(new GRFConfig(this->files[GFT_EXTRA].filename));
378 
379  /* We know the palette of the base set, so if the base NewGRF is not
380  * setting one, use the palette of the base set and not the global
381  * one which might be the wrong palette for this base NewGRF.
382  * The value set here might be overridden via action14 later. */
383  switch (this->palette) {
384  case PAL_DOS: this->extra_cfg->palette |= GRFP_GRF_DOS; break;
385  case PAL_WINDOWS: this->extra_cfg->palette |= GRFP_GRF_WINDOWS; break;
386  default: break;
387  }
388  FillGRFDetails(this->extra_cfg.get(), false, BASESET_DIR);
389  }
390  return *this->extra_cfg;
391 }
392 
393 bool GraphicsSet::IsConfigurable() const
394 {
395  const GRFConfig &cfg = this->GetOrCreateExtraConfig();
396  /* This check is more strict than the one for NewGRF Settings.
397  * There are no legacy basesets with parameters, but without Action14 */
398  return !cfg.param_info.empty();
399 }
400 
401 void GraphicsSet::CopyCompatibleConfig(const GraphicsSet &src)
402 {
403  const GRFConfig *src_cfg = src.GetExtraConfig();
404  if (src_cfg == nullptr || src_cfg->num_params == 0) return;
405  GRFConfig &dest_cfg = this->GetOrCreateExtraConfig();
406  if (dest_cfg.IsCompatible(src_cfg->version)) return;
407  dest_cfg.CopyParams(*src_cfg);
408 }
409 
420 {
421  size_t size = 0;
422  FILE *f = FioFOpenFile(file->filename, "rb", subdir, &size);
423  if (f == nullptr) return MD5File::CR_NO_FILE;
424 
425  size_t max = GRFGetSizeOfDataSection(f);
426 
427  FioFCloseFile(f);
428 
429  return file->CheckMD5(subdir, max);
430 }
431 
432 
443 {
444  size_t size;
445  FILE *f = FioFOpenFile(this->filename, "rb", subdir, &size);
446 
447  if (f == nullptr) 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  FioFCloseFile(f);
462 
463  checksum.Finish(digest);
464  return this->hash == digest ? CR_MATCH : CR_MISMATCH;
465 }
466 
468 static const char * const _graphics_file_names[] = { "base", "logos", "arctic", "tropical", "toyland", "extra" };
469 
471 template <class T, size_t Tnum_files, bool Tsearch_in_tars>
473 
474 template <class Tbase_set>
476 {
477  if (BaseMedia<Tbase_set>::used_set != nullptr) return true;
478 
479  const Tbase_set *best = nullptr;
480  for (const Tbase_set *c = BaseMedia<Tbase_set>::available_sets; c != nullptr; c = c->next) {
481  /* Skip unusable sets */
482  if (c->GetNumMissing() != 0) continue;
483 
484  if (best == nullptr ||
485  (best->fallback && !c->fallback) ||
486  best->valid_files < c->valid_files ||
487  (best->valid_files == c->valid_files && (
488  (best->shortname == c->shortname && best->version < c->version) ||
489  (best->palette != PAL_DOS && c->palette == PAL_DOS)))) {
490  best = c;
491  }
492  }
493 
495  return BaseMedia<Tbase_set>::used_set != nullptr;
496 }
497 
498 template <class Tbase_set>
499 /* static */ const char *BaseMedia<Tbase_set>::GetExtension()
500 {
501  return ".obg"; // OpenTTD Base Graphics
502 }
503 
factory.hpp
base_media_func.h
PAL_DOS
@ PAL_DOS
Use the DOS palette.
Definition: gfx_type.h:300
BaseMedia::DetermineBestSet
static bool DetermineBestSet()
Determine the graphics pack that has to be used.
Definition: gfxinit.cpp:475
SoundsSet
All data of a sounds set.
Definition: base_media_base.h:294
LoadSpriteTables
static void LoadSpriteTables()
Actually load the sprite tables.
Definition: gfxinit.cpp:151
IsInsideMM
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
GFT_EXTRA
@ GFT_EXTRA
Extra sprites that were not part of the original sprites.
Definition: base_media_base.h:247
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:356
InitializeUnicodeGlyphMap
void InitializeUnicodeGlyphMap()
Initialize the glyph map.
Definition: fontcache.h:173
Blitter
How all blitters should look like.
Definition: base.hpp:29
BLT_8BPP
@ BLT_8BPP
Base set has 8 bpp sprites only.
Definition: base_media_base.h:253
MD5File::CR_MISMATCH
@ CR_MISMATCH
The file did exist, just the md5 checksum did not match.
Definition: base_media_base.h:30
BaseSet::FillSetDetails
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.
Definition: base_media_func.h:42
MD5File::ChecksumResult
ChecksumResult
The result of a checksum check.
Definition: base_media_base.h:27
BASESET_DIR
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
Definition: fileio_type.h:116
BaseSet::name
std::string name
The name of the base set.
Definition: base_media_base.h:61
IniItem
A single "line" in an ini file.
Definition: ini_type.h:23
GFT_BASE
@ GFT_BASE
Base sprites for all climates.
Definition: base_media_base.h:242
IniGroup::GetItem
const IniItem * GetItem(const std::string &name) const
Get the item with the given name.
Definition: ini_load.cpp:52
BaseSet< GraphicsSet, MAX_GFT, true >::NUM_FILES
static const size_t NUM_FILES
Number of files in this set.
Definition: base_media_base.h:53
IniGroup
A group within an ini file.
Definition: ini_type.h:34
BlitterFactory::SelectBlitter
static Blitter * SelectBlitter(const std::string &name)
Find the requested blitter and return its class.
Definition: factory.hpp:96
GCS_NOT_FOUND
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
Definition: newgrf_config.h:37
_display_opt
byte _display_opt
What do we want to draw/do?
Definition: transparency_gui.cpp:26
BLT_32BPP
@ BLT_32BPP
Base set has both 8 bpp and 32 bpp sprites.
Definition: base_media_base.h:254
SpriteFile::GetContainerVersion
byte GetContainerVersion() const
Get the version number of container type used by the file.
Definition: sprite_file_type.hpp:38
fios.h
palette_func.h
VideoDriver::ClearSystemSprites
virtual void ClearSystemSprites()
Clear all cached sprites.
Definition: video_driver.hpp:106
RandomAccessFile::ReadByte
byte ReadByte()
Read a byte from the file.
Definition: random_access_file.cpp:101
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:619
GCF_INIT_ONLY
@ GCF_INIT_ONLY
GRF file is processed up to GLS_INIT.
Definition: newgrf_config.h:28
UpdateCursorSize
void UpdateCursorSize()
Update cursor dimension.
Definition: gfx.cpp:1621
gfx_func.h
MD5File::CR_MATCH
@ CR_MATCH
The file did exist and the md5 checksum did match.
Definition: base_media_base.h:29
MD5File::missing_warning
std::string missing_warning
warning when this file is missing
Definition: base_media_base.h:36
DO_FULL_ANIMATION
@ DO_FULL_ANIMATION
Perform palette animation.
Definition: openttd.h:49
GRFP_GRF_DOS
@ GRFP_GRF_DOS
The NewGRF says the DOS palette can be used.
Definition: newgrf_config.h:71
_landscape_spriteindexes
static const SpriteID *const _landscape_spriteindexes[]
Offsets for loading the different "replacement" sprites in the files.
Definition: gfxinit.cpp:33
LoadNewGRF
void LoadNewGRF(uint load_index, uint num_baseset)
Load all the NewGRFs.
Definition: newgrf.cpp:10039
GRFConfig::version
uint32_t version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
Definition: newgrf_config.h:162
LoadNextSprite
bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id)
Load a real or recolour sprite.
Definition: spritecache.cpp:609
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:147
MAX_SPRITES
@ MAX_SPRITES
Maximum number of sprites that can be loaded at a given time.
Definition: sprites.h:1551
ReInitAllWindows
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
Definition: window.cpp:3316
GfxClearSpriteCache
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information.
Definition: spritecache.cpp:1036
S8BPP_NONE
@ S8BPP_NONE
No support for 8bpp by OS or hardware, force 32bpp blitters.
Definition: gfx_type.h:331
FioFOpenFile
FILE * 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:263
GRFConfig::SetParameterDefaults
void SetParameterDefaults()
Set the default value for all parameters as specified by action14.
Definition: newgrf_config.cpp:123
SwitchNewGRFBlitter
static bool SwitchNewGRFBlitter()
Check blitter needed by NewGRF config and switch if needed.
Definition: gfxinit.cpp:248
IniItem::value
std::optional< std::string > value
The value of this item.
Definition: ini_type.h:25
_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:167
HasAntialiasedFonts
bool HasAntialiasedFonts()
Should any of the active fonts be anti-aliased?
Definition: fontcache.cpp:240
BaseMedia
Base for all base media (graphics, sounds)
Definition: base_media_base.h:176
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:138
safeguards.h
GRFGetSizeOfDataSection
size_t GRFGetSizeOfDataSection(FILE *f)
Get the data section size of a GRF.
Definition: newgrf_config.cpp:255
MD5File::filename
std::string filename
filename
Definition: base_media_base.h:34
GRFP_BLT_32BPP
@ GRFP_BLT_32BPP
The NewGRF prefers a 32 bpp blitter.
Definition: newgrf_config.h:77
MD5File::CheckMD5
ChecksumResult CheckMD5(Subdirectory subdir, size_t max_size) const
Calculate and check the MD5 hash of the supplied filename.
Definition: gfxinit.cpp:442
CheckExternalFiles
void CheckExternalFiles()
Checks whether the MD5 checksums of the files are correct.
Definition: gfxinit.cpp:117
GraphicsSet::blitter
BlitterType blitter
Blitter of this graphics set.
Definition: base_media_base.h:265
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:78
IniLoadFile::GetGroup
const IniGroup * GetGroup(const std::string &name) const
Get the group with the given name.
Definition: ini_load.cpp:119
sprites.h
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:188
landscape_sprite.h
stdafx.h
GRFConfig::CopyParams
void CopyParams(const GRFConfig &src)
Copy the parameter information from the src config.
Definition: newgrf_config.cpp:87
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:200
GRFConfig::palette
uint8_t palette
GRFPalette, bitset.
Definition: newgrf_config.h:170
_graphics_file_names
static const char *const _graphics_file_names[]
Names corresponding to the GraphicsFileType.
Definition: gfxinit.cpp:468
GRFConfig::param_info
std::vector< std::optional< GRFParameterInfo > > param_info
NOSAVE: extra information about the parameters.
Definition: newgrf_config.h:171
GraphicsSet::GetOrCreateExtraConfig
GRFConfig & GetOrCreateExtraConfig() const
Return configuration for the extra GRF, or lazily create it.
Definition: gfxinit.cpp:374
GFT_LOGOS
@ GFT_LOGOS
Logos, landscape icons and original terrain generator sprites.
Definition: base_media_base.h:243
INSTANTIATE_BASE_MEDIA_METHODS
#define INSTANTIATE_BASE_MEDIA_METHODS(repl_type, set_type)
Force instantiation of methods so we don't get linker errors.
Definition: base_media_func.h:414
CheckBlitter
void CheckBlitter()
Check whether we still use the right blitter, or use another (better) one.
Definition: gfxinit.cpp:317
SpriteFile
RandomAccessFile with some extra information specific for sprite files.
Definition: sprite_file_type.hpp:19
Blitter::GetName
virtual const char * GetName()=0
Get the name of the blitter, the same as the Factory-instance returns.
_blitter_autodetected
bool _blitter_autodetected
Was the blitter autodetected or specified by the user?
Definition: driver.cpp:40
GCS_DISABLED
@ GCS_DISABLED
GRF file is disabled.
Definition: newgrf_config.h:36
GFT_ARCTIC
@ GFT_ARCTIC
Landscape replacement sprites for arctic.
Definition: base_media_base.h:244
GRFConfig::flags
uint8_t flags
NOSAVE: GCF_Flags, bitset.
Definition: newgrf_config.h:164
GRFP_GRF_WINDOWS
@ GRFP_GRF_WINDOWS
The NewGRF says the Windows palette can be used.
Definition: newgrf_config.h:72
IniFile
Ini file that supports both loading and saving.
Definition: ini_type.h:88
MD5File
Structure holding filename and MD5 information about a single file.
Definition: base_media_base.h:25
GraphicsSet::CheckMD5
static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir)
Calculate and check the MD5 hash of the supplied GRF.
Definition: gfxinit.cpp:419
video_driver.hpp
BlitterFactory::GetBlitterFactory
static BlitterFactory * GetBlitterFactory(const std::string &name)
Get the blitter factory with the given name.
Definition: factory.hpp:114
LoadGrfFileIndexed
static void LoadGrfFileIndexed(const std::string &filename, const SpriteID *index_tbl, bool needs_palette_remap)
Load an old fashioned GRF file to replace already loaded sprites.
Definition: gfxinit.cpp:83
GRFConfig::next
struct GRFConfig * next
NOSAVE: Next item in the linked list.
Definition: newgrf_config.h:174
transparency.h
SPR_OPENTTD_BASE
static const SpriteID SPR_OPENTTD_BASE
Extra graphic spritenumbers.
Definition: sprites.h:56
GraphicsSet::palette
PaletteType palette
Palette of this graphics set.
Definition: base_media_base.h:264
newgrf.h
BaseSet
Information about a single base set.
Definition: base_media_base.h:49
MD5File::CR_NO_FILE
@ CR_NO_FILE
The file did not exist.
Definition: base_media_base.h:31
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
GfxLoadSprites
void GfxLoadSprites()
Initialise and load all the sprites.
Definition: gfxinit.cpp:327
fetch_metadata
#define fetch_metadata(name)
Try to read a single piece of metadata and return false if it doesn't exist.
Definition: base_media_func.h:25
_grfconfig
GRFConfig * _grfconfig
First item in list of current GRF set up.
Definition: newgrf_config.cpp:164
window_func.h
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
GRFConfig::num_params
uint8_t num_params
Number of used parameters.
Definition: newgrf_config.h:168
fontcache.h
LoadGrfFile
static uint LoadGrfFile(const std::string &filename, uint load_index, bool needs_palette_remap)
Load an old fashioned GRF file.
Definition: gfxinit.cpp:46
ReadGRFSpriteOffsets
void ReadGRFSpriteOffsets(SpriteFile &file)
Parse the sprite section of GRFs.
Definition: spritecache.cpp:553
GraphicsSet::extra_cfg
std::unique_ptr< GRFConfig > extra_cfg
Parameters for extra GRF.
Definition: base_media_base.h:262
BaseMedia< GraphicsSet >::GetUsedSet
static const GraphicsSet * GetUsedSet()
Return the used set.
Definition: base_media_func.h:394
PAL_WINDOWS
@ PAL_WINDOWS
Use the Windows palette.
Definition: gfx_type.h:301
BaseSet::GetNumInvalid
int GetNumInvalid() const
Get the number of invalid files.
Definition: base_media_base.h:94
MD5File::hash
MD5Hash hash
md5 sum of the file
Definition: base_media_base.h:35
ClrBit
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
BaseSet< SoundsSet, 1, true >::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:149
BaseMedia::GetExtension
static const char * GetExtension()
Get the extension that is used to identify this set.
Definition: gfxinit.cpp:499
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:84
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:324
GraphicsSet
All data of a graphics set.
Definition: base_media_base.h:260
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:185
MAX_GFT
@ MAX_GFT
We are looking for this amount of GRFs.
Definition: base_media_base.h:248
BaseSet::files
MD5File files[NUM_FILES]
All files part of this set.
Definition: base_media_base.h:68
FioFCloseFile
void FioFCloseFile(FILE *f)
Close a file in a safe way.
Definition: fileio.cpp:148
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103