aboutsummaryrefslogtreecommitdiff
path: root/engines/saga
diff options
context:
space:
mode:
authorAndrew Kurushin2010-10-20 22:02:33 +0000
committerAndrew Kurushin2010-10-20 22:02:33 +0000
commitd97d21e0292d536727d926e8bbd3219ecd664caf (patch)
tree8f5079c7d9a4423519a1026107408f655ac4446a /engines/saga
parentdb55d81b085c891d30b9b2b646d0da1bea7e1ef1 (diff)
downloadscummvm-rg350-d97d21e0292d536727d926e8bbd3219ecd664caf.tar.gz
scummvm-rg350-d97d21e0292d536727d926e8bbd3219ecd664caf.tar.bz2
scummvm-rg350-d97d21e0292d536727d926e8bbd3219ecd664caf.zip
SAGA: replace Sprite "::*alloc" & "::free" with Common::Array
svn-id: r53658
Diffstat (limited to 'engines/saga')
-rw-r--r--engines/saga/sprite.cpp68
-rw-r--r--engines/saga/sprite.h7
2 files changed, 35 insertions, 40 deletions
diff --git a/engines/saga/sprite.cpp b/engines/saga/sprite.cpp
index 184e728552..6d9d1b6669 100644
--- a/engines/saga/sprite.cpp
+++ b/engines/saga/sprite.cpp
@@ -51,13 +51,6 @@ Sprite::Sprite(SagaEngine *vm) : _vm(vm) {
error("Sprite::Sprite resource context not found");
}
- _decodeBufLen = DECODE_BUF_LEN;
-
- _decodeBuf = (byte *)malloc(_decodeBufLen);
- if (_decodeBuf == NULL) {
- memoryError("Sprite::Sprite");
- }
-
if (_vm->getGameId() == GID_ITE) {
loadList(_vm->getResourceDescription()->mainSpritesResourceId, _mainSprites);
_arrowSprites = _saveReminderSprites = _inventorySprites = _mainSprites;
@@ -78,7 +71,6 @@ Sprite::Sprite(SagaEngine *vm) : _vm(vm) {
Sprite::~Sprite() {
debug(8, "Shutting down sprite subsystem...");
- free(_decodeBuf);
}
void Sprite::loadList(int resourceId, SpriteList &spriteList) {
@@ -153,26 +145,27 @@ void Sprite::loadList(int resourceId, SpriteList &spriteList) {
outputLength = spriteInfo->width * spriteInfo->height;
inputLength = spriteListLength - (spriteDataPointer - spriteListData);
- decodeRLEBuffer(spriteDataPointer, inputLength, outputLength);
spriteInfo->decodedBuffer.resize(outputLength);
- byte *dst = spriteInfo->getBuffer();
-
+ if (outputLength > 0) {
+ decodeRLEBuffer(spriteDataPointer, inputLength, outputLength);
+ byte *dst = spriteInfo->getBuffer();
#ifdef ENABLE_IHNM
- // IHNM sprites are upside-down, for reasons which i can only
- // assume are perverse. To simplify things, flip them now. Not
- // at drawing time.
+ // IHNM sprites are upside-down, for reasons which i can only
+ // assume are perverse. To simplify things, flip them now. Not
+ // at drawing time.
- if (_vm->getGameId() == GID_IHNM) {
- byte *src = _decodeBuf + spriteInfo->width * (spriteInfo->height - 1);
+ if (_vm->getGameId() == GID_IHNM) {
+ byte *src = &_decodeBuf[spriteInfo->width * (spriteInfo->height - 1)];
- for (int j = 0; j < spriteInfo->height; j++) {
- memcpy(dst, src, spriteInfo->width);
- src -= spriteInfo->width;
- dst += spriteInfo->width;
- }
- } else
+ for (int j = 0; j < spriteInfo->height; j++) {
+ memcpy(dst, src, spriteInfo->width);
+ src -= spriteInfo->width;
+ dst += spriteInfo->width;
+ }
+ } else
#endif
- memcpy(dst, _decodeBuf, outputLength);
+ memcpy(dst, &_decodeBuf.front(), outputLength);
+ }
}
free(spriteListData);
@@ -194,8 +187,13 @@ void Sprite::getScaledSpriteBuffer(SpriteList &spriteList, uint spriteNumber, in
yAlign = (spriteInfo->yAlign * scale) >> 8;
height = (spriteInfo->height * scale + 0x7f) >> 8;
width = (spriteInfo->width * scale + 0x7f) >> 8;
- scaleBuffer(spriteInfo->getBuffer(), spriteInfo->width, spriteInfo->height, scale);
- buffer = _decodeBuf;
+ size_t outLength = width * height;
+ if (outLength > 0) {
+ scaleBuffer(spriteInfo->getBuffer(), spriteInfo->width, spriteInfo->height, scale, outLength);
+ buffer = &_decodeBuf.front();
+ } else {
+ buffer = NULL;
+ }
} else {
xAlign = spriteInfo->xAlign;
yAlign = spriteInfo->yAlign;
@@ -406,15 +404,11 @@ void Sprite::decodeRLEBuffer(const byte *inputBuffer, size_t inLength, size_t ou
byte *outPointerEnd;
int c;
- if (outLength > _decodeBufLen) { // TODO: may we should make dynamic growing?
- error("Sprite::decodeRLEBuffer outLength > _decodeBufLen");
- }
-
- outPointer = _decodeBuf;
- outPointerEnd = _decodeBuf + outLength;
- outPointerEnd--;
+ _decodeBuf.resize(outLength);
+ outPointer = &_decodeBuf.front();
+ outPointerEnd = &_decodeBuf.back();
- memset(outPointer, 0, outLength);
+ memset(outPointer, 0, _decodeBuf.size());
MemoryReadStream readS(inputBuffer, inLength);
@@ -444,10 +438,14 @@ void Sprite::decodeRLEBuffer(const byte *inputBuffer, size_t inLength, size_t ou
}
}
-void Sprite::scaleBuffer(const byte *src, int width, int height, int scale) {
+void Sprite::scaleBuffer(const byte *src, int width, int height, int scale, size_t outLength) {
byte skip = 256 - scale; // skip factor
byte vskip = 0x80, hskip;
- byte *dst = _decodeBuf;
+
+ _decodeBuf.resize(outLength);
+ byte *dst = &_decodeBuf.front();
+
+ memset(dst, 0, _decodeBuf.size());
for (int i = 0; i < height; i++) {
vskip += skip;
diff --git a/engines/saga/sprite.h b/engines/saga/sprite.h
index f429d1f4e8..f1eae3811f 100644
--- a/engines/saga/sprite.h
+++ b/engines/saga/sprite.h
@@ -33,8 +33,6 @@ namespace Saga {
#define SPRITE_ZMAX 16
#define SPRITE_ZMASK 0x0F
-#define DECODE_BUF_LEN 64000
-
struct SpriteInfo {
Common::Array<byte> decodedBuffer;
int width;
@@ -86,12 +84,11 @@ public:
private:
void decodeRLEBuffer(const byte *inputBuffer, size_t inLength, size_t outLength);
- void scaleBuffer(const byte *src, int width, int height, int scale);
+ void scaleBuffer(const byte *src, int width, int height, int scale, size_t outLength);
SagaEngine *_vm;
ResourceContext *_spriteContext;
- byte *_decodeBuf;
- size_t _decodeBufLen;
+ Common::Array<byte> _decodeBuf;
};
} // End of namespace Saga