summaryrefslogtreecommitdiff
path: root/src/spritecache.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-01-14 16:16:33 +0000
committerfrosch <frosch@openttd.org>2011-01-14 16:16:33 +0000
commitd811238dd0050fc9cc443eae7d0a60742fa02fa2 (patch)
tree78941633b30cd9ee9e93e3e5dcb2c208c46993a4 /src/spritecache.cpp
parentff469ab352e78f20ba13d44a90fae0eb27587d1a (diff)
downloadopenttd-d811238dd0050fc9cc443eae7d0a60742fa02fa2.tar.xz
(svn r21785) -Codechange: Make ReadSprite() not operate on the sprite chache directly.
Diffstat (limited to 'src/spritecache.cpp')
-rw-r--r--src/spritecache.cpp23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/spritecache.cpp b/src/spritecache.cpp
index e3281b908..5ebbee2f1 100644
--- a/src/spritecache.cpp
+++ b/src/spritecache.cpp
@@ -177,7 +177,7 @@ uint GetMaxSpriteID()
static void *AllocSprite(size_t);
-static void *ReadSprite(SpriteCache *sc, SpriteID id, SpriteType sprite_type)
+static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_type)
{
uint8 file_slot = sc->file_slot;
size_t file_pos = sc->file_pos;
@@ -194,9 +194,7 @@ static void *ReadSprite(SpriteCache *sc, SpriteID id, SpriteType sprite_type)
SpriteLoader::Sprite sprite;
if (sprite_loader.LoadSprite(&sprite, file_slot, sc->id, sprite_type)) {
- sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
-
- return sc->ptr;
+ return BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
}
/* If the PNG couldn't be loaded, fall back to 8bpp grfs */
#else
@@ -224,8 +222,6 @@ static void *ReadSprite(SpriteCache *sc, SpriteID id, SpriteType sprite_type)
static const int RECOLOUR_SPRITE_SIZE = 257;
byte *dest = (byte *)AllocSprite(max(RECOLOUR_SPRITE_SIZE, num));
- sc->ptr = dest;
-
if (_palette_remap_grf[sc->file_slot]) {
byte *dest_tmp = AllocaM(byte, max(RECOLOUR_SPRITE_SIZE, num));
@@ -241,7 +237,7 @@ static void *ReadSprite(SpriteCache *sc, SpriteID id, SpriteType sprite_type)
FioReadBlock(dest, num);
}
- return sc->ptr;
+ return dest;
}
/* Ugly hack to work around the problem that the old landscape
@@ -261,7 +257,6 @@ static void *ReadSprite(SpriteCache *sc, SpriteID id, SpriteType sprite_type)
num = width * height;
sprite = (Sprite *)AllocSprite(sizeof(*sprite) + num);
- sc->ptr = sprite;
sprite->height = height;
sprite->width = width;
sprite->x_offs = FioReadWord();
@@ -281,7 +276,7 @@ static void *ReadSprite(SpriteCache *sc, SpriteID id, SpriteType sprite_type)
}
}
- return sc->ptr;
+ return sprite;
}
assert(sprite_type == ST_NORMAL || sprite_type == ST_FONT);
@@ -293,9 +288,7 @@ static void *ReadSprite(SpriteCache *sc, SpriteID id, SpriteType sprite_type)
if (id == SPR_IMG_QUERY) usererror("Okay... something went horribly wrong. I couldn't load the fallback sprite. What should I do?");
return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL);
}
- sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
-
- return sc->ptr;
+ return BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
}
@@ -586,12 +579,10 @@ void *GetRawSprite(SpriteID sprite, SpriteType type)
/* Update LRU */
sc->lru = ++_sprite_lru_counter;
- void *p = sc->ptr;
-
/* Load the sprite, if it is not loaded, yet */
- if (p == NULL) p = ReadSprite(sc, sprite, type);
+ if (sc->ptr == NULL) sc->ptr = ReadSprite(sc, sprite, type);
- return p;
+ return sc->ptr;
}