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