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 },
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;
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;
303 if (strcmp(repl_blitter, cur_blitter) == 0) {
309 DEBUG(misc, 1,
"Switching blitter from '%s' to '%s'... ", cur_blitter, repl_blitter);
311 if (new_blitter == NULL) NOT_REACHED();
312 DEBUG(misc, 1,
"Successfully switched to %s.", repl_blitter);
350 bool GraphicsSet::FillSetDetails(
IniFile *ini,
const char *path,
const char *full_filename)
361 item = metadata->
GetItem(
"blitter",
false);
406 size =
min(size, max_size);
413 while ((len = fread(buffer, 1, (size >
sizeof(buffer)) ?
sizeof(buffer) : size, f)) != 0 && size != 0) {
415 checksum.Append(buffer, len);
420 checksum.Finish(digest);
425 static const char *
const _graphics_file_names[] = {
"base",
"logos",
"arctic",
"tropical",
"toyland",
"extra" };
428 template <
class T,
size_t Tnum_files,
bool Tsearch_in_tars>
431 template <
class Tbase_set>
436 const Tbase_set *best = NULL;
439 if (c->GetNumMissing() != 0)
continue;
442 (best->fallback && !c->fallback) ||
443 best->valid_files < c->valid_files ||
444 (best->valid_files == c->valid_files && (
445 (best->shortname == c->shortname && best->version < c->version) ||
455 template <
class Tbase_set>