OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
13 #include "3rdparty/md5/md5.h"
22 #define SET_TYPE "graphics"
33 _landscape_spriteindexes_arctic,
34 _landscape_spriteindexes_tropic,
35 _landscape_spriteindexes_toyland,
45 static uint
LoadGrfFile(
const char *filename, uint load_index,
bool needs_palette_remap)
47 uint load_index_org = load_index;
52 Debug(sprite, 2,
"Reading grf-file '{}'", filename);
55 if (container_ver == 0)
usererror(
"Base grf '%s' is corrupt", filename);
57 if (container_ver >= 2) {
60 if (compression != 0)
usererror(
"Unsupported compression format");
67 usererror(
"Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files.");
70 Debug(sprite, 2,
"Currently {} sprites are loaded", load_index);
72 return load_index - load_index_org;
89 Debug(sprite, 2,
"Reading indexed grf-file '{}'", filename);
92 if (container_ver == 0)
usererror(
"Base grf '%s' is corrupt", filename);
94 if (container_ver >= 2) {
97 if (compression != 0)
usererror(
"Unsupported compression format");
100 while ((start = *index_tbl++) != END) {
101 uint end = *index_tbl++;
107 }
while (++start <= end);
122 Debug(grf, 1,
"Using the {} base graphics set", used_set->
name);
124 static const size_t ERROR_MESSAGE_LENGTH = 256;
125 static const size_t MISSING_FILE_MESSAGE_LENGTH = 128;
132 char *add_pos = error_msg;
133 const char *last =
lastof(error_msg);
137 add_pos +=
seprintf(add_pos, last,
"Trying to load graphics set '%s', 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.c_str());
142 add_pos +=
seprintf(add_pos, last,
"\n");
147 add_pos +=
seprintf(add_pos, last,
"Trying to load sound set '%s', 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.c_str());
155 if (add_pos != error_msg)
ShowInfoF(
"%s", error_msg);
197 static const char *master_filename =
"OPENTTD.GRF";
219 master->
next = extra;
239 static void RealChangeBlitter(
const char *repl_blitter)
242 if (strcmp(cur_blitter, repl_blitter) == 0)
return;
244 Debug(driver, 1,
"Switching blitter from '{}' to '{}'... ", cur_blitter, repl_blitter);
246 if (new_blitter ==
nullptr) NOT_REACHED();
247 Debug(driver, 1,
"Successfully switched to {}.", repl_blitter);
280 uint depth_wanted_by_grf = _support8bpp !=
S8BPP_NONE ? 8 : 32;
289 static const struct {
292 uint min_base_depth, max_base_depth, min_grf_depth, max_grf_depth;
293 } replacement_blitters[] = {
294 {
"8bpp-optimized", 2, 8, 8, 8, 8 },
295 {
"40bpp-anim", 2, 8, 32, 8, 32 },
297 {
"32bpp-sse4", 0, 32, 32, 8, 32 },
298 {
"32bpp-ssse3", 0, 32, 32, 8, 32 },
299 {
"32bpp-sse2", 0, 32, 32, 8, 32 },
300 {
"32bpp-sse4-anim", 1, 32, 32, 8, 32 },
302 {
"32bpp-optimized", 0, 8, 32, 8, 32 },
304 {
"32bpp-sse2-anim", 1, 8, 32, 8, 32 },
306 {
"32bpp-anim", 1, 8, 32, 8, 32 },
312 for (uint i = 0; i <
lengthof(replacement_blitters); i++) {
313 if (animation_wanted && (replacement_blitters[i].animation == 0))
continue;
314 if (!animation_wanted && (replacement_blitters[i].animation == 1))
continue;
316 if (!
IsInsideMM(depth_wanted_by_base, replacement_blitters[i].min_base_depth, replacement_blitters[i].max_base_depth + 1))
continue;
317 if (!
IsInsideMM(depth_wanted_by_grf, replacement_blitters[i].min_grf_depth, replacement_blitters[i].max_grf_depth + 1))
continue;
318 const char *repl_blitter = replacement_blitters[i].name;
320 if (strcmp(repl_blitter, cur_blitter) == 0) {
358 bool GraphicsSet::FillSetDetails(
IniFile *ini,
const char *path,
const char *full_filename)
369 item = metadata->
GetItem(
"blitter",
false);
414 size = std::min(size, max_size);
421 while ((len = fread(buffer, 1, (size >
sizeof(buffer)) ?
sizeof(buffer) : size, f)) != 0 && size != 0) {
423 checksum.Append(buffer, len);
428 checksum.Finish(digest);
433 static const char *
const _graphics_file_names[] = {
"base",
"logos",
"arctic",
"tropical",
"toyland",
"extra" };
436 template <
class T,
size_t Tnum_files,
bool Tsearch_in_tars>
439 template <
class Tbase_set>
444 const Tbase_set *best =
nullptr;
447 if (c->GetNumMissing() != 0)
continue;
449 if (best ==
nullptr ||
450 (best->fallback && !c->fallback) ||
451 best->valid_files < c->valid_files ||
452 (best->valid_files == c->valid_files && (
453 (best->shortname == c->shortname && best->version < c->version) ||
463 template <
class Tbase_set>
@ PAL_DOS
Use the DOS palette.
void CDECL usererror(const char *s,...)
Error handling for fatal user errors.
All data of a sounds set.
static void LoadSpriteTables()
Actually load the sprite tables.
byte landscape
the landscape we're currently in
How all blitters should look like.
@ CR_MISMATCH
The file did exist, just the md5 checksum did not match.
ChecksumResult
The result of a checksum check.
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
std::string name
The name of the base set.
A single "line" in an ini file.
static const size_t NUM_FILES
Number of files in this set.
A group within an ini file.
static Blitter * SelectBlitter(const std::string &name)
Find the requested blitter and return its class.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
byte _display_opt
What do we want to draw/do?
byte GetContainerVersion() const
Get the version number of container type used by the file.
virtual void ClearSystemSprites()
Clear all cached sprites.
byte ReadByte()
Read a byte from the file.
GameCreationSettings game_creation
settings used during the creation of a game (map)
@ GCF_INIT_ONLY
GRF file is processed up to GLS_INIT.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
void UpdateCursorSize()
Update cursor dimension.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
@ CR_MATCH
The file did exist and the md5 checksum did match.
@ DO_FULL_ANIMATION
Perform palette animation.
@ GRFP_GRF_DOS
The NewGRF says the DOS palette can be used.
static const SpriteID *const _landscape_spriteindexes[]
Offsets for loading the different "replacement" sprites in the files.
void LoadNewGRF(uint load_index, uint num_baseset)
Load all the NewGRFs.
bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id)
Load a real or recolour sprite.
const char * missing_warning
warning when this file is missing
uint8 hash[16]
md5 sum of the file
static void LoadGrfFileIndexed(const char *filename, const SpriteID *index_tbl, bool needs_palette_remap)
Load an old fashioned GRF file to replace already loaded sprites.
Information about GRF, used in the game and (part of it) in savegames.
@ MAX_SPRITES
Maximum number of sprites that can be loaded at a given time.
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information.
@ S8BPP_NONE
No support for 8bpp by OS or hardware, force 32bpp blitters.
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.
static bool SwitchNewGRFBlitter()
Check blitter needed by NewGRF config and switch if needed.
std::optional< std::string > value
The value of this item.
uint8 flags
NOSAVE: GCF_Flags, bitset.
uint _missing_extra_graphics
Number of sprites provided by the fallback extra GRF, i.e. missing in the baseset.
bool HasAntialiasedFonts()
Should any of the active fonts be anti-aliased?
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
size_t GRFGetSizeOfDataSection(FILE *f)
Get the data section size of a GRF.
@ GRFP_BLT_32BPP
The NewGRF prefers a 32 bpp blitter.
ChecksumResult CheckMD5(Subdirectory subdir, size_t max_size) const
Calculate and check the MD5 hash of the supplied filename.
void CheckExternalFiles()
Checks whether the MD5 checksums of the files are correct.
BlitterType blitter
Blitter of this graphics set.
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.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
static const char *const _graphics_file_names[]
Names corresponding to the GraphicsFileType.
static uint LoadGrfFile(const char *filename, uint load_index, bool needs_palette_remap)
Load an old fashioned GRF file.
void CheckBlitter()
Check whether we still use the right blitter, or use another (better) one.
RandomAccessFile with some extra information specific for sprite files.
virtual const char * GetName()=0
Get the name of the blitter, the same as the Factory-instance returns.
bool _blitter_autodetected
Was the blitter autodetected or specified by the user?
@ GCS_DISABLED
GRF file is disabled.
@ GRFP_GRF_WINDOWS
The NewGRF says the Windows palette can be used.
Ini file that supports both loading and saving.
Structure holding filename and MD5 information about a single file.
static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir)
Calculate and check the MD5 hash of the supplied GRF.
static BlitterFactory * GetBlitterFactory(const std::string &name)
Get the blitter factory with the given name.
struct GRFConfig * next
NOSAVE: Next item in the linked list.
static const SpriteID SPR_OPENTTD_BASE
Extra graphic spritenumbers.
PaletteType palette
Palette of this graphics set.
Information about a single base set.
@ CR_NO_FILE
The file did not exist.
void CDECL ShowInfoF(const char *str,...)
Shows some information on the console/a popup box depending on the OS.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Subdirectory
The different kinds of subdirectories OpenTTD uses.
void GfxLoadSprites()
Initialise and load all the sprites.
static void InitializeUnicodeGlyphMap()
Initialize the glyph map.
uint8 palette
GRFPalette, bitset.
const char * filename
filename
GRFConfig * _grfconfig
First item in list of current GRF set up.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
#define lengthof(x)
Return the length of an fixed size array.
void ReadGRFSpriteOffsets(SpriteFile &file)
Parse the sprite section of GRFs.
IniItem * GetItem(const std::string &name, bool create)
Get the item with the given name, and if it doesn't exist and create is true it creates a new item.
@ PAL_WINDOWS
Use the Windows palette.
int GetNumInvalid() const
Get the number of invalid files.
static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir)
Calculate and check the MD5 hash of the supplied file.
bool FillSetDetails(IniFile *ini, const char *path, const char *full_filename, bool allow_empty_filename=true)
Read the set information from a loaded ini.
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 FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir)
Find the GRFID of a given grf, and calculate its md5sum.
#define lastof(x)
Get the last element of an fixed size array.
All data of a graphics set.
uint GetSpriteCountForFile(const std::string &filename, SpriteID begin, SpriteID end)
Count the sprites which originate from a specific file in a range of SpriteIDs.
MD5File files[NUM_FILES]
All files part of this set.
void FioFCloseFile(FILE *f)
Close a file in a safe way.
IniGroup * GetGroup(const std::string &name, bool create_new=true)
Get the group with the given name.