15 #include "3rdparty/md5/md5.h"
24 #define SET_TYPE "graphics"
38 _landscape_spriteindexes_arctic,
39 _landscape_spriteindexes_tropic,
40 _landscape_spriteindexes_toyland,
50 static uint
LoadGrfFile(
const char *filename, uint load_index,
int file_index)
52 uint load_index_org = load_index;
57 DEBUG(sprite, 2,
"Reading grf-file '%s'", filename);
60 if (container_ver == 0)
usererror(
"Base grf '%s' is corrupt", filename);
62 if (container_ver >= 2) {
65 if (compression != 0)
usererror(
"Unsupported compression format");
68 while (
LoadNextSprite(load_index, file_index, sprite_id, container_ver)) {
72 usererror(
"Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files.");
75 DEBUG(sprite, 2,
"Currently %i sprites are loaded", load_index);
77 return load_index - load_index_org;
94 DEBUG(sprite, 2,
"Reading indexed grf-file '%s'", filename);
97 if (container_ver == 0)
usererror(
"Base grf '%s' is corrupt", filename);
99 if (container_ver >= 2) {
102 if (compression != 0)
usererror(
"Unsupported compression format");
105 while ((start = *index_tbl++) != END) {
106 uint end = *index_tbl++;
109 bool b =
LoadNextSprite(start, file_index, sprite_id, container_ver);
112 }
while (++start <= end);
127 DEBUG(grf, 1,
"Using the %s base graphics set", used_set->
name);
129 static const size_t ERROR_MESSAGE_LENGTH = 256;
130 static const size_t MISSING_FILE_MESSAGE_LENGTH = 128;
137 char *add_pos = error_msg;
138 const char *last =
lastof(error_msg);
142 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.txt.\n\nThe following files are corrupted or missing:\n", used_set->
name);
147 add_pos +=
seprintf(add_pos, last,
"\n");
152 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.txt.\n\nThe following files are corrupted or missing:\n", sounds_set->
name);
160 if (add_pos != error_msg)
ShowInfoF(
"%s", error_msg);
249 uint depth_wanted_by_grf = _support8bpp ==
S8BPP_NONE ? 32 : 8;
256 static const struct {
259 uint min_base_depth, max_base_depth, min_grf_depth, max_grf_depth;
260 } replacement_blitters[] = {
262 {
"32bpp-sse4", 0, 32, 32, 8, 32 },
263 {
"32bpp-ssse3", 0, 32, 32, 8, 32 },
264 {
"32bpp-sse2", 0, 32, 32, 8, 32 },
265 {
"32bpp-sse4-anim", 1, 32, 32, 8, 32 },
267 {
"8bpp-optimized", 2, 8, 8, 8, 8 },
268 {
"32bpp-optimized", 0, 8, 32, 8, 32 },
269 {
"32bpp-anim", 1, 8, 32, 8, 32 },
275 for (uint i = 0; i <
lengthof(replacement_blitters); i++) {
276 if (animation_wanted && (replacement_blitters[i].animation == 0))
continue;
277 if (!animation_wanted && (replacement_blitters[i].animation == 1))
continue;
279 if (!
IsInsideMM(depth_wanted_by_base, replacement_blitters[i].min_base_depth, replacement_blitters[i].max_base_depth + 1))
continue;
280 if (!
IsInsideMM(depth_wanted_by_grf, replacement_blitters[i].min_grf_depth, replacement_blitters[i].max_grf_depth + 1))
continue;
281 const char *repl_blitter = replacement_blitters[i].name;
283 if (strcmp(repl_blitter, cur_blitter) == 0)
return false;
286 DEBUG(misc, 1,
"Switching blitter from '%s' to '%s'... ", cur_blitter, repl_blitter);
288 if (new_blitter == NULL) NOT_REACHED();
289 DEBUG(misc, 1,
"Successfully switched to %s.", repl_blitter);
325 bool GraphicsSet::FillSetDetails(
IniFile *ini,
const char *path,
const char *full_filename)
336 item = metadata->
GetItem(
"blitter",
false);
381 size =
min(size, max_size);
388 while ((len = fread(buffer, 1, (size >
sizeof(buffer)) ?
sizeof(buffer) : size, f)) != 0 && size != 0) {
390 checksum.Append(buffer, len);
395 checksum.Finish(digest);
400 static const char *
const _graphics_file_names[] = {
"base",
"logos",
"arctic",
"tropical",
"toyland",
"extra" };
403 template <
class T,
size_t Tnum_files,
bool Tsearch_in_tars>
406 template <
class Tbase_set>
411 const Tbase_set *best = NULL;
414 if (c->GetNumMissing() != 0)
continue;
417 (best->fallback && !c->fallback) ||
418 best->valid_files < c->valid_files ||
419 (best->valid_files == c->valid_files && (
420 (best->shortname == c->shortname && best->version < c->version) ||
430 template <
class Tbase_set>