author | tron |
Sun, 13 Feb 2005 08:12:03 +0000 | |
changeset 1361 | 10d9b95e7a81 |
parent 1357 | a5acbb1f20fe |
child 1363 | 01d3de5d8039 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1250
diff
changeset
|
3 |
#include "debug.h" |
0 | 4 |
#include "gfx.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
|
5 |
#include "spritecache.h" |
0 | 6 |
#include "fileio.h" |
463
91bcad840bcd
(svn r687) Export InitNewGRFFile() and DecodeSpecialSprite() properly.
pasky
parents:
452
diff
changeset
|
7 |
#include "newgrf.h" |
961 | 8 |
#include "md5.h" |
0 | 9 |
#include <ctype.h> |
10 |
||
11 |
#define SPRITECACHE_ID 0xF00F0006 |
|
12 |
#define SPRITE_CACHE_SIZE 1024*1024 |
|
13 |
||
14 |
||
15 |
//#define WANT_SPRITESIZES |
|
16 |
#define WANT_NEW_LRU |
|
17 |
//#define WANT_LOCKED |
|
18 |
||
19 |
||
452
520e4ed6945d
(svn r662) [newgrf] Moved grfspecial.c to newgrf.c/newgrf.h
dominik
parents:
442
diff
changeset
|
20 |
/* These are used in newgrf.c: */ |
361
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
21 |
|
0 | 22 |
int _skip_sprites = 0; |
361
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
23 |
int _replace_sprites_count[16]; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
24 |
int _replace_sprites_offset[16]; |
0 | 25 |
|
368
32aad6ad36e1
(svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents:
366
diff
changeset
|
26 |
static const char *_cur_grffile; |
32aad6ad36e1
(svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents:
366
diff
changeset
|
27 |
static int _loading_stage; |
0 | 28 |
static int _skip_specials; |
392
3657d06c6564
(svn r584) -newgrf: Increase chance to get a TTDPatch savegame using custom GRF files loaded (pasky)
darkvater
parents:
368
diff
changeset
|
29 |
uint16 _custom_sprites_base; |
1348 | 30 |
static Sprite _cur_sprite; |
0 | 31 |
|
361
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
32 |
|
0 | 33 |
static byte *_sprite_ptr[NUM_SPRITES]; |
34 |
static uint16 _sprite_size[NUM_SPRITES]; |
|
35 |
static uint32 _sprite_file_pos[NUM_SPRITES]; |
|
36 |
||
37 |
// This one is probably not needed. |
|
38 |
#if defined(WANT_LOCKED) |
|
39 |
static bool _sprite_locked[NUM_SPRITES]; |
|
40 |
#endif |
|
41 |
||
42 |
#if defined(WANT_NEW_LRU) |
|
43 |
static int16 _sprite_lru_new[NUM_SPRITES]; |
|
44 |
#else |
|
45 |
static uint16 _sprite_lru[NUM_SPRITES]; |
|
46 |
static uint16 _sprite_lru_cur[NUM_SPRITES]; |
|
47 |
#endif |
|
48 |
||
49 |
#ifdef WANT_SPRITESIZES |
|
50 |
static int8 _sprite_xoffs[NUM_SPRITES]; |
|
51 |
static int8 _sprite_yoffs[NUM_SPRITES]; |
|
52 |
static uint16 _sprite_xsize[NUM_SPRITES]; |
|
53 |
static uint8 _sprite_ysize[NUM_SPRITES]; |
|
54 |
#endif |
|
55 |
||
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
56 |
typedef struct MemBlock { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
57 |
uint32 size; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
58 |
byte data[VARARRAY_SIZE]; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
59 |
} MemBlock; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
60 |
|
0 | 61 |
static uint _sprite_lru_counter; |
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
62 |
static MemBlock *_spritecache_ptr; |
0 | 63 |
static uint32 _spritecache_size; |
64 |
static int _compact_cache_counter; |
|
65 |
||
961 | 66 |
typedef struct MD5File { |
67 |
const char * const filename; // filename |
|
962
c1de16d93e46
(svn r1454) -Fix: small warnings in spritecache.c
darkvater
parents:
961
diff
changeset
|
68 |
const md5_byte_t hash[16]; // md5 sum of the file |
961 | 69 |
} MD5File; |
70 |
||
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
71 |
typedef struct FileList { |
961 | 72 |
const MD5File basic[4]; // grf files that always have to be loaded |
73 |
const MD5File landscape[3]; // landscape specific grf files |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
74 |
} FileList; |
0 | 75 |
|
961 | 76 |
#include "table/files.h" |
0 | 77 |
#include "table/landscape_sprite.h" |
78 |
||
79 |
static const uint16 * const _landscape_spriteindexes[] = { |
|
80 |
_landscape_spriteindexes_1, |
|
81 |
_landscape_spriteindexes_2, |
|
82 |
_landscape_spriteindexes_3, |
|
83 |
}; |
|
84 |
||
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
85 |
static const uint16 * const _slopes_spriteindexes[] = { |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
86 |
_slopes_spriteindexes_0, |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
87 |
_slopes_spriteindexes_1, |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
88 |
_slopes_spriteindexes_2, |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
89 |
_slopes_spriteindexes_3, |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
90 |
}; |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
91 |
|
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
|
92 |
static void CompactSpriteCache(void); |
0 | 93 |
|
94 |
static void ReadSpriteHeaderSkipData(int num, int load_index) |
|
95 |
{ |
|
96 |
byte type; |
|
97 |
int deaf = 0; |
|
98 |
||
99 |
if (_skip_sprites) { |
|
100 |
if (_skip_sprites > 0) |
|
101 |
_skip_sprites--; |
|
102 |
deaf = 1; |
|
103 |
} |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
104 |
|
0 | 105 |
type = FioReadByte(); |
364
9e93d102fd4a
(svn r552) -newgrf: Include bits forgotten when merging octo's ReplaceSprites support - it would replace even special sprites in the way now. (pasky)
darkvater
parents:
361
diff
changeset
|
106 |
_cur_sprite.info = type; |
0 | 107 |
if (type == 0xFF) { |
108 |
/* We need to really skip only special sprites in the deaf |
|
109 |
* mode. It won't hurt to proceed regular sprites as usual |
|
110 |
* because if no special sprite referencing to them is |
|
111 |
* processed, they themselves are never referenced and loaded |
|
112 |
* on their own. */ |
|
113 |
if (_skip_specials || deaf) { |
|
114 |
FioSkipBytes(num); |
|
115 |
} else { |
|
368
32aad6ad36e1
(svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents:
366
diff
changeset
|
116 |
DecodeSpecialSprite(_cur_grffile, num, load_index, _loading_stage); |
0 | 117 |
} |
118 |
return; |
|
119 |
} |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
120 |
|
0 | 121 |
#ifdef WANT_SPRITESIZES |
122 |
_cur_sprite.height = FioReadByte(); |
|
123 |
_cur_sprite.width = FioReadWord(); |
|
124 |
_cur_sprite.x_offs = FioReadWord(); |
|
125 |
_cur_sprite.y_offs = FioReadWord(); |
|
126 |
#else |
|
127 |
FioSkipBytes(7); |
|
128 |
#endif |
|
129 |
num -= 8; |
|
130 |
if (num == 0) |
|
131 |
return; |
|
132 |
||
133 |
if (type & 2) { |
|
134 |
FioSkipBytes(num); |
|
1355 | 135 |
} else { |
136 |
while (num > 0) { |
|
137 |
int8 i = FioReadByte(); |
|
138 |
if (i >= 0) { |
|
139 |
num -= i; |
|
140 |
FioSkipBytes(i); |
|
141 |
} else { |
|
142 |
i = -(i >> 3); |
|
143 |
num -= i; |
|
144 |
FioReadByte(); |
|
145 |
} |
|
0 | 146 |
} |
147 |
} |
|
148 |
} |
|
149 |
||
1361 | 150 |
static void ReadSprite(SpriteID id, void *buffer) |
0 | 151 |
{ |
1354
5e5c89b9b169
(svn r1858) Let ReadSprite() handle the subtleties of loading a sprite, not its caller
tron
parents:
1353
diff
changeset
|
152 |
uint num = _sprite_size[id]; |
0 | 153 |
byte type; |
1361 | 154 |
byte* dest; |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
155 |
|
1354
5e5c89b9b169
(svn r1858) Let ReadSprite() handle the subtleties of loading a sprite, not its caller
tron
parents:
1353
diff
changeset
|
156 |
FioSeekToFile(_sprite_file_pos[id]); |
5e5c89b9b169
(svn r1858) Let ReadSprite() handle the subtleties of loading a sprite, not its caller
tron
parents:
1353
diff
changeset
|
157 |
|
0 | 158 |
type = FioReadByte(); |
159 |
/* We've decoded special sprites when reading headers. */ |
|
160 |
if (type != 0xFF) { |
|
161 |
/* read sprite hdr */ |
|
1361 | 162 |
Sprite* sprite = buffer; |
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
163 |
sprite->info = type; |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
164 |
sprite->height = FioReadByte(); |
1354
5e5c89b9b169
(svn r1858) Let ReadSprite() handle the subtleties of loading a sprite, not its caller
tron
parents:
1353
diff
changeset
|
165 |
if (id == 142) sprite->height = 10; // Compensate for a TTD bug |
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
166 |
sprite->width = FioReadWord(); |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
167 |
sprite->x_offs = FioReadWord(); |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
168 |
sprite->y_offs = FioReadWord(); |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
169 |
dest = sprite->data; |
0 | 170 |
num -= 8; |
1361 | 171 |
} else { |
172 |
dest = buffer; |
|
0 | 173 |
} |
174 |
||
175 |
if (type & 2) { |
|
1355 | 176 |
for (; num > 0; --num) |
0 | 177 |
*dest++ = FioReadByte(); |
1355 | 178 |
} else { |
179 |
while (num > 0) { |
|
180 |
int8 i = FioReadByte(); |
|
0 | 181 |
|
1355 | 182 |
if (i >= 0) { |
183 |
num -= i; |
|
184 |
for (; i > 0; --i) |
|
185 |
*dest++ = FioReadByte(); |
|
186 |
} else { |
|
187 |
const byte* rel = dest - (((i & 7) << 8) | FioReadByte()); |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
188 |
|
1355 | 189 |
i = -(i >> 3); |
190 |
num -= i; |
|
191 |
||
192 |
for (; i > 0; --i) |
|
193 |
*dest++ = *rel++; |
|
194 |
} |
|
0 | 195 |
} |
196 |
} |
|
197 |
} |
|
198 |
||
199 |
||
200 |
static bool LoadNextSprite(int load_index, byte file_index) |
|
201 |
{ |
|
202 |
uint16 size; |
|
361
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
203 |
uint32 file_pos; |
0 | 204 |
|
1355 | 205 |
size = FioReadWord(); |
206 |
if (size == 0) |
|
0 | 207 |
return false; |
208 |
||
361
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
209 |
file_pos = FioGetPos() | (file_index << 24); |
0 | 210 |
|
211 |
ReadSpriteHeaderSkipData(size, load_index); |
|
212 |
||
1355 | 213 |
if (_replace_sprites_count[0] > 0 && _cur_sprite.info != 0xFF) { |
361
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
214 |
int count = _replace_sprites_count[0]; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
215 |
int offset = _replace_sprites_offset[0]; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
216 |
|
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
217 |
_replace_sprites_offset[0]++; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
218 |
_replace_sprites_count[0]--; |
862
d7e52ef99f42
(svn r1343) -Fix: [Graphic] Autorail icon is now correct (Darkvater)
truelight
parents:
614
diff
changeset
|
219 |
|
361
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
220 |
if ((offset + count) <= NUM_SPRITES) { |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
221 |
load_index = offset; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
222 |
} else { |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
223 |
DEBUG(spritecache, 1) ("Sprites to be replaced are out of range: %x+%x", |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
224 |
count, offset); |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
225 |
_replace_sprites_offset[0] = 0; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
226 |
_replace_sprites_count[0] = 0; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
227 |
} |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
228 |
|
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
229 |
if (_replace_sprites_count[0] == 0) { |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
230 |
int i; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
231 |
|
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
232 |
for (i = 0; i < 15; i++) { |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
233 |
_replace_sprites_count[i] = _replace_sprites_count[i + 1]; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
234 |
_replace_sprites_offset[i] = _replace_sprites_offset[i + 1]; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
235 |
} |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
236 |
_replace_sprites_count[i] = 0; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
237 |
_replace_sprites_offset[i] = 0; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
238 |
} |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
239 |
} |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
240 |
|
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
241 |
_sprite_size[load_index] = size; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
242 |
_sprite_file_pos[load_index] = file_pos; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
243 |
|
0 | 244 |
#ifdef WANT_SPRITESIZES |
245 |
_sprite_xsize[load_index] = _cur_sprite.width; |
|
246 |
_sprite_ysize[load_index] = _cur_sprite.height; |
|
247 |
||
248 |
_sprite_xoffs[load_index] = _cur_sprite.x_offs; |
|
249 |
_sprite_yoffs[load_index] = _cur_sprite.y_offs; |
|
250 |
#endif |
|
251 |
||
252 |
_sprite_ptr[load_index] = NULL; |
|
253 |
#if defined(WANT_LOCKED) |
|
254 |
_sprite_locked[load_index] = false; |
|
255 |
#endif |
|
256 |
||
257 |
#if defined(WANT_NEW_LRU) |
|
258 |
_sprite_lru_new[load_index] = 0; |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
259 |
#else |
0 | 260 |
_sprite_lru[load_index] = 0xFFFF; |
261 |
_sprite_lru_cur[load_index] = 0; |
|
262 |
#endif |
|
263 |
||
264 |
return true; |
|
265 |
} |
|
266 |
||
1355 | 267 |
static void SkipSprites(uint count) |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
268 |
{ |
1355 | 269 |
for (; count > 0; --count) |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
270 |
{ |
1355 | 271 |
uint16 size = FioReadWord(); |
272 |
||
273 |
if (size == 0) |
|
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
274 |
return; |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
275 |
|
1355 | 276 |
ReadSpriteHeaderSkipData(size, NUM_SPRITES - 1); |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
277 |
} |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
278 |
} |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
279 |
|
0 | 280 |
static int LoadGrfFile(const char *filename, int load_index, int file_index) |
281 |
{ |
|
282 |
int load_index_org = load_index; |
|
283 |
||
284 |
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
|
285 |
|
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
|
286 |
/* Thou shalt use LoadNewGrfFile() if thou loadeth a GRF file that |
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
|
287 |
* might contain some special sprites. */ |
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
|
288 |
_skip_specials = 1; |
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
|
289 |
_skip_sprites = 0; |
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
|
290 |
|
366
9d2630b8b4de
(svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents:
365
diff
changeset
|
291 |
DEBUG(spritecache, 2) ("Reading grf-file ``%s''", filename); |
0 | 292 |
|
293 |
while (LoadNextSprite(load_index, file_index)) { |
|
294 |
load_index++; |
|
295 |
if (load_index >= NUM_SPRITES) { |
|
296 |
error("Too many sprites. Recompile with higher NUM_SPRITES value or remove some custom GRF files."); |
|
297 |
} |
|
298 |
} |
|
299 |
||
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
|
300 |
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
|
301 |
} |
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
|
302 |
|
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
|
303 |
static int LoadNewGrfFile(const char *filename, int load_index, int file_index) |
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
|
304 |
{ |
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
|
305 |
int i; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
306 |
|
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
|
307 |
FioOpenFile(file_index, filename); |
368
32aad6ad36e1
(svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents:
366
diff
changeset
|
308 |
_cur_grffile = 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
|
309 |
_skip_specials = 0; |
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
|
310 |
_skip_sprites = 0; |
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
|
311 |
|
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
|
312 |
DEBUG(spritecache, 2) ("Reading newgrf-file ``%s'' [offset: %u]", |
366
9d2630b8b4de
(svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents:
365
diff
changeset
|
313 |
filename, load_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
|
314 |
|
442
913a307af50d
(svn r651) LoadNewGrfFile() now doesn't care about num_sprites and just loads whatever is
miham
parents:
425
diff
changeset
|
315 |
/* Skip the first sprite; we don't care about how many sprites this |
913a307af50d
(svn r651) LoadNewGrfFile() now doesn't care about num_sprites and just loads whatever is
miham
parents:
425
diff
changeset
|
316 |
* does contain; newest TTDPatches and George's longvehicles don't |
913a307af50d
(svn r651) LoadNewGrfFile() now doesn't care about num_sprites and just loads whatever is
miham
parents:
425
diff
changeset
|
317 |
* neither, apparently. */ |
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
|
318 |
{ |
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
|
319 |
int length; |
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
|
320 |
byte type; |
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
|
321 |
|
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
|
322 |
length = FioReadWord(); |
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
|
323 |
type = FioReadByte(); |
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
|
324 |
|
1355 | 325 |
if (length == 4 && type == 0xFF) { |
442
913a307af50d
(svn r651) LoadNewGrfFile() now doesn't care about num_sprites and just loads whatever is
miham
parents:
425
diff
changeset
|
326 |
FioReadDword(); |
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
|
327 |
} else { |
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
|
328 |
error("Custom .grf has invalid format."); |
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
|
329 |
} |
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
|
330 |
} |
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
|
331 |
|
442
913a307af50d
(svn r651) LoadNewGrfFile() now doesn't care about num_sprites and just loads whatever is
miham
parents:
425
diff
changeset
|
332 |
for (i = 0; LoadNextSprite(load_index + i, file_index); i++) { |
913a307af50d
(svn r651) LoadNewGrfFile() now doesn't care about num_sprites and just loads whatever is
miham
parents:
425
diff
changeset
|
333 |
if (load_index + i >= NUM_SPRITES) |
913a307af50d
(svn r651) LoadNewGrfFile() now doesn't care about num_sprites and just loads whatever is
miham
parents:
425
diff
changeset
|
334 |
error("Too many sprites (%x). Recompile with higher NUM_SPRITES value or remove some custom GRF files.", |
913a307af50d
(svn r651) LoadNewGrfFile() now doesn't care about num_sprites and just loads whatever is
miham
parents:
425
diff
changeset
|
335 |
load_index + i); |
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
|
336 |
} |
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
|
337 |
|
361
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
338 |
/* Clean up. */ |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
339 |
_skip_sprites = 0; |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
340 |
memset(_replace_sprites_count, 0, 16 * sizeof(*_replace_sprites_count)); |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
341 |
memset(_replace_sprites_offset, 0, 16 * sizeof(*_replace_sprites_offset)); |
0 | 342 |
|
442
913a307af50d
(svn r651) LoadNewGrfFile() now doesn't care about num_sprites and just loads whatever is
miham
parents:
425
diff
changeset
|
343 |
return i; |
0 | 344 |
} |
345 |
||
346 |
static void LoadGrfIndexed(const char *filename, const uint16 *index_tbl, int file_index) |
|
347 |
{ |
|
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
348 |
int start; |
0 | 349 |
|
350 |
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
|
351 |
_skip_specials = 1; |
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
|
352 |
_skip_sprites = 0; |
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
|
353 |
|
366
9d2630b8b4de
(svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents:
365
diff
changeset
|
354 |
DEBUG(spritecache, 2) ("Reading indexed grf-file ``%s''", filename); |
0 | 355 |
|
1355 | 356 |
for (; (start = *index_tbl++) != 0xffff;) { |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
357 |
int end = *index_tbl++; |
1355 | 358 |
if(start == 0xfffe) { // skip sprites (amount in second var) |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
359 |
SkipSprites(end); |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
360 |
} else { // load sprites and use indexes from start to end |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
361 |
do { |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
362 |
bool b = LoadNextSprite(start, file_index); |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
363 |
assert(b); |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
364 |
} while (++start <= end); |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
365 |
} |
0 | 366 |
} |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
367 |
} |
0 | 368 |
|
1355 | 369 |
typedef size_t CDECL fread_t(void*, size_t, size_t, FILE*); |
0 | 370 |
|
371 |
static bool HandleCachedSpriteHeaders(const char *filename, bool read) |
|
372 |
{ |
|
373 |
FILE *f; |
|
374 |
fread_t *proc; |
|
375 |
uint32 hdr; |
|
376 |
||
377 |
if (!_cache_sprites) |
|
378 |
return false; |
|
379 |
||
380 |
if (read) { |
|
381 |
f = fopen(filename, "rb"); |
|
382 |
proc = fread; |
|
383 |
||
384 |
if (f == NULL) |
|
385 |
return false; |
|
386 |
||
387 |
proc(&hdr, sizeof(hdr), 1, f); |
|
388 |
if (hdr != SPRITECACHE_ID) { |
|
389 |
fclose(f); |
|
390 |
return false; |
|
391 |
} |
|
392 |
} else { |
|
393 |
f = fopen(filename, "wb"); |
|
394 |
proc = (fread_t*) fwrite; |
|
395 |
||
396 |
if (f == NULL) |
|
397 |
return false; |
|
398 |
||
399 |
hdr = SPRITECACHE_ID; |
|
400 |
proc(&hdr, sizeof(hdr), 1, f); |
|
401 |
} |
|
402 |
||
403 |
proc(_sprite_size, 1, sizeof(_sprite_size), f); |
|
404 |
proc(_sprite_file_pos, 1, sizeof(_sprite_file_pos), f); |
|
405 |
||
406 |
#if 0 |
|
407 |
proc(_sprite_xsize, 1, sizeof(_sprite_xsize), f); |
|
408 |
proc(_sprite_ysize, 1, sizeof(_sprite_ysize), f); |
|
409 |
proc(_sprite_xoffs, 1, sizeof(_sprite_xoffs), f); |
|
410 |
proc(_sprite_yoffs, 1, sizeof(_sprite_yoffs), f); |
|
411 |
#endif |
|
412 |
||
413 |
#if !defined(WANT_NEW_LRU) |
|
414 |
if (read) |
|
415 |
memset(_sprite_lru, 0xFF, sizeof(_sprite_lru)); |
|
416 |
#endif |
|
417 |
||
418 |
fclose(f); |
|
419 |
return true; |
|
420 |
} |
|
421 |
||
422 |
#define S_FREE_MASK 1 |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
423 |
|
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
424 |
static inline MemBlock* NextBlock(MemBlock* block) |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
425 |
{ |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
426 |
return (MemBlock*)((byte*)block + (block->size & ~S_FREE_MASK)); |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
427 |
} |
0 | 428 |
|
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
|
429 |
static uint32 GetSpriteCacheUsage(void) |
0 | 430 |
{ |
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
431 |
size_t tot_size = 0; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
432 |
MemBlock* s; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
433 |
|
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
434 |
for (s = _spritecache_ptr; s->size != 0; s = NextBlock(s)) |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
435 |
if (!(s->size & S_FREE_MASK)) tot_size += s->size; |
0 | 436 |
|
437 |
return tot_size; |
|
438 |
} |
|
439 |
||
440 |
||
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
|
441 |
void IncreaseSpriteLRU(void) |
0 | 442 |
{ |
443 |
int i; |
|
444 |
||
445 |
// Increase all LRU values |
|
446 |
#if defined(WANT_NEW_LRU) |
|
447 |
if (_sprite_lru_counter > 16384) { |
|
448 |
DEBUG(spritecache, 2) ("fixing lru %d, inuse=%d", _sprite_lru_counter, GetSpriteCacheUsage()); |
|
449 |
||
1355 | 450 |
for (i = 0; i != NUM_SPRITES; i++) |
0 | 451 |
if (_sprite_ptr[i] != NULL) { |
452 |
if (_sprite_lru_new[i] >= 0) { |
|
453 |
_sprite_lru_new[i] = -1; |
|
454 |
} else if (_sprite_lru_new[i] != -32768) { |
|
455 |
_sprite_lru_new[i]--; |
|
456 |
} |
|
457 |
} |
|
458 |
_sprite_lru_counter = 0; |
|
459 |
} |
|
460 |
#else |
|
1355 | 461 |
for (i = 0; i != NUM_SPRITES; i++) |
0 | 462 |
if (_sprite_ptr[i] != NULL && _sprite_lru[i] != 65535) |
463 |
_sprite_lru[i]++; |
|
464 |
// Reset the lru counter. |
|
465 |
_sprite_lru_counter = 0; |
|
466 |
#endif |
|
467 |
||
468 |
// Compact sprite cache every now and then. |
|
469 |
if (++_compact_cache_counter >= 740) { |
|
470 |
CompactSpriteCache(); |
|
471 |
_compact_cache_counter = 0; |
|
472 |
} |
|
473 |
} |
|
474 |
||
475 |
// Called when holes in the sprite cache should be removed. |
|
476 |
// That is accomplished by moving the cached data. |
|
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
|
477 |
static void CompactSpriteCache(void) |
0 | 478 |
{ |
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
479 |
MemBlock *s; |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
480 |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
481 |
DEBUG(spritecache, 2) ( |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
482 |
"compacting sprite cache, inuse=%d", GetSpriteCacheUsage() |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
483 |
); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
484 |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
485 |
for (s = _spritecache_ptr; s->size != 0;) { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
486 |
if (s->size & S_FREE_MASK) { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
487 |
MemBlock* next = NextBlock(s); |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
488 |
MemBlock temp; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
489 |
byte** i; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
490 |
|
0 | 491 |
// Since free blocks are automatically coalesced, this should hold true. |
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
492 |
assert(!(next->size & S_FREE_MASK)); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
493 |
|
0 | 494 |
// If the next block is the sentinel block, we can safely return |
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
495 |
if (next->size == 0) |
0 | 496 |
break; |
497 |
||
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
498 |
// Locate the sprite belonging to the next pointer. |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
499 |
for (i = _sprite_ptr; *i != next->data; ++i) { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
500 |
assert(i != endof(_sprite_ptr)); |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
501 |
} |
0 | 502 |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
503 |
#ifdef WANT_LOCKED |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
504 |
if (_sprite_locked[i]) { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
505 |
s = next; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
506 |
continue; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
507 |
} |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
508 |
#endif |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
509 |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
510 |
*i = s->data; // Adjust sprite array entry |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
511 |
// Swap this and the next block |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
512 |
temp = *s; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
513 |
memmove(s, next, next->size); |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
514 |
s = NextBlock(s); |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
515 |
*s = temp; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
516 |
|
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
517 |
// Coalesce free blocks |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
518 |
while (NextBlock(s)->size & S_FREE_MASK) { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
519 |
s->size += NextBlock(s)->size & ~S_FREE_MASK; |
0 | 520 |
} |
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
521 |
} else { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
522 |
s = NextBlock(s); |
0 | 523 |
} |
524 |
} |
|
525 |
} |
|
526 |
||
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
|
527 |
static void DeleteEntryFromSpriteCache(void) |
0 | 528 |
{ |
529 |
int i; |
|
530 |
int best = -1; |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
531 |
MemBlock* s; |
0 | 532 |
int cur_lru; |
533 |
||
534 |
DEBUG(spritecache, 2) ("DeleteEntryFromSpriteCache, inuse=%d", GetSpriteCacheUsage()); |
|
535 |
||
536 |
#if defined(WANT_NEW_LRU) |
|
537 |
cur_lru = 0xffff; |
|
1355 | 538 |
for (i = 0; i != NUM_SPRITES; i++) { |
0 | 539 |
if (_sprite_ptr[i] != 0 && |
540 |
_sprite_lru_new[i] < cur_lru |
|
541 |
#if defined(WANT_LOCKED) |
|
1355 | 542 |
&& !_sprite_locked[i] |
543 |
#endif |
|
0 | 544 |
) { |
545 |
cur_lru = _sprite_lru_new[i]; |
|
546 |
best = i; |
|
547 |
} |
|
548 |
} |
|
549 |
#else |
|
550 |
{ |
|
551 |
uint16 cur_lru = 0, cur_lru_cur = 0xffff; |
|
1355 | 552 |
for (i = 0; i != NUM_SPRITES; i++) { |
0 | 553 |
if (_sprite_ptr[i] == 0 || |
554 |
#if defined(WANT_LOCKED) |
|
555 |
_sprite_locked[i] || |
|
556 |
#endif |
|
557 |
_sprite_lru[i] < cur_lru) |
|
558 |
continue; |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
559 |
|
0 | 560 |
// Found a sprite with a higher LRU value, then remember it. |
561 |
if (_sprite_lru[i] != cur_lru) { |
|
562 |
cur_lru = _sprite_lru[i]; |
|
563 |
best = i; |
|
564 |
||
565 |
// Else if both sprites were very recently referenced, compare by the cur value instead. |
|
566 |
} else if (cur_lru == 0 && _sprite_lru_cur[i] <= cur_lru_cur) { |
|
567 |
cur_lru_cur = _sprite_lru_cur[i]; |
|
568 |
cur_lru = _sprite_lru[i]; |
|
569 |
best = i; |
|
570 |
} |
|
571 |
} |
|
572 |
} |
|
573 |
#endif |
|
574 |
||
575 |
// Display an error message and die, in case we found no sprite at all. |
|
576 |
// This shouldn't really happen, unless all sprites are locked. |
|
577 |
if (best == -1) |
|
578 |
error("Out of sprite memory"); |
|
579 |
||
580 |
// Mark the block as free (the block must be in use) |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
581 |
s = (MemBlock*)_sprite_ptr[best] - 1; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
582 |
assert(!(s->size & S_FREE_MASK)); |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
583 |
s->size |= S_FREE_MASK; |
0 | 584 |
_sprite_ptr[best] = NULL; |
585 |
||
586 |
// And coalesce adjacent free blocks |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
587 |
for (s = _spritecache_ptr; s->size != 0; s = NextBlock(s)) { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
588 |
if (s->size & S_FREE_MASK) { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
589 |
while (NextBlock(s)->size & S_FREE_MASK) { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
590 |
s->size += NextBlock(s)->size & ~S_FREE_MASK; |
0 | 591 |
} |
592 |
} |
|
593 |
} |
|
594 |
} |
|
595 |
||
1355 | 596 |
static byte *LoadSpriteToMem(SpriteID sprite) |
0 | 597 |
{ |
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
598 |
size_t mem_req; |
0 | 599 |
|
600 |
DEBUG(spritecache, 9) ("load sprite %d", sprite); |
|
601 |
||
602 |
// Number of needed bytes |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
603 |
mem_req = sizeof(MemBlock) + _sprite_size[sprite]; |
0 | 604 |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
605 |
/* Align this to an uint32 boundary. This also makes sure that the 2 least |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
606 |
* bits are not used, so we could use those for other things. */ |
0 | 607 |
mem_req = (mem_req + sizeof(uint32) - 1) & ~(sizeof(uint32) - 1); |
608 |
||
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
609 |
for (;;) { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
610 |
MemBlock* s; |
0 | 611 |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
612 |
for (s = _spritecache_ptr; s->size != 0; s = NextBlock(s)) { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
613 |
if (s->size & S_FREE_MASK) { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
614 |
size_t cur_size = s->size & ~S_FREE_MASK; |
0 | 615 |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
616 |
/* Is the block exactly the size we need or |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
617 |
* big enough for an additional free block? */ |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
618 |
if (cur_size == mem_req || |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
619 |
cur_size >= mem_req + sizeof(MemBlock)) { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
620 |
// Set size and in use |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
621 |
s->size = mem_req; |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
622 |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
623 |
// Do we need to inject a free block too? |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
624 |
if (cur_size != mem_req) { |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
625 |
NextBlock(s)->size = (cur_size - mem_req) | S_FREE_MASK; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
626 |
} |
0 | 627 |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
628 |
_sprite_ptr[sprite] = s->data; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
629 |
|
1354
5e5c89b9b169
(svn r1858) Let ReadSprite() handle the subtleties of loading a sprite, not its caller
tron
parents:
1353
diff
changeset
|
630 |
ReadSprite(sprite, s->data); |
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
631 |
|
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
632 |
// Return sprite ptr |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
633 |
return s->data; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
634 |
} |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
635 |
} |
0 | 636 |
} |
637 |
||
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
638 |
// Reached sentinel, but no block found yet. Delete some old entry. |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
639 |
DeleteEntryFromSpriteCache(); |
0 | 640 |
} |
641 |
} |
|
642 |
||
643 |
#if defined(NEW_ROTATION) |
|
644 |
#define X15(x) else if (s >= x && s < (x+15)) { s = _rotate_tile_sprite[s - x] + x; } |
|
645 |
#define X19(x) else if (s >= x && s < (x+19)) { s = _rotate_tile_sprite[s - x] + x; } |
|
646 |
#define MAP(from,to,map) else if (s >= from && s <= to) { s = map[s - from] + from; } |
|
647 |
||
648 |
||
410 | 649 |
static uint RotateSprite(uint s) |
0 | 650 |
{ |
651 |
static const byte _rotate_tile_sprite[19] = { 0,2,4,6,8,10,12,14,1,3,5,7,9,11,13,17,18,16,15 }; |
|
652 |
static const byte _coast_map[9] = {0, 4, 3, 1, 2, 6, 8, 5, 7}; |
|
653 |
static const byte _fence_map[6] = {1, 0, 5, 4, 3, 2}; |
|
654 |
||
655 |
if (0); |
|
656 |
X19(752) |
|
657 |
X15(990-1) |
|
658 |
X19(3924) |
|
659 |
X19(3943) |
|
660 |
X19(3962) |
|
661 |
X19(3981) |
|
662 |
X19(4000) |
|
663 |
X19(4023) |
|
664 |
X19(4042) |
|
665 |
MAP(4061,4069,_coast_map) |
|
666 |
X19(4126) |
|
667 |
X19(4145) |
|
668 |
X19(4164) |
|
669 |
X19(4183) |
|
670 |
X19(4202) |
|
671 |
X19(4221) |
|
672 |
X19(4240) |
|
673 |
X19(4259) |
|
674 |
X19(4259) |
|
675 |
X19(4278) |
|
676 |
MAP(4090, 4095, _fence_map) |
|
677 |
MAP(4096, 4101, _fence_map) |
|
678 |
MAP(4102, 4107, _fence_map) |
|
679 |
MAP(4108, 4113, _fence_map) |
|
680 |
MAP(4114, 4119, _fence_map) |
|
681 |
MAP(4120, 4125, _fence_map) |
|
682 |
return s; |
|
683 |
} |
|
684 |
#endif |
|
685 |
||
1361 | 686 |
const void *GetRawSprite(SpriteID sprite) |
0 | 687 |
{ |
688 |
byte *p; |
|
689 |
||
690 |
assert(sprite < NUM_SPRITES); |
|
691 |
||
692 |
#if defined(NEW_ROTATION) |
|
693 |
sprite = RotateSprite(sprite); |
|
694 |
#endif |
|
695 |
||
696 |
// Update LRU |
|
697 |
#if defined(WANT_NEW_LRU) |
|
698 |
_sprite_lru_new[sprite] = ++_sprite_lru_counter; |
|
699 |
#else |
|
700 |
_sprite_lru_cur[sprite] = ++_sprite_lru_counter; |
|
701 |
_sprite_lru[sprite] = 0; |
|
702 |
#endif |
|
703 |
||
704 |
// Check if the sprite is loaded already? |
|
705 |
p = _sprite_ptr[sprite]; |
|
706 |
if (p == NULL) |
|
707 |
p = LoadSpriteToMem(sprite); // No, need to load it. |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
708 |
return p; |
0 | 709 |
} |
710 |
||
711 |
byte _sprite_page_to_load = 0xFF; |
|
712 |
||
713 |
static const char * const _cached_filenames[4] = { |
|
714 |
"cached_sprites.xxx", |
|
715 |
"cached_sprites.xx1", |
|
716 |
"cached_sprites.xx2", |
|
717 |
"cached_sprites.xx3", |
|
718 |
}; |
|
719 |
||
884
9750c41c5860
(svn r1369) -Feature(ish): Added sprites for up/down and left/right arrows. Anywhere where there are horizontal scrollers these are now left/right arrows
darkvater
parents:
862
diff
changeset
|
720 |
#define OPENTTD_SPRITES_COUNT 98 |
0 | 721 |
static const uint16 _openttd_grf_indexes[] = { |
722 |
SPR_OPENTTD_BASE+0, SPR_OPENTTD_BASE+7, // icons etc |
|
579
08ce4c50bd32
(svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents:
504
diff
changeset
|
723 |
134, 134, // euro symbol medium size |
08ce4c50bd32
(svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents:
504
diff
changeset
|
724 |
582, 582, // euro symbol large size |
08ce4c50bd32
(svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents:
504
diff
changeset
|
725 |
358, 358, // euro symbol tiny |
08ce4c50bd32
(svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents:
504
diff
changeset
|
726 |
SPR_OPENTTD_BASE+11, SPR_OPENTTD_BASE+57, // more icons |
0 | 727 |
648, 648, // nordic char: æ |
728 |
616, 616, // nordic char: Æ |
|
729 |
666, 666, // nordic char: Ø |
|
730 |
634, 634, // nordic char: Ø |
|
143 | 731 |
SPR_OPENTTD_BASE+62, SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT, // more icons |
0 | 732 |
0xffff, |
733 |
}; |
|
734 |
||
961 | 735 |
/* FUNCTIONS FOR CHECKING MD5 SUMS OF GRF FILES */ |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
736 |
|
961 | 737 |
/* Check that the supplied MD5 hash matches that stored for the supplied filename */ |
738 |
static bool CheckMD5Digest(const MD5File file, md5_byte_t *digest, bool warn) |
|
739 |
{ |
|
740 |
int i, matching_bytes=0; |
|
741 |
||
742 |
/* Loop through each byte of the file MD5 and the stored MD5... */ |
|
743 |
for (i = 0; i < 16; i++) |
|
744 |
{ |
|
745 |
if (file.hash[i] == digest[i]) |
|
746 |
matching_bytes++; |
|
747 |
}; |
|
748 |
||
749 |
/* If all bytes of the MD5's match (i.e. the MD5's match)... */ |
|
750 |
if (matching_bytes == 16) { |
|
751 |
return true; |
|
752 |
} else { |
|
753 |
if (warn) printf("MD5 of %s is ****INCORRECT**** - File Corrupt.\n", file.filename); |
|
754 |
return false; |
|
755 |
}; |
|
756 |
} |
|
757 |
||
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
966
diff
changeset
|
758 |
/* Calculate and check the MD5 hash of the supplied filename. |
961 | 759 |
* returns true if the checksum is correct */ |
760 |
static bool FileMD5(const MD5File file, bool warn) |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
761 |
{ |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
762 |
FILE *f; |
961 | 763 |
char buf[MAX_PATH]; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
764 |
|
961 | 765 |
md5_state_t filemd5state; |
766 |
int len=0; |
|
767 |
md5_byte_t buffer[1024], digest[16]; |
|
768 |
||
769 |
// open file |
|
770 |
sprintf(buf, "%s%s", _path.data_dir, file.filename); |
|
771 |
f = fopen(buf, "rb"); |
|
772 |
||
773 |
#if !defined(WIN32) |
|
774 |
if (f == NULL) { |
|
1329 | 775 |
char *s; |
961 | 776 |
// make lower case and check again |
1355 | 777 |
for (s = buf + strlen(_path.data_dir) - 1; *s != '\0'; s++) |
961 | 778 |
*s = tolower(*s); |
779 |
f = fopen(buf, "rb"); |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
780 |
} |
961 | 781 |
#endif |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
782 |
|
862
d7e52ef99f42
(svn r1343) -Fix: [Graphic] Autorail icon is now correct (Darkvater)
truelight
parents:
614
diff
changeset
|
783 |
if (f != NULL) { |
961 | 784 |
md5_init(&filemd5state); |
1355 | 785 |
while ((len = fread(buffer, 1, 1024, f)) != 0) |
961 | 786 |
md5_append(&filemd5state, buffer, len); |
787 |
||
788 |
if (ferror(f)) |
|
1355 | 789 |
if (warn) printf("Error Reading from %s \n", buf); |
961 | 790 |
fclose(f); |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
966
diff
changeset
|
791 |
|
961 | 792 |
md5_finish(&filemd5state, digest); |
793 |
return CheckMD5Digest(file, digest, warn); |
|
794 |
} else { // file not found |
|
795 |
return false; |
|
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
966
diff
changeset
|
796 |
} |
961 | 797 |
} |
798 |
||
799 |
/* Checks, if either the Windows files exist (TRG1R.GRF) or the DOS files (TRG1.GRF) |
|
800 |
* by comparing the MD5 checksums of the files. _use_dos_palette is set accordingly. |
|
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
966
diff
changeset
|
801 |
* If neither are found, Windows palette is assumed. |
961 | 802 |
* |
803 |
* (Note: Also checks sample.cat for corruption) */ |
|
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
|
804 |
void CheckExternalFiles(void) |
961 | 805 |
{ |
1355 | 806 |
uint i; |
807 |
// count of files from this version |
|
808 |
uint dos = 0; |
|
809 |
uint win = 0; |
|
961 | 810 |
|
1355 | 811 |
for (i = 0; i < 2; i++) |
812 |
if (FileMD5(files_dos.basic[i], true)) |
|
961 | 813 |
dos++; |
1355 | 814 |
for (i = 0; i < 3; i++) |
815 |
if (FileMD5(files_dos.landscape[i], true)) |
|
961 | 816 |
dos++; |
817 |
||
1355 | 818 |
for (i = 0; i < 2; i++) |
819 |
if (FileMD5(files_win.basic[i], true)) |
|
961 | 820 |
win++; |
1355 | 821 |
for (i = 0; i < 3; i++) |
822 |
if (FileMD5(files_win.landscape[i], true)) |
|
961 | 823 |
win++; |
824 |
||
1355 | 825 |
if (!FileMD5(sample_cat_win, false) && !FileMD5(sample_cat_dos, false)) |
961 | 826 |
printf("Your sample.cat file is corrupted or missing!"); |
827 |
||
828 |
if (win == 5) { // always use the Windows palette if all Windows files are present |
|
829 |
_use_dos_palette = false; |
|
830 |
} else if (dos == 5) { // else use the DOS palette if all DOS files are present |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
831 |
_use_dos_palette = true; |
961 | 832 |
} else { // some files are missing, regardless of palette. Use Windows |
833 |
_use_dos_palette = false; |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
834 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
835 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
836 |
|
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
|
837 |
static void LoadSpriteTables(void) |
0 | 838 |
{ |
1355 | 839 |
uint i; |
840 |
uint j; |
|
841 |
const FileList *files; // list of grf files to be loaded. Either Windows files or DOS files |
|
0 | 842 |
|
368
32aad6ad36e1
(svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents:
366
diff
changeset
|
843 |
_loading_stage = 1; |
32aad6ad36e1
(svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents:
366
diff
changeset
|
844 |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
845 |
/* |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
846 |
* Note for developers: |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
847 |
* Keep in mind that when you add a LoadGrfIndexed in the 'if'-section below |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
848 |
* that you should also add the corresponding FioOpenFile to the 'else'-section |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
849 |
* below. |
364
9e93d102fd4a
(svn r552) -newgrf: Include bits forgotten when merging octo's ReplaceSprites support - it would replace even special sprites in the way now. (pasky)
darkvater
parents:
361
diff
changeset
|
850 |
* |
9e93d102fd4a
(svn r552) -newgrf: Include bits forgotten when merging octo's ReplaceSprites support - it would replace even special sprites in the way now. (pasky)
darkvater
parents:
361
diff
changeset
|
851 |
* TODO: |
9e93d102fd4a
(svn r552) -newgrf: Include bits forgotten when merging octo's ReplaceSprites support - it would replace even special sprites in the way now. (pasky)
darkvater
parents:
361
diff
changeset
|
852 |
* I think we can live entirely without Indexed GRFs, but I have to |
9e93d102fd4a
(svn r552) -newgrf: Include bits forgotten when merging octo's ReplaceSprites support - it would replace even special sprites in the way now. (pasky)
darkvater
parents:
361
diff
changeset
|
853 |
* invest that further. --octo |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
854 |
*/ |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
855 |
|
1355 | 856 |
files = _use_dos_palette? &files_dos : &files_win; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
857 |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
858 |
// Try to load the sprites from cache |
0 | 859 |
if (!HandleCachedSpriteHeaders(_cached_filenames[_opt.landscape], true)) { |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
860 |
// We do not have the sprites in cache yet, or cache is disabled |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
861 |
// So just load all files from disk.. |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
862 |
|
0 | 863 |
int load_index = 0; |
368
32aad6ad36e1
(svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents:
366
diff
changeset
|
864 |
|
1355 | 865 |
for (i = 0; files->basic[i].filename != NULL; i++) { |
961 | 866 |
load_index += LoadGrfFile(files->basic[i].filename, load_index, (byte)i); |
0 | 867 |
} |
868 |
||
869 |
LoadGrfIndexed("openttd.grf", _openttd_grf_indexes, i++); |
|
870 |
||
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
871 |
if (_sprite_page_to_load != 0) |
1355 | 872 |
LoadGrfIndexed( |
873 |
files->landscape[_sprite_page_to_load - 1].filename, |
|
874 |
_landscape_spriteindexes[_sprite_page_to_load - 1], |
|
875 |
i++ |
|
876 |
); |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
877 |
|
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
878 |
LoadGrfIndexed("trkfoundw.grf", _slopes_spriteindexes[_opt.landscape], i++); |
0 | 879 |
|
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
1019
diff
changeset
|
880 |
load_index = SPR_AUTORAIL_BASE; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
1019
diff
changeset
|
881 |
load_index += LoadGrfFile("autorail.grf", load_index, i++); |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
1019
diff
changeset
|
882 |
|
0 | 883 |
load_index = SPR_CANALS_BASE; |
884 |
load_index += LoadGrfFile("canalsw.grf", load_index, i++); |
|
142 | 885 |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
886 |
load_index = SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT + 1; |
142 | 887 |
|
368
32aad6ad36e1
(svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents:
366
diff
changeset
|
888 |
|
1355 | 889 |
/* Load newgrf sprites |
890 |
* in each loading stage, (try to) open each file specified in the config |
|
891 |
* and load information from it. */ |
|
392
3657d06c6564
(svn r584) -newgrf: Increase chance to get a TTDPatch savegame using custom GRF files loaded (pasky)
darkvater
parents:
368
diff
changeset
|
892 |
_custom_sprites_base = load_index; |
1198
010e5986ed74
(svn r1702) - Fix: [ 1110407 ] Game does not crash any more when a newgrf file doesn't exist
dominik
parents:
1093
diff
changeset
|
893 |
for (_loading_stage = 0; _loading_stage < 2; _loading_stage++) { |
1250
1b8d4b11aab3
(svn r1754) - Fix: you can once again load newgrf files with lots of sprites. Index wasn't reset in second run, thus counting them double.
darkvater
parents:
1198
diff
changeset
|
894 |
load_index = _custom_sprites_base; |
1198
010e5986ed74
(svn r1702) - Fix: [ 1110407 ] Game does not crash any more when a newgrf file doesn't exist
dominik
parents:
1093
diff
changeset
|
895 |
for (j = 0; j != lengthof(_newgrf_files) && _newgrf_files[j]; j++) { |
1355 | 896 |
if (!FiosCheckFileExists(_newgrf_files[j])) |
1198
010e5986ed74
(svn r1702) - Fix: [ 1110407 ] Game does not crash any more when a newgrf file doesn't exist
dominik
parents:
1093
diff
changeset
|
897 |
continue; |
010e5986ed74
(svn r1702) - Fix: [ 1110407 ] Game does not crash any more when a newgrf file doesn't exist
dominik
parents:
1093
diff
changeset
|
898 |
if (_loading_stage == 0) |
010e5986ed74
(svn r1702) - Fix: [ 1110407 ] Game does not crash any more when a newgrf file doesn't exist
dominik
parents:
1093
diff
changeset
|
899 |
InitNewGRFFile(_newgrf_files[j], load_index); |
010e5986ed74
(svn r1702) - Fix: [ 1110407 ] Game does not crash any more when a newgrf file doesn't exist
dominik
parents:
1093
diff
changeset
|
900 |
load_index += LoadNewGrfFile(_newgrf_files[j], load_index, i++); |
010e5986ed74
(svn r1702) - Fix: [ 1110407 ] Game does not crash any more when a newgrf file doesn't exist
dominik
parents:
1093
diff
changeset
|
901 |
} |
366
9d2630b8b4de
(svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents:
365
diff
changeset
|
902 |
} |
0 | 903 |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
904 |
// If needed, save the cache to file |
0 | 905 |
HandleCachedSpriteHeaders(_cached_filenames[_opt.landscape], false); |
906 |
} else { |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
907 |
// We have sprites cached. We just loaded the cached files |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
908 |
// now we only have to open a file-pointer to all the original grf-files |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
909 |
// This is very important. Not all sprites are in the cache. So sometimes |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
910 |
// the game needs to load the sprite from disk. When the file is not |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
911 |
// open it can not read. So all files that are in the 'if'-section |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
912 |
// above should also be in this 'else'-section. |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
913 |
// |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
914 |
// NOTE: the order of the files must be identical as in the section above!! |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
915 |
|
1355 | 916 |
for (i = 0; files->basic[i].filename != NULL; i++) |
961 | 917 |
FioOpenFile(i,files->basic[i].filename); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
918 |
|
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
919 |
FioOpenFile(i++, "openttd.grf"); |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
920 |
|
0 | 921 |
if (_sprite_page_to_load != 0) |
1355 | 922 |
FioOpenFile(i++, files->landscape[_sprite_page_to_load - 1].filename); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
923 |
|
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
924 |
FioOpenFile(i++, "trkfoundw.grf"); |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
925 |
FioOpenFile(i++, "canalsw.grf"); |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
926 |
|
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
927 |
// FIXME: if a user changes his newgrf's, the cached-sprites gets |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
928 |
// invalid. We should have some kind of check for this. |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
929 |
// The best solution for this is to delete the cached-sprites.. but how |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
930 |
// do we detect it? |
1355 | 931 |
for (j = 0; j != lengthof(_newgrf_files) && _newgrf_files[j] != NULL; j++) |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
932 |
FioOpenFile(i++, _newgrf_files[j]); |
0 | 933 |
} |
934 |
||
935 |
_compact_cache_counter = 0; |
|
936 |
} |
|
937 |
||
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
938 |
static void GfxInitSpriteMem(void *ptr, uint32 size) |
0 | 939 |
{ |
940 |
// initialize sprite cache heap |
|
941 |
_spritecache_ptr = ptr; |
|
942 |
_spritecache_size = size; |
|
943 |
||
944 |
// A big free block |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
945 |
_spritecache_ptr->size = (size - sizeof(MemBlock)) | S_FREE_MASK; |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
946 |
// Sentinel block (identified by size == 0) |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
947 |
NextBlock(_spritecache_ptr)->size = 0; |
0 | 948 |
|
949 |
memset(_sprite_ptr, 0, sizeof(_sprite_ptr)); |
|
950 |
} |
|
951 |
||
952 |
||
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
|
953 |
void GfxLoadSprites(void) |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1070
diff
changeset
|
954 |
{ |
0 | 955 |
static byte *_sprite_mem; |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
956 |
|
0 | 957 |
// Need to reload the sprites only if the landscape changed |
958 |
if (_sprite_page_to_load != _opt.landscape) { |
|
959 |
_sprite_page_to_load = _opt.landscape; |
|
960 |
||
961 |
// Sprite cache |
|
962 |
DEBUG(spritecache, 1) ("Loading sprite set %d.", _sprite_page_to_load); |
|
963 |
||
964 |
// Reuse existing memory? |
|
965 |
if (_sprite_mem == NULL) _sprite_mem = malloc(SPRITE_CACHE_SIZE); |
|
966 |
GfxInitSpriteMem(_sprite_mem, SPRITE_CACHE_SIZE); |
|
967 |
LoadSpriteTables(); |
|
968 |
GfxInitPalettes(); |
|
969 |
} |
|
970 |
} |
|
971 |
||
972 |
||
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
|
973 |
const SpriteDimension *GetSpriteDimension(SpriteID sprite) |
0 | 974 |
{ |
975 |
static SpriteDimension sd_static; |
|
1355 | 976 |
SpriteDimension *sd = &sd_static; |
0 | 977 |
|
1355 | 978 |
#ifdef WANT_SPRITESIZES |
979 |
sd->xoffs = _sprite_xoffs[sprite]; |
|
980 |
sd->yoffs = _sprite_yoffs[sprite]; |
|
981 |
sd->xsize = _sprite_xsize[sprite]; |
|
982 |
sd->ysize = _sprite_ysize[sprite]; |
|
983 |
#else |
|
984 |
const Sprite* p = GetSprite(sprite); |
|
0 | 985 |
|
986 |
/* decode sprite header */ |
|
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
987 |
sd->xoffs = p->x_offs; |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
988 |
sd->yoffs = p->y_offs; |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
989 |
sd->xsize = p->width; |
1348 | 990 |
sd->ysize = p->height; |
0 | 991 |
#endif |
1355 | 992 |
|
0 | 993 |
return sd; |
994 |
} |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
995 |