author | rubidium |
Wed, 07 May 2008 21:45:27 +0000 | |
changeset 10457 | ea18877d8eba |
parent 10429 | 1b99254f9607 |
child 10707 | 81a4013a7680 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10429
1b99254f9607
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8928
diff
changeset
|
3 |
/** @file gfxinit.cpp Initializing of the (GRF) graphics. */ |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6429
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1844
diff
changeset
|
6 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1250
diff
changeset
|
7 |
#include "debug.h" |
2340
0a9f3eeccb96
(svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
tron
parents:
2339
diff
changeset
|
8 |
#include "gfxinit.h" |
1349
07514c2cc6d1
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1348
diff
changeset
|
9 |
#include "spritecache.h" |
0 | 10 |
#include "fileio.h" |
8301
47e8f031a6ab
(svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents:
8296
diff
changeset
|
11 |
#include "fios.h" |
463
91bcad840bcd
(svn r687) Export InitNewGRFFile() and DecodeSpecialSprite() properly.
pasky
parents:
452
diff
changeset
|
12 |
#include "newgrf.h" |
961 | 13 |
#include "md5.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2142
diff
changeset
|
14 |
#include "variables.h" |
5156
5edaa8f9b295
(svn r7254) -Fix (r7250): move unicode glyph map initialisation to just before newgrf files are loaded, else newgrf glyphs will be cleared out too. (thanks Hadez)
peter1138
parents:
5151
diff
changeset
|
15 |
#include "fontcache.h" |
8619
c2434269c3eb
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8617
diff
changeset
|
16 |
#include "gfx_func.h" |
8709
4187ad809fe7
(svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents:
8629
diff
changeset
|
17 |
#include "core/alloc_func.hpp" |
8732
b18f578f7c16
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents:
8710
diff
changeset
|
18 |
#include "core/bitmath_func.hpp" |
4472
745f9ebe2216
(svn r6257) Use memcmp() to check the MD5 sum instead of using a home brewed loop
tron
parents:
4209
diff
changeset
|
19 |
#include <string.h> |
8766
c86cfa3a7580
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8760
diff
changeset
|
20 |
#include "settings_type.h" |
0 | 21 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8732
diff
changeset
|
22 |
#include "table/sprites.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8732
diff
changeset
|
23 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
24 |
struct MD5File { |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6429
diff
changeset
|
25 |
const char * filename; ///< filename |
8629
c764b6319d60
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8627
diff
changeset
|
26 |
uint8 hash[16]; ///< md5 sum of the file |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
27 |
}; |
961 | 28 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
29 |
struct FileList { |
8378
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
30 |
MD5File basic[2]; ///< GRF files that always have to be loaded |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
31 |
MD5File landscape[3]; ///< Landscape specific grf files |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
32 |
MD5File sound; ///< Sound samples |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
33 |
MD5File openttd; ///< GRF File with OTTD specific graphics |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
34 |
}; |
0 | 35 |
|
961 | 36 |
#include "table/files.h" |
0 | 37 |
#include "table/landscape_sprite.h" |
38 |
||
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
39 |
static const SpriteID * const _landscape_spriteindexes[] = { |
0 | 40 |
_landscape_spriteindexes_1, |
41 |
_landscape_spriteindexes_2, |
|
42 |
_landscape_spriteindexes_3, |
|
43 |
}; |
|
44 |
||
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
45 |
static uint LoadGrfFile(const char *filename, uint load_index, int file_index) |
0 | 46 |
{ |
2342
c19fb4f2df30
(svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents:
2340
diff
changeset
|
47 |
uint load_index_org = load_index; |
7404
fc0559157f16
(svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight
parents:
7276
diff
changeset
|
48 |
uint sprite_id = 0; |
0 | 49 |
|
50 |
FioOpenFile(file_index, filename); |
|
365
5752af05ed75
(svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents:
364
diff
changeset
|
51 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5296
diff
changeset
|
52 |
DEBUG(sprite, 2, "Reading grf-file '%s'", filename); |
0 | 53 |
|
7404
fc0559157f16
(svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight
parents:
7276
diff
changeset
|
54 |
while (LoadNextSprite(load_index, file_index, sprite_id)) { |
0 | 55 |
load_index++; |
7404
fc0559157f16
(svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight
parents:
7276
diff
changeset
|
56 |
sprite_id++; |
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
57 |
if (load_index >= MAX_SPRITES) { |
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
58 |
error("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files."); |
0 | 59 |
} |
60 |
} |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5296
diff
changeset
|
61 |
DEBUG(sprite, 2, "Currently %i sprites are loaded", load_index); |
0 | 62 |
|
365
5752af05ed75
(svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents:
364
diff
changeset
|
63 |
return load_index - load_index_org; |
5752af05ed75
(svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents:
364
diff
changeset
|
64 |
} |
5752af05ed75
(svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents:
364
diff
changeset
|
65 |
|
2342
c19fb4f2df30
(svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents:
2340
diff
changeset
|
66 |
|
8268
a83cbd95f3d3
(svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents:
8263
diff
changeset
|
67 |
void LoadSpritesIndexed(int file_index, uint *sprite_id, const SpriteID *index_tbl) |
a83cbd95f3d3
(svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents:
8263
diff
changeset
|
68 |
{ |
a83cbd95f3d3
(svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents:
8263
diff
changeset
|
69 |
uint start; |
a83cbd95f3d3
(svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents:
8263
diff
changeset
|
70 |
while ((start = *index_tbl++) != END) { |
a83cbd95f3d3
(svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents:
8263
diff
changeset
|
71 |
uint end = *index_tbl++; |
a83cbd95f3d3
(svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents:
8263
diff
changeset
|
72 |
|
8928
b3c4a8968fe1
(svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents:
8907
diff
changeset
|
73 |
do { |
b3c4a8968fe1
(svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents:
8907
diff
changeset
|
74 |
#ifdef NDEBUG |
b3c4a8968fe1
(svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents:
8907
diff
changeset
|
75 |
LoadNextSprite(start, file_index, *sprite_id); |
b3c4a8968fe1
(svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents:
8907
diff
changeset
|
76 |
#else |
b3c4a8968fe1
(svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents:
8907
diff
changeset
|
77 |
bool b = LoadNextSprite(start, file_index, *sprite_id); |
b3c4a8968fe1
(svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents:
8907
diff
changeset
|
78 |
assert(b); |
b3c4a8968fe1
(svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents:
8907
diff
changeset
|
79 |
#endif |
b3c4a8968fe1
(svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents:
8907
diff
changeset
|
80 |
(*sprite_id)++; |
b3c4a8968fe1
(svn r12002) -Cleanup (r11981): Remove obsolete code to skip sprites from indexed GRFs.
peter1138
parents:
8907
diff
changeset
|
81 |
} while (++start <= end); |
8268
a83cbd95f3d3
(svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents:
8263
diff
changeset
|
82 |
} |
a83cbd95f3d3
(svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents:
8263
diff
changeset
|
83 |
} |
a83cbd95f3d3
(svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents:
8263
diff
changeset
|
84 |
|
2342
c19fb4f2df30
(svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents:
2340
diff
changeset
|
85 |
static void LoadGrfIndexed(const char* filename, const SpriteID* index_tbl, int file_index) |
365
5752af05ed75
(svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents:
364
diff
changeset
|
86 |
{ |
7404
fc0559157f16
(svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight
parents:
7276
diff
changeset
|
87 |
uint sprite_id = 0; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
88 |
|
365
5752af05ed75
(svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents:
364
diff
changeset
|
89 |
FioOpenFile(file_index, filename); |
5752af05ed75
(svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents:
364
diff
changeset
|
90 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5296
diff
changeset
|
91 |
DEBUG(sprite, 2, "Reading indexed grf-file '%s'", filename); |
0 | 92 |
|
8268
a83cbd95f3d3
(svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents:
8263
diff
changeset
|
93 |
LoadSpritesIndexed(file_index, &sprite_id, index_tbl); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
94 |
} |
0 | 95 |
|
96 |
||
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
97 |
/** |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
98 |
* Calculate and check the MD5 hash of the supplied filename. |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
99 |
* @param file filename and expected MD5 hash for the given filename. |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
100 |
* @return true if the checksum is correct. |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
101 |
*/ |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
102 |
static bool FileMD5(const MD5File file) |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
103 |
{ |
8070
959633559d9f
(svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents:
7413
diff
changeset
|
104 |
size_t size; |
959633559d9f
(svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents:
7413
diff
changeset
|
105 |
FILE *f = FioFOpenFile(file.filename, "rb", DATA_DIR, &size); |
5733
8b3c5398687f
(svn r7766) -Fix: [OSX] removed incorrect debug message about corrupted/missing grf files
bjarni
parents:
5726
diff
changeset
|
106 |
|
862
d7e52ef99f42
(svn r1343) -Fix: [Graphic] Autorail icon is now correct (Darkvater)
truelight
parents:
614
diff
changeset
|
107 |
if (f != NULL) { |
8629
c764b6319d60
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8627
diff
changeset
|
108 |
Md5 checksum; |
c764b6319d60
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8627
diff
changeset
|
109 |
uint8 buffer[1024]; |
c764b6319d60
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8627
diff
changeset
|
110 |
uint8 digest[16]; |
2028
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
111 |
size_t len; |
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
112 |
|
8070
959633559d9f
(svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents:
7413
diff
changeset
|
113 |
while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) { |
959633559d9f
(svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents:
7413
diff
changeset
|
114 |
size -= len; |
8629
c764b6319d60
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8627
diff
changeset
|
115 |
checksum.Append(buffer, len); |
8070
959633559d9f
(svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents:
7413
diff
changeset
|
116 |
} |
961 | 117 |
|
8088
7c1a4dd586ae
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
8070
diff
changeset
|
118 |
FioFCloseFile(f); |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
966
diff
changeset
|
119 |
|
8629
c764b6319d60
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8627
diff
changeset
|
120 |
checksum.Finish(digest); |
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
121 |
return memcmp(file.hash, digest, sizeof(file.hash)) == 0; |
961 | 122 |
} else { // file not found |
123 |
return false; |
|
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
966
diff
changeset
|
124 |
} |
961 | 125 |
} |
126 |
||
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
127 |
/** |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
128 |
* Determine the palette that has to be used. |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
129 |
* - forced DOS palette via command line -> leave it that way |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
130 |
* - all Windows files present -> Windows palette |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
131 |
* - all DOS files present -> DOS palette |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
132 |
* - no Windows files present and any DOS file present -> DOS palette |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
133 |
* - otherwise -> Windows palette |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
134 |
*/ |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
135 |
static void DeterminePalette() |
961 | 136 |
{ |
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
137 |
if (_use_dos_palette) return; |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
138 |
|
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
139 |
/* Count of files from the different versions. */ |
1355 | 140 |
uint dos = 0; |
141 |
uint win = 0; |
|
961 | 142 |
|
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
143 |
for (uint i = 0; i < lengthof(files_dos.basic); i++) if (FioCheckFileExists(files_dos.basic[i].filename)) dos++; |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
144 |
for (uint i = 0; i < lengthof(files_dos.landscape); i++) if (FioCheckFileExists(files_dos.landscape[i].filename)) dos++; |
961 | 145 |
|
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
146 |
for (uint i = 0; i < lengthof(files_win.basic); i++) if (FioCheckFileExists(files_win.basic[i].filename)) win++; |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
147 |
for (uint i = 0; i < lengthof(files_win.landscape); i++) if (FioCheckFileExists(files_win.landscape[i].filename)) win++; |
4934
5f937d83f3eb
(svn r6921) - PEBKAC: Add an MD5 sum check of our own data files, and warn if they don't match.
peter1138
parents:
4795
diff
changeset
|
148 |
|
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
149 |
if (win == 5) { |
961 | 150 |
_use_dos_palette = false; |
1381 | 151 |
} else if (dos == 5 || (win == 0 && dos > 0)) { |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
152 |
_use_dos_palette = true; |
1380
7faf03f67dc3
(svn r1884) Change palette detection algorithm: Use the DOS palette if there are no Windows .grfs but at least one DOS .grf
tron
parents:
1378
diff
changeset
|
153 |
} else { |
961 | 154 |
_use_dos_palette = false; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
155 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
156 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
157 |
|
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
158 |
/** |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
159 |
* Checks whether the MD5 checksums of the files are correct. |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
160 |
* |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
161 |
* @note Also checks sample.cat and other required non-NewGRF GRFs for corruption. |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
162 |
*/ |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
163 |
void CheckExternalFiles() |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
164 |
{ |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
165 |
DeterminePalette(); |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
166 |
|
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
167 |
static const size_t ERROR_MESSAGE_LENGTH = 128; |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
168 |
const FileList *files = _use_dos_palette ? &files_dos : &files_win; |
8378
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
169 |
char error_msg[ERROR_MESSAGE_LENGTH * (lengthof(files->basic) + lengthof(files->landscape) + 3)]; |
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
170 |
error_msg[0] = '\0'; |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
171 |
char *add_pos = error_msg; |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
172 |
|
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
173 |
for (uint i = 0; i < lengthof(files->basic); i++) { |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
174 |
if (!FileMD5(files->basic[i])) { |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
175 |
add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! You can find '%s' on your Transport Tycoon Deluxe CD-ROM.\n", files->basic[i].filename, files->basic[i].filename); |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
176 |
} |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
177 |
} |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
178 |
|
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
179 |
for (uint i = 0; i < lengthof(files->landscape); i++) { |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
180 |
if (!FileMD5(files->landscape[i])) { |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
181 |
add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! You can find '%s' on your Transport Tycoon Deluxe CD-ROM.\n", files->landscape[i].filename, files->landscape[i].filename); |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
182 |
} |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
183 |
} |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
184 |
|
8378
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
185 |
if (!FileMD5(files_win.sound) && !FileMD5(files_dos.sound)) { |
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
186 |
add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your 'sample.cat' file is corrupted or missing! You can find 'sample.cat' on your Transport Tycoon Deluxe CD-ROM.\n"); |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
187 |
} |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
188 |
|
8378
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
189 |
if (!FileMD5(files->openttd)) { |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
190 |
add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! The file was part of your installation.\n", files->openttd.filename); |
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
191 |
} |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
192 |
|
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
193 |
if (add_pos != error_msg) ShowInfoF(error_msg); |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
194 |
} |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
195 |
|
2342
c19fb4f2df30
(svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents:
2340
diff
changeset
|
196 |
|
6573 | 197 |
static void LoadSpriteTables() |
0 | 198 |
{ |
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
199 |
const FileList *files = _use_dos_palette ? &files_dos : &files_win; |
8301
47e8f031a6ab
(svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents:
8296
diff
changeset
|
200 |
uint i = FIRST_GRF_SLOT; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
201 |
|
8907
5104ad700e31
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138
parents:
8871
diff
changeset
|
202 |
LoadGrfFile(files->basic[0].filename, 0, i++); |
2353 | 203 |
|
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
204 |
/* |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
205 |
* The second basic file always starts at the given location and does |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
206 |
* contain a different amount of sprites depending on the "type"; DOS |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
207 |
* has a few sprites less. However, we do not care about those missing |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
208 |
* sprites as they are not shown anyway (logos in intro game). |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
209 |
*/ |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
210 |
LoadGrfFile(files->basic[1].filename, 4793, i++); |
0 | 211 |
|
8337
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
212 |
/* |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
213 |
* Load additional sprites for climates other than temperate. |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
214 |
* This overwrites some of the temperate sprites, such as foundations |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
215 |
* and the ground sprites. |
fd294edef5be
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
rubidium
parents:
8301
diff
changeset
|
216 |
*/ |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6574
diff
changeset
|
217 |
if (_opt.landscape != LT_TEMPERATE) { |
2309 | 218 |
LoadGrfIndexed( |
5151
0f939d1c0896
(svn r7246) -Codechange: Always reload sprite and NewGRF data when loading or starting a game, instead of only when the climate type is different.
peter1138
parents:
5000
diff
changeset
|
219 |
files->landscape[_opt.landscape - 1].filename, |
0f939d1c0896
(svn r7246) -Codechange: Always reload sprite and NewGRF data when loading or starting a game, instead of only when the climate type is different.
peter1138
parents:
5000
diff
changeset
|
220 |
_landscape_spriteindexes[_opt.landscape - 1], |
2309 | 221 |
i++ |
222 |
); |
|
223 |
} |
|
0 | 224 |
|
5156
5edaa8f9b295
(svn r7254) -Fix (r7250): move unicode glyph map initialisation to just before newgrf files are loaded, else newgrf glyphs will be cleared out too. (thanks Hadez)
peter1138
parents:
5151
diff
changeset
|
225 |
/* Initialize the unicode to sprite mapping table */ |
5edaa8f9b295
(svn r7254) -Fix (r7250): move unicode glyph map initialisation to just before newgrf files are loaded, else newgrf glyphs will be cleared out too. (thanks Hadez)
peter1138
parents:
5151
diff
changeset
|
226 |
InitializeUnicodeGlyphMap(); |
5edaa8f9b295
(svn r7254) -Fix (r7250): move unicode glyph map initialisation to just before newgrf files are loaded, else newgrf glyphs will be cleared out too. (thanks Hadez)
peter1138
parents:
5151
diff
changeset
|
227 |
|
8378
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
228 |
/* |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
229 |
* Load the base NewGRF with OTTD required graphics as first NewGRF. |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
230 |
* However, we do not want it to show up in the list of used NewGRFs, |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
231 |
* so we have to manually add it, and then remove it later. |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
232 |
*/ |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
233 |
GRFConfig *top = _grfconfig; |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
234 |
GRFConfig *master = CallocT<GRFConfig>(1); |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
235 |
master->filename = strdup(files->openttd.filename); |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
236 |
FillGRFDetails(master, false); |
8425
72a71d480c5f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
8378
diff
changeset
|
237 |
ClrBit(master->flags, GCF_INIT_ONLY); |
8378
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
238 |
master->next = top; |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
239 |
_grfconfig = master; |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
240 |
|
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
241 |
LoadNewGRF(SPR_NEWGRFS_BASE, i); |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
242 |
|
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
243 |
/* Free and remove the top element. */ |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
244 |
ClearGRFConfig(&master); |
9f849e5763e2
(svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents:
8337
diff
changeset
|
245 |
_grfconfig = top; |
0 | 246 |
} |
247 |
||
248 |
||
6573 | 249 |
void GfxLoadSprites() |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1070
diff
changeset
|
250 |
{ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5296
diff
changeset
|
251 |
DEBUG(sprite, 2, "Loading sprite set %d", _opt.landscape); |
0 | 252 |
|
5151
0f939d1c0896
(svn r7246) -Codechange: Always reload sprite and NewGRF data when loading or starting a game, instead of only when the climate type is different.
peter1138
parents:
5000
diff
changeset
|
253 |
GfxInitSpriteMem(); |
0f939d1c0896
(svn r7246) -Codechange: Always reload sprite and NewGRF data when loading or starting a game, instead of only when the climate type is different.
peter1138
parents:
5000
diff
changeset
|
254 |
LoadSpriteTables(); |
0f939d1c0896
(svn r7246) -Codechange: Always reload sprite and NewGRF data when loading or starting a game, instead of only when the climate type is different.
peter1138
parents:
5000
diff
changeset
|
255 |
GfxInitPalettes(); |
0 | 256 |
} |