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