[Scummvm-cvs-logs] SF.net SVN: scummvm:[53658] scummvm/trunk/engines/saga
h00ligan at users.sourceforge.net
h00ligan at users.sourceforge.net
Thu Oct 21 00:02:33 CEST 2010
Revision: 53658
http://scummvm.svn.sourceforge.net/scummvm/?rev=53658&view=rev
Author: h00ligan
Date: 2010-10-20 22:02:33 +0000 (Wed, 20 Oct 2010)
Log Message:
-----------
SAGA: replace Sprite "::*alloc" & "::free" with Common::Array
Modified Paths:
--------------
scummvm/trunk/engines/saga/sprite.cpp
scummvm/trunk/engines/saga/sprite.h
Modified: scummvm/trunk/engines/saga/sprite.cpp
===================================================================
--- scummvm/trunk/engines/saga/sprite.cpp 2010-10-20 21:47:26 UTC (rev 53657)
+++ scummvm/trunk/engines/saga/sprite.cpp 2010-10-20 22:02:33 UTC (rev 53658)
@@ -51,13 +51,6 @@
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() {
debug(8, "Shutting down sprite subsystem...");
- free(_decodeBuf);
}
void Sprite::loadList(int resourceId, SpriteList &spriteList) {
@@ -153,26 +145,27 @@
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 @@
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,16 +404,12 @@
byte *outPointerEnd;
int c;
- if (outLength > _decodeBufLen) { // TODO: may we should make dynamic growing?
- error("Sprite::decodeRLEBuffer outLength > _decodeBufLen");
- }
+ _decodeBuf.resize(outLength);
+ outPointer = &_decodeBuf.front();
+ outPointerEnd = &_decodeBuf.back();
- outPointer = _decodeBuf;
- outPointerEnd = _decodeBuf + outLength;
- outPointerEnd--;
+ memset(outPointer, 0, _decodeBuf.size());
- memset(outPointer, 0, outLength);
-
MemoryReadStream readS(inputBuffer, inLength);
while (!readS.eos() && (outPointer < outPointerEnd)) {
@@ -444,11 +438,15 @@
}
}
-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;
Modified: scummvm/trunk/engines/saga/sprite.h
===================================================================
--- scummvm/trunk/engines/saga/sprite.h 2010-10-20 21:47:26 UTC (rev 53657)
+++ scummvm/trunk/engines/saga/sprite.h 2010-10-20 22:02:33 UTC (rev 53658)
@@ -33,8 +33,6 @@
#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 @@
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
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list