author | tron |
Mon, 08 Aug 2005 21:35:27 +0000 | |
changeset 2319 | 9902d3ffa309 |
parent 2313 | 6ebd32b859af |
child 2321 | 455694cdbada |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1844
diff
changeset
|
4 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1250
diff
changeset
|
5 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.h" |
0 | 7 |
#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
|
8 |
#include "spritecache.h" |
1363
01d3de5d8039
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1361
diff
changeset
|
9 |
#include "table/sprites.h" |
0 | 10 |
#include "fileio.h" |
463
91bcad840bcd
(svn r687) Export InitNewGRFFile() and DecodeSpecialSprite() properly.
pasky
parents:
452
diff
changeset
|
11 |
#include "newgrf.h" |
961 | 12 |
#include "md5.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2142
diff
changeset
|
13 |
#include "variables.h" |
0 | 14 |
#include <ctype.h> |
15 |
||
16 |
#define SPRITE_CACHE_SIZE 1024*1024 |
|
17 |
||
18 |
#define WANT_NEW_LRU |
|
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 |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
34 |
static void* _sprite_ptr[MAX_SPRITES]; |
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
35 |
static uint16 _sprite_size[MAX_SPRITES]; |
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
36 |
static uint32 _sprite_file_pos[MAX_SPRITES]; |
0 | 37 |
|
38 |
#if defined(WANT_NEW_LRU) |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
39 |
static int16 _sprite_lru_new[MAX_SPRITES]; |
0 | 40 |
#else |
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
41 |
static uint16 _sprite_lru[MAX_SPRITES]; |
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
42 |
static uint16 _sprite_lru_cur[MAX_SPRITES]; |
0 | 43 |
#endif |
44 |
||
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
} 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
|
49 |
|
0 | 50 |
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
|
51 |
static MemBlock *_spritecache_ptr; |
0 | 52 |
static uint32 _spritecache_size; |
53 |
static int _compact_cache_counter; |
|
54 |
||
961 | 55 |
typedef struct MD5File { |
56 |
const char * const filename; // filename |
|
962
c1de16d93e46
(svn r1454) -Fix: small warnings in spritecache.c
darkvater
parents:
961
diff
changeset
|
57 |
const md5_byte_t hash[16]; // md5 sum of the file |
961 | 58 |
} MD5File; |
59 |
||
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
60 |
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
|
61 |
const MD5File basic[5]; // grf files that always have to be loaded |
961 | 62 |
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
|
63 |
} FileList; |
0 | 64 |
|
961 | 65 |
#include "table/files.h" |
0 | 66 |
#include "table/landscape_sprite.h" |
67 |
||
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
68 |
static const SpriteID * const _landscape_spriteindexes[] = { |
0 | 69 |
_landscape_spriteindexes_1, |
70 |
_landscape_spriteindexes_2, |
|
71 |
_landscape_spriteindexes_3, |
|
72 |
}; |
|
73 |
||
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
74 |
static const SpriteID * const _slopes_spriteindexes[] = { |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
75 |
_slopes_spriteindexes_0, |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
76 |
_slopes_spriteindexes_1, |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
77 |
_slopes_spriteindexes_2, |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
78 |
_slopes_spriteindexes_3, |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
79 |
}; |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
80 |
|
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
|
81 |
static void CompactSpriteCache(void); |
0 | 82 |
|
83 |
static void ReadSpriteHeaderSkipData(int num, int load_index) |
|
84 |
{ |
|
85 |
byte type; |
|
86 |
int deaf = 0; |
|
87 |
||
88 |
if (_skip_sprites) { |
|
89 |
if (_skip_sprites > 0) |
|
90 |
_skip_sprites--; |
|
91 |
deaf = 1; |
|
92 |
} |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
93 |
|
0 | 94 |
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
|
95 |
_cur_sprite.info = type; |
0 | 96 |
if (type == 0xFF) { |
97 |
/* We need to really skip only special sprites in the deaf |
|
98 |
* mode. It won't hurt to proceed regular sprites as usual |
|
99 |
* because if no special sprite referencing to them is |
|
100 |
* processed, they themselves are never referenced and loaded |
|
101 |
* on their own. */ |
|
102 |
if (_skip_specials || deaf) { |
|
103 |
FioSkipBytes(num); |
|
104 |
} else { |
|
368
32aad6ad36e1
(svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents:
366
diff
changeset
|
105 |
DecodeSpecialSprite(_cur_grffile, num, load_index, _loading_stage); |
0 | 106 |
} |
107 |
return; |
|
108 |
} |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
109 |
|
0 | 110 |
FioSkipBytes(7); |
111 |
num -= 8; |
|
112 |
if (num == 0) |
|
113 |
return; |
|
114 |
||
115 |
if (type & 2) { |
|
116 |
FioSkipBytes(num); |
|
1355 | 117 |
} else { |
118 |
while (num > 0) { |
|
119 |
int8 i = FioReadByte(); |
|
120 |
if (i >= 0) { |
|
121 |
num -= i; |
|
122 |
FioSkipBytes(i); |
|
123 |
} else { |
|
124 |
i = -(i >> 3); |
|
125 |
num -= i; |
|
126 |
FioReadByte(); |
|
127 |
} |
|
0 | 128 |
} |
129 |
} |
|
130 |
} |
|
131 |
||
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
|
132 |
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
|
133 |
|
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
|
134 |
static void* ReadSprite(SpriteID id) |
0 | 135 |
{ |
1354
5e5c89b9b169
(svn r1858) Let ReadSprite() handle the subtleties of loading a sprite, not its caller
tron
parents:
1353
diff
changeset
|
136 |
uint num = _sprite_size[id]; |
0 | 137 |
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
|
138 |
|
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
|
139 |
DEBUG(spritecache, 9) ("load sprite %d", id); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
140 |
|
1378
ebb8d52f0352
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
141 |
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
|
142 |
error( |
ebb8d52f0352
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
143 |
"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
|
144 |
"Probable cause: Wrong/missing NewGRFs", |
ebb8d52f0352
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
145 |
id |
ebb8d52f0352
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
146 |
); |
ebb8d52f0352
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
147 |
} |
ebb8d52f0352
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
148 |
|
1354
5e5c89b9b169
(svn r1858) Let ReadSprite() handle the subtleties of loading a sprite, not its caller
tron
parents:
1353
diff
changeset
|
149 |
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
|
150 |
|
0 | 151 |
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
|
152 |
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
|
153 |
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
|
154 |
|
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
|
155 |
_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
|
156 |
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
|
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 |
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
|
159 |
} 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
|
160 |
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
|
161 |
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
|
162 |
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
|
163 |
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
|
164 |
|
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
|
165 |
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
|
166 |
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
|
167 |
_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
|
168 |
sprite->info = type; |
2015 | 169 |
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
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
|
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
174 |
dest = sprite->data; |
1355 | 175 |
while (num > 0) { |
176 |
int8 i = FioReadByte(); |
|
0 | 177 |
|
1355 | 178 |
if (i >= 0) { |
179 |
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
|
180 |
for (; i > 0; --i) *dest++ = FioReadByte(); |
1355 | 181 |
} else { |
182 |
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
|
183 |
|
1355 | 184 |
i = -(i >> 3); |
185 |
num -= i; |
|
186 |
||
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
|
187 |
for (; i > 0; --i) *dest++ = *rel++; |
1355 | 188 |
} |
0 | 189 |
} |
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
|
190 |
|
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
|
191 |
return sprite; |
0 | 192 |
} |
193 |
} |
|
194 |
||
195 |
||
196 |
static bool LoadNextSprite(int load_index, byte file_index) |
|
197 |
{ |
|
198 |
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
|
199 |
uint32 file_pos; |
0 | 200 |
|
1355 | 201 |
size = FioReadWord(); |
202 |
if (size == 0) |
|
0 | 203 |
return false; |
204 |
||
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
|
205 |
file_pos = FioGetPos() | (file_index << 24); |
0 | 206 |
|
207 |
ReadSpriteHeaderSkipData(size, load_index); |
|
208 |
||
1355 | 209 |
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
|
210 |
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
|
211 |
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
|
212 |
|
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
|
213 |
_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
|
214 |
_replace_sprites_count[0]--; |
862
d7e52ef99f42
(svn r1343) -Fix: [Graphic] Autorail icon is now correct (Darkvater)
truelight
parents:
614
diff
changeset
|
215 |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
216 |
if ((offset + count) <= MAX_SPRITES) { |
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
|
217 |
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
|
218 |
} 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
|
219 |
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
|
220 |
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
|
221 |
_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
|
222 |
_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
|
223 |
} |
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 |
|
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
225 |
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
|
226 |
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
|
227 |
|
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
228 |
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
|
229 |
_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
|
230 |
_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
|
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_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
|
233 |
_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
|
234 |
} |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
235 |
} |
ad7a042ee0eb
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
236 |
|
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 |
_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
|
238 |
_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
|
239 |
|
0 | 240 |
_sprite_ptr[load_index] = NULL; |
241 |
||
242 |
#if defined(WANT_NEW_LRU) |
|
243 |
_sprite_lru_new[load_index] = 0; |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
244 |
#else |
0 | 245 |
_sprite_lru[load_index] = 0xFFFF; |
246 |
_sprite_lru_cur[load_index] = 0; |
|
247 |
#endif |
|
248 |
||
249 |
return true; |
|
250 |
} |
|
251 |
||
1355 | 252 |
static void SkipSprites(uint count) |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
253 |
{ |
1355 | 254 |
for (; count > 0; --count) |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
255 |
{ |
1355 | 256 |
uint16 size = FioReadWord(); |
257 |
||
258 |
if (size == 0) |
|
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
259 |
return; |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
260 |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
261 |
ReadSpriteHeaderSkipData(size, MAX_SPRITES - 1); |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
262 |
} |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
263 |
} |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
264 |
|
0 | 265 |
static int LoadGrfFile(const char *filename, int load_index, int file_index) |
266 |
{ |
|
267 |
int load_index_org = load_index; |
|
268 |
||
269 |
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
|
270 |
|
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
|
271 |
/* 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
|
272 |
* 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
|
273 |
_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
|
274 |
_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
|
275 |
|
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
|
276 |
DEBUG(spritecache, 2) ("Reading grf-file ``%s''", filename); |
0 | 277 |
|
278 |
while (LoadNextSprite(load_index, file_index)) { |
|
279 |
load_index++; |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
280 |
if (load_index >= MAX_SPRITES) { |
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
281 |
error("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files."); |
0 | 282 |
} |
283 |
} |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
284 |
DEBUG(spritecache, 2) ("Currently %i sprites are loaded", load_index); |
0 | 285 |
|
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
|
286 |
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
|
287 |
} |
5752af05ed75
(svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents:
364
diff
changeset
|
288 |
|
5752af05ed75
(svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents:
364
diff
changeset
|
289 |
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
|
290 |
{ |
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
|
291 |
int i; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
292 |
|
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
|
293 |
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
|
294 |
_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
|
295 |
_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
|
296 |
_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
|
297 |
|
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
|
298 |
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
|
299 |
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
|
300 |
|
442
913a307af50d
(svn r651) LoadNewGrfFile() now doesn't care about num_sprites and just loads whatever is
miham
parents:
425
diff
changeset
|
301 |
/* 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
|
302 |
* 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
|
303 |
* 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
|
304 |
{ |
5752af05ed75
(svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents:
364
diff
changeset
|
305 |
int 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
|
306 |
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
|
307 |
|
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
|
308 |
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
|
309 |
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
|
310 |
|
1355 | 311 |
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
|
312 |
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
|
313 |
} 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
|
314 |
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
|
315 |
} |
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 |
|
442
913a307af50d
(svn r651) LoadNewGrfFile() now doesn't care about num_sprites and just loads whatever is
miham
parents:
425
diff
changeset
|
318 |
for (i = 0; LoadNextSprite(load_index + i, file_index); i++) { |
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
319 |
if (load_index + i >= MAX_SPRITES) |
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
320 |
error("Too many sprites (0x%X). Recompile with higher MAX_SPRITES value or remove some custom GRF files.", |
442
913a307af50d
(svn r651) LoadNewGrfFile() now doesn't care about num_sprites and just loads whatever is
miham
parents:
425
diff
changeset
|
321 |
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
|
322 |
} |
5752af05ed75
(svn r553) -newgrf: Special routine for loading newgrf files. LoadNewGrfFile() introduced; will get more handy when loading stages will be introduced (octo and pasky).
darkvater
parents:
364
diff
changeset
|
323 |
|
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
|
324 |
/* 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
|
325 |
_skip_sprites = 0; |
2313
6ebd32b859af
(svn r2839) Remove stuff missed in r2833, properly calculate the size of two arrays and simplify GetSpriteDimension()?a bit
tron
parents:
2309
diff
changeset
|
326 |
memset(_replace_sprites_count, 0, sizeof(_replace_sprites_count)); |
6ebd32b859af
(svn r2839) Remove stuff missed in r2833, properly calculate the size of two arrays and simplify GetSpriteDimension()?a bit
tron
parents:
2309
diff
changeset
|
327 |
memset(_replace_sprites_offset, 0, sizeof(_replace_sprites_offset)); |
0 | 328 |
|
442
913a307af50d
(svn r651) LoadNewGrfFile() now doesn't care about num_sprites and just loads whatever is
miham
parents:
425
diff
changeset
|
329 |
return i; |
0 | 330 |
} |
331 |
||
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
332 |
static void LoadGrfIndexed(const char *filename, const SpriteID *index_tbl, int file_index) |
0 | 333 |
{ |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
334 |
int start; |
0 | 335 |
|
336 |
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
|
337 |
_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
|
338 |
_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
|
339 |
|
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
|
340 |
DEBUG(spritecache, 2) ("Reading indexed grf-file ``%s''", filename); |
0 | 341 |
|
1355 | 342 |
for (; (start = *index_tbl++) != 0xffff;) { |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
343 |
int end = *index_tbl++; |
1355 | 344 |
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
|
345 |
SkipSprites(end); |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
346 |
} 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
|
347 |
do { |
1844
372dae999453
(svn r2349) - Fix: remove warning from release build when assertions are no longer active
Darkvater
parents:
1725
diff
changeset
|
348 |
#ifdef NDEBUG |
372dae999453
(svn r2349) - Fix: remove warning from release build when assertions are no longer active
Darkvater
parents:
1725
diff
changeset
|
349 |
LoadNextSprite(start, file_index); |
372dae999453
(svn r2349) - Fix: remove warning from release build when assertions are no longer active
Darkvater
parents:
1725
diff
changeset
|
350 |
#else |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
351 |
bool b = LoadNextSprite(start, file_index); |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
352 |
assert(b); |
1844
372dae999453
(svn r2349) - Fix: remove warning from release build when assertions are no longer active
Darkvater
parents:
1725
diff
changeset
|
353 |
#endif |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
354 |
} while (++start <= end); |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
355 |
} |
0 | 356 |
} |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
357 |
} |
0 | 358 |
|
359 |
||
360 |
#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
|
361 |
|
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
|
362 |
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
|
363 |
{ |
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
|
364 |
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
|
365 |
} |
0 | 366 |
|
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
|
367 |
static uint32 GetSpriteCacheUsage(void) |
0 | 368 |
{ |
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
|
369 |
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
|
370 |
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
|
371 |
|
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
|
372 |
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
|
373 |
if (!(s->size & S_FREE_MASK)) tot_size += s->size; |
0 | 374 |
|
375 |
return tot_size; |
|
376 |
} |
|
377 |
||
378 |
||
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
|
379 |
void IncreaseSpriteLRU(void) |
0 | 380 |
{ |
381 |
int i; |
|
382 |
||
383 |
// Increase all LRU values |
|
384 |
#if defined(WANT_NEW_LRU) |
|
385 |
if (_sprite_lru_counter > 16384) { |
|
386 |
DEBUG(spritecache, 2) ("fixing lru %d, inuse=%d", _sprite_lru_counter, GetSpriteCacheUsage()); |
|
387 |
||
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
388 |
for (i = 0; i != MAX_SPRITES; i++) |
0 | 389 |
if (_sprite_ptr[i] != NULL) { |
390 |
if (_sprite_lru_new[i] >= 0) { |
|
391 |
_sprite_lru_new[i] = -1; |
|
392 |
} else if (_sprite_lru_new[i] != -32768) { |
|
393 |
_sprite_lru_new[i]--; |
|
394 |
} |
|
395 |
} |
|
396 |
_sprite_lru_counter = 0; |
|
397 |
} |
|
398 |
#else |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
399 |
for (i = 0; i != MAX_SPRITES; i++) |
0 | 400 |
if (_sprite_ptr[i] != NULL && _sprite_lru[i] != 65535) |
401 |
_sprite_lru[i]++; |
|
402 |
// Reset the lru counter. |
|
403 |
_sprite_lru_counter = 0; |
|
404 |
#endif |
|
405 |
||
406 |
// Compact sprite cache every now and then. |
|
407 |
if (++_compact_cache_counter >= 740) { |
|
408 |
CompactSpriteCache(); |
|
409 |
_compact_cache_counter = 0; |
|
410 |
} |
|
411 |
} |
|
412 |
||
413 |
// Called when holes in the sprite cache should be removed. |
|
414 |
// 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
|
415 |
static void CompactSpriteCache(void) |
0 | 416 |
{ |
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
|
417 |
MemBlock *s; |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
418 |
|
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
|
419 |
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
|
420 |
"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
|
421 |
); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
422 |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
423 |
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
|
424 |
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
|
425 |
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
|
426 |
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
|
427 |
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
|
428 |
|
0 | 429 |
// 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
|
430 |
assert(!(next->size & S_FREE_MASK)); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
431 |
|
0 | 432 |
// 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
|
433 |
if (next->size == 0) |
0 | 434 |
break; |
435 |
||
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
|
436 |
// 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
|
437 |
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
|
438 |
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
|
439 |
} |
0 | 440 |
|
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
|
441 |
*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
|
442 |
// 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
|
443 |
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
|
444 |
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
|
445 |
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
|
446 |
*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
|
447 |
|
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
|
448 |
// 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
|
449 |
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
|
450 |
s->size += NextBlock(s)->size & ~S_FREE_MASK; |
0 | 451 |
} |
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
|
452 |
} 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
|
453 |
s = NextBlock(s); |
0 | 454 |
} |
455 |
} |
|
456 |
} |
|
457 |
||
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
|
458 |
static void DeleteEntryFromSpriteCache(void) |
0 | 459 |
{ |
460 |
int i; |
|
461 |
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
|
462 |
MemBlock* s; |
0 | 463 |
int cur_lru; |
464 |
||
465 |
DEBUG(spritecache, 2) ("DeleteEntryFromSpriteCache, inuse=%d", GetSpriteCacheUsage()); |
|
466 |
||
467 |
#if defined(WANT_NEW_LRU) |
|
468 |
cur_lru = 0xffff; |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
469 |
for (i = 0; i != MAX_SPRITES; i++) { |
2305
f0856e98f7a5
(svn r2829) Remove sprite locking, it was never used anyway
tron
parents:
2244
diff
changeset
|
470 |
if (_sprite_ptr[i] != NULL && _sprite_lru_new[i] < cur_lru) { |
0 | 471 |
cur_lru = _sprite_lru_new[i]; |
472 |
best = i; |
|
473 |
} |
|
474 |
} |
|
475 |
#else |
|
476 |
{ |
|
477 |
uint16 cur_lru = 0, cur_lru_cur = 0xffff; |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
478 |
for (i = 0; i != MAX_SPRITES; i++) { |
2305
f0856e98f7a5
(svn r2829) Remove sprite locking, it was never used anyway
tron
parents:
2244
diff
changeset
|
479 |
if (_sprite_ptr[i] == NULL || _sprite_lru[i] < cur_lru) continue; |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
480 |
|
0 | 481 |
// Found a sprite with a higher LRU value, then remember it. |
482 |
if (_sprite_lru[i] != cur_lru) { |
|
483 |
cur_lru = _sprite_lru[i]; |
|
484 |
best = i; |
|
485 |
||
486 |
// Else if both sprites were very recently referenced, compare by the cur value instead. |
|
487 |
} else if (cur_lru == 0 && _sprite_lru_cur[i] <= cur_lru_cur) { |
|
488 |
cur_lru_cur = _sprite_lru_cur[i]; |
|
489 |
cur_lru = _sprite_lru[i]; |
|
490 |
best = i; |
|
491 |
} |
|
492 |
} |
|
493 |
} |
|
494 |
#endif |
|
495 |
||
496 |
// Display an error message and die, in case we found no sprite at all. |
|
497 |
// This shouldn't really happen, unless all sprites are locked. |
|
498 |
if (best == -1) |
|
499 |
error("Out of sprite memory"); |
|
500 |
||
501 |
// 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
|
502 |
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
|
503 |
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
|
504 |
s->size |= S_FREE_MASK; |
0 | 505 |
_sprite_ptr[best] = NULL; |
506 |
||
507 |
// 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
|
508 |
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
|
509 |
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
|
510 |
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
|
511 |
s->size += NextBlock(s)->size & ~S_FREE_MASK; |
0 | 512 |
} |
513 |
} |
|
514 |
} |
|
515 |
} |
|
516 |
||
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
|
517 |
static void* AllocSprite(size_t mem_req) |
0 | 518 |
{ |
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
|
519 |
mem_req += sizeof(MemBlock); |
0 | 520 |
|
1353
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
521 |
/* 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
|
522 |
* bits are not used, so we could use those for other things. */ |
0 | 523 |
mem_req = (mem_req + sizeof(uint32) - 1) & ~(sizeof(uint32) - 1); |
524 |
||
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
|
525 |
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
|
526 |
MemBlock* s; |
0 | 527 |
|
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
|
528 |
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
|
529 |
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
|
530 |
size_t cur_size = s->size & ~S_FREE_MASK; |
0 | 531 |
|
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
|
532 |
/* 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
|
533 |
* 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
|
534 |
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
|
535 |
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
|
536 |
// 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
|
537 |
s->size = mem_req; |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
538 |
|
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
|
539 |
// 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
|
540 |
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
|
541 |
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
|
542 |
} |
0 | 543 |
|
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
|
544 |
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
|
545 |
} |
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
|
546 |
} |
0 | 547 |
} |
548 |
||
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
|
549 |
// 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
|
550 |
DeleteEntryFromSpriteCache(); |
0 | 551 |
} |
552 |
} |
|
553 |
||
554 |
#if defined(NEW_ROTATION) |
|
555 |
#define X15(x) else if (s >= x && s < (x+15)) { s = _rotate_tile_sprite[s - x] + x; } |
|
556 |
#define X19(x) else if (s >= x && s < (x+19)) { s = _rotate_tile_sprite[s - x] + x; } |
|
557 |
#define MAP(from,to,map) else if (s >= from && s <= to) { s = map[s - from] + from; } |
|
558 |
||
559 |
||
410 | 560 |
static uint RotateSprite(uint s) |
0 | 561 |
{ |
562 |
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 }; |
|
563 |
static const byte _coast_map[9] = {0, 4, 3, 1, 2, 6, 8, 5, 7}; |
|
564 |
static const byte _fence_map[6] = {1, 0, 5, 4, 3, 2}; |
|
565 |
||
566 |
if (0); |
|
567 |
X19(752) |
|
568 |
X15(990-1) |
|
569 |
X19(3924) |
|
570 |
X19(3943) |
|
571 |
X19(3962) |
|
572 |
X19(3981) |
|
573 |
X19(4000) |
|
574 |
X19(4023) |
|
575 |
X19(4042) |
|
576 |
MAP(4061,4069,_coast_map) |
|
577 |
X19(4126) |
|
578 |
X19(4145) |
|
579 |
X19(4164) |
|
580 |
X19(4183) |
|
581 |
X19(4202) |
|
582 |
X19(4221) |
|
583 |
X19(4240) |
|
584 |
X19(4259) |
|
585 |
X19(4259) |
|
586 |
X19(4278) |
|
587 |
MAP(4090, 4095, _fence_map) |
|
588 |
MAP(4096, 4101, _fence_map) |
|
589 |
MAP(4102, 4107, _fence_map) |
|
590 |
MAP(4108, 4113, _fence_map) |
|
591 |
MAP(4114, 4119, _fence_map) |
|
592 |
MAP(4120, 4125, _fence_map) |
|
593 |
return s; |
|
594 |
} |
|
595 |
#endif |
|
596 |
||
1361 | 597 |
const void *GetRawSprite(SpriteID sprite) |
0 | 598 |
{ |
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
|
599 |
void* p; |
0 | 600 |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
601 |
assert(sprite < MAX_SPRITES); |
0 | 602 |
|
603 |
#if defined(NEW_ROTATION) |
|
604 |
sprite = RotateSprite(sprite); |
|
605 |
#endif |
|
606 |
||
607 |
// Update LRU |
|
608 |
#if defined(WANT_NEW_LRU) |
|
609 |
_sprite_lru_new[sprite] = ++_sprite_lru_counter; |
|
610 |
#else |
|
2026 | 611 |
_sprite_lru_cur[sprite] = ++_sprite_lru_counter; |
0 | 612 |
_sprite_lru[sprite] = 0; |
613 |
#endif |
|
614 |
||
615 |
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
|
616 |
// 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
|
617 |
if (p == NULL) p = ReadSprite(sprite); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
618 |
return p; |
0 | 619 |
} |
620 |
||
621 |
byte _sprite_page_to_load = 0xFF; |
|
622 |
||
2244 | 623 |
#define OPENTTD_SPRITES_COUNT 100 |
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
624 |
static const SpriteID _openttd_grf_indexes[] = { |
2026 | 625 |
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
|
626 |
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
|
627 |
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
|
628 |
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
|
629 |
SPR_OPENTTD_BASE+11, SPR_OPENTTD_BASE+57, // more icons |
0 | 630 |
648, 648, // nordic char: æ |
631 |
616, 616, // nordic char: Æ |
|
632 |
666, 666, // nordic char: Ø |
|
633 |
634, 634, // nordic char: Ø |
|
143 | 634 |
SPR_OPENTTD_BASE+62, SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT, // more icons |
0 | 635 |
0xffff, |
636 |
}; |
|
637 |
||
961 | 638 |
/* 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
|
639 |
|
961 | 640 |
/* Check that the supplied MD5 hash matches that stored for the supplied filename */ |
641 |
static bool CheckMD5Digest(const MD5File file, md5_byte_t *digest, bool warn) |
|
642 |
{ |
|
2028
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
643 |
uint i; |
961 | 644 |
|
645 |
/* Loop through each byte of the file MD5 and the stored MD5... */ |
|
2028
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
646 |
for (i = 0; i < 16; i++) if (file.hash[i] != digest[i]) break; |
961 | 647 |
|
648 |
/* If all bytes of the MD5's match (i.e. the MD5's match)... */ |
|
2028
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
649 |
if (i == 16) { |
961 | 650 |
return true; |
651 |
} else { |
|
2028
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
652 |
if (warn) fprintf(stderr, "MD5 of %s is ****INCORRECT**** - File Corrupt.\n", file.filename); |
961 | 653 |
return false; |
654 |
}; |
|
655 |
} |
|
656 |
||
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
966
diff
changeset
|
657 |
/* Calculate and check the MD5 hash of the supplied filename. |
961 | 658 |
* returns true if the checksum is correct */ |
659 |
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
|
660 |
{ |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
661 |
FILE *f; |
961 | 662 |
char buf[MAX_PATH]; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
663 |
|
961 | 664 |
// open file |
665 |
sprintf(buf, "%s%s", _path.data_dir, file.filename); |
|
666 |
f = fopen(buf, "rb"); |
|
667 |
||
668 |
#if !defined(WIN32) |
|
669 |
if (f == NULL) { |
|
1329 | 670 |
char *s; |
961 | 671 |
// make lower case and check again |
1355 | 672 |
for (s = buf + strlen(_path.data_dir) - 1; *s != '\0'; s++) |
961 | 673 |
*s = tolower(*s); |
674 |
f = fopen(buf, "rb"); |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
675 |
} |
961 | 676 |
#endif |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
677 |
|
862
d7e52ef99f42
(svn r1343) -Fix: [Graphic] Autorail icon is now correct (Darkvater)
truelight
parents:
614
diff
changeset
|
678 |
if (f != NULL) { |
2028
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
679 |
md5_state_t filemd5state; |
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
680 |
md5_byte_t buffer[1024]; |
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
681 |
md5_byte_t digest[16]; |
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
682 |
size_t len; |
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
683 |
|
961 | 684 |
md5_init(&filemd5state); |
2028
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
685 |
while ((len = fread(buffer, 1, sizeof(buffer), f)) != 0) |
961 | 686 |
md5_append(&filemd5state, buffer, len); |
687 |
||
2028
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
688 |
if (ferror(f) && warn) fprintf(stderr, "Error Reading from %s \n", buf); |
961 | 689 |
fclose(f); |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
966
diff
changeset
|
690 |
|
961 | 691 |
md5_finish(&filemd5state, digest); |
692 |
return CheckMD5Digest(file, digest, warn); |
|
693 |
} else { // file not found |
|
694 |
return false; |
|
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
966
diff
changeset
|
695 |
} |
961 | 696 |
} |
697 |
||
698 |
/* Checks, if either the Windows files exist (TRG1R.GRF) or the DOS files (TRG1.GRF) |
|
699 |
* 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
|
700 |
* If neither are found, Windows palette is assumed. |
961 | 701 |
* |
702 |
* (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
|
703 |
void CheckExternalFiles(void) |
961 | 704 |
{ |
1355 | 705 |
uint i; |
706 |
// count of files from this version |
|
707 |
uint dos = 0; |
|
708 |
uint win = 0; |
|
961 | 709 |
|
2028
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
710 |
for (i = 0; i < 2; i++) if (FileMD5(files_dos.basic[i], true)) dos++; |
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
711 |
for (i = 0; i < 3; i++) if (FileMD5(files_dos.landscape[i], true)) dos++; |
961 | 712 |
|
2028
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
713 |
for (i = 0; i < 2; i++) if (FileMD5(files_win.basic[i], true)) win++; |
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
714 |
for (i = 0; i < 3; i++) if (FileMD5(files_win.landscape[i], true)) win++; |
961 | 715 |
|
1355 | 716 |
if (!FileMD5(sample_cat_win, false) && !FileMD5(sample_cat_dos, false)) |
2028
d7686f53adf2
(svn r2537) Small changes, especially use fprintf to stderr for warnings and errors instead of plain printf
tron
parents:
2027
diff
changeset
|
717 |
fprintf(stderr, "Your sample.cat file is corrupted or missing!\n"); |
961 | 718 |
|
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
|
719 |
/* |
1389 | 720 |
* 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
|
721 |
* 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
|
722 |
* 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
|
723 |
* 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
|
724 |
* 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
|
725 |
*/ |
1389 | 726 |
if (_use_dos_palette) { |
727 |
return; |
|
728 |
} else if (win == 5) { |
|
961 | 729 |
_use_dos_palette = false; |
1381 | 730 |
} 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
|
731 |
_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
|
732 |
} else { |
961 | 733 |
_use_dos_palette = false; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
734 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
735 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
579
diff
changeset
|
736 |
|
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
|
737 |
static void LoadSpriteTables(void) |
0 | 738 |
{ |
2309 | 739 |
int load_index = 0; |
1355 | 740 |
uint i; |
741 |
uint j; |
|
742 |
const FileList *files; // list of grf files to be loaded. Either Windows files or DOS files |
|
0 | 743 |
|
368
32aad6ad36e1
(svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents:
366
diff
changeset
|
744 |
_loading_stage = 1; |
32aad6ad36e1
(svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents:
366
diff
changeset
|
745 |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
746 |
/* |
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
|
747 |
* 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
|
748 |
* 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
|
749 |
* invest that further. --octo |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
750 |
*/ |
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
751 |
|
1355 | 752 |
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
|
753 |
|
2309 | 754 |
for (i = 0; files->basic[i].filename != NULL; i++) { |
755 |
load_index += LoadGrfFile(files->basic[i].filename, load_index, i); |
|
756 |
} |
|
0 | 757 |
|
2309 | 758 |
LoadGrfIndexed("openttd.grf", _openttd_grf_indexes, i++); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
759 |
|
2309 | 760 |
if (_sprite_page_to_load != 0) { |
761 |
LoadGrfIndexed( |
|
762 |
files->landscape[_sprite_page_to_load - 1].filename, |
|
763 |
_landscape_spriteindexes[_sprite_page_to_load - 1], |
|
764 |
i++ |
|
765 |
); |
|
766 |
} |
|
0 | 767 |
|
2309 | 768 |
LoadGrfIndexed("trkfoundw.grf", _slopes_spriteindexes[_opt.landscape], i++); |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
1019
diff
changeset
|
769 |
|
2309 | 770 |
load_index = SPR_AUTORAIL_BASE; |
771 |
load_index += LoadGrfFile("autorail.grf", load_index, i++); |
|
142 | 772 |
|
2309 | 773 |
load_index = SPR_CANALS_BASE; |
774 |
load_index += LoadGrfFile("canalsw.grf", load_index, i++); |
|
775 |
||
776 |
load_index = SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT + 1; |
|
142 | 777 |
|
368
32aad6ad36e1
(svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents:
366
diff
changeset
|
778 |
|
2309 | 779 |
/* Load newgrf sprites |
780 |
* in each loading stage, (try to) open each file specified in the config |
|
781 |
* and load information from it. */ |
|
782 |
_custom_sprites_base = load_index; |
|
783 |
for (_loading_stage = 0; _loading_stage < 2; _loading_stage++) { |
|
784 |
load_index = _custom_sprites_base; |
|
785 |
for (j = 0; j != lengthof(_newgrf_files) && _newgrf_files[j]; j++) { |
|
786 |
if (!FiosCheckFileExists(_newgrf_files[j])) { |
|
787 |
// TODO: usrerror() |
|
788 |
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
|
789 |
} |
2309 | 790 |
if (_loading_stage == 0) InitNewGRFFile(_newgrf_files[j], load_index); |
791 |
load_index += LoadNewGrfFile(_newgrf_files[j], load_index, i++); |
|
792 |
DEBUG(spritecache, 2) ("Currently %i sprites are loaded", load_index); |
|
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
|
793 |
} |
0 | 794 |
} |
795 |
||
796 |
_compact_cache_counter = 0; |
|
797 |
} |
|
798 |
||
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
|
799 |
static void GfxInitSpriteMem(void *ptr, uint32 size) |
0 | 800 |
{ |
801 |
// initialize sprite cache heap |
|
802 |
_spritecache_ptr = ptr; |
|
803 |
_spritecache_size = size; |
|
804 |
||
805 |
// 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
|
806 |
_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
|
807 |
// 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
|
808 |
NextBlock(_spritecache_ptr)->size = 0; |
0 | 809 |
|
810 |
memset(_sprite_ptr, 0, sizeof(_sprite_ptr)); |
|
811 |
} |
|
812 |
||
813 |
||
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
|
814 |
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
|
815 |
{ |
0 | 816 |
static byte *_sprite_mem; |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
817 |
|
0 | 818 |
// Need to reload the sprites only if the landscape changed |
819 |
if (_sprite_page_to_load != _opt.landscape) { |
|
820 |
_sprite_page_to_load = _opt.landscape; |
|
821 |
||
822 |
// Sprite cache |
|
823 |
DEBUG(spritecache, 1) ("Loading sprite set %d.", _sprite_page_to_load); |
|
824 |
||
825 |
// Reuse existing memory? |
|
826 |
if (_sprite_mem == NULL) _sprite_mem = malloc(SPRITE_CACHE_SIZE); |
|
827 |
GfxInitSpriteMem(_sprite_mem, SPRITE_CACHE_SIZE); |
|
828 |
LoadSpriteTables(); |
|
829 |
GfxInitPalettes(); |
|
830 |
} |
|
831 |
} |