author | matthijs |
Wed, 22 Mar 2006 22:26:16 +0000 | |
branch | 0.4.5 |
changeset 9958 | bed516c67d61 |
parent 2548 | 97ada3bd2702 |
child 3565 | 03d870cc3dcd |
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" |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2407
diff
changeset
|
7 |
#include "macros.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" |
11 |
||
12 |
#define SPRITE_CACHE_SIZE 1024*1024 |
|
13 |
||
14 |
#define WANT_NEW_LRU |
|
15 |
||
16 |
||
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
17 |
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
|
18 |
static uint32 _sprite_file_pos[MAX_SPRITES]; |
0 | 19 |
|
20 |
#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
|
21 |
static int16 _sprite_lru_new[MAX_SPRITES]; |
0 | 22 |
#else |
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
23 |
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
|
24 |
static uint16 _sprite_lru_cur[MAX_SPRITES]; |
0 | 25 |
#endif |
26 |
||
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
|
27 |
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
|
28 |
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
|
29 |
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
|
30 |
} 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
|
31 |
|
0 | 32 |
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
|
33 |
static MemBlock *_spritecache_ptr; |
0 | 34 |
static int _compact_cache_counter; |
35 |
||
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
|
36 |
static void CompactSpriteCache(void); |
0 | 37 |
|
2342
c19fb4f2df30
(svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents:
2340
diff
changeset
|
38 |
static bool ReadSpriteHeaderSkipData(void) |
0 | 39 |
{ |
2329
f68428464540
(svn r2855) Make ReadSpriteHeaderSkipData() responsible for detecting the end of a grf file instead of its callers - this simplifies the code a bit
tron
parents:
2321
diff
changeset
|
40 |
uint16 num = FioReadWord(); |
0 | 41 |
byte type; |
42 |
||
2329
f68428464540
(svn r2855) Make ReadSpriteHeaderSkipData() responsible for detecting the end of a grf file instead of its callers - this simplifies the code a bit
tron
parents:
2321
diff
changeset
|
43 |
if (num == 0) return false; |
f68428464540
(svn r2855) Make ReadSpriteHeaderSkipData() responsible for detecting the end of a grf file instead of its callers - this simplifies the code a bit
tron
parents:
2321
diff
changeset
|
44 |
|
0 | 45 |
type = FioReadByte(); |
46 |
if (type == 0xFF) { |
|
2342
c19fb4f2df30
(svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents:
2340
diff
changeset
|
47 |
FioSkipBytes(num); |
2329
f68428464540
(svn r2855) Make ReadSpriteHeaderSkipData() responsible for detecting the end of a grf file instead of its callers - this simplifies the code a bit
tron
parents:
2321
diff
changeset
|
48 |
return true; |
0 | 49 |
} |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
50 |
|
0 | 51 |
FioSkipBytes(7); |
52 |
num -= 8; |
|
2329
f68428464540
(svn r2855) Make ReadSpriteHeaderSkipData() responsible for detecting the end of a grf file instead of its callers - this simplifies the code a bit
tron
parents:
2321
diff
changeset
|
53 |
if (num == 0) return true; |
0 | 54 |
|
55 |
if (type & 2) { |
|
56 |
FioSkipBytes(num); |
|
1355 | 57 |
} else { |
58 |
while (num > 0) { |
|
59 |
int8 i = FioReadByte(); |
|
60 |
if (i >= 0) { |
|
61 |
num -= i; |
|
62 |
FioSkipBytes(i); |
|
63 |
} else { |
|
64 |
i = -(i >> 3); |
|
65 |
num -= i; |
|
66 |
FioReadByte(); |
|
67 |
} |
|
0 | 68 |
} |
69 |
} |
|
2329
f68428464540
(svn r2855) Make ReadSpriteHeaderSkipData() responsible for detecting the end of a grf file instead of its callers - this simplifies the code a bit
tron
parents:
2321
diff
changeset
|
70 |
|
f68428464540
(svn r2855) Make ReadSpriteHeaderSkipData() responsible for detecting the end of a grf file instead of its callers - this simplifies the code a bit
tron
parents:
2321
diff
changeset
|
71 |
return true; |
0 | 72 |
} |
73 |
||
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
|
74 |
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
|
75 |
|
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
|
76 |
static void* ReadSprite(SpriteID id) |
0 | 77 |
{ |
2321
455694cdbada
(svn r2847) Don't remember the size of sprites during initialisation. Since the sprite loading was altered this is no longer necessary.
tron
parents:
2319
diff
changeset
|
78 |
uint num; |
0 | 79 |
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
|
80 |
|
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
|
81 |
DEBUG(spritecache, 9) ("load sprite %d", id); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
82 |
|
2321
455694cdbada
(svn r2847) Don't remember the size of sprites during initialisation. Since the sprite loading was altered this is no longer necessary.
tron
parents:
2319
diff
changeset
|
83 |
if (_sprite_file_pos[id] == 0 && id != 0) { |
1378
ebb8d52f0352
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
84 |
error( |
ebb8d52f0352
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
85 |
"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
|
86 |
"Probable cause: Wrong/missing NewGRFs", |
ebb8d52f0352
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
87 |
id |
ebb8d52f0352
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
88 |
); |
ebb8d52f0352
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
89 |
} |
ebb8d52f0352
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
90 |
|
1354
5e5c89b9b169
(svn r1858) Let ReadSprite() handle the subtleties of loading a sprite, not its caller
tron
parents:
1353
diff
changeset
|
91 |
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
|
92 |
|
2321
455694cdbada
(svn r2847) Don't remember the size of sprites during initialisation. Since the sprite loading was altered this is no longer necessary.
tron
parents:
2319
diff
changeset
|
93 |
num = FioReadWord(); |
0 | 94 |
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
|
95 |
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
|
96 |
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
|
97 |
|
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
|
98 |
_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
|
99 |
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
|
100 |
|
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
|
101 |
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
|
102 |
} 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
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
|
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
|
108 |
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
|
109 |
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
|
110 |
_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
|
111 |
sprite->info = type; |
2015 | 112 |
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
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
|
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
117 |
dest = sprite->data; |
1355 | 118 |
while (num > 0) { |
119 |
int8 i = FioReadByte(); |
|
0 | 120 |
|
1355 | 121 |
if (i >= 0) { |
122 |
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
|
123 |
for (; i > 0; --i) *dest++ = FioReadByte(); |
1355 | 124 |
} else { |
125 |
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
|
126 |
|
1355 | 127 |
i = -(i >> 3); |
128 |
num -= i; |
|
129 |
||
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
|
130 |
for (; i > 0; --i) *dest++ = *rel++; |
1355 | 131 |
} |
0 | 132 |
} |
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
|
133 |
|
0230ed9186bc
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
134 |
return sprite; |
0 | 135 |
} |
136 |
} |
|
137 |
||
138 |
||
2340
0a9f3eeccb96
(svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
tron
parents:
2339
diff
changeset
|
139 |
bool LoadNextSprite(int load_index, byte file_index) |
0 | 140 |
{ |
2321
455694cdbada
(svn r2847) Don't remember the size of sprites during initialisation. Since the sprite loading was altered this is no longer necessary.
tron
parents:
2319
diff
changeset
|
141 |
uint32 file_pos = FioGetPos() | (file_index << 24); |
0 | 142 |
|
2342
c19fb4f2df30
(svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents:
2340
diff
changeset
|
143 |
if (!ReadSpriteHeaderSkipData()) return false; |
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
|
144 |
|
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
|
145 |
_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
|
146 |
|
0 | 147 |
_sprite_ptr[load_index] = NULL; |
148 |
||
149 |
#if defined(WANT_NEW_LRU) |
|
150 |
_sprite_lru_new[load_index] = 0; |
|
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
151 |
#else |
0 | 152 |
_sprite_lru[load_index] = 0xFFFF; |
153 |
_sprite_lru_cur[load_index] = 0; |
|
154 |
#endif |
|
155 |
||
156 |
return true; |
|
157 |
} |
|
158 |
||
2407 | 159 |
|
160 |
void DupSprite(SpriteID old, SpriteID new) |
|
161 |
{ |
|
162 |
_sprite_file_pos[new] = _sprite_file_pos[old]; |
|
163 |
_sprite_ptr[new] = NULL; |
|
164 |
} |
|
165 |
||
166 |
||
2340
0a9f3eeccb96
(svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
tron
parents:
2339
diff
changeset
|
167 |
void SkipSprites(uint count) |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
168 |
{ |
2329
f68428464540
(svn r2855) Make ReadSpriteHeaderSkipData() responsible for detecting the end of a grf file instead of its callers - this simplifies the code a bit
tron
parents:
2321
diff
changeset
|
169 |
for (; count > 0; --count) { |
2342
c19fb4f2df30
(svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents:
2340
diff
changeset
|
170 |
if (!ReadSpriteHeaderSkipData()) return; |
37
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
171 |
} |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
172 |
} |
61bf1df68d82
(svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents:
0
diff
changeset
|
173 |
|
0 | 174 |
|
175 |
#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
|
176 |
|
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
|
177 |
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
|
178 |
{ |
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
|
179 |
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
|
180 |
} |
0 | 181 |
|
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
|
182 |
static uint32 GetSpriteCacheUsage(void) |
0 | 183 |
{ |
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
|
184 |
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
|
185 |
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
|
186 |
|
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
|
187 |
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
|
188 |
if (!(s->size & S_FREE_MASK)) tot_size += s->size; |
0 | 189 |
|
190 |
return tot_size; |
|
191 |
} |
|
192 |
||
193 |
||
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
|
194 |
void IncreaseSpriteLRU(void) |
0 | 195 |
{ |
196 |
int i; |
|
197 |
||
198 |
// Increase all LRU values |
|
199 |
#if defined(WANT_NEW_LRU) |
|
200 |
if (_sprite_lru_counter > 16384) { |
|
201 |
DEBUG(spritecache, 2) ("fixing lru %d, inuse=%d", _sprite_lru_counter, GetSpriteCacheUsage()); |
|
202 |
||
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
203 |
for (i = 0; i != MAX_SPRITES; i++) |
0 | 204 |
if (_sprite_ptr[i] != NULL) { |
205 |
if (_sprite_lru_new[i] >= 0) { |
|
206 |
_sprite_lru_new[i] = -1; |
|
207 |
} else if (_sprite_lru_new[i] != -32768) { |
|
208 |
_sprite_lru_new[i]--; |
|
209 |
} |
|
210 |
} |
|
211 |
_sprite_lru_counter = 0; |
|
212 |
} |
|
213 |
#else |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
214 |
for (i = 0; i != MAX_SPRITES; i++) |
0 | 215 |
if (_sprite_ptr[i] != NULL && _sprite_lru[i] != 65535) |
216 |
_sprite_lru[i]++; |
|
217 |
// Reset the lru counter. |
|
218 |
_sprite_lru_counter = 0; |
|
219 |
#endif |
|
220 |
||
221 |
// Compact sprite cache every now and then. |
|
222 |
if (++_compact_cache_counter >= 740) { |
|
223 |
CompactSpriteCache(); |
|
224 |
_compact_cache_counter = 0; |
|
225 |
} |
|
226 |
} |
|
227 |
||
228 |
// Called when holes in the sprite cache should be removed. |
|
229 |
// 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
|
230 |
static void CompactSpriteCache(void) |
0 | 231 |
{ |
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
|
232 |
MemBlock *s; |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
233 |
|
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
|
234 |
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
|
235 |
"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
|
236 |
); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
237 |
|
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
|
238 |
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
|
239 |
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
|
240 |
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
|
241 |
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
|
242 |
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
|
243 |
|
0 | 244 |
// 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
|
245 |
assert(!(next->size & S_FREE_MASK)); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
246 |
|
0 | 247 |
// 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
|
248 |
if (next->size == 0) |
0 | 249 |
break; |
250 |
||
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
|
251 |
// 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
|
252 |
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
|
253 |
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
|
254 |
} |
0 | 255 |
|
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
|
256 |
*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
|
257 |
// 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
|
258 |
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
|
259 |
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
|
260 |
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
|
261 |
*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
|
262 |
|
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
|
263 |
// 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
|
264 |
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
|
265 |
s->size += NextBlock(s)->size & ~S_FREE_MASK; |
0 | 266 |
} |
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
|
267 |
} 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
|
268 |
s = NextBlock(s); |
0 | 269 |
} |
270 |
} |
|
271 |
} |
|
272 |
||
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
|
273 |
static void DeleteEntryFromSpriteCache(void) |
0 | 274 |
{ |
275 |
int i; |
|
276 |
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
|
277 |
MemBlock* s; |
0 | 278 |
int cur_lru; |
279 |
||
280 |
DEBUG(spritecache, 2) ("DeleteEntryFromSpriteCache, inuse=%d", GetSpriteCacheUsage()); |
|
281 |
||
282 |
#if defined(WANT_NEW_LRU) |
|
283 |
cur_lru = 0xffff; |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
284 |
for (i = 0; i != MAX_SPRITES; i++) { |
2305
f0856e98f7a5
(svn r2829) Remove sprite locking, it was never used anyway
tron
parents:
2244
diff
changeset
|
285 |
if (_sprite_ptr[i] != NULL && _sprite_lru_new[i] < cur_lru) { |
0 | 286 |
cur_lru = _sprite_lru_new[i]; |
287 |
best = i; |
|
288 |
} |
|
289 |
} |
|
290 |
#else |
|
291 |
{ |
|
292 |
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
|
293 |
for (i = 0; i != MAX_SPRITES; i++) { |
2305
f0856e98f7a5
(svn r2829) Remove sprite locking, it was never used anyway
tron
parents:
2244
diff
changeset
|
294 |
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
|
295 |
|
0 | 296 |
// Found a sprite with a higher LRU value, then remember it. |
297 |
if (_sprite_lru[i] != cur_lru) { |
|
298 |
cur_lru = _sprite_lru[i]; |
|
299 |
best = i; |
|
300 |
||
301 |
// Else if both sprites were very recently referenced, compare by the cur value instead. |
|
302 |
} else if (cur_lru == 0 && _sprite_lru_cur[i] <= cur_lru_cur) { |
|
303 |
cur_lru_cur = _sprite_lru_cur[i]; |
|
304 |
cur_lru = _sprite_lru[i]; |
|
305 |
best = i; |
|
306 |
} |
|
307 |
} |
|
308 |
} |
|
309 |
#endif |
|
310 |
||
311 |
// Display an error message and die, in case we found no sprite at all. |
|
312 |
// This shouldn't really happen, unless all sprites are locked. |
|
313 |
if (best == -1) |
|
314 |
error("Out of sprite memory"); |
|
315 |
||
316 |
// 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
|
317 |
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
|
318 |
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
|
319 |
s->size |= S_FREE_MASK; |
0 | 320 |
_sprite_ptr[best] = NULL; |
321 |
||
322 |
// 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
|
323 |
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
|
324 |
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
|
325 |
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
|
326 |
s->size += NextBlock(s)->size & ~S_FREE_MASK; |
0 | 327 |
} |
328 |
} |
|
329 |
} |
|
330 |
} |
|
331 |
||
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
|
332 |
static void* AllocSprite(size_t mem_req) |
0 | 333 |
{ |
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
|
334 |
mem_req += sizeof(MemBlock); |
0 | 335 |
|
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
|
336 |
/* 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
|
337 |
* bits are not used, so we could use those for other things. */ |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2407
diff
changeset
|
338 |
mem_req = ALIGN(mem_req, sizeof(uint32)); |
0 | 339 |
|
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
|
340 |
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
|
341 |
MemBlock* s; |
0 | 342 |
|
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
|
343 |
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
|
344 |
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
|
345 |
size_t cur_size = s->size & ~S_FREE_MASK; |
0 | 346 |
|
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
|
347 |
/* 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
|
348 |
* 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
|
349 |
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
|
350 |
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
|
351 |
// 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
|
352 |
s->size = mem_req; |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
353 |
|
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
|
354 |
// 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
|
355 |
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
|
356 |
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
|
357 |
} |
0 | 358 |
|
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
|
359 |
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
|
360 |
} |
48b59d472641
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
361 |
} |
0 | 362 |
} |
363 |
||
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
|
364 |
// 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
|
365 |
DeleteEntryFromSpriteCache(); |
0 | 366 |
} |
367 |
} |
|
368 |
||
369 |
#if defined(NEW_ROTATION) |
|
370 |
#define X15(x) else if (s >= x && s < (x+15)) { s = _rotate_tile_sprite[s - x] + x; } |
|
371 |
#define X19(x) else if (s >= x && s < (x+19)) { s = _rotate_tile_sprite[s - x] + x; } |
|
372 |
#define MAP(from,to,map) else if (s >= from && s <= to) { s = map[s - from] + from; } |
|
373 |
||
374 |
||
410 | 375 |
static uint RotateSprite(uint s) |
0 | 376 |
{ |
377 |
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 }; |
|
378 |
static const byte _coast_map[9] = {0, 4, 3, 1, 2, 6, 8, 5, 7}; |
|
379 |
static const byte _fence_map[6] = {1, 0, 5, 4, 3, 2}; |
|
380 |
||
381 |
if (0); |
|
382 |
X19(752) |
|
383 |
X15(990-1) |
|
384 |
X19(3924) |
|
385 |
X19(3943) |
|
386 |
X19(3962) |
|
387 |
X19(3981) |
|
388 |
X19(4000) |
|
389 |
X19(4023) |
|
390 |
X19(4042) |
|
391 |
MAP(4061,4069,_coast_map) |
|
392 |
X19(4126) |
|
393 |
X19(4145) |
|
394 |
X19(4164) |
|
395 |
X19(4183) |
|
396 |
X19(4202) |
|
397 |
X19(4221) |
|
398 |
X19(4240) |
|
399 |
X19(4259) |
|
400 |
X19(4259) |
|
401 |
X19(4278) |
|
402 |
MAP(4090, 4095, _fence_map) |
|
403 |
MAP(4096, 4101, _fence_map) |
|
404 |
MAP(4102, 4107, _fence_map) |
|
405 |
MAP(4108, 4113, _fence_map) |
|
406 |
MAP(4114, 4119, _fence_map) |
|
407 |
MAP(4120, 4125, _fence_map) |
|
408 |
return s; |
|
409 |
} |
|
410 |
#endif |
|
411 |
||
1361 | 412 |
const void *GetRawSprite(SpriteID sprite) |
0 | 413 |
{ |
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
|
414 |
void* p; |
0 | 415 |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
416 |
assert(sprite < MAX_SPRITES); |
0 | 417 |
|
418 |
#if defined(NEW_ROTATION) |
|
419 |
sprite = RotateSprite(sprite); |
|
420 |
#endif |
|
421 |
||
422 |
// Update LRU |
|
423 |
#if defined(WANT_NEW_LRU) |
|
424 |
_sprite_lru_new[sprite] = ++_sprite_lru_counter; |
|
425 |
#else |
|
2026 | 426 |
_sprite_lru_cur[sprite] = ++_sprite_lru_counter; |
0 | 427 |
_sprite_lru[sprite] = 0; |
428 |
#endif |
|
429 |
||
430 |
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
|
431 |
// 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
|
432 |
if (p == NULL) p = ReadSprite(sprite); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
433 |
return p; |
0 | 434 |
} |
435 |
||
961 | 436 |
|
2340
0a9f3eeccb96
(svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
tron
parents:
2339
diff
changeset
|
437 |
void GfxInitSpriteMem(void) |
0 | 438 |
{ |
439 |
// initialize sprite cache heap |
|
2339
1c64119d5a3b
(svn r2865) Push the responsibility for allocating the sprite heap into GfxInitSpriteMem()
tron
parents:
2329
diff
changeset
|
440 |
if (_spritecache_ptr == NULL) _spritecache_ptr = malloc(SPRITE_CACHE_SIZE); |
0 | 441 |
|
442 |
// A big free block |
|
2339
1c64119d5a3b
(svn r2865) Push the responsibility for allocating the sprite heap into GfxInitSpriteMem()
tron
parents:
2329
diff
changeset
|
443 |
_spritecache_ptr->size = (SPRITE_CACHE_SIZE - sizeof(MemBlock)) | S_FREE_MASK; |
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
|
444 |
// 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
|
445 |
NextBlock(_spritecache_ptr)->size = 0; |
0 | 446 |
|
447 |
memset(_sprite_ptr, 0, sizeof(_sprite_ptr)); |
|
448 |
||
2340
0a9f3eeccb96
(svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
tron
parents:
2339
diff
changeset
|
449 |
_compact_cache_counter = 0; |
0 | 450 |
} |