author | peter1138 |
Wed, 03 Jan 2007 09:32:01 +0000 | |
changeset 5500 | 91a9244b4644 |
parent 5475 | 2e6990a8c7c4 |
child 5501 | b4e81fd72b3a |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1844
diff
changeset
|
4 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1250
diff
changeset
|
5 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.h" |
2548
49c8a096033f
(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
15979a2e9001
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1348
diff
changeset
|
8 |
#include "spritecache.h" |
1363
775a7ee52369
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1361
diff
changeset
|
9 |
#include "table/sprites.h" |
0 | 10 |
#include "fileio.h" |
11 |
||
12 |
#define SPRITE_CACHE_SIZE 1024*1024 |
|
13 |
||
14 |
||
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
15 |
static void* _sprite_ptr[MAX_SPRITES]; |
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
16 |
static uint32 _sprite_file_pos[MAX_SPRITES]; |
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
17 |
static int16 _sprite_lru_new[MAX_SPRITES]; |
0 | 18 |
|
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
19 |
typedef struct MemBlock { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
20 |
uint32 size; |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
21 |
byte data[VARARRAY_SIZE]; |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
22 |
} MemBlock; |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
23 |
|
0 | 24 |
static uint _sprite_lru_counter; |
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
25 |
static MemBlock *_spritecache_ptr; |
0 | 26 |
static int _compact_cache_counter; |
27 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1070
diff
changeset
|
28 |
static void CompactSpriteCache(void); |
0 | 29 |
|
2342
aae24c9661ba
(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
|
30 |
static bool ReadSpriteHeaderSkipData(void) |
0 | 31 |
{ |
2329
c4d9fc4006b1
(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
|
32 |
uint16 num = FioReadWord(); |
0 | 33 |
byte type; |
34 |
||
2329
c4d9fc4006b1
(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
|
35 |
if (num == 0) return false; |
c4d9fc4006b1
(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
|
36 |
|
0 | 37 |
type = FioReadByte(); |
38 |
if (type == 0xFF) { |
|
2342
aae24c9661ba
(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
|
39 |
FioSkipBytes(num); |
5150
fe410b84b302
(svn r7242) -Fix: Don't load 1-byte pseudo sprites, as used in some NewGRF sets. If the sprite is ever drawn this will result in a "missing sprite" error instead of undefined misbehaviour leading to segmentation faults...
peter1138
parents:
4522
diff
changeset
|
40 |
/* Some NewGRF files have "empty" pseudo-sprites which are 1 |
fe410b84b302
(svn r7242) -Fix: Don't load 1-byte pseudo sprites, as used in some NewGRF sets. If the sprite is ever drawn this will result in a "missing sprite" error instead of undefined misbehaviour leading to segmentation faults...
peter1138
parents:
4522
diff
changeset
|
41 |
* byte long. Catch these so the sprites won't be displayed. */ |
fe410b84b302
(svn r7242) -Fix: Don't load 1-byte pseudo sprites, as used in some NewGRF sets. If the sprite is ever drawn this will result in a "missing sprite" error instead of undefined misbehaviour leading to segmentation faults...
peter1138
parents:
4522
diff
changeset
|
42 |
return num != 1; |
0 | 43 |
} |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
44 |
|
0 | 45 |
FioSkipBytes(7); |
46 |
num -= 8; |
|
2329
c4d9fc4006b1
(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
|
47 |
if (num == 0) return true; |
0 | 48 |
|
49 |
if (type & 2) { |
|
50 |
FioSkipBytes(num); |
|
1355 | 51 |
} else { |
52 |
while (num > 0) { |
|
53 |
int8 i = FioReadByte(); |
|
54 |
if (i >= 0) { |
|
55 |
num -= i; |
|
56 |
FioSkipBytes(i); |
|
57 |
} else { |
|
58 |
i = -(i >> 3); |
|
59 |
num -= i; |
|
60 |
FioReadByte(); |
|
61 |
} |
|
0 | 62 |
} |
63 |
} |
|
2329
c4d9fc4006b1
(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
|
64 |
|
c4d9fc4006b1
(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
|
65 |
return true; |
0 | 66 |
} |
67 |
||
3565
ef0a9ef56fa0
(svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents:
2548
diff
changeset
|
68 |
/* Check if the given Sprite ID exists */ |
ef0a9ef56fa0
(svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents:
2548
diff
changeset
|
69 |
bool SpriteExists(SpriteID id) |
ef0a9ef56fa0
(svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents:
2548
diff
changeset
|
70 |
{ |
ef0a9ef56fa0
(svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents:
2548
diff
changeset
|
71 |
/* Special case for Sprite ID zero -- its position is also 0... */ |
ef0a9ef56fa0
(svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents:
2548
diff
changeset
|
72 |
return _sprite_file_pos[id] != 0 || id == 0; |
ef0a9ef56fa0
(svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents:
2548
diff
changeset
|
73 |
} |
ef0a9ef56fa0
(svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents:
2548
diff
changeset
|
74 |
|
2014
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
75 |
static void* AllocSprite(size_t); |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
76 |
|
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
77 |
static void* ReadSprite(SpriteID id) |
0 | 78 |
{ |
2321
75be68dfaaf2
(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
|
79 |
uint num; |
0 | 80 |
byte type; |
2014
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
81 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5150
diff
changeset
|
82 |
DEBUG(sprite, 9, "Load sprite %d", id); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
83 |
|
3565
ef0a9ef56fa0
(svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents:
2548
diff
changeset
|
84 |
if (!SpriteExists(id)) { |
1378
23d4f642c989
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
85 |
error( |
23d4f642c989
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
86 |
"Tried to load non-existing sprite #%d.\n" |
23d4f642c989
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
87 |
"Probable cause: Wrong/missing NewGRFs", |
23d4f642c989
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
88 |
id |
23d4f642c989
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
89 |
); |
23d4f642c989
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
90 |
} |
23d4f642c989
(svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents:
1363
diff
changeset
|
91 |
|
1354
4f9416233d06
(svn r1858) Let ReadSprite() handle the subtleties of loading a sprite, not its caller
tron
parents:
1353
diff
changeset
|
92 |
FioSeekToFile(_sprite_file_pos[id]); |
4f9416233d06
(svn r1858) Let ReadSprite() handle the subtleties of loading a sprite, not its caller
tron
parents:
1353
diff
changeset
|
93 |
|
2321
75be68dfaaf2
(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
|
94 |
num = FioReadWord(); |
0 | 95 |
type = FioReadByte(); |
2014
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
96 |
if (type == 0xFF) { |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
97 |
byte* dest = AllocSprite(num); |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
98 |
|
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
99 |
_sprite_ptr[id] = dest; |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
100 |
FioReadBlock(dest, num); |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
101 |
|
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
102 |
return dest; |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
103 |
} else { |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
104 |
uint height = FioReadByte(); |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
105 |
uint width = FioReadWord(); |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
106 |
Sprite* sprite; |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
107 |
byte* dest; |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
108 |
|
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
109 |
num = (type & 0x02) ? width * height : num - 8; |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
110 |
sprite = AllocSprite(sizeof(*sprite) + num); |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
111 |
_sprite_ptr[id] = sprite; |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
112 |
sprite->info = type; |
2015 | 113 |
sprite->height = (id != 142) ? height : 10; // Compensate for a TTD bug |
2014
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
114 |
sprite->width = width; |
1351
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
115 |
sprite->x_offs = FioReadWord(); |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
116 |
sprite->y_offs = FioReadWord(); |
2014
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
117 |
|
1351
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
118 |
dest = sprite->data; |
1355 | 119 |
while (num > 0) { |
120 |
int8 i = FioReadByte(); |
|
0 | 121 |
|
1355 | 122 |
if (i >= 0) { |
123 |
num -= i; |
|
2014
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
124 |
for (; i > 0; --i) *dest++ = FioReadByte(); |
1355 | 125 |
} else { |
126 |
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
|
127 |
|
1355 | 128 |
i = -(i >> 3); |
129 |
num -= i; |
|
130 |
||
2014
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
131 |
for (; i > 0; --i) *dest++ = *rel++; |
1355 | 132 |
} |
0 | 133 |
} |
2014
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
134 |
|
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
135 |
return sprite; |
0 | 136 |
} |
137 |
} |
|
138 |
||
139 |
||
2340
e18ef06bc59a
(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
|
140 |
bool LoadNextSprite(int load_index, byte file_index) |
0 | 141 |
{ |
2321
75be68dfaaf2
(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
|
142 |
uint32 file_pos = FioGetPos() | (file_index << 24); |
0 | 143 |
|
2342
aae24c9661ba
(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
|
144 |
if (!ReadSpriteHeaderSkipData()) return false; |
361
95307fb1c3f8
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
145 |
|
3591
a5febb93bc11
(svn r4481) - Fix: Validate the given sprite ID when loading a sprite.
peter1138
parents:
3565
diff
changeset
|
146 |
if (load_index >= MAX_SPRITES) { |
a5febb93bc11
(svn r4481) - Fix: Validate the given sprite ID when loading a sprite.
peter1138
parents:
3565
diff
changeset
|
147 |
error("Tried to load too many sprites (#%d; max %d)", load_index, MAX_SPRITES); |
a5febb93bc11
(svn r4481) - Fix: Validate the given sprite ID when loading a sprite.
peter1138
parents:
3565
diff
changeset
|
148 |
} |
a5febb93bc11
(svn r4481) - Fix: Validate the given sprite ID when loading a sprite.
peter1138
parents:
3565
diff
changeset
|
149 |
|
361
95307fb1c3f8
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
150 |
_sprite_file_pos[load_index] = file_pos; |
95307fb1c3f8
(svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents:
184
diff
changeset
|
151 |
|
0 | 152 |
_sprite_ptr[load_index] = NULL; |
153 |
||
154 |
_sprite_lru_new[load_index] = 0; |
|
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
e18ef06bc59a
(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
c4d9fc4006b1
(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
aae24c9661ba
(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
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
176 |
|
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
177 |
static inline MemBlock* NextBlock(MemBlock* block) |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
178 |
{ |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
179 |
return (MemBlock*)((byte*)block + (block->size & ~S_FREE_MASK)); |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
180 |
} |
0 | 181 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1070
diff
changeset
|
182 |
static uint32 GetSpriteCacheUsage(void) |
0 | 183 |
{ |
4321
958a8e9c012b
(svn r5974) -Codechange: added casts all around the place to make Windows 64bit happy (michi_cc)
truelight
parents:
3591
diff
changeset
|
184 |
uint32 tot_size = 0; |
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
185 |
MemBlock* s; |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
186 |
|
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
187 |
for (s = _spritecache_ptr; s->size != 0; s = NextBlock(s)) |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
188 |
if (!(s->size & S_FREE_MASK)) tot_size += s->size; |
0 | 189 |
|
190 |
return tot_size; |
|
191 |
} |
|
192 |
||
193 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1070
diff
changeset
|
194 |
void IncreaseSpriteLRU(void) |
0 | 195 |
{ |
196 |
int i; |
|
197 |
||
198 |
// Increase all LRU values |
|
199 |
if (_sprite_lru_counter > 16384) { |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5150
diff
changeset
|
200 |
DEBUG(sprite, 3, "Fixing lru %d, inuse=%d", _sprite_lru_counter, GetSpriteCacheUsage()); |
0 | 201 |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
202 |
for (i = 0; i != MAX_SPRITES; i++) |
0 | 203 |
if (_sprite_ptr[i] != NULL) { |
204 |
if (_sprite_lru_new[i] >= 0) { |
|
205 |
_sprite_lru_new[i] = -1; |
|
206 |
} else if (_sprite_lru_new[i] != -32768) { |
|
207 |
_sprite_lru_new[i]--; |
|
208 |
} |
|
209 |
} |
|
210 |
_sprite_lru_counter = 0; |
|
211 |
} |
|
212 |
||
213 |
// Compact sprite cache every now and then. |
|
214 |
if (++_compact_cache_counter >= 740) { |
|
215 |
CompactSpriteCache(); |
|
216 |
_compact_cache_counter = 0; |
|
217 |
} |
|
218 |
} |
|
219 |
||
220 |
// Called when holes in the sprite cache should be removed. |
|
221 |
// That is accomplished by moving the cached data. |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1070
diff
changeset
|
222 |
static void CompactSpriteCache(void) |
0 | 223 |
{ |
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
224 |
MemBlock *s; |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
225 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5150
diff
changeset
|
226 |
DEBUG(sprite, 3, "Compacting sprite cache, inuse=%d", GetSpriteCacheUsage()); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
227 |
|
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
228 |
for (s = _spritecache_ptr; s->size != 0;) { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
229 |
if (s->size & S_FREE_MASK) { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
230 |
MemBlock* next = NextBlock(s); |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
231 |
MemBlock temp; |
2014
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
232 |
void** i; |
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
233 |
|
0 | 234 |
// Since free blocks are automatically coalesced, this should hold true. |
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
235 |
assert(!(next->size & S_FREE_MASK)); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
236 |
|
0 | 237 |
// If the next block is the sentinel block, we can safely return |
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
238 |
if (next->size == 0) |
0 | 239 |
break; |
240 |
||
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
241 |
// Locate the sprite belonging to the next pointer. |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
242 |
for (i = _sprite_ptr; *i != next->data; ++i) { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
243 |
assert(i != endof(_sprite_ptr)); |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
244 |
} |
0 | 245 |
|
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
246 |
*i = s->data; // Adjust sprite array entry |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
247 |
// Swap this and the next block |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
248 |
temp = *s; |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
249 |
memmove(s, next, next->size); |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
250 |
s = NextBlock(s); |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
251 |
*s = temp; |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
252 |
|
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
253 |
// Coalesce free blocks |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
254 |
while (NextBlock(s)->size & S_FREE_MASK) { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
255 |
s->size += NextBlock(s)->size & ~S_FREE_MASK; |
0 | 256 |
} |
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
257 |
} else { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
258 |
s = NextBlock(s); |
0 | 259 |
} |
260 |
} |
|
261 |
} |
|
262 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1070
diff
changeset
|
263 |
static void DeleteEntryFromSpriteCache(void) |
0 | 264 |
{ |
265 |
int i; |
|
266 |
int best = -1; |
|
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
267 |
MemBlock* s; |
0 | 268 |
int cur_lru; |
269 |
||
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5150
diff
changeset
|
270 |
DEBUG(sprite, 3, "DeleteEntryFromSpriteCache, inuse=%d", GetSpriteCacheUsage()); |
0 | 271 |
|
272 |
cur_lru = 0xffff; |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
273 |
for (i = 0; i != MAX_SPRITES; i++) { |
2305
c0b38090ec7a
(svn r2829) Remove sprite locking, it was never used anyway
tron
parents:
2244
diff
changeset
|
274 |
if (_sprite_ptr[i] != NULL && _sprite_lru_new[i] < cur_lru) { |
0 | 275 |
cur_lru = _sprite_lru_new[i]; |
276 |
best = i; |
|
277 |
} |
|
278 |
} |
|
279 |
||
280 |
// Display an error message and die, in case we found no sprite at all. |
|
281 |
// This shouldn't really happen, unless all sprites are locked. |
|
282 |
if (best == -1) |
|
283 |
error("Out of sprite memory"); |
|
284 |
||
285 |
// Mark the block as free (the block must be in use) |
|
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
286 |
s = (MemBlock*)_sprite_ptr[best] - 1; |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
287 |
assert(!(s->size & S_FREE_MASK)); |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
288 |
s->size |= S_FREE_MASK; |
0 | 289 |
_sprite_ptr[best] = NULL; |
290 |
||
291 |
// And coalesce adjacent free blocks |
|
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
292 |
for (s = _spritecache_ptr; s->size != 0; s = NextBlock(s)) { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
293 |
if (s->size & S_FREE_MASK) { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
294 |
while (NextBlock(s)->size & S_FREE_MASK) { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
295 |
s->size += NextBlock(s)->size & ~S_FREE_MASK; |
0 | 296 |
} |
297 |
} |
|
298 |
} |
|
299 |
} |
|
300 |
||
2014
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
301 |
static void* AllocSprite(size_t mem_req) |
0 | 302 |
{ |
2014
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
303 |
mem_req += sizeof(MemBlock); |
0 | 304 |
|
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
305 |
/* Align this to an uint32 boundary. This also makes sure that the 2 least |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
306 |
* bits are not used, so we could use those for other things. */ |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2407
diff
changeset
|
307 |
mem_req = ALIGN(mem_req, sizeof(uint32)); |
0 | 308 |
|
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
309 |
for (;;) { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
310 |
MemBlock* s; |
0 | 311 |
|
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
312 |
for (s = _spritecache_ptr; s->size != 0; s = NextBlock(s)) { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
313 |
if (s->size & S_FREE_MASK) { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
314 |
size_t cur_size = s->size & ~S_FREE_MASK; |
0 | 315 |
|
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
316 |
/* Is the block exactly the size we need or |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
317 |
* big enough for an additional free block? */ |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
318 |
if (cur_size == mem_req || |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
319 |
cur_size >= mem_req + sizeof(MemBlock)) { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
320 |
// Set size and in use |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
321 |
s->size = mem_req; |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
322 |
|
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
323 |
// Do we need to inject a free block too? |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
324 |
if (cur_size != mem_req) { |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
325 |
NextBlock(s)->size = (cur_size - mem_req) | S_FREE_MASK; |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
326 |
} |
0 | 327 |
|
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
328 |
return s->data; |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
329 |
} |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
330 |
} |
0 | 331 |
} |
332 |
||
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
333 |
// Reached sentinel, but no block found yet. Delete some old entry. |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
334 |
DeleteEntryFromSpriteCache(); |
0 | 335 |
} |
336 |
} |
|
337 |
||
338 |
#if defined(NEW_ROTATION) |
|
339 |
#define X15(x) else if (s >= x && s < (x+15)) { s = _rotate_tile_sprite[s - x] + x; } |
|
340 |
#define X19(x) else if (s >= x && s < (x+19)) { s = _rotate_tile_sprite[s - x] + x; } |
|
341 |
#define MAP(from,to,map) else if (s >= from && s <= to) { s = map[s - from] + from; } |
|
342 |
||
343 |
||
410 | 344 |
static uint RotateSprite(uint s) |
0 | 345 |
{ |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4321
diff
changeset
|
346 |
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 }; |
0 | 347 |
static const byte _coast_map[9] = {0, 4, 3, 1, 2, 6, 8, 5, 7}; |
348 |
static const byte _fence_map[6] = {1, 0, 5, 4, 3, 2}; |
|
349 |
||
350 |
if (0); |
|
351 |
X19(752) |
|
352 |
X15(990-1) |
|
353 |
X19(3924) |
|
354 |
X19(3943) |
|
355 |
X19(3962) |
|
356 |
X19(3981) |
|
357 |
X19(4000) |
|
358 |
X19(4023) |
|
359 |
X19(4042) |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4321
diff
changeset
|
360 |
MAP(4061, 4069, _coast_map) |
0 | 361 |
X19(4126) |
362 |
X19(4145) |
|
363 |
X19(4164) |
|
364 |
X19(4183) |
|
365 |
X19(4202) |
|
366 |
X19(4221) |
|
367 |
X19(4240) |
|
368 |
X19(4259) |
|
369 |
X19(4259) |
|
370 |
X19(4278) |
|
371 |
MAP(4090, 4095, _fence_map) |
|
372 |
MAP(4096, 4101, _fence_map) |
|
373 |
MAP(4102, 4107, _fence_map) |
|
374 |
MAP(4108, 4113, _fence_map) |
|
375 |
MAP(4114, 4119, _fence_map) |
|
376 |
MAP(4120, 4125, _fence_map) |
|
377 |
return s; |
|
378 |
} |
|
379 |
#endif |
|
380 |
||
1361 | 381 |
const void *GetRawSprite(SpriteID sprite) |
0 | 382 |
{ |
2014
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
383 |
void* p; |
0 | 384 |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
385 |
assert(sprite < MAX_SPRITES); |
0 | 386 |
|
387 |
#if defined(NEW_ROTATION) |
|
388 |
sprite = RotateSprite(sprite); |
|
389 |
#endif |
|
390 |
||
391 |
// Update LRU |
|
392 |
_sprite_lru_new[sprite] = ++_sprite_lru_counter; |
|
393 |
||
394 |
p = _sprite_ptr[sprite]; |
|
2014
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
395 |
// Load the sprite, if it is not loaded, yet |
ccfe4fa81a14
(svn r2522) Reorganize sprite load and decompression in order to remove a special case from the sprite blitter, which decompressed certain sprites every time when blitting them
tron
parents:
1891
diff
changeset
|
396 |
if (p == NULL) p = ReadSprite(sprite); |
184
dbeaaaf8b2bb
(svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents:
182
diff
changeset
|
397 |
return p; |
0 | 398 |
} |
399 |
||
961 | 400 |
|
2340
e18ef06bc59a
(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
|
401 |
void GfxInitSpriteMem(void) |
0 | 402 |
{ |
403 |
// initialize sprite cache heap |
|
2339
b03b1fb8ccfe
(svn r2865) Push the responsibility for allocating the sprite heap into GfxInitSpriteMem()
tron
parents:
2329
diff
changeset
|
404 |
if (_spritecache_ptr == NULL) _spritecache_ptr = malloc(SPRITE_CACHE_SIZE); |
0 | 405 |
|
406 |
// A big free block |
|
2339
b03b1fb8ccfe
(svn r2865) Push the responsibility for allocating the sprite heap into GfxInitSpriteMem()
tron
parents:
2329
diff
changeset
|
407 |
_spritecache_ptr->size = (SPRITE_CACHE_SIZE - sizeof(MemBlock)) | S_FREE_MASK; |
1353
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
408 |
// Sentinel block (identified by size == 0) |
c5892a0dadad
(svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents:
1352
diff
changeset
|
409 |
NextBlock(_spritecache_ptr)->size = 0; |
0 | 410 |
|
411 |
memset(_sprite_ptr, 0, sizeof(_sprite_ptr)); |
|
412 |
||
2340
e18ef06bc59a
(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
|
413 |
_compact_cache_counter = 0; |
0 | 414 |
} |