src/spritecache.cpp
author convert-repo
Mon, 07 Apr 2008 16:21:55 +0000
changeset 10076 dfd70e42c4ae
parent 9237 9f210581c3a9
child 10429 1b99254f9607
permissions -rw-r--r--
update tags
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6916
diff changeset
     3
/** @file spritecache.cpp */
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1844
diff changeset
     6
#include "openttd.h"
7392
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
     7
#include "variables.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1250
diff changeset
     8
#include "debug.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
     9
#include "spritecache.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "fileio.h"
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
    11
#include "spriteloader/grf.hpp"
8626
440dfcd14c4a (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8609
diff changeset
    12
#include "core/alloc_func.hpp"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8626
diff changeset
    13
#include "core/math_func.hpp"
7397
d371cc0fbb3c (svn r10148) -Fix r10143: make --without-png to compile again
truelight
parents: 7392
diff changeset
    14
#ifdef WITH_PNG
7392
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
    15
#include "spriteloader/png.hpp"
7397
d371cc0fbb3c (svn r10148) -Fix r10143: make --without-png to compile again
truelight
parents: 7392
diff changeset
    16
#endif /* WITH_PNG */
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7404
diff changeset
    17
#include "blitter/factory.hpp"
7299
74e163f03bbc (svn r10042) -Codechange: Replace hardcoded spritecache size with a configuration
peter1138
parents: 7295
diff changeset
    18
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8710
diff changeset
    19
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8710
diff changeset
    20
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
    21
/* Default of 4MB spritecache */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
    22
uint _sprite_cache_size = 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    25
struct SpriteCache {
9237
9f210581c3a9 (svn r12436) -Cleanup: minor coding style
peter1138
parents: 9058
diff changeset
    26
	void *ptr;
7392
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
    27
	uint32 id;
9237
9f210581c3a9 (svn r12436) -Cleanup: minor coding style
peter1138
parents: 9058
diff changeset
    28
	uint32 file_pos;
8869
1e62a45d7599 (svn r11939) -Codechange: some type fixes and very initial steps into supporting NDS by default. Based on work by Dominik.
rubidium
parents: 8760
diff changeset
    29
	uint16 file_slot;
9237
9f210581c3a9 (svn r12436) -Cleanup: minor coding style
peter1138
parents: 9058
diff changeset
    30
	int16 lru;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    31
};
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    32
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    33
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    34
static uint _spritecache_items = 0;
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    35
static SpriteCache *_spritecache = NULL;
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    36
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    37
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    38
static inline SpriteCache *GetSpriteCache(uint index)
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    39
{
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    40
	return &_spritecache[index];
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    41
}
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    42
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    43
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    44
static SpriteCache *AllocateSpriteCache(uint index)
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    45
{
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    46
	if (index >= _spritecache_items) {
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    47
		/* Add another 1024 items to the 'pool' */
8423
8453e9a0f0b5 (svn r11480) -Codechange: Rename the function ALIGN fitting to the naming style
skidd13
parents: 8072
diff changeset
    48
		uint items = Align(index + 1, 1024);
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    49
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    50
		DEBUG(sprite, 4, "Increasing sprite cache to %d items (%d bytes)", items, items * sizeof(*_spritecache));
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    51
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5838
diff changeset
    52
		_spritecache = ReallocT(_spritecache, items);
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    53
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    54
		/* Reset the new items and update the count */
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    55
		memset(_spritecache + _spritecache_items, 0, (items - _spritecache_items) * sizeof(*_spritecache));
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    56
		_spritecache_items = items;
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    57
	}
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    58
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    59
	return GetSpriteCache(index);
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    60
}
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
    61
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    63
struct MemBlock {
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
    64
	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
    65
	byte data[VARARRAY_SIZE];
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    66
};
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
    67
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
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
    69
static MemBlock *_spritecache_ptr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
static int _compact_cache_counter;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6213
diff changeset
    72
static void CompactSpriteCache();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6213
diff changeset
    74
static bool ReadSpriteHeaderSkipData()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
{
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
    76
	uint16 num = FioReadWord();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	byte type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
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
    79
	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
    80
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
	type = FioReadByte();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
	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
    83
		FioSkipBytes(num);
5150
247343201280 (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
    84
		/* Some NewGRF files have "empty" pseudo-sprites which are 1
247343201280 (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
    85
		 * byte long. Catch these so the sprites won't be displayed. */
247343201280 (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
    86
		return num != 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	}
184
dbeaaaf8b2bb (svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents: 182
diff changeset
    88
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
	FioSkipBytes(7);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
	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
    91
	if (num == 0) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	if (type & 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
		FioSkipBytes(num);
1355
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
    95
	} else {
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
    96
		while (num > 0) {
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
    97
			int8 i = FioReadByte();
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
    98
			if (i >= 0) {
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
    99
				num -= i;
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   100
				FioSkipBytes(i);
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   101
			} else {
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   102
				i = -(i >> 3);
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   103
				num -= i;
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   104
				FioReadByte();
aa6c2b776727 (svn r1859) Miscellaneous style changes
tron
parents: 1354
diff changeset
   105
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	}
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
   108
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
   109
	return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
3565
03d870cc3dcd (svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents: 2548
diff changeset
   112
/* Check if the given Sprite ID exists */
03d870cc3dcd (svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents: 2548
diff changeset
   113
bool SpriteExists(SpriteID id)
03d870cc3dcd (svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents: 2548
diff changeset
   114
{
03d870cc3dcd (svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents: 2548
diff changeset
   115
	/* Special case for Sprite ID zero -- its position is also 0... */
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   116
	if (id == 0) return true;
5953
7000c5bdd70b (svn r8166) -Fix (r7797): Protect against out of bounds access to the sprite ptr
peter1138
parents: 5860
diff changeset
   117
	if (id >= _spritecache_items) return false;
8072
417f041eaee8 (svn r11101) -Fix r11099: the check: file_pos == 0, no longer works; adjust the check with file_slot. This solves the ? sprites with autorail (nice catch Progman)
truelight
parents: 8066
diff changeset
   118
	return !(GetSpriteCache(id)->file_pos == 0 && GetSpriteCache(id)->file_slot == 0);
3565
03d870cc3dcd (svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents: 2548
diff changeset
   119
}
03d870cc3dcd (svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents: 2548
diff changeset
   120
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
   121
void* AllocSprite(size_t);
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
   122
7365
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   123
static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
{
8066
7acd480e05c9 (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 7585
diff changeset
   125
	uint8 file_slot = sc->file_slot;
7295
4af0cd4cab3d (svn r10038) -Fix (r8634): Sprite resulting from '?' substitution was reloaded into the cache entry for SPR_IMG_QUERY instead of the original sprite cache entry. This resulted in unaccounted missing sprite cache memory, and was exacerbated because the original missing sprite was not cached, so it did it again and again and again. Slowdowns and boom. Etc.
peter1138
parents: 6977
diff changeset
   126
	uint32 file_pos = sc->file_pos;
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
   127
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5150
diff changeset
   128
	DEBUG(sprite, 9, "Load sprite %d", id);
184
dbeaaaf8b2bb (svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents: 182
diff changeset
   129
3565
03d870cc3dcd (svn r4446) - Add function to determine if a Sprite ID exists.
peter1138
parents: 2548
diff changeset
   130
	if (!SpriteExists(id)) {
6213
164d84e1c5b4 (svn r8634) -Codechange: replace missing sprites with a red question mark.
rubidium
parents: 5971
diff changeset
   131
		DEBUG(sprite, 1, "Tried to load non-existing sprite #%d. Probable cause: Wrong/missing NewGRFs", id);
164d84e1c5b4 (svn r8634) -Codechange: replace missing sprites with a red question mark.
rubidium
parents: 5971
diff changeset
   132
164d84e1c5b4 (svn r8634) -Codechange: replace missing sprites with a red question mark.
rubidium
parents: 5971
diff changeset
   133
		/* SPR_IMG_QUERY is a BIG FAT RED ? */
164d84e1c5b4 (svn r8634) -Codechange: replace missing sprites with a red question mark.
rubidium
parents: 5971
diff changeset
   134
		id = SPR_IMG_QUERY;
8066
7acd480e05c9 (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 7585
diff changeset
   135
		file_slot = GetSpriteCache(SPR_IMG_QUERY)->file_slot;
7acd480e05c9 (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 7585
diff changeset
   136
		file_pos  = GetSpriteCache(SPR_IMG_QUERY)->file_pos;
1378
ebb8d52f0352 (svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents: 1363
diff changeset
   137
	}
ebb8d52f0352 (svn r1882) Add a basic check if a non-existent sprite gets accessed.
tron
parents: 1363
diff changeset
   138
7399
8e062c789dec (svn r10150) -Fix r10148: show a message to users when using 32bpp blitter and no libpng available
truelight
parents: 7398
diff changeset
   139
	if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) {
7397
d371cc0fbb3c (svn r10148) -Fix r10143: make --without-png to compile again
truelight
parents: 7392
diff changeset
   140
#ifdef WITH_PNG
7392
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   141
		/* Try loading 32bpp graphics in case we are 32bpp output */
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   142
		SpriteLoaderPNG sprite_loader;
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   143
		SpriteLoader::Sprite sprite;
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   144
8870
461ed7760525 (svn r11940) -Codechange: Store short filename once per open file instead of once per sprite cache entry. Not all file types need this, but most of the time no sprite cache entry needed it either.
peter1138
parents: 8869
diff changeset
   145
		if (sprite_loader.LoadSprite(&sprite, file_slot, sc->id)) {
7392
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   146
			sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   147
			free(sprite.data);
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   148
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   149
			return sc->ptr;
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   150
		}
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   151
		/* If the PNG couldn't be loaded, fall back to 8bpp grfs */
7399
8e062c789dec (svn r10150) -Fix r10148: show a message to users when using 32bpp blitter and no libpng available
truelight
parents: 7398
diff changeset
   152
#else
8e062c789dec (svn r10150) -Fix r10148: show a message to users when using 32bpp blitter and no libpng available
truelight
parents: 7398
diff changeset
   153
		static bool show_once = true;
8e062c789dec (svn r10150) -Fix r10148: show a message to users when using 32bpp blitter and no libpng available
truelight
parents: 7398
diff changeset
   154
		if (show_once) {
8e062c789dec (svn r10150) -Fix r10148: show a message to users when using 32bpp blitter and no libpng available
truelight
parents: 7398
diff changeset
   155
			DEBUG(misc, 0, "You are running a 32bpp blitter, but this build is without libpng support; falling back to 8bpp graphics");
8e062c789dec (svn r10150) -Fix r10148: show a message to users when using 32bpp blitter and no libpng available
truelight
parents: 7398
diff changeset
   156
			show_once = false;
8e062c789dec (svn r10150) -Fix r10148: show a message to users when using 32bpp blitter and no libpng available
truelight
parents: 7398
diff changeset
   157
		}
8e062c789dec (svn r10150) -Fix r10148: show a message to users when using 32bpp blitter and no libpng available
truelight
parents: 7398
diff changeset
   158
#endif /* WITH_PNG */
7392
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   159
	}
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   160
8066
7acd480e05c9 (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 7585
diff changeset
   161
	FioSeekToFile(file_slot, file_pos);
1354
5e5c89b9b169 (svn r1858) Let ReadSprite() handle the subtleties of loading a sprite, not its caller
tron
parents: 1353
diff changeset
   162
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
   163
	/* Read the size and type */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
   164
	int num  = FioReadWord();
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
   165
	byte type = FioReadByte();
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
   166
	/* Type 0xFF indicates either a colormap or some other non-sprite info */
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
   167
	if (type == 0xFF) {
7365
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   168
		if (real_sprite) {
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   169
			static byte warning_level = 0;
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   170
			DEBUG(sprite, warning_level, "Tried to load non sprite #%d as a real sprite. Probable cause: NewGRF interference", id);
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   171
			warning_level = 6;
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   172
			if (id == SPR_IMG_QUERY) error("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non- sprite?");
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   173
			return (void*)GetSprite(SPR_IMG_QUERY);
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   174
		}
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   175
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
   176
		byte *dest = (byte *)AllocSprite(num);
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
   177
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   178
		sc->ptr = dest;
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
   179
		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
   180
7361
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   181
		return sc->ptr;
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   182
	}
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   183
	/* Ugly hack to work around the problem that the old landscape
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   184
	 *  generator assumes that those sprites are stored uncompressed in
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   185
	 *  the memory, and they are only read directly by the code, never
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   186
	 *  send to the blitter. So do not send it to the blitter (which will
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   187
	 *  result in a data array in the format the blitter likes most), but
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   188
	 *  read the data directly from disk and store that as sprite.
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   189
	 * Ugly: yes. Other solution: no. Blame the original author or
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   190
	 *  something ;) The image should really have been a data-stream
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   191
	 *  (so type = 0xFF basicly). */
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   192
	if (id >= 4845 && id <= 4881) {
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   193
		uint height = FioReadByte();
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   194
		uint width  = FioReadWord();
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   195
		Sprite *sprite;
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   196
		byte *dest;
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   197
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   198
		num = width * height;
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   199
		sprite = (Sprite *)AllocSprite(sizeof(*sprite) + num);
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   200
		sc->ptr = sprite;
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   201
		sprite->height = height;
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   202
		sprite->width  = width;
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   203
		sprite->x_offs = FioReadWord();
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   204
		sprite->y_offs = FioReadWord();
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   205
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   206
		dest = sprite->data;
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   207
		while (num > 0) {
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   208
			int8 i = FioReadByte();
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   209
			if (i >= 0) {
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   210
				num -= i;
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   211
				for (; i > 0; --i) *dest++ = FioReadByte();
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   212
			} else {
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   213
				const byte* rel = dest - (((i & 7) << 8) | FioReadByte());
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   214
				i = -(i >> 3);
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   215
				num -= i;
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   216
				for (; i > 0; --i) *dest++ = *rel++;
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   217
			}
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   218
		}
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   219
8314452833ad (svn r10105) -Fix r10092: fix sprite 4845 till 4881 (inclusive), so they store the data as on the disk in the memory, as the old landscape generate assumes this. Talking about ugly hacks...
truelight
parents: 7352
diff changeset
   220
		return sc->ptr;
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
   221
	}
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
   222
7365
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   223
	if (!real_sprite) {
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   224
		static byte warning_level = 0;
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   225
		DEBUG(sprite, warning_level, "Tried to load real sprite #%d as a non sprite. Probable cause: NewGRF interference", id);
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   226
		warning_level = 6;
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   227
	}
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   228
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
   229
	SpriteLoaderGrf sprite_loader;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
   230
	SpriteLoader::Sprite sprite;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
8870
461ed7760525 (svn r11940) -Codechange: Store short filename once per open file instead of once per sprite cache entry. Not all file types need this, but most of the time no sprite cache entry needed it either.
peter1138
parents: 8869
diff changeset
   232
	if (!sprite_loader.LoadSprite(&sprite, file_slot, file_pos)) return NULL;
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
   233
	if (id == 142) sprite.height = 10; // Compensate for a TTD bug
7352
e2e8432018f6 (svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents: 7348
diff changeset
   234
	sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
   235
	free(sprite.data);
184
dbeaaaf8b2bb (svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents: 182
diff changeset
   236
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
   237
	return sc->ptr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
8066
7acd480e05c9 (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 7585
diff changeset
   241
bool LoadNextSprite(int load_index, byte file_slot, uint file_sprite_id)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
{
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   243
	SpriteCache *sc;
8066
7acd480e05c9 (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 7585
diff changeset
   244
	uint32 file_pos = FioGetPos();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
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
   246
	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
   247
3591
05a4b88d875f (svn r4481) - Fix: Validate the given sprite ID when loading a sprite.
peter1138
parents: 3565
diff changeset
   248
	if (load_index >= MAX_SPRITES) {
05a4b88d875f (svn r4481) - Fix: Validate the given sprite ID when loading a sprite.
peter1138
parents: 3565
diff changeset
   249
		error("Tried to load too many sprites (#%d; max %d)", load_index, MAX_SPRITES);
05a4b88d875f (svn r4481) - Fix: Validate the given sprite ID when loading a sprite.
peter1138
parents: 3565
diff changeset
   250
	}
05a4b88d875f (svn r4481) - Fix: Validate the given sprite ID when loading a sprite.
peter1138
parents: 3565
diff changeset
   251
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   252
	sc = AllocateSpriteCache(load_index);
8066
7acd480e05c9 (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 7585
diff changeset
   253
	sc->file_slot = file_slot;
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   254
	sc->file_pos = file_pos;
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   255
	sc->ptr = NULL;
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   256
	sc->lru = 0;
7404
fc0559157f16 (svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight
parents: 7399
diff changeset
   257
	sc->id = file_sprite_id;
7392
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   258
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
2407
983f1d8a0614 (svn r2933) Implement the non-breaking space
tron
parents: 2342
diff changeset
   262
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   263
void DupSprite(SpriteID old_spr, SpriteID new_spr)
2407
983f1d8a0614 (svn r2933) Implement the non-breaking space
tron
parents: 2342
diff changeset
   264
{
8931
d84c34673a0f (svn r12005) -Fix [FS#1717]: possible reading from an invalid pointer. Patch by PhilSophus.
rubidium
parents: 8928
diff changeset
   265
	SpriteCache *scnew = AllocateSpriteCache(new_spr); // may reallocate: so put it first
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   266
	SpriteCache *scold = GetSpriteCache(old_spr);
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   267
8066
7acd480e05c9 (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 7585
diff changeset
   268
	scnew->file_slot = scold->file_slot;
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   269
	scnew->file_pos = scold->file_pos;
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   270
	scnew->ptr = NULL;
7392
a716551b0c7f (svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
truelight
parents: 7365
diff changeset
   271
	scnew->id = scold->id;
2407
983f1d8a0614 (svn r2933) Implement the non-breaking space
tron
parents: 2342
diff changeset
   272
}
983f1d8a0614 (svn r2933) Implement the non-breaking space
tron
parents: 2342
diff changeset
   273
983f1d8a0614 (svn r2933) Implement the non-breaking space
tron
parents: 2342
diff changeset
   274
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
#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
   276
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
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
   278
{
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
   279
	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
   280
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6213
diff changeset
   282
static uint32 GetSpriteCacheUsage()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
{
4321
b763b7007162 (svn r5974) -Codechange: added casts all around the place to make Windows 64bit happy (michi_cc)
truelight
parents: 3591
diff changeset
   284
	uint32 tot_size = 0;
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
   285
	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
   286
9058
b9c3fec968b8 (svn r12140) -Codechange: A bit of code style fixes(Geektoo).
belugas
parents: 8931
diff changeset
   287
	for (s = _spritecache_ptr; s->size != 0; s = NextBlock(s)) {
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
   288
		if (!(s->size & S_FREE_MASK)) tot_size += s->size;
9058
b9c3fec968b8 (svn r12140) -Codechange: A bit of code style fixes(Geektoo).
belugas
parents: 8931
diff changeset
   289
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
	return tot_size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6213
diff changeset
   295
void IncreaseSpriteLRU()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
{
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   297
	/* Increase all LRU values */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	if (_sprite_lru_counter > 16384) {
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   299
		SpriteID i;
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   300
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5150
diff changeset
   301
		DEBUG(sprite, 3, "Fixing lru %d, inuse=%d", _sprite_lru_counter, GetSpriteCacheUsage());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   303
		for (i = 0; i != _spritecache_items; i++) {
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   304
			SpriteCache *sc = GetSpriteCache(i);
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   305
			if (sc->ptr != NULL) {
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   306
				if (sc->lru >= 0) {
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   307
					sc->lru = -1;
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   308
				} else if (sc->lru != -32768) {
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   309
					sc->lru--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
			}
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   312
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
		_sprite_lru_counter = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   316
	/* Compact sprite cache every now and then. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
	if (++_compact_cache_counter >= 740) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
		CompactSpriteCache();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
		_compact_cache_counter = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   323
/** Called when holes in the sprite cache should be removed.
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   324
 * That is accomplished by moving the cached data. */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6213
diff changeset
   325
static void CompactSpriteCache()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
{
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
   327
	MemBlock *s;
184
dbeaaaf8b2bb (svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents: 182
diff changeset
   328
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5150
diff changeset
   329
	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
   330
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
   331
	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
   332
		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
   333
			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
   334
			MemBlock temp;
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   335
			SpriteID 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
   336
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   337
			/* 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
   338
			assert(!(next->size & S_FREE_MASK));
184
dbeaaaf8b2bb (svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents: 182
diff changeset
   339
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   340
			/* If the next block is the sentinel block, we can safely return */
9237
9f210581c3a9 (svn r12436) -Cleanup: minor coding style
peter1138
parents: 9058
diff changeset
   341
			if (next->size == 0) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   343
			/* Locate the sprite belonging to the next pointer. */
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   344
			for (i = 0; GetSpriteCache(i)->ptr != next->data; i++) {
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   345
				assert(i != _spritecache_items);
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
   346
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   348
			GetSpriteCache(i)->ptr = s->data; // Adjust sprite array entry
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   349
			/* Swap this and the next 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
   350
			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
   351
			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
   352
			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
   353
			*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
   354
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   355
			/* Coalesce 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
   356
			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
   357
				s->size += NextBlock(s)->size & ~S_FREE_MASK;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   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
		} 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
   360
			s = NextBlock(s);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6213
diff changeset
   365
static void DeleteEntryFromSpriteCache()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
{
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   367
	SpriteID i;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   368
	uint best = UINT_MAX;
1353
48b59d472641 (svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents: 1352
diff changeset
   369
	MemBlock* s;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
	int cur_lru;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5150
diff changeset
   372
	DEBUG(sprite, 3, "DeleteEntryFromSpriteCache, inuse=%d", GetSpriteCacheUsage());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
	cur_lru = 0xffff;
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   375
	for (i = 0; i != _spritecache_items; i++) {
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   376
		SpriteCache *sc = GetSpriteCache(i);
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   377
		if (sc->ptr != NULL && sc->lru < cur_lru) {
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   378
			cur_lru = sc->lru;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
			best = i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   383
	/* Display an error message and die, in case we found no sprite at all.
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   384
	 * This shouldn't really happen, unless all sprites are locked. */
8536
95419f22b9ab (svn r11600) -Cleanup: remove extra out-of-memory checks, since it's now done in *allocT functions.
glx
parents: 8533
diff changeset
   385
	if (best == (uint)-1) error("Out of sprite memory");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   387
	/* Mark the block as free (the block must be in use) */
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   388
	s = (MemBlock*)GetSpriteCache(best)->ptr - 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
   389
	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
   390
	s->size |= S_FREE_MASK;
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   391
	GetSpriteCache(best)->ptr = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   393
	/* 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
   394
	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
   395
		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
   396
			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
   397
				s->size += NextBlock(s)->size & ~S_FREE_MASK;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7299
diff changeset
   403
void* AllocSprite(size_t mem_req)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
{
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
   405
	mem_req += sizeof(MemBlock);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
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
   407
	/* 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
   408
	 * bits are not used, so we could use those for other things. */
8423
8453e9a0f0b5 (svn r11480) -Codechange: Rename the function ALIGN fitting to the naming style
skidd13
parents: 8072
diff changeset
   409
	mem_req = Align(mem_req, sizeof(uint32));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
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
   411
	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
   412
		MemBlock* s;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
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
   414
		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
   415
			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
   416
				size_t cur_size = s->size & ~S_FREE_MASK;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
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
   418
				/* 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
   419
				 * 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
   420
				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
   421
						cur_size >= mem_req + sizeof(MemBlock)) {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   422
					/* Set size and 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
   423
					s->size = mem_req;
184
dbeaaaf8b2bb (svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents: 182
diff changeset
   424
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   425
					/* Do we need to inject a free block too? */
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
   426
					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
   427
						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
   428
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
1353
48b59d472641 (svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents: 1352
diff changeset
   430
					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
   431
				}
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
   432
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   435
		/* Reached sentinel, but no block found yet. Delete some old entry. */
1353
48b59d472641 (svn r1857) Rewrite parts of the sprite heap. It's functionally equivalent but should be easier to read and maintain.
tron
parents: 1352
diff changeset
   436
		DeleteEntryFromSpriteCache();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
7365
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   441
const void *GetRawSprite(SpriteID sprite, bool real_sprite)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
{
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   443
	SpriteCache *sc;
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
   444
	void* p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
5953
7000c5bdd70b (svn r8166) -Fix (r7797): Protect against out of bounds access to the sprite ptr
peter1138
parents: 5860
diff changeset
   446
	assert(sprite < _spritecache_items);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   448
	sc = GetSpriteCache(sprite);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   450
	/* Update LRU */
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   451
	sc->lru = ++_sprite_lru_counter;
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   452
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   453
	p = sc->ptr;
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   454
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   455
	/* Load the sprite, if it is not loaded, yet */
7365
d484a635f91d (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD).
rubidium
parents: 7361
diff changeset
   456
	if (p == NULL) p = ReadSprite(sc, sprite, real_sprite);
9058
b9c3fec968b8 (svn r12140) -Codechange: A bit of code style fixes(Geektoo).
belugas
parents: 8931
diff changeset
   457
184
dbeaaaf8b2bb (svn r185) -Fix: [1016954] Cached_sprites does now work again
truelight
parents: 182
diff changeset
   458
	return p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 884
diff changeset
   461
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6213
diff changeset
   462
void GfxInitSpriteMem()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
{
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   464
	/* initialize sprite cache heap */
8533
a9b708fe4a00 (svn r11597) -Change: replace all remaining instances of (re|m|c)alloc with (Re|M|C)allocT and add a check for out-of-memory situations to the *allocT functions.
rubidium
parents: 8423
diff changeset
   465
	if (_spritecache_ptr == NULL) _spritecache_ptr = (MemBlock*)MallocT<byte>(_sprite_cache_size * 1024 * 1024);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   467
	/* A big free block */
7299
74e163f03bbc (svn r10042) -Codechange: Replace hardcoded spritecache size with a configuration
peter1138
parents: 7295
diff changeset
   468
	_spritecache_ptr->size = ((_sprite_cache_size * 1024 * 1024) - sizeof(MemBlock)) | S_FREE_MASK;
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   469
	/* Sentinel block (identified by size == 0) */
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
   470
	NextBlock(_spritecache_ptr)->size = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
5755
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   472
	/* Reset the spritecache 'pool' */
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   473
	free(_spritecache);
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   474
	_spritecache_items = 0;
5db1cb757991 (svn r7797) -Codechange: Replace static _sprite_ptr and associated arrays with dynamic array to allow variable number of sprites. This does not change the sprite limit.
peter1138
parents: 5752
diff changeset
   475
	_spritecache = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
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
   477
	_compact_cache_counter = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
}