MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / LoadGrfFileIndexed

Function LoadGrfFileIndexed

src/gfxinit.cpp:82–106  ·  view source on GitHub ↗

* Load an old fashioned GRF file to replace already loaded sprites. * @param filename The name of the file to open. * @param index_tbl The offsets of each of the sprites. * @param needs_palette_remap Whether the colours in the GRF file need a palette remap. * @return The number of loaded sprites. */

Source from the content-addressed store, hash-verified

80 * @return The number of loaded sprites.
81 */
82static 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
108/**
109 * Checks whether the MD5 checksums of the files are correct.

Callers 1

LoadSpriteTablesFunction · 0.85

Calls 4

ReadGRFSpriteOffsetsFunction · 0.85
LoadNextSpriteFunction · 0.85
GetContainerVersionMethod · 0.80
ReadByteMethod · 0.45

Tested by

no test coverage detected