author | tron |
Sat, 06 Nov 2004 09:24:28 +0000 | |
changeset 338 | 04ad3e897bf8 |
parent 184 | dbeaaaf8b2bb |
child 361 | ad7a042ee0eb |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
#include "gfx.h" |
|
4 |
#include "fileio.h" |
|
5 |
#include <ctype.h> |
|
6 |
||
7 |
#define SPRITECACHE_ID 0xF00F0006 |
|
8 |
#define SPRITE_CACHE_SIZE 1024*1024 |
|
9 |
||
10 |
||
11 |
//#define WANT_SPRITESIZES |
|
12 |
#define WANT_NEW_LRU |
|
13 |
//#define WANT_LOCKED |
|
14 |
||
15 |
||
16 |
int _skip_sprites = 0; |
|
17 |
||
18 |
static const char *_cur_grffile; |
|
19 |
static int _skip_specials; |
|
20 |
static SpriteHdr _cur_sprite; |
|
21 |
||
22 |
static byte *_sprite_ptr[NUM_SPRITES]; |
|
23 |
static uint16 _sprite_size[NUM_SPRITES]; |
|
24 |
static uint32 _sprite_file_pos[NUM_SPRITES]; |
|
25 |
||
26 |
// This one is probably not needed. |
|
27 |
#if defined(WANT_LOCKED) |
|
28 |
static bool _sprite_locked[NUM_SPRITES]; |
|
29 |
#endif |
|
30 |
||
31 |
#if defined(WANT_NEW_LRU) |
|
32 |
static int16 _sprite_lru_new[NUM_SPRITES]; |
|
33 |
#else |
|
34 |
static uint16 _sprite_lru[NUM_SPRITES]; |
|
35 |
static uint16 _sprite_lru_cur[NUM_SPRITES]; |
|
36 |
#endif |
|
37 |
||
38 |
#ifdef WANT_SPRITESIZES |
|
39 |
static int8 _sprite_xoffs[NUM_SPRITES]; |
|
40 |
static int8 _sprite_yoffs[NUM_SPRITES]; |
|
41 |
static uint16 _sprite_xsize[NUM_SPRITES]; |
|
42 |
static uint8 _sprite_ysize[NUM_SPRITES]; |
|
43 |
#endif |
|
44 |
||
45 |
static uint _sprite_lru_counter; |
|
46 |
static byte *_spritecache_ptr; |
|
47 |
static uint32 _spritecache_size; |
|
48 |
static int _compact_cache_counter; |
|
49 |
||
50 |
||
51 |
static const char * const _filename_list[] = { |
|
52 |
"TRG1R.GRF", |
|
53 |
"TRGIR.GRF", |
|
54 |
"signalsw.grf", //0x1320 - 0x1405 inclusive |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
55 |
// "openttd.grf", //0x1406 - |
0 | 56 |
NULL |
57 |
}; |
|
58 |
||
59 |
static const char * const _landscape_filenames[] = { |
|
60 |
"TRGCR.GRF", |
|
61 |
"TRGHR.GRF", |
|
62 |
"TRGTR.GRF" |
|
63 |
}; |
|
64 |
||
65 |
||
66 |
#include "table/landscape_sprite.h" |
|
67 |
||
68 |
static const uint16 * const _landscape_spriteindexes[] = { |
|
69 |
_landscape_spriteindexes_1, |
|
70 |
_landscape_spriteindexes_2, |
|
71 |
_landscape_spriteindexes_3, |
|
72 |
}; |
|
73 |
||
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
74 |
static const uint16 * const _slopes_spriteindexes[] = { |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
75 |
_slopes_spriteindexes_0, |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
76 |
_slopes_spriteindexes_1, |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
77 |
_slopes_spriteindexes_2, |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
78 |
_slopes_spriteindexes_3, |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
79 |
}; |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
80 |
|
0 | 81 |
static void CompactSpriteCache(); |
82 |
||
83 |
void DecodeSpecialSprite(const char *filename, int num, int load_index); |
|
84 |
||
85 |
static void ReadSpriteHeaderSkipData(int num, int load_index) |
|
86 |
{ |
|
87 |
byte type; |
|
88 |
int8 i; |
|
89 |
int deaf = 0; |
|
90 |
||
91 |
if (_skip_sprites) { |
|
92 |
if (_skip_sprites > 0) |
|
93 |
_skip_sprites--; |
|
94 |
deaf = 1; |
|
95 |
} |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
96 |
|
0 | 97 |
type = FioReadByte(); |
98 |
if (type == 0xFF) { |
|
99 |
/* We need to really skip only special sprites in the deaf |
|
100 |
* mode. It won't hurt to proceed regular sprites as usual |
|
101 |
* because if no special sprite referencing to them is |
|
102 |
* processed, they themselves are never referenced and loaded |
|
103 |
* on their own. */ |
|
104 |
if (_skip_specials || deaf) { |
|
105 |
FioSkipBytes(num); |
|
106 |
} else { |
|
107 |
DecodeSpecialSprite(_cur_grffile, num, load_index); |
|
108 |
} |
|
109 |
return; |
|
110 |
} |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
111 |
|
0 | 112 |
_cur_sprite.info = type; |
113 |
#ifdef WANT_SPRITESIZES |
|
114 |
_cur_sprite.height = FioReadByte(); |
|
115 |
_cur_sprite.width = FioReadWord(); |
|
116 |
_cur_sprite.x_offs = FioReadWord(); |
|
117 |
_cur_sprite.y_offs = FioReadWord(); |
|
118 |
#else |
|
119 |
FioSkipBytes(7); |
|
120 |
#endif |
|
121 |
num -= 8; |
|
122 |
if (num == 0) |
|
123 |
return; |
|
124 |
||
125 |
if (type & 2) { |
|
126 |
FioSkipBytes(num); |
|
127 |
return; |
|
128 |
} |
|
129 |
||
130 |
while (num) { |
|
131 |
i = FioReadByte(); |
|
132 |
if (i>=0) { |
|
133 |
num -= i; |
|
134 |
FioSkipBytes(i); |
|
135 |
} else { |
|
136 |
i = -(i >> 3); |
|
137 |
num -= i; |
|
138 |
FioReadByte(); |
|
139 |
} |
|
140 |
} |
|
141 |
} |
|
142 |
||
143 |
static void ReadSprite(int num, byte *dest) |
|
144 |
{ |
|
145 |
byte type; |
|
146 |
byte *rel; |
|
147 |
int8 i; |
|
148 |
int j, dist; |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
149 |
|
0 | 150 |
type = FioReadByte(); |
151 |
/* We've decoded special sprites when reading headers. */ |
|
152 |
if (type != 0xFF) { |
|
153 |
/* read sprite hdr */ |
|
154 |
*dest++ = type; |
|
155 |
for(j=0; j!=7; j++) |
|
156 |
*dest++ = FioReadByte(); |
|
157 |
num -= 8; |
|
158 |
} |
|
159 |
||
160 |
if (type & 2) { |
|
161 |
while (num--) |
|
162 |
*dest++ = FioReadByte(); |
|
163 |
return; |
|
164 |
} |
|
165 |
||
166 |
while (num) { |
|
167 |
i = FioReadByte(); |
|
168 |
if (i>=0) { |
|
169 |
num -= i; |
|
170 |
while (i--) |
|
171 |
*dest++ = FioReadByte(); |
|
172 |
} else { |
|
173 |
dist = -(((i&7)<<8)|FioReadByte()); |
|
174 |
i = -(i >> 3); |
|
175 |
num -= i; |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
176 |
|
0 | 177 |
rel = &dest[dist]; |
178 |
while (i--) |
|
179 |
*dest++ = *rel++; |
|
180 |
} |
|
181 |
} |
|
182 |
} |
|
183 |
||
184 |
||
185 |
static bool LoadNextSprite(int load_index, byte file_index) |
|
186 |
{ |
|
187 |
uint16 size; |
|
188 |
||
189 |
if ( (size = FioReadWord()) == 0) |
|
190 |
return false; |
|
191 |
||
192 |
_sprite_size[load_index] = size; |
|
193 |
_sprite_file_pos[load_index] = FioGetPos() | (file_index << 24); |
|
194 |
||
195 |
ReadSpriteHeaderSkipData(size, load_index); |
|
196 |
||
197 |
#ifdef WANT_SPRITESIZES |
|
198 |
_sprite_xsize[load_index] = _cur_sprite.width; |
|
199 |
_sprite_ysize[load_index] = _cur_sprite.height; |
|
200 |
||
201 |
_sprite_xoffs[load_index] = _cur_sprite.x_offs; |
|
202 |
_sprite_yoffs[load_index] = _cur_sprite.y_offs; |
|
203 |
#endif |
|
204 |
||
205 |
_sprite_ptr[load_index] = NULL; |
|
206 |
#if defined(WANT_LOCKED) |
|
207 |
_sprite_locked[load_index] = false; |
|
208 |
#endif |
|
209 |
||
210 |
#if defined(WANT_NEW_LRU) |
|
211 |
_sprite_lru_new[load_index] = 0; |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
212 |
#else |
0 | 213 |
_sprite_lru[load_index] = 0xFFFF; |
214 |
_sprite_lru_cur[load_index] = 0; |
|
215 |
#endif |
|
216 |
||
217 |
return true; |
|
218 |
} |
|
219 |
||
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
220 |
static void SkipSprites(int count) |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
221 |
{ |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
222 |
while(count>0) |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
223 |
{ |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
224 |
uint16 size; |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
225 |
if ( (size = FioReadWord()) == 0) |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
226 |
return; |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
227 |
|
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
228 |
ReadSpriteHeaderSkipData(size, NUM_SPRITES-1); |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
229 |
count--; |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
230 |
} |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
231 |
} |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
232 |
|
0 | 233 |
// Checks, if trg1r.grf is the Windows version |
234 |
static bool CheckGrfFile() |
|
235 |
{ |
|
236 |
byte check; |
|
237 |
FioSeekToFile(38); // Byte 38 has the value 0x21 in Windows version, 0x07 in DOS |
|
238 |
check = FioReadWord(); |
|
239 |
FioSeekToFile(0); |
|
240 |
return (check==0x21); |
|
241 |
} |
|
242 |
||
243 |
static int LoadGrfFile(const char *filename, int load_index, int file_index) |
|
244 |
{ |
|
245 |
int load_index_org = load_index; |
|
246 |
||
247 |
FioOpenFile(file_index, filename); |
|
248 |
_cur_grffile = filename; |
|
249 |
_skip_specials = !strncmp(filename, "TRG", 3); |
|
250 |
||
251 |
if(file_index==0 && !_ignore_wrong_grf) |
|
252 |
if(!CheckGrfFile()) |
|
253 |
error("Wrong version of grf files!\nThe Windows 95 edition of Transport Tycoon Deluxe is required to play OTTD!\n(you can disable this message by starting with the \"-i\" switch."); |
|
254 |
||
255 |
while (LoadNextSprite(load_index, file_index)) { |
|
256 |
load_index++; |
|
257 |
if (load_index >= NUM_SPRITES) { |
|
258 |
error("Too many sprites. Recompile with higher NUM_SPRITES value or remove some custom GRF files."); |
|
259 |
} |
|
260 |
} |
|
261 |
||
262 |
_skip_sprites = 0; // clean up |
|
263 |
||
264 |
return load_index - load_index_org; |
|
265 |
} |
|
266 |
||
267 |
static void LoadGrfIndexed(const char *filename, const uint16 *index_tbl, int file_index) |
|
268 |
{ |
|
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
269 |
int start; |
0 | 270 |
|
271 |
FioOpenFile(file_index, filename); |
|
74
d23a80ef6361
(svn r75) -Add proper crediting to graphics artists to about box.
darkvater
parents:
37
diff
changeset
|
272 |
_cur_grffile = filename; |
0 | 273 |
|
274 |
for(;(start=*index_tbl++) != 0xffff;) { |
|
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
275 |
int end = *index_tbl++; |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
276 |
if(start==0xfffe) { // skip sprites (amount in second var) |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
277 |
SkipSprites(end); |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
278 |
} 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
|
279 |
do { |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
280 |
bool b = LoadNextSprite(start, file_index); |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
281 |
assert(b); |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
282 |
} while (++start <= end); |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
283 |
} |
0 | 284 |
} |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
285 |
} |
0 | 286 |
|
287 |
typedef size_t CDECL fread_t(void*,size_t,size_t,FILE*); |
|
288 |
||
289 |
static bool HandleCachedSpriteHeaders(const char *filename, bool read) |
|
290 |
{ |
|
291 |
FILE *f; |
|
292 |
fread_t *proc; |
|
293 |
uint32 hdr; |
|
294 |
||
295 |
if (!_cache_sprites) |
|
296 |
return false; |
|
297 |
||
298 |
if (read) { |
|
299 |
f = fopen(filename, "rb"); |
|
300 |
proc = fread; |
|
301 |
||
302 |
if (f == NULL) |
|
303 |
return false; |
|
304 |
||
305 |
proc(&hdr, sizeof(hdr), 1, f); |
|
306 |
if (hdr != SPRITECACHE_ID) { |
|
307 |
fclose(f); |
|
308 |
return false; |
|
309 |
} |
|
310 |
} else { |
|
311 |
f = fopen(filename, "wb"); |
|
312 |
proc = (fread_t*) fwrite; |
|
313 |
||
314 |
if (f == NULL) |
|
315 |
return false; |
|
316 |
||
317 |
hdr = SPRITECACHE_ID; |
|
318 |
proc(&hdr, sizeof(hdr), 1, f); |
|
319 |
} |
|
320 |
||
321 |
proc(_sprite_size, 1, sizeof(_sprite_size), f); |
|
322 |
proc(_sprite_file_pos, 1, sizeof(_sprite_file_pos), f); |
|
323 |
||
324 |
#if 0 |
|
325 |
proc(_sprite_xsize, 1, sizeof(_sprite_xsize), f); |
|
326 |
proc(_sprite_ysize, 1, sizeof(_sprite_ysize), f); |
|
327 |
proc(_sprite_xoffs, 1, sizeof(_sprite_xoffs), f); |
|
328 |
proc(_sprite_yoffs, 1, sizeof(_sprite_yoffs), f); |
|
329 |
#endif |
|
330 |
||
331 |
#if !defined(WANT_NEW_LRU) |
|
332 |
if (read) |
|
333 |
memset(_sprite_lru, 0xFF, sizeof(_sprite_lru)); |
|
334 |
#endif |
|
335 |
||
336 |
fclose(f); |
|
337 |
return true; |
|
338 |
} |
|
339 |
||
340 |
#define S_DATA(x) (*(uint32*)(x)) |
|
341 |
#define S_FREE_MASK 1 |
|
342 |
#define S_HDRSIZE sizeof(uint32) |
|
343 |
||
344 |
static uint32 GetSpriteCacheUsage() |
|
345 |
{ |
|
346 |
byte *s = _spritecache_ptr; |
|
347 |
size_t cur_size, tot_size = 0; |
|
348 |
for(; (cur_size=S_DATA(s)) != 0; s+=cur_size) { |
|
349 |
if ( cur_size & S_FREE_MASK ) { |
|
350 |
cur_size--; |
|
351 |
} else { |
|
352 |
tot_size += cur_size; |
|
353 |
} |
|
354 |
} |
|
355 |
||
356 |
return tot_size; |
|
357 |
} |
|
358 |
||
359 |
||
360 |
void IncreaseSpriteLRU() |
|
361 |
{ |
|
362 |
int i; |
|
363 |
||
364 |
// Increase all LRU values |
|
365 |
#if defined(WANT_NEW_LRU) |
|
366 |
if (_sprite_lru_counter > 16384) { |
|
367 |
DEBUG(spritecache, 2) ("fixing lru %d, inuse=%d", _sprite_lru_counter, GetSpriteCacheUsage()); |
|
368 |
||
369 |
for(i=0; i!=NUM_SPRITES; i++) |
|
370 |
if (_sprite_ptr[i] != NULL) { |
|
371 |
if (_sprite_lru_new[i] >= 0) { |
|
372 |
_sprite_lru_new[i] = -1; |
|
373 |
} else if (_sprite_lru_new[i] != -32768) { |
|
374 |
_sprite_lru_new[i]--; |
|
375 |
} |
|
376 |
} |
|
377 |
_sprite_lru_counter = 0; |
|
378 |
} |
|
379 |
#else |
|
380 |
for(i=0; i!=NUM_SPRITES; i++) |
|
381 |
if (_sprite_ptr[i] != NULL && _sprite_lru[i] != 65535) |
|
382 |
_sprite_lru[i]++; |
|
383 |
// Reset the lru counter. |
|
384 |
_sprite_lru_counter = 0; |
|
385 |
#endif |
|
386 |
||
387 |
// Compact sprite cache every now and then. |
|
388 |
if (++_compact_cache_counter >= 740) { |
|
389 |
CompactSpriteCache(); |
|
390 |
_compact_cache_counter = 0; |
|
391 |
} |
|
392 |
} |
|
393 |
||
394 |
// Called when holes in the sprite cache should be removed. |
|
395 |
// That is accomplished by moving the cached data. |
|
396 |
static void CompactSpriteCache() |
|
397 |
{ |
|
398 |
byte *s, *t; |
|
399 |
size_t size, sizeb, cur_size; |
|
400 |
int i; |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
401 |
|
0 | 402 |
DEBUG(spritecache, 2) ("compacting sprite cache, inuse=%d", GetSpriteCacheUsage()); |
403 |
||
404 |
s = _spritecache_ptr; |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
405 |
|
0 | 406 |
while (true) { |
407 |
size = S_DATA(s); |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
408 |
|
0 | 409 |
// Only look for free blocks. |
410 |
if (size & S_FREE_MASK) { |
|
411 |
size -= S_FREE_MASK; |
|
412 |
// Since free blocks are automatically coalesced, this should hold true. |
|
413 |
assert(!(S_DATA(s+size) & S_FREE_MASK)); |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
414 |
|
0 | 415 |
// If the next block is the sentinel block, we can safely return |
416 |
if ( (sizeb=S_DATA(s + size)) == 0) |
|
417 |
break; |
|
418 |
||
419 |
// Locate the sprite number belonging to the next pointer. |
|
420 |
for(i=0,t=s+size+S_HDRSIZE; _sprite_ptr[i] != t; i++) {assert(i < NUM_SPRITES);} |
|
421 |
||
422 |
// If it's locked, we must not move it. |
|
423 |
#if defined(WANT_LOCKED) |
|
424 |
if (!_sprite_locked[i]) { |
|
425 |
#endif |
|
426 |
||
427 |
// Offset the sprite pointer by the size of the free block |
|
428 |
_sprite_ptr[i] -= size; |
|
429 |
||
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
430 |
// Move the memory |
0 | 431 |
memcpy_overlapping(s+S_HDRSIZE, s+S_HDRSIZE+size, sizeb - S_HDRSIZE ); |
432 |
||
433 |
// What we just did had the effect of swapping the allocated block with the free block, so we need to update |
|
434 |
// the block pointers. First update the allocated one. It is in use. |
|
435 |
S_DATA(s) = sizeb; |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
436 |
|
0 | 437 |
// Then coalesce the free ones that follow. |
438 |
s += sizeb; |
|
439 |
while ((cur_size = S_DATA(s+size)) & S_FREE_MASK) |
|
440 |
size += cur_size - S_FREE_MASK; |
|
441 |
S_DATA(s) = size + S_FREE_MASK; |
|
442 |
continue; |
|
443 |
#if defined(WANT_LOCKED) |
|
444 |
} |
|
445 |
#endif |
|
446 |
} |
|
447 |
// Continue with next block until the sentinel is reached. |
|
448 |
s += size; |
|
449 |
if (size == 0) |
|
450 |
break; |
|
451 |
} |
|
452 |
} |
|
453 |
||
454 |
static void DeleteEntryFromSpriteCache() |
|
455 |
{ |
|
456 |
int i; |
|
457 |
int best = -1; |
|
458 |
byte *s; |
|
459 |
size_t cur_size, cur; |
|
460 |
int cur_lru; |
|
461 |
||
462 |
DEBUG(spritecache, 2) ("DeleteEntryFromSpriteCache, inuse=%d", GetSpriteCacheUsage()); |
|
463 |
||
464 |
#if defined(WANT_NEW_LRU) |
|
465 |
cur_lru = 0xffff; |
|
466 |
for(i=0; i!=NUM_SPRITES; i++) { |
|
467 |
if (_sprite_ptr[i] != 0 && |
|
468 |
_sprite_lru_new[i] < cur_lru |
|
469 |
#if defined(WANT_LOCKED) |
|
470 |
&& !_sprite_locked[i]) { |
|
471 |
#else |
|
472 |
) { |
|
473 |
#endif |
|
474 |
cur_lru = _sprite_lru_new[i]; |
|
475 |
best = i; |
|
476 |
} |
|
477 |
} |
|
478 |
#else |
|
479 |
{ |
|
480 |
uint16 cur_lru = 0, cur_lru_cur = 0xffff; |
|
481 |
for(i=0; i!=NUM_SPRITES; i++) { |
|
482 |
if (_sprite_ptr[i] == 0 || |
|
483 |
#if defined(WANT_LOCKED) |
|
484 |
_sprite_locked[i] || |
|
485 |
#endif |
|
486 |
_sprite_lru[i] < cur_lru) |
|
487 |
continue; |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
488 |
|
0 | 489 |
// Found a sprite with a higher LRU value, then remember it. |
490 |
if (_sprite_lru[i] != cur_lru) { |
|
491 |
cur_lru = _sprite_lru[i]; |
|
492 |
best = i; |
|
493 |
||
494 |
// Else if both sprites were very recently referenced, compare by the cur value instead. |
|
495 |
} else if (cur_lru == 0 && _sprite_lru_cur[i] <= cur_lru_cur) { |
|
496 |
cur_lru_cur = _sprite_lru_cur[i]; |
|
497 |
cur_lru = _sprite_lru[i]; |
|
498 |
best = i; |
|
499 |
} |
|
500 |
} |
|
501 |
} |
|
502 |
#endif |
|
503 |
||
504 |
// Display an error message and die, in case we found no sprite at all. |
|
505 |
// This shouldn't really happen, unless all sprites are locked. |
|
506 |
if (best == -1) |
|
507 |
error("Out of sprite memory"); |
|
508 |
||
509 |
// Mark the block as free (the block must be in use) |
|
510 |
s = _sprite_ptr[best]; |
|
511 |
assert(!(S_DATA(s - S_HDRSIZE) & S_FREE_MASK)); |
|
512 |
S_DATA(s - S_HDRSIZE) += S_FREE_MASK; |
|
513 |
_sprite_ptr[best] = NULL; |
|
514 |
||
515 |
// And coalesce adjacent free blocks |
|
516 |
s = _spritecache_ptr; |
|
517 |
for(; (cur_size=S_DATA(s)) != 0; s+=cur_size) { |
|
518 |
if ( cur_size & S_FREE_MASK ) { |
|
519 |
while ((cur=S_DATA(s+cur_size-S_FREE_MASK)) & S_FREE_MASK) { |
|
520 |
cur_size += cur - S_FREE_MASK; |
|
521 |
S_DATA(s) = cur_size; |
|
522 |
} |
|
523 |
cur_size--; |
|
524 |
} |
|
525 |
} |
|
526 |
} |
|
527 |
||
528 |
static byte *LoadSpriteToMem(int sprite) |
|
529 |
{ |
|
530 |
byte *s; |
|
531 |
size_t mem_req, cur_size; |
|
532 |
||
533 |
DEBUG(spritecache, 9) ("load sprite %d", sprite); |
|
534 |
||
535 |
restart: |
|
536 |
// Number of needed bytes |
|
537 |
mem_req = _sprite_size[sprite] + S_HDRSIZE; |
|
538 |
||
539 |
// Align this to an uint32 boundary. This also makes sure that the 2 least bit are not used, |
|
540 |
// so we could use those for other things. |
|
541 |
mem_req = (mem_req + sizeof(uint32) - 1) & ~(sizeof(uint32) - 1); |
|
542 |
||
543 |
s = _spritecache_ptr; |
|
544 |
for(;;) { |
|
545 |
for(;;) { |
|
546 |
cur_size = S_DATA(s); |
|
547 |
if (! (cur_size & S_FREE_MASK) ) break; |
|
548 |
||
549 |
cur_size -= S_FREE_MASK; |
|
550 |
||
551 |
// Now s points at a free block. |
|
552 |
// The block is exactly the size we need? |
|
553 |
if (cur_size != mem_req) { |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
554 |
|
0 | 555 |
// No.. is it too small? |
556 |
if (cur_size < mem_req + S_HDRSIZE) |
|
557 |
break; |
|
558 |
||
559 |
// Block was big enough, and we need to inject a free block too. |
|
560 |
S_DATA(s + mem_req) = cur_size - mem_req + S_FREE_MASK; |
|
561 |
||
562 |
} |
|
563 |
// Set size and in use |
|
564 |
S_DATA(s) = mem_req; |
|
565 |
||
566 |
_sprite_ptr[sprite] = (s += S_HDRSIZE); |
|
567 |
||
568 |
FioSeekToFile(_sprite_file_pos[sprite]); |
|
569 |
ReadSprite(_sprite_size[sprite], s); |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
570 |
|
0 | 571 |
// Patch the height to compensate for a TTD bug? |
572 |
if (sprite == 142) { s[1] = 10; } |
|
573 |
||
574 |
// Return sprite ptr |
|
575 |
return s; |
|
576 |
} |
|
577 |
||
578 |
// Reached sentinel, but no block found yet. Need to delete some old entries. |
|
579 |
if (cur_size == 0) { |
|
580 |
DeleteEntryFromSpriteCache(); |
|
581 |
goto restart; |
|
582 |
} |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
583 |
|
0 | 584 |
s += cur_size; |
585 |
} |
|
586 |
} |
|
587 |
||
588 |
#if defined(NEW_ROTATION) |
|
589 |
#define X15(x) else if (s >= x && s < (x+15)) { s = _rotate_tile_sprite[s - x] + x; } |
|
590 |
#define X19(x) else if (s >= x && s < (x+19)) { s = _rotate_tile_sprite[s - x] + x; } |
|
591 |
#define MAP(from,to,map) else if (s >= from && s <= to) { s = map[s - from] + from; } |
|
592 |
||
593 |
||
594 |
uint RotateSprite(uint s) |
|
595 |
{ |
|
596 |
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 }; |
|
597 |
static const byte _coast_map[9] = {0, 4, 3, 1, 2, 6, 8, 5, 7}; |
|
598 |
static const byte _fence_map[6] = {1, 0, 5, 4, 3, 2}; |
|
599 |
||
600 |
if (0); |
|
601 |
X19(752) |
|
602 |
X15(990-1) |
|
603 |
X19(3924) |
|
604 |
X19(3943) |
|
605 |
X19(3962) |
|
606 |
X19(3981) |
|
607 |
X19(4000) |
|
608 |
X19(4023) |
|
609 |
X19(4042) |
|
610 |
MAP(4061,4069,_coast_map) |
|
611 |
X19(4126) |
|
612 |
X19(4145) |
|
613 |
X19(4164) |
|
614 |
X19(4183) |
|
615 |
X19(4202) |
|
616 |
X19(4221) |
|
617 |
X19(4240) |
|
618 |
X19(4259) |
|
619 |
X19(4259) |
|
620 |
X19(4278) |
|
621 |
MAP(4090, 4095, _fence_map) |
|
622 |
MAP(4096, 4101, _fence_map) |
|
623 |
MAP(4102, 4107, _fence_map) |
|
624 |
MAP(4108, 4113, _fence_map) |
|
625 |
MAP(4114, 4119, _fence_map) |
|
626 |
MAP(4120, 4125, _fence_map) |
|
627 |
return s; |
|
628 |
} |
|
629 |
#endif |
|
630 |
||
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
631 |
byte *GetSpritePtr(uint sprite) |
0 | 632 |
{ |
633 |
byte *p; |
|
634 |
||
635 |
assert(sprite < NUM_SPRITES); |
|
636 |
||
637 |
#if defined(NEW_ROTATION) |
|
638 |
sprite = RotateSprite(sprite); |
|
639 |
#endif |
|
640 |
||
641 |
// Update LRU |
|
642 |
#if defined(WANT_NEW_LRU) |
|
643 |
_sprite_lru_new[sprite] = ++_sprite_lru_counter; |
|
644 |
#else |
|
645 |
_sprite_lru_cur[sprite] = ++_sprite_lru_counter; |
|
646 |
_sprite_lru[sprite] = 0; |
|
647 |
#endif |
|
648 |
||
649 |
// Check if the sprite is loaded already? |
|
650 |
p = _sprite_ptr[sprite]; |
|
651 |
if (p == NULL) |
|
652 |
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
|
653 |
return p; |
0 | 654 |
} |
655 |
||
656 |
byte _sprite_page_to_load = 0xFF; |
|
657 |
||
658 |
static const char * const _cached_filenames[4] = { |
|
659 |
"cached_sprites.xxx", |
|
660 |
"cached_sprites.xx1", |
|
661 |
"cached_sprites.xx2", |
|
662 |
"cached_sprites.xx3", |
|
663 |
}; |
|
664 |
||
143 | 665 |
#define OPENTTD_SPRITES_COUNT 70 |
0 | 666 |
static const uint16 _openttd_grf_indexes[] = { |
667 |
SPR_OPENTTD_BASE+0, SPR_OPENTTD_BASE+7, // icons etc |
|
668 |
98,98, // euro symbol medium size |
|
669 |
546,546, // euro symbol large size |
|
670 |
SPR_OPENTTD_BASE+10, SPR_OPENTTD_BASE+57, // more icons |
|
671 |
648, 648, // nordic char: æ |
|
672 |
616, 616, // nordic char: Æ |
|
673 |
666, 666, // nordic char: Ø |
|
674 |
634, 634, // nordic char: Ø |
|
143 | 675 |
SPR_OPENTTD_BASE+62, SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT, // more icons |
0 | 676 |
0xffff, |
677 |
}; |
|
678 |
||
679 |
static void LoadSpriteTables() |
|
680 |
{ |
|
681 |
int i,j; |
|
682 |
||
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
683 |
/* |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
684 |
* Note for developers: |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
685 |
* 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
|
686 |
* 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
|
687 |
* below. |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
688 |
*/ |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
689 |
|
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
690 |
// Try to load the sprites from cache |
0 | 691 |
if (!HandleCachedSpriteHeaders(_cached_filenames[_opt.landscape], true)) { |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
692 |
// 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
|
693 |
// So just load all files from disk.. |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
694 |
|
0 | 695 |
int load_index = 0; |
696 |
for(i=0; _filename_list[i] != NULL; i++) { |
|
697 |
load_index += LoadGrfFile(_filename_list[i], load_index, (byte)i); |
|
698 |
} |
|
699 |
||
700 |
LoadGrfIndexed("openttd.grf", _openttd_grf_indexes, i++); |
|
701 |
||
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
702 |
if (_sprite_page_to_load != 0) |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
703 |
LoadGrfIndexed(_landscape_filenames[_sprite_page_to_load-1], _landscape_spriteindexes[_sprite_page_to_load-1], i++); |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
704 |
|
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
705 |
LoadGrfIndexed("trkfoundw.grf", _slopes_spriteindexes[_opt.landscape], i++); |
0 | 706 |
|
707 |
load_index = SPR_CANALS_BASE; |
|
708 |
load_index += LoadGrfFile("canalsw.grf", load_index, i++); |
|
142 | 709 |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
710 |
load_index = SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT + 1; |
142 | 711 |
|
0 | 712 |
for(j=0; j!=lengthof(_newgrf_files) && _newgrf_files[j]; j++) |
713 |
load_index += LoadGrfFile(_newgrf_files[j], load_index, i++); |
|
714 |
||
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
715 |
// If needed, save the cache to file |
0 | 716 |
HandleCachedSpriteHeaders(_cached_filenames[_opt.landscape], false); |
717 |
} else { |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
718 |
// 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
|
719 |
// 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
|
720 |
// 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
|
721 |
// 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
|
722 |
// 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
|
723 |
// above should also be in this 'else'-section. |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
724 |
// |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
725 |
// 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
|
726 |
|
0 | 727 |
for(i=0; _filename_list[i] != NULL; i++) |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
728 |
FioOpenFile(i,_filename_list[i]); |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
729 |
|
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
730 |
FioOpenFile(i++, "openttd.grf"); |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
731 |
|
0 | 732 |
if (_sprite_page_to_load != 0) |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
733 |
FioOpenFile(i++, _landscape_filenames[_sprite_page_to_load-1]); |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
734 |
|
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
735 |
FioOpenFile(i++, "trkfoundw.grf"); |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
736 |
FioOpenFile(i++, "canalsw.grf"); |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
737 |
|
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
738 |
// 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
|
739 |
// 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
|
740 |
// 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
|
741 |
// do we detect it? |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
742 |
for(j=0; j!=lengthof(_newgrf_files) && _newgrf_files[j]; j++) |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
743 |
FioOpenFile(i++, _newgrf_files[j]); |
0 | 744 |
} |
745 |
||
746 |
_compact_cache_counter = 0; |
|
747 |
} |
|
748 |
||
749 |
void GfxInitSpriteMem(byte *ptr, uint32 size) |
|
750 |
{ |
|
751 |
// initialize sprite cache heap |
|
752 |
_spritecache_ptr = ptr; |
|
753 |
_spritecache_size = size; |
|
754 |
||
755 |
// Sentinel block (identified by size=0) |
|
756 |
S_DATA(ptr + size - S_HDRSIZE) = 0; |
|
757 |
// A big free block |
|
758 |
S_DATA(ptr) = size - S_HDRSIZE + S_FREE_MASK; |
|
759 |
||
760 |
memset(_sprite_ptr, 0, sizeof(_sprite_ptr)); |
|
761 |
} |
|
762 |
||
763 |
||
764 |
void GfxLoadSprites() { |
|
765 |
static byte *_sprite_mem; |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
766 |
|
0 | 767 |
// Need to reload the sprites only if the landscape changed |
768 |
if (_sprite_page_to_load != _opt.landscape) { |
|
769 |
_sprite_page_to_load = _opt.landscape; |
|
770 |
||
771 |
// Sprite cache |
|
772 |
DEBUG(spritecache, 1) ("Loading sprite set %d.", _sprite_page_to_load); |
|
773 |
||
774 |
// Reuse existing memory? |
|
775 |
if (_sprite_mem == NULL) _sprite_mem = malloc(SPRITE_CACHE_SIZE); |
|
776 |
GfxInitSpriteMem(_sprite_mem, SPRITE_CACHE_SIZE); |
|
777 |
LoadSpriteTables(); |
|
778 |
GfxInitPalettes(); |
|
779 |
} |
|
780 |
} |
|
781 |
||
782 |
||
783 |
const SpriteDimension *GetSpriteDimension(uint sprite) |
|
784 |
{ |
|
785 |
static SpriteDimension sd_static; |
|
786 |
SpriteDimension *sd; |
|
787 |
||
788 |
#ifndef WANT_SPRITESIZES |
|
789 |
byte *p; |
|
790 |
||
791 |
p = _sprite_ptr[sprite]; |
|
792 |
if (p == NULL) |
|
793 |
p = GetSpritePtr(sprite); |
|
794 |
||
795 |
/* decode sprite header */ |
|
796 |
sd = &sd_static; |
|
797 |
sd->xoffs = (int16)READ_LE_UINT16(&((SpriteHdr*)p)->x_offs); |
|
798 |
sd->yoffs = (int16)READ_LE_UINT16(&((SpriteHdr*)p)->y_offs); |
|
799 |
sd->xsize = READ_LE_UINT16(&((SpriteHdr*)p)->width); |
|
800 |
sd->ysize = ((SpriteHdr*)p)->height; |
|
801 |
#else |
|
802 |
sd = &sd_static; |
|
803 |
sd->xoffs = _sprite_xoffs[sprite]; |
|
804 |
sd->yoffs = _sprite_yoffs[sprite]; |
|
805 |
sd->xsize = _sprite_xsize[sprite]; |
|
806 |
sd->ysize = _sprite_ysize[sprite]; |
|
807 |
#endif |
|
808 |
/* sd->xoffs = _sprite_xoffs[sprite]; |
|
809 |
sd->yoffs = _sprite_yoffs[sprite]; |
|
810 |
sd->xsize = _sprite_xsize[sprite]; |
|
811 |
sd->ysize = _sprite_ysize[sprite]; |
|
812 |
*/ |
|
813 |
return sd; |
|
814 |
} |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
815 |