src/spritecache.cpp
branchcustombridgeheads
changeset 5650 aefc131bf5ce
parent 5649 55c8267c933f
--- a/src/spritecache.cpp	Thu Jan 11 13:41:16 2007 +0000
+++ b/src/spritecache.cpp	Mon Jan 15 20:14:06 2007 +0000
@@ -8,6 +8,7 @@
 #include "spritecache.h"
 #include "table/sprites.h"
 #include "fileio.h"
+#include "helpers.hpp"
 
 #define SPRITE_CACHE_SIZE 1024*1024
 
@@ -37,7 +38,7 @@
 
 		DEBUG(sprite, 4, "Increasing sprite cache to %d items (%d bytes)", items, items * sizeof(*_spritecache));
 
-		_spritecache = realloc(_spritecache, items * sizeof(*_spritecache));
+		ReallocT(&_spritecache, items);
 
 		if (_spritecache == NULL) {
 			error("Unable to allocate sprite cache of %d items (%d bytes)", items, items * sizeof(*_spritecache));
@@ -132,7 +133,7 @@
 	num  = FioReadWord();
 	type = FioReadByte();
 	if (type == 0xFF) {
-		byte* dest = AllocSprite(num);
+		byte* dest = (byte*)AllocSprite(num);
 
 		sc->ptr = dest;
 		FioReadBlock(dest, num);
@@ -145,7 +146,7 @@
 		byte* dest;
 
 		num = (type & 0x02) ? width * height : num - 8;
-		sprite = AllocSprite(sizeof(*sprite) + num);
+		sprite = (Sprite*)AllocSprite(sizeof(*sprite) + num);
 		sc->ptr = sprite;
 		sprite->info   = type;
 		sprite->height = (id != 142) ? height : 10; // Compensate for a TTD bug
@@ -195,10 +196,10 @@
 }
 
 
-void DupSprite(SpriteID old, SpriteID new)
+void DupSprite(SpriteID old_spr, SpriteID new_spr)
 {
-	SpriteCache *scold = GetSpriteCache(old);
-	SpriteCache *scnew = AllocateSpriteCache(new);
+	SpriteCache *scold = GetSpriteCache(old_spr);
+	SpriteCache *scnew = AllocateSpriteCache(new_spr);
 
 	scnew->file_pos = scold->file_pos;
 	scnew->ptr = NULL;
@@ -306,7 +307,7 @@
 static void DeleteEntryFromSpriteCache(void)
 {
 	SpriteID i;
-	uint best = -1;
+	uint best = UINT_MAX;
 	MemBlock* s;
 	int cur_lru;
 
@@ -403,7 +404,7 @@
 void GfxInitSpriteMem(void)
 {
 	// initialize sprite cache heap
-	if (_spritecache_ptr == NULL) _spritecache_ptr = malloc(SPRITE_CACHE_SIZE);
+	if (_spritecache_ptr == NULL) _spritecache_ptr = (MemBlock*)malloc(SPRITE_CACHE_SIZE);
 
 	// A big free block
 	_spritecache_ptr->size = (SPRITE_CACHE_SIZE - sizeof(MemBlock)) | S_FREE_MASK;