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);
228 master->
next = extra;
267 uint depth_wanted_by_grf = _support8bpp ==
S8BPP_NONE ? 32 : 8;
274 static const struct {
277 uint min_base_depth, max_base_depth, min_grf_depth, max_grf_depth;
278 } replacement_blitters[] = {
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 },
285 {
"8bpp-optimized", 2, 8, 8, 8, 8 },
286 {
"32bpp-optimized", 0, 8, 32, 8, 32 },
287 {
"32bpp-anim", 1, 8, 32, 8, 32 },
293 for (uint i = 0; i <
lengthof(replacement_blitters); i++) {
294 if (animation_wanted && (replacement_blitters[i].animation == 0))
continue;
295 if (!animation_wanted && (replacement_blitters[i].animation == 1))
continue;
297 if (!
IsInsideMM(depth_wanted_by_base, replacement_blitters[i].min_base_depth, replacement_blitters[i].max_base_depth + 1))
continue;
298 if (!
IsInsideMM(depth_wanted_by_grf, replacement_blitters[i].min_grf_depth, replacement_blitters[i].max_grf_depth + 1))
continue;
299 const char *repl_blitter = replacement_blitters[i].name;
301 if (strcmp(repl_blitter, cur_blitter) == 0)
return false;
304 DEBUG(misc, 1,
"Switching blitter from '%s' to '%s'... ", cur_blitter, repl_blitter);
306 if (new_blitter == NULL) NOT_REACHED();
307 DEBUG(misc, 1,
"Successfully switched to %s.", repl_blitter);
343 bool GraphicsSet::FillSetDetails(
IniFile *ini,
const char *path,
const char *full_filename)
354 item = metadata->
GetItem(
"blitter",
false);
399 size =
min(size, max_size);
406 while ((len = fread(buffer, 1, (size >
sizeof(buffer)) ?
sizeof(buffer) : size, f)) != 0 && size != 0) {
408 checksum.Append(buffer, len);
413 checksum.Finish(digest);
418 static const char *
const _graphics_file_names[] = {
"base",
"logos",
"arctic",
"tropical",
"toyland",
"extra" };
421 template <
class T,
size_t Tnum_files,
bool Tsearch_in_tars>
424 template <
class Tbase_set>
429 const Tbase_set *best = NULL;
432 if (c->GetNumMissing() != 0)
continue;
435 (best->fallback && !c->fallback) ||
436 best->valid_files < c->valid_files ||
437 (best->valid_files == c->valid_files && (
438 (best->shortname == c->shortname && best->version < c->version) ||
448 template <
class Tbase_set>