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