aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorAndrew Kurushin2010-10-22 23:13:17 +0000
committerAndrew Kurushin2010-10-22 23:13:17 +0000
commitf24394b85f5d34815659c50cd956c262f4b79d68 (patch)
tree8c93e3f052133b154b1686e00b4066b3967f0c02 /engines
parentb8ff3eb4913dd22bc75ae360baadadd95151077f (diff)
downloadscummvm-rg350-f24394b85f5d34815659c50cd956c262f4b79d68.tar.gz
scummvm-rg350-f24394b85f5d34815659c50cd956c262f4b79d68.tar.bz2
scummvm-rg350-f24394b85f5d34815659c50cd956c262f4b79d68.zip
SAGA: replace Actor::_pathCell, Anim::*, Converse::text, IsoMap::*, Music::_songTable, ObjectMap::*, PalAnim::*, Scene::sceneLut, SndRes::_fxTable* malloc based arrays with Common::Array implementation
add ByteArray type fix debug Tile Hittest frame drawing debug 0x%x => 0x%X svn-id: r53719
Diffstat (limited to 'engines')
-rw-r--r--engines/saga/actor.cpp7
-rw-r--r--engines/saga/actor.h6
-rw-r--r--engines/saga/actor_walk.cpp8
-rw-r--r--engines/saga/animation.cpp56
-rw-r--r--engines/saga/animation.h29
-rw-r--r--engines/saga/detection.cpp2
-rw-r--r--engines/saga/font.cpp2
-rw-r--r--engines/saga/font.h2
-rw-r--r--engines/saga/gfx.cpp5
-rw-r--r--engines/saga/gfx.h7
-rw-r--r--engines/saga/image.cpp43
-rw-r--r--engines/saga/interface.cpp17
-rw-r--r--engines/saga/interface.h3
-rw-r--r--engines/saga/introproc_ihnm.cpp4
-rw-r--r--engines/saga/isomap.cpp67
-rw-r--r--engines/saga/isomap.h11
-rw-r--r--engines/saga/itedata.cpp2
-rw-r--r--engines/saga/itedata.h8
-rw-r--r--engines/saga/music.cpp6
-rw-r--r--engines/saga/music.h3
-rw-r--r--engines/saga/objectmap.cpp167
-rw-r--r--engines/saga/objectmap.h32
-rw-r--r--engines/saga/palanim.cpp139
-rw-r--r--engines/saga/palanim.h19
-rw-r--r--engines/saga/resource.cpp15
-rw-r--r--engines/saga/resource_res.cpp20
-rw-r--r--engines/saga/saga.cpp2
-rw-r--r--engines/saga/saga.h12
-rw-r--r--engines/saga/saveload.cpp6
-rw-r--r--engines/saga/scene.cpp56
-rw-r--r--engines/saga/scene.h28
-rw-r--r--engines/saga/script.cpp4
-rw-r--r--engines/saga/script.h4
-rw-r--r--engines/saga/sfuncs.cpp10
-rw-r--r--engines/saga/sfuncs_ihnm.cpp4
-rw-r--r--engines/saga/sndres.cpp22
-rw-r--r--engines/saga/sndres.h11
-rw-r--r--engines/saga/sprite.cpp10
-rw-r--r--engines/saga/sprite.h12
-rw-r--r--engines/saga/sthread.cpp8
40 files changed, 329 insertions, 540 deletions
diff --git a/engines/saga/actor.cpp b/engines/saga/actor.cpp
index be011d0119..f743fc4324 100644
--- a/engines/saga/actor.cpp
+++ b/engines/saga/actor.cpp
@@ -218,7 +218,7 @@ Actor::Actor(SagaEngine *vm) : _vm(vm) {
_yCellCount = _vm->_scene->getHeight();
_xCellCount = _vm->getDisplayInfo().width;
- _pathCell = (int8 *)malloc(_yCellCount * _xCellCount * sizeof(*_pathCell));
+ _pathCell.resize(_yCellCount * _xCellCount);
_pathRect.left = 0;
_pathRect.right = _vm->getDisplayInfo().width;
@@ -295,7 +295,6 @@ Actor::Actor(SagaEngine *vm) : _vm(vm) {
Actor::~Actor() {
debug(9, "Actor::~Actor()");
- free(_pathCell);
//release resources
freeProtagStates();
freeActorList();
@@ -445,7 +444,7 @@ void Actor::loadActorList(int protagonistIdx, int actorCount, int actorsResource
actor = _actors[i] = new ActorData();
actor->_id = objectIndexToId(kGameObjectActor, i); //actorIndexToId(i);
actor->_index = i;
- debug(4, "init actor id=0x%x index=%d", actor->_id, actor->_index);
+ debug(4, "init actor id=0x%X index=%d", actor->_id, actor->_index);
actorS.readUint32LE(); //next displayed
actorS.readByte(); //type
actor->_flags = actorS.readByte();
@@ -1162,7 +1161,7 @@ void Actor::drawActors() {
return;
}
- if (_vm->_scene->_entryList.entryListCount == 0) {
+ if (_vm->_scene->_entryList.empty()) {
return;
}
diff --git a/engines/saga/actor.h b/engines/saga/actor.h
index 7b287177ff..ede2ee714b 100644
--- a/engines/saga/actor.h
+++ b/engines/saga/actor.h
@@ -196,6 +196,8 @@ struct ActorFrameSequence {
ActorFrameRange directions[ACTOR_DIRECTIONS_COUNT];
};
+//typedef Common::Array<ActorFrameSequence> ActorFrameSequences;
+
uint pathLine(PointList &pointList, uint idx, const Point &point1, const Point &point2);
struct Location {
@@ -376,7 +378,7 @@ public:
int32 _frameNumber; // current frame number
- Common::Array<byte> _tileDirections;
+ ByteArray _tileDirections;
Common::Array<Point> _walkStepsPoints;
@@ -624,7 +626,7 @@ private:
Rect _barrierList[ACTOR_BARRIERS_MAX];
int _barrierCount;
- int8 *_pathCell;
+ Common::Array<int8> _pathCell;
int _xCellCount;
int _yCellCount;
diff --git a/engines/saga/actor_walk.cpp b/engines/saga/actor_walk.cpp
index 589bc89c85..620b8ee2b6 100644
--- a/engines/saga/actor_walk.cpp
+++ b/engines/saga/actor_walk.cpp
@@ -227,12 +227,12 @@ void Actor::updateActorsScene(int actorsEntrance) {
if (_protagonist == NULL)
return;
- if ((actorsEntrance >= 0) && (_vm->_scene->_entryList.entryListCount > 0)) {
- if (_vm->_scene->_entryList.entryListCount <= actorsEntrance) {
+ if ((actorsEntrance >= 0) && (!_vm->_scene->_entryList.empty())) {
+ if (_vm->_scene->_entryList.size() <= uint(actorsEntrance)) {
actorsEntrance = 0; //OCEAN bug
}
- sceneEntry = _vm->_scene->_entryList.getEntry(actorsEntrance);
+ sceneEntry = &_vm->_scene->_entryList[actorsEntrance];
if (_vm->_scene->getFlags() & kSceneFlagISO) {
_protagonist->_location = sceneEntry->location;
} else {
@@ -722,7 +722,7 @@ void Actor::handleActions(int msec, bool setup) {
void Actor::direct(int msec) {
- if (_vm->_scene->_entryList.entryListCount == 0) {
+ if (_vm->_scene->_entryList.empty()) {
return;
}
diff --git a/engines/saga/animation.cpp b/engines/saga/animation.cpp
index 0d65d2f191..a99ecea01a 100644
--- a/engines/saga/animation.cpp
+++ b/engines/saga/animation.cpp
@@ -42,8 +42,6 @@ namespace Saga {
Anim::Anim(SagaEngine *vm) : _vm(vm) {
uint16 i;
- _cutawayList = NULL;
- _cutawayListLength = 0;
_cutawayActive = false;
for (i = 0; i < MAX_ANIMATIONS; i++)
@@ -55,21 +53,16 @@ Anim::Anim(SagaEngine *vm) : _vm(vm) {
Anim::~Anim() {
reset();
-#ifdef ENABLE_IHNM
- freeCutawayList();
-#endif
}
#ifdef ENABLE_IHNM
void Anim::loadCutawayList(const byte *resourcePointer, size_t resourceLength) {
- free(_cutawayList);
- _cutawayListLength = resourceLength / 8;
- _cutawayList = (Cutaway *)malloc(_cutawayListLength * sizeof(Cutaway));
+ _cutawayList.resize(resourceLength / 8);
MemoryReadStream cutawayS(resourcePointer, resourceLength);
- for (int i = 0; i < _cutawayListLength; i++) {
+ for (uint i = 0; i < _cutawayList.size(); i++) {
_cutawayList[i].backgroundResourceId = cutawayS.readUint16LE();
_cutawayList[i].animResourceId = cutawayS.readUint16LE();
_cutawayList[i].cycles = cutawayS.readSint16LE();
@@ -77,10 +70,8 @@ void Anim::loadCutawayList(const byte *resourcePointer, size_t resourceLength) {
}
}
-void Anim::freeCutawayList() {
- free(_cutawayList);
- _cutawayList = NULL;
- _cutawayListLength = 0;
+void Anim::clearCutawayList() {
+ _cutawayList.clear();
}
int Anim::playCutaway(int cut, bool fade) {
@@ -404,11 +395,11 @@ void Anim::load(uint16 animId, const byte *animResourceData, size_t animResource
if (animId >= MAX_ANIMATIONS) {
if (animId >= MAX_ANIMATIONS + ARRAYSIZE(_cutawayAnimations))
error("Anim::load could not find unused animation slot");
- anim = _cutawayAnimations[animId - MAX_ANIMATIONS] = new AnimationData(animResourceData, animResourceLength);
+ anim = _cutawayAnimations[animId - MAX_ANIMATIONS] = new AnimationData();
} else
- anim = _animations[animId] = new AnimationData(animResourceData, animResourceLength);
+ anim = _animations[animId] = new AnimationData();
- MemoryReadStreamEndian headerReadS(anim->resourceData, anim->resourceLength, _vm->isBigEndian());
+ MemoryReadStreamEndian headerReadS(animResourceData, animResourceLength, _vm->isBigEndian());
anim->magic = headerReadS.readUint16LE(); // cause ALWAYS LE
anim->screenWidth = headerReadS.readUint16();
anim->screenHeight = headerReadS.readUint16();
@@ -418,23 +409,30 @@ void Anim::load(uint16 animId, const byte *animResourceData, size_t animResource
anim->maxFrame = headerReadS.readByte() - 1;
anim->loopFrame = headerReadS.readByte() - 1;
temp = headerReadS.readUint16BE();
- anim->start = headerReadS.pos();
+ size_t start;
+
+ start = headerReadS.pos();
if (temp == (uint16)(-1)) {
temp = 0;
}
- anim->start += temp;
+ start += temp;
+ size_t dataOffset = headerReadS.pos();
+ if (dataOffset != start) {
+ warning("Anim::load animId=%d start != dataOffset 0x%X 0x%X", animId, start, dataOffset);
+ }
+
+ anim->resourceData.resize(animResourceLength - dataOffset);
+
+ memcpy(anim->resourceData.getBuffer(), animResourceData + dataOffset, anim->resourceData.size());
// Cache frame offsets
// WORKAROUND: Cutaway with background resource ID 37 (loaded as cutaway #4) is ending credits.
// For some reason it has wrong number of frames specified in its header. So we calculate it here:
- if (animId > MAX_ANIMATIONS && _cutawayListLength > 4 && _cutawayList[4].backgroundResourceId == 37 && anim->maxFrame == 143)
+ if (animId > MAX_ANIMATIONS && _cutawayList.size() > 4 && _cutawayList[4].backgroundResourceId == 37 && anim->maxFrame == 143)
anim->maxFrame = fillFrameOffsets(anim, false);
- anim->frameOffsets = (size_t *)malloc((anim->maxFrame + 1) * sizeof(*anim->frameOffsets));
- if (anim->frameOffsets == NULL) {
- memoryError("Anim::load");
- }
+ anim->frameOffsets.resize(anim->maxFrame + 1);
fillFrameOffsets(anim);
@@ -688,7 +686,7 @@ void Anim::decodeFrame(AnimationData *anim, size_t frameOffset, byte *buf, size_
error("decodeFrame() Buffer size inadequate");
}
- MemoryReadStream readS(anim->resourceData + frameOffset, anim->resourceLength - frameOffset);
+ MemoryReadStream readS(&anim->resourceData[frameOffset], anim->resourceData.size() - frameOffset);
// FIXME: This is thrown when the first video of the IHNM end sequence is shown (the "turn off screen"
// video), however the video is played correctly and the rest of the end sequence continues normally
@@ -825,9 +823,7 @@ int Anim::fillFrameOffsets(AnimationData *anim, bool reallyFill) {
int i;
bool longData = isLongData();
- MemoryReadStreamEndian readS(anim->resourceData, anim->resourceLength, !_vm->isBigEndian()); // RLE has inversion BE<>LE
-
- readS.seek(12);
+ MemoryReadStreamEndian readS(&anim->resourceData.front(), anim->resourceData.size(), !_vm->isBigEndian()); // RLE has inversion BE<>LE
while (readS.pos() != readS.size()) {
if (reallyFill) {
@@ -843,7 +839,7 @@ int Anim::fillFrameOffsets(AnimationData *anim, bool reallyFill) {
// including the frame header, is in big endian format
do {
markByte = readS.readByte();
-// debug(7, "_pos=%x currentFrame=%i markByte=%x", readS.pos(), currentFrame, markByte);
+// debug(7, "_pos=%X currentFrame=%i markByte=%X", readS.pos(), currentFrame, markByte);
switch (markByte) {
case SAGA_FRAME_START: // Start of frame
@@ -942,9 +938,9 @@ void Anim::animInfo() {
void Anim::cutawayInfo() {
uint16 i;
- _vm->_console->DebugPrintf("There are %d cutaways loaded:\n", _cutawayListLength);
+ _vm->_console->DebugPrintf("There are %d cutaways loaded:\n", _cutawayList.size());
- for (i = 0; i < _cutawayListLength; i++) {
+ for (i = 0; i < _cutawayList.size(); i++) {
_vm->_console->DebugPrintf("%02d: Bg res: %u Anim res: %u Cycles: %u Framerate: %u\n", i,
_cutawayList[i].backgroundResourceId, _cutawayList[i].animResourceId,
_cutawayList[i].cycles, _cutawayList[i].frameRate);
diff --git a/engines/saga/animation.h b/engines/saga/animation.h
index 72b145089c..6a783dceb0 100644
--- a/engines/saga/animation.h
+++ b/engines/saga/animation.h
@@ -66,8 +66,7 @@ struct Cutaway {
// Animation info array member
struct AnimationData {
- byte *resourceData;
- size_t resourceLength;
+ ByteArray resourceData;
uint16 magic;
@@ -80,10 +79,8 @@ struct AnimationData {
int16 maxFrame;
int16 loopFrame;
- int16 start;
-
int16 currentFrame;
- size_t *frameOffsets;
+ Common::Array<size_t> frameOffsets;
uint16 completed;
uint16 cycles;
@@ -93,17 +90,6 @@ struct AnimationData {
AnimationState state;
int16 linkId;
uint16 flags;
-
- AnimationData(const byte *animResourceData, size_t animResourceLength) {
- memset(this, 0, sizeof(*this));
- resourceLength = animResourceLength;
- resourceData = (byte*)malloc(animResourceLength);
- memcpy(resourceData, animResourceData, animResourceLength);
- }
- ~AnimationData() {
- free(frameOffsets);
- free(resourceData);
- }
};
class Anim {
@@ -112,7 +98,7 @@ public:
~Anim();
void loadCutawayList(const byte *resourcePointer, size_t resourceLength);
- void freeCutawayList();
+ void clearCutawayList();
int playCutaway(int cut, bool fade);
void endCutaway();
void returnFromCutaway();
@@ -154,9 +140,9 @@ public:
bool hasCutaway() { return _cutawayActive; }
void setCutAwayMode(int mode) { _cutAwayMode = mode; }
- int cutawayListLength() { return _cutawayListLength; }
- int cutawayBgResourceID(int cutaway) { return _cutawayList[cutaway].backgroundResourceId; }
- int cutawayAnimResourceID(int cutaway) { return _cutawayList[cutaway].animResourceId; }
+// int cutawayListLength() { return _cutawayListLength; }
+// int cutawayBgResourceID(int cutaway) { return _cutawayList[cutaway].backgroundResourceId; }
+// int cutawayAnimResourceID(int cutaway) { return _cutawayList[cutaway].animResourceId; }
private:
void decodeFrame(AnimationData *anim, size_t frameOffset, byte *buf, size_t bufLength);
@@ -205,9 +191,8 @@ private:
SagaEngine *_vm;
AnimationData *_animations[MAX_ANIMATIONS];
AnimationData *_cutawayAnimations[2];
- Cutaway *_cutawayList;
+ Common::Array<Cutaway> _cutawayList;
PalEntry saved_pal[PAL_ENTRIES];
- int _cutawayListLength;
bool _cutawayActive;
int _cutAwayMode;
bool _cutAwayFade;
diff --git a/engines/saga/detection.cpp b/engines/saga/detection.cpp
index 7913291527..edfafff70a 100644
--- a/engines/saga/detection.cpp
+++ b/engines/saga/detection.cpp
@@ -259,7 +259,7 @@ SaveStateDescriptor SagaMetaEngine::querySaveMetaInfos(const char *target, int s
version = SWAP_BYTES_32(version);
}
- debug(2, "Save version: %x", version);
+ debug(2, "Save version: 0x%X", version);
if (version < 4)
warning("This savegame is not endian-safe. There may be problems");
diff --git a/engines/saga/font.cpp b/engines/saga/font.cpp
index 05f22d685f..3e82bf88e4 100644
--- a/engines/saga/font.cpp
+++ b/engines/saga/font.cpp
@@ -109,7 +109,7 @@ void Font::loadFont(FontData *font, uint32 fontResourceId) {
}
font->normal.font.resize(fontResourceLength - FONT_DESCSIZE);
- memcpy(&font->normal.font.front(), fontResourcePointer + FONT_DESCSIZE, fontResourceLength - FONT_DESCSIZE);
+ memcpy(font->normal.font.getBuffer(), fontResourcePointer + FONT_DESCSIZE, fontResourceLength - FONT_DESCSIZE);
free(fontResourcePointer);
diff --git a/engines/saga/font.h b/engines/saga/font.h
index a85906c799..6f66545756 100644
--- a/engines/saga/font.h
+++ b/engines/saga/font.h
@@ -120,7 +120,7 @@ struct FontCharEntry {
struct FontStyle {
FontHeader header;
FontCharEntry fontCharEntry[256];
- Common::Array<byte> font;
+ ByteArray font;
};
struct FontData {
diff --git a/engines/saga/gfx.cpp b/engines/saga/gfx.cpp
index 40a633ac5d..e698a3b1bd 100644
--- a/engines/saga/gfx.cpp
+++ b/engines/saga/gfx.cpp
@@ -564,8 +564,9 @@ bool hitTestPoly(const Point *points, unsigned int npoints, const Point& test_po
// This method adds a dirty rectangle automatically
void Gfx::drawFrame(const Common::Point &p1, const Common::Point &p2, int color) {
- _backBuffer.drawFrame(p1, p2, color);
- _vm->_render->addDirtyRect(Common::Rect(p1.x, p1.y, p2.x + 1, p2.y + 1));
+ Common::Rect rect(MIN(p1.x, p2.x), MIN(p1.y, p2.y), MAX(p1.x, p2.x) + 1, MAX(p1.y, p2.y) + 1);
+ _backBuffer.frameRect(rect, color);
+ _vm->_render->addDirtyRect(rect);
}
// This method adds a dirty rectangle automatically
diff --git a/engines/saga/gfx.h b/engines/saga/gfx.h
index f3ccad469f..18d88503ce 100644
--- a/engines/saga/gfx.h
+++ b/engines/saga/gfx.h
@@ -108,10 +108,7 @@ struct Surface : Graphics::Surface {
rect.right = w;
rect.bottom = h;
}
- void drawFrame(const Common::Point &p1, const Common::Point &p2, int color) {
- Common::Rect rect(MIN(p1.x, p2.x), MIN(p1.y, p2.y), MAX(p1.x, p2.x) + 1, MAX(p1.y, p2.y) + 1);
- frameRect(rect, color);
- }
+
void drawRect(const Common::Rect &destRect, int color) {
Common::Rect rect(w , h);
rect.clip(destRect);
@@ -198,7 +195,7 @@ public:
// WARNING: This method does not add a dirty rectangle automatically.
// Whenever it gets called, the corresponding caller must take care
// to add the corresponding dirty rectangle itself
- void drawPolyLine(Common::Point *points, int count, int color) {
+ void drawPolyLine(const Common::Point *points, int count, int color) {
_backBuffer.drawPolyLine(points, count, color);
}
diff --git a/engines/saga/image.cpp b/engines/saga/image.cpp
index 7d8eb83550..50aac48771 100644
--- a/engines/saga/image.cpp
+++ b/engines/saga/image.cpp
@@ -53,8 +53,7 @@ int SagaEngine::decodeBGImage(const byte *image_data, size_t image_size,
int modex_height;
const byte *RLE_data_ptr;
size_t RLE_data_len;
- byte *decode_buf;
- size_t decode_buf_len;
+ ByteArray decodeBuffer;
byte *out_buf;
size_t out_buf_len;
@@ -75,28 +74,23 @@ int SagaEngine::decodeBGImage(const byte *image_data, size_t image_size,
modex_height = granulate(hdr.height, 4);
- decode_buf_len = hdr.width * modex_height;
- decode_buf = (byte *)malloc(decode_buf_len);
+ decodeBuffer.resize(hdr.width * modex_height);
out_buf_len = hdr.width * hdr.height;
out_buf = (byte *)malloc(out_buf_len);
- if (decodeBGImageRLE(RLE_data_ptr,
- RLE_data_len, decode_buf, decode_buf_len) != SUCCESS) {
- free(decode_buf);
+ if (decodeBGImageRLE(RLE_data_ptr, RLE_data_len, decodeBuffer) != SUCCESS) {
free(out_buf);
return FAILURE;
}
- unbankBGImage(out_buf, decode_buf, hdr.width, hdr.height);
+ unbankBGImage(out_buf, decodeBuffer.getBuffer(), hdr.width, hdr.height);
// For some reason bg images in IHNM are upside down
if (getGameId() == GID_IHNM && !flip) {
flipImage(out_buf, hdr.width, hdr.height);
}
- free(decode_buf);
-
*output_buf_len = out_buf_len;
*output_buf = out_buf;
@@ -106,9 +100,10 @@ int SagaEngine::decodeBGImage(const byte *image_data, size_t image_size,
return SUCCESS;
}
-int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len) {
+int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray &outbuf) {
const byte *inbuf_ptr;
byte *outbuf_ptr;
+ byte *outbuf_start;
uint32 inbuf_remain;
const byte *inbuf_end;
@@ -134,13 +129,13 @@ int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outb
inbuf_ptr = inbuf;
inbuf_remain = inbuf_len;
- outbuf_ptr = outbuf;
- outbuf_remain = outbuf_len;
+ outbuf_start = outbuf_ptr = outbuf.getBuffer();
+ outbuf_remain = outbuf.size();
+ outbuf_end = (outbuf_start + outbuf_remain) - 1;
+ memset(outbuf_start, 0, outbuf_remain);
inbuf_end = (inbuf + inbuf_len) - 1;
- outbuf_end = (outbuf + outbuf_len) - 1;
- memset(outbuf, 0, outbuf_len);
while ((inbuf_remain > 1) && (outbuf_remain > 0) && !decode_err) {
@@ -194,7 +189,7 @@ int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outb
runcount = ((mark_byte >> 3) & 0x07U) + 3;
backtrack_amount = *inbuf_ptr;
- if (!inbuf_remain || (backtrack_amount > (outbuf_ptr - outbuf)) || (runcount > outbuf_remain)) {
+ if (!inbuf_remain || (backtrack_amount > (outbuf_ptr - outbuf_start)) || (runcount > outbuf_remain)) {
return FAILURE;
}
@@ -277,7 +272,7 @@ int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outb
inbuf_ptr++;
runcount = *inbuf_ptr++;
- if ((backtrack_amount > (outbuf_ptr - outbuf)) || (outbuf_remain < runcount)) {
+ if ((backtrack_amount > (outbuf_ptr - outbuf_start)) || (outbuf_remain < runcount)) {
return FAILURE;
}
@@ -301,15 +296,17 @@ int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outb
int SagaEngine::flipImage(byte *img_buf, int columns, int scanlines) {
int line;
- byte *tmp_scan;
+ ByteArray tmp_scan;
byte *flip_p1;
byte *flip_p2;
+ byte *flip_tmp;
int flipcount = scanlines / 2;
- tmp_scan = (byte *)malloc(columns);
- if (tmp_scan == NULL) {
+ tmp_scan.resize(columns);
+ flip_tmp = tmp_scan.getBuffer();
+ if (flip_tmp == NULL) {
return FAILURE;
}
@@ -317,15 +314,13 @@ int SagaEngine::flipImage(byte *img_buf, int columns, int scanlines) {
flip_p2 = img_buf + (columns * (scanlines - 1));
for (line = 0; line < flipcount; line++) {
- memcpy(tmp_scan, flip_p1, columns);
+ memcpy(flip_tmp, flip_p1, columns);
memcpy(flip_p1, flip_p2, columns);
- memcpy(flip_p2, tmp_scan, columns);
+ memcpy(flip_p2, flip_tmp, columns);
flip_p1 += columns;
flip_p2 -= columns;
}
- free(tmp_scan);
-
return SUCCESS;
}
diff --git a/engines/saga/interface.cpp b/engines/saga/interface.cpp
index 95f7f5501f..cb879f5ed2 100644
--- a/engines/saga/interface.cpp
+++ b/engines/saga/interface.cpp
@@ -2420,18 +2420,9 @@ void Interface::drawVerbPanelText(PanelButton *panelButton, KnownColor textKnown
// Converse stuff
-void Interface::converseInit() {
- for (int i = 0; i < CONVERSE_MAX_TEXTS; i++)
- _converseText[i].text = NULL;
- converseClear();
-}
-
void Interface::converseClear() {
for (int i = 0; i < CONVERSE_MAX_TEXTS; i++) {
- if (_converseText[i].text != NULL) {
- free(_converseText[i].text);
- _converseText[i].text = NULL;
- }
+ _converseText[i].text.clear();
_converseText[i].stringNum = -1;
_converseText[i].replyId = 0;
_converseText[i].replyFlags = 0;
@@ -2477,8 +2468,8 @@ bool Interface::converseAddText(const char *text, int strId, int replyId, byte r
return true;
}
- _converseText[_converseTextCount].text = (char *)malloc(i + 1);
- strncpy(_converseText[_converseTextCount].text, _converseWorkString, i);
+ _converseText[_converseTextCount].text.resize(i + 1);
+ strncpy(&_converseText[_converseTextCount].text.front(), _converseWorkString, i);
_converseText[_converseTextCount].strId = strId;
_converseText[_converseTextCount].text[i] = 0;
@@ -2588,7 +2579,7 @@ void Interface::converseDisplayTextLines() {
rect.left += 8;
_vm->_gfx->drawRect(rect, backgnd);
- str = _converseText[relPos].text;
+ str = &_converseText[relPos].text.front();
if (_converseText[relPos].textNum == 0) { // first entry
textPoint.x = rect.left - 6;
diff --git a/engines/saga/interface.h b/engines/saga/interface.h
index 0fbe5bef20..f6e147bc3e 100644
--- a/engines/saga/interface.h
+++ b/engines/saga/interface.h
@@ -164,7 +164,7 @@ struct InterfacePanel {
};
struct Converse {
- char *text;
+ Common::Array<char> text;
int strId;
int stringNum;
int textNum;
@@ -356,7 +356,6 @@ private:
void processStatusTextInput(Common::KeyState keystate);
public:
- void converseInit();
void converseClear();
bool converseAddText(const char *text, int strId, int replyId, byte replyFlags, int replyBit);
void converseDisplayText();
diff --git a/engines/saga/introproc_ihnm.cpp b/engines/saga/introproc_ihnm.cpp
index e149753dfd..d38b71e7a5 100644
--- a/engines/saga/introproc_ihnm.cpp
+++ b/engines/saga/introproc_ihnm.cpp
@@ -83,7 +83,7 @@ int Scene::IHNMStartProc() {
}
_vm->_music->setVolume(0, 1000);
- _vm->_anim->freeCutawayList();
+ _vm->_anim->clearCutawayList();
// Queue first scene
firstScene.loadFlag = kLoadBySceneNumber;
@@ -114,7 +114,7 @@ int Scene::IHNMCreditsProc() {
}
_vm->_music->setVolume(0, 1000);
- _vm->_anim->freeCutawayList();
+ _vm->_anim->clearCutawayList();
return SUCCESS;
}
diff --git a/engines/saga/isomap.cpp b/engines/saga/isomap.cpp
index 197055a45d..00903c4ae4 100644
--- a/engines/saga/isomap.cpp
+++ b/engines/saga/isomap.cpp
@@ -85,16 +85,21 @@ static const IsoMap::TilePoint hardDirTable[8] = {
{ 0, 1, 0, SAGA_STRAIGHT_HARD_COST},
};
-IsoMap::IsoMap(SagaEngine *vm) : _vm(vm) {
- _tileData = NULL;
- _tileDataLength = 0;
+static const int16 directions[8][2] = {
+ { 16, 16},
+ { 16, 0},
+ { 16, -16},
+ { 0, -16},
+ { -16, -16},
+ { -16, 0},
+ { -16, 16},
+ { 0, 16}
+};
- _multiTableData = NULL;
- _multiDataCount = 0;
+IsoMap::IsoMap(SagaEngine *vm) : _vm(vm) {
_viewScroll.x = (128 - 8) * 16;
_viewScroll.x = (128 - 8) * 16 - 64;
_viewDiff = 1;
-
}
void IsoMap::loadImages(const byte *resourcePointer, size_t resourceLength) {
@@ -112,7 +117,8 @@ void IsoMap::loadImages(const byte *resourcePointer, size_t resourceLength) {
i = readS.readUint16();
i = i / SAGA_ISOTILEDATA_LEN;
_tilesTable.resize(i);
-
+ Common::Array<size_t> tempOffsets;
+ tempOffsets.resize(_tilesTable.size());
readS.seek(0);
@@ -120,7 +126,7 @@ void IsoMap::loadImages(const byte *resourcePointer, size_t resourceLength) {
tileData = &_tilesTable[i];
tileData->height = readS.readByte();
tileData->attributes = readS.readSByte();
- tileData->offset = readS.readUint16();
+ tempOffsets[i] = readS.readUint16();
tileData->terrainMask = readS.readUint16();
tileData->FGDBGDAttr = readS.readByte();
readS.readByte(); //skip
@@ -128,12 +134,11 @@ void IsoMap::loadImages(const byte *resourcePointer, size_t resourceLength) {
offsetDiff = readS.pos();
- _tileDataLength = resourceLength - offsetDiff;
- _tileData = (byte*)malloc(_tileDataLength);
- memcpy(_tileData, resourcePointer + offsetDiff, _tileDataLength);
+ _tileData.resize(resourceLength - offsetDiff);
+ memcpy(_tileData.getBuffer(), resourcePointer + offsetDiff, _tileData.size());
for (i = 0; i < _tilesTable.size(); i++) {
- _tilesTable[i].offset -= offsetDiff;
+ _tilesTable[i].tilePointer = _tileData.getBuffer() + tempOffsets[i] - offsetDiff;
}
}
@@ -240,26 +245,21 @@ void IsoMap::loadMulti(const byte * resourcePointer, size_t resourceLength) {
_multiTable[i].offset -= offsetDiff;
}
- _multiDataCount = (readS.size() - readS.pos()) / 2;
+ uint16 multiDataCount = (readS.size() - readS.pos()) / 2;
- _multiTableData = (int16 *)malloc(_multiDataCount * sizeof(*_multiTableData));
- for (i = 0; i < _multiDataCount; i++) {
+ _multiTableData.resize(multiDataCount);
+ for (i = 0; i < _multiTableData.size(); i++) {
_multiTableData[i] = readS.readSint16();
}
}
-void IsoMap::freeMem() {
+void IsoMap::clear() {
_tilesTable.clear();
_tilePlatformList.clear();
_metaTileList.clear();
_multiTable.clear();
-
- free(_tileData);
- _tileData = NULL;
-
- free(_multiTableData);
- _multiTableData = NULL;
- _multiDataCount = 0;
+ _tileData.clear();
+ _multiTableData.clear();
}
void IsoMap::adjustScroll(bool jump) {
@@ -344,12 +344,12 @@ int16 IsoMap::findMulti(int16 tileIndex, int16 absU, int16 absV, int16 absH) {
state = multiTileEntryData->currentState;
offset = (ru + state * multiTileEntryData->uSize) * multiTileEntryData->vSize + rv;
- offset *= sizeof(*_multiTableData);
+ offset *= sizeof(int16);
offset += multiTileEntryData->offset;
- if (offset + sizeof(*_multiTableData) - 1 >= _multiDataCount * sizeof(*_multiTableData)) {
+ if (offset + sizeof(int16) > _multiTableData.size() * sizeof(int16)) {
error("wrong multiTileEntryData->offset");
}
- tiles = (int16*)((byte*)_multiTableData + offset);
+ tiles = (int16*)((byte*)&_multiTableData.front() + offset);
tileIndex = *tiles;
if (tileIndex >= 256) {
warning("something terrible happened");
@@ -707,7 +707,7 @@ void IsoMap::drawTile(uint16 tileIndex, const Point &point, const Location *loca
return;
}
- tilePointer = _tileData + _tilesTable[tileIndex].offset;
+ tilePointer = _tilesTable[tileIndex].tilePointer;
height = _tilesTable[tileIndex].height;
if ((height <= 8) || (height > 64)) {
@@ -1613,19 +1613,6 @@ void IsoMap::setTileDoorState(int doorNumber, int doorState) {
multiTileEntryData->currentState = doorState;
}
-static const int16 directions[8][2] = {
- { 16, 16},
- { 16, 0},
- { 16, -16},
- { 0, -16},
- { -16, -16},
- { -16, 0},
- { -16, 16},
- { 0, 16}
-};
-
-
-
bool IsoMap::nextTileTarget(ActorData* actor) {
uint16 dir;
diff --git a/engines/saga/isomap.h b/engines/saga/isomap.h
index 46173e2b13..e2502d4a77 100644
--- a/engines/saga/isomap.h
+++ b/engines/saga/isomap.h
@@ -95,7 +95,7 @@ enum TileMapEdgeType {
struct IsoTileData {
byte height;
int8 attributes;
- size_t offset;
+ byte *tilePointer;
uint16 terrainMask;
byte FGDBGDAttr;
int8 GetMaskRule() const {
@@ -154,14 +154,13 @@ class IsoMap {
public:
IsoMap(SagaEngine *vm);
~IsoMap() {
- freeMem();
}
void loadImages(const byte * resourcePointer, size_t resourceLength);
void loadMap(const byte * resourcePointer, size_t resourceLength);
void loadPlatforms(const byte * resourcePointer, size_t resourceLength);
void loadMetaTiles(const byte * resourcePointer, size_t resourceLength);
void loadMulti(const byte * resourcePointer, size_t resourceLength);
- void freeMem();
+ void clear();
void draw();
void drawSprite(SpriteList &spriteList, int spriteNumber, const Location &location, const Point &screenPosition, int scale);
void adjustScroll(bool jump);
@@ -213,16 +212,14 @@ private:
IsoTileData *getTile(int16 u, int16 v, int16 z);
- byte *_tileData;
- size_t _tileDataLength;
+ ByteArray _tileData;
Common::Array<IsoTileData> _tilesTable;
Common::Array<TilePlatformData> _tilePlatformList;
Common::Array<MetaTileData> _metaTileList;
Common::Array<MultiTileEntryData> _multiTable;
- uint16 _multiDataCount;
- int16 *_multiTableData;
+ Common::Array<int16> _multiTableData;
TileMapData _tileMap;
diff --git a/engines/saga/itedata.cpp b/engines/saga/itedata.cpp
index 7503818319..ab0aa12d18 100644
--- a/engines/saga/itedata.cpp
+++ b/engines/saga/itedata.cpp
@@ -269,7 +269,7 @@ ObjectTableData ITE_ObjectTable[ITE_OBJECTCOUNT] = {
{ 54, 281, 620, 352, 0, 80, 46, 0 } // Orb of Storms in Dam Lab
};
-FxTable ITE_SfxTable[ITE_SFXCOUNT] = {
+IteFxTable ITE_SfxTable[ITE_SFXCOUNT] = {
{ 14, 127 }, // Door open
{ 15, 127 }, // Door close
{ 16, 63 }, // Rush water (floppy volume: 127)
diff --git a/engines/saga/itedata.h b/engines/saga/itedata.h
index 71041902bc..f0f626a51a 100644
--- a/engines/saga/itedata.h
+++ b/engines/saga/itedata.h
@@ -77,16 +77,16 @@ struct ObjectTableData {
uint16 interactBits;
};
-struct FxTable {
- int res;
- int vol;
+struct IteFxTable {
+ byte res;
+ byte vol;
};
#define ITE_OBJECTCOUNT 39
#define ITE_SFXCOUNT 63
extern ObjectTableData ITE_ObjectTable[ITE_OBJECTCOUNT];
-extern FxTable ITE_SfxTable[ITE_SFXCOUNT];
+extern IteFxTable ITE_SfxTable[ITE_SFXCOUNT];
extern const char *ITEinterfaceTextStrings[][53];
diff --git a/engines/saga/music.cpp b/engines/saga/music.cpp
index 199b0dfd8a..3fa38d30fb 100644
--- a/engines/saga/music.cpp
+++ b/engines/saga/music.cpp
@@ -182,9 +182,6 @@ Music::Music(SagaEngine *vm, Audio::Mixer *mixer) : _vm(vm), _mixer(mixer) {
_parser->setTimerRate(_driver->getBaseTempo());
_parser->property(MidiParser::mpCenterPitchWheelOnUnload, 1);
- _songTableLen = 0;
- _songTable = 0;
-
_midiMusicData = NULL;
_digitalMusic = false;
}
@@ -197,7 +194,6 @@ Music::~Music() {
_parser->setMidiDriver(NULL);
delete _parser;
- free(_songTable);
free(_midiMusicData);
}
@@ -260,7 +256,7 @@ void Music::play(uint32 resourceId, MusicFlags flags) {
Audio::SeekableAudioStream *audioStream = NULL;
byte *resourceData;
size_t resourceSize;
- uint32 loopStart;
+ uint32 loopStart = 0;
debug(2, "Music::play %d, %d", resourceId, flags);
diff --git a/engines/saga/music.h b/engines/saga/music.h
index e3d5723145..3219cebc03 100644
--- a/engines/saga/music.h
+++ b/engines/saga/music.h
@@ -106,8 +106,7 @@ public:
void setVolume(int volume, int time = 1);
int getVolume() { return _currentVolume; }
- int32 *_songTable;
- int _songTableLen;
+ Common::Array<int32> _songTable;
private:
SagaEngine *_vm;
diff --git a/engines/saga/objectmap.cpp b/engines/saga/objectmap.cpp
index 02179d1d49..a74a620ce7 100644
--- a/engines/saga/objectmap.cpp
+++ b/engines/saga/objectmap.cpp
@@ -45,84 +45,58 @@
namespace Saga {
-HitZone::HitZone(MemoryReadStreamEndian *readStream, int index, int sceneNumber): _index(index) {
- int i, j;
- HitZone::ClickArea *clickArea;
- Point *point;
-
+void HitZone::load(SagaEngine *vm, MemoryReadStreamEndian *readStream, int index, int sceneNumber) {
+ _index = index;
_flags = readStream->readByte();
- _clickAreasCount = readStream->readByte();
+ _clickAreas.resize(readStream->readByte());
_rightButtonVerb = readStream->readByte();
readStream->readByte(); // pad
_nameIndex = readStream->readUint16();
_scriptNumber = readStream->readUint16();
- _clickAreas = (HitZone::ClickArea *)malloc(_clickAreasCount * sizeof(*_clickAreas));
-
- if (_clickAreas == NULL) {
- memoryError("HitZone::HitZone");
- }
-
- for (i = 0; i < _clickAreasCount; i++) {
- clickArea = &_clickAreas[i];
- clickArea->pointsCount = readStream->readUint16LE();
+ for (ClickAreas::iterator i = _clickAreas.begin(); i != _clickAreas.end(); ++i) {
+ i->resize(readStream->readUint16LE());
- assert(clickArea->pointsCount);
+ assert(!i->empty());
- clickArea->points = (Point *)malloc(clickArea->pointsCount * sizeof(*(clickArea->points)));
- if (clickArea->points == NULL) {
- memoryError("HitZone::HitZone");
- }
-
- for (j = 0; j < clickArea->pointsCount; j++) {
- point = &clickArea->points[j];
- point->x = readStream->readSint16();
- point->y = readStream->readSint16();
+ for (ClickArea::iterator j = i->begin(); j != i->end(); ++j) {
+ j->x = readStream->readSint16();
+ j->y = readStream->readSint16();
// WORKAROUND: bug #1259608: "ITE: Riff ignores command in Ferret merchant center"
// Apparently ITE Mac version has bug in game data. Both ObjectMap and ActionMap
// for exit area are little taller (y = 123) and thus Riff goes to exit
// when clicked on barrel of nails.
- if (sceneNumber == 18 && index == 0 && i == 0 && j == 0 && point->y == 123)
- point->y = 129;
+ if (vm->getGameId() == GID_ITE) {
+ if (sceneNumber == 18 && index == 0 && (i == _clickAreas.begin()) && (j == i->begin()) && j->y == 123) {
+ j->y = 129;
+ }
+ }
}
}
}
-HitZone::~HitZone() {
- for (int i = 0; i < _clickAreasCount; i++) {
- free(_clickAreas[i].points);
- }
- free(_clickAreas);
-}
-
bool HitZone::getSpecialPoint(Point &specialPoint) const {
- int i, pointsCount;
- HitZone::ClickArea *clickArea;
- Point *points;
-
- for (i = 0; i < _clickAreasCount; i++) {
- clickArea = &_clickAreas[i];
- pointsCount = clickArea->pointsCount;
- points = clickArea->points;
- if (pointsCount == 1) {
- specialPoint = points[0];
+ for (ClickAreas::const_iterator i = _clickAreas.begin(); i != _clickAreas.end(); ++i) {
+ if (i->size() == 1) {
+ specialPoint = (*i)[0];
return true;
}
}
return false;
}
+
bool HitZone::hitTest(const Point &testPoint) {
- int i, pointsCount;
- HitZone::ClickArea *clickArea;
- Point *points;
+ const Point *points;
+ uint pointsCount;
if (_flags & kHitZoneEnabled) {
- for (i = 0; i < _clickAreasCount; i++) {
- clickArea = &_clickAreas[i];
- pointsCount = clickArea->pointsCount;
- points = clickArea->points;
-
+ for (ClickAreas::const_iterator i = _clickAreas.begin(); i != _clickAreas.end(); ++i) {
+ pointsCount = i->size();
+ if (pointsCount < 2) {
+ continue;
+ }
+ points = &i->front();
if (pointsCount == 2) {
// Hit-test a box region
if ((testPoint.x >= points[0].x) &&
@@ -132,11 +106,9 @@ bool HitZone::hitTest(const Point &testPoint) {
return true;
}
} else {
- if (pointsCount > 2) {
- // Hit-test a polygon
- if (hitTestPoly(points, pointsCount, testPoint)) {
- return true;
- }
+ // Hit-test a polygon
+ if (hitTestPoly(points, pointsCount, testPoint)) {
+ return true;
}
}
}
@@ -146,26 +118,25 @@ bool HitZone::hitTest(const Point &testPoint) {
#ifdef SAGA_DEBUG
void HitZone::draw(SagaEngine *vm, int color) {
- int i, pointsCount, j;
+ int pointsCount, j;
Location location;
- HitZone::ClickArea *clickArea;
- Point *points;
+ HitZone::ClickArea tmpPoints;
+ const Point *points;
Point specialPoint1;
Point specialPoint2;
- for (i = 0; i < _clickAreasCount; i++) {
- clickArea = &_clickAreas[i];
- pointsCount = clickArea->pointsCount;
+ for (ClickAreas::const_iterator i = _clickAreas.begin(); i != _clickAreas.end(); ++i) {
+ pointsCount = i->size();
+ points = &i->front();
if (vm->_scene->getFlags() & kSceneFlagISO) {
- points = (Point*)malloc(sizeof(Point) * pointsCount);
+ tmpPoints.resize(pointsCount);
for (j = 0; j < pointsCount; j++) {
- location.u() = clickArea->points[j].x;
- location.v() = clickArea->points[j].y;
+ location.u() = points[j].x;
+ location.v() = points[j].y;
location.z = 0;
- vm->_isoMap->tileCoordsToScreenPoint(location, points[j]);
+ vm->_isoMap->tileCoordsToScreenPoint(location, tmpPoints[j]);
}
- } else {
- points = clickArea->points;
+ points = &tmpPoints.front();
}
if (pointsCount == 2) {
@@ -179,10 +150,6 @@ void HitZone::draw(SagaEngine *vm, int color) {
vm->_gfx->drawPolyLine(points, pointsCount, color);
}
}
- if (vm->_scene->getFlags() & kSceneFlagISO) {
- free(points);
- }
-
}
if (getSpecialPoint(specialPoint1)) {
specialPoint2 = specialPoint1;
@@ -197,7 +164,11 @@ void HitZone::draw(SagaEngine *vm, int color) {
// Loads an object map resource ( objects ( clickareas ( points ) ) )
void ObjectMap::load(const byte *resourcePointer, size_t resourceLength) {
- int i;
+ uint i;
+
+ if (!_hitZoneList.empty()) {
+ error("ObjectMap::load _hitZoneList not empty");
+ }
if (resourceLength == 0) {
return;
@@ -209,43 +180,21 @@ void ObjectMap::load(const byte *resourcePointer, size_t resourceLength) {
MemoryReadStreamEndian readS(resourcePointer, resourceLength, _vm->isBigEndian());
- _hitZoneListCount = readS.readSint16();
- if (_hitZoneListCount < 0) {
- error("ObjectMap::load _hitZoneListCount < 0");
- }
-
- if (_hitZoneList)
- error("ObjectMap::load _hitZoneList != NULL");
+ _hitZoneList.resize(readS.readUint16());
- _hitZoneList = (HitZone **) malloc(_hitZoneListCount * sizeof(HitZone *));
- if (_hitZoneList == NULL) {
- memoryError("ObjectMap::load");
- }
-
- for (i = 0; i < _hitZoneListCount; i++) {
- _hitZoneList[i] = new HitZone(&readS, i, _vm->_scene->currentSceneNumber());
+ for (i = 0; i < _hitZoneList.size(); i++) {
+ _hitZoneList[i].load(_vm, &readS, i, _vm->_scene->currentSceneNumber());
}
}
-void ObjectMap::freeMem() {
- int i;
-
- if (_hitZoneList) {
- for (i = 0; i < _hitZoneListCount; i++) {
- delete _hitZoneList[i];
- }
-
- free(_hitZoneList);
- _hitZoneList = NULL;
- }
- _hitZoneListCount = 0;
+void ObjectMap::clear() {
+ _hitZoneList.clear();
}
-
#ifdef SAGA_DEBUG
void ObjectMap::draw(const Point& testPoint, int color, int color2) {
- int i;
- int hitZoneIndex;
+ uint i;
+ uint hitZoneIndex;
char txtBuf[32];
Point pickPoint;
Point textPoint;
@@ -260,8 +209,8 @@ void ObjectMap::draw(const Point& testPoint, int color, int color2) {
hitZoneIndex = hitTest(pickPoint);
- for (i = 0; i < _hitZoneListCount; i++) {
- _hitZoneList[i]->draw(_vm, (hitZoneIndex == i) ? color2 : color);
+ for (i = 0; i < _hitZoneList.size(); i++) {
+ _hitZoneList[i].draw(_vm, (hitZoneIndex == i) ? color2 : color);
}
if (hitZoneIndex != -1) {
@@ -274,11 +223,11 @@ void ObjectMap::draw(const Point& testPoint, int color, int color2) {
#endif
int ObjectMap::hitTest(const Point& testPoint) {
- int i;
+ uint i;
// Loop through all scene objects
- for (i = 0; i < _hitZoneListCount; i++) {
- if (_hitZoneList[i]->hitTest(testPoint)) {
+ for (i = 0; i < _hitZoneList.size(); i++) {
+ if (_hitZoneList[i].hitTest(testPoint)) {
return i;
}
}
@@ -287,7 +236,7 @@ int ObjectMap::hitTest(const Point& testPoint) {
}
void ObjectMap::cmdInfo() {
- _vm->_console->DebugPrintf("%d zone(s) loaded.\n\n", _hitZoneListCount);
+ _vm->_console->DebugPrintf("%d zone(s) loaded.\n\n", _hitZoneList.size());
}
} // End of namespace Saga
diff --git a/engines/saga/objectmap.h b/engines/saga/objectmap.h
index df0dcffe57..727c5f1faa 100644
--- a/engines/saga/objectmap.h
+++ b/engines/saga/objectmap.h
@@ -33,14 +33,10 @@ namespace Saga {
class HitZone {
private:
- struct ClickArea {
- int pointsCount;
- Point *points;
- };
-
+ typedef Common::Array<Point> ClickArea;
+ typedef Common::Array<ClickArea> ClickAreas;
public:
- HitZone(MemoryReadStreamEndian *readStream, int index, int sceneNumber);
- ~HitZone();
+ void load(SagaEngine *vm, MemoryReadStreamEndian *readStream, int index, int sceneNumber);
int getNameIndex() const {
return _nameIndex;
@@ -76,40 +72,37 @@ public:
return objectIndexToId(kGameObjectStepZone, _index);
}
bool getSpecialPoint(Point &specialPoint) const;
+#ifdef SAGA_DEBUG
void draw(SagaEngine *vm, int color); // for debugging
+#endif
bool hitTest(const Point &testPoint);
private:
int _flags; // Saga::HitZoneFlags
- int _clickAreasCount;
int _rightButtonVerb;
int _nameIndex;
int _scriptNumber;
int _index;
- ClickArea *_clickAreas;
+ ClickAreas _clickAreas;
};
class ObjectMap {
public:
ObjectMap(SagaEngine *vm) : _vm(vm) {
- _hitZoneList = NULL;
- _hitZoneListCount = 0;
-
- }
- ~ObjectMap() {
- freeMem();
}
void load(const byte *resourcePointer, size_t resourceLength);
- void freeMem();
+ void clear();
+#ifdef SAGA_DEBUG
void draw(const Point& testPoint, int color, int color2); // for debugging
+#endif
int hitTest(const Point& testPoint);
HitZone *getHitZone(int16 index) {
- if ((index < 0) || (index >= _hitZoneListCount)) {
+ if (uint(index) >= _hitZoneList.size()) {
return NULL;
}
- return _hitZoneList[index];
+ return &_hitZoneList[index];
}
void cmdInfo();
@@ -117,8 +110,7 @@ public:
private:
SagaEngine *_vm;
- int _hitZoneListCount;
- HitZone **_hitZoneList;
+ Common::Array<HitZone> _hitZoneList;
};
} // End of namespace Saga
diff --git a/engines/saga/palanim.cpp b/engines/saga/palanim.cpp
index dc892b845a..48eb0f5ec9 100644
--- a/engines/saga/palanim.cpp
+++ b/engines/saga/palanim.cpp
@@ -35,83 +35,54 @@
namespace Saga {
PalAnim::PalAnim(SagaEngine *vm) : _vm(vm) {
- _loaded = false;
- _entryCount = 0;
- _entries = NULL;
}
-PalAnim::~PalAnim() {
-}
-
-int PalAnim::loadPalAnim(const byte *resdata, size_t resdata_len) {
- void *test_p;
+void PalAnim::loadPalAnim(const byte *resdata, size_t resdata_len) {
- uint16 i;
-
- if (_loaded) {
- freePalAnim();
- }
+ clear();
if (resdata == NULL) {
- return FAILURE;
+ return;
}
MemoryReadStreamEndian readS(resdata, resdata_len, _vm->isBigEndian());
if (_vm->getGameId() == GID_IHNM) {
- return SUCCESS;
+ return;
}
- _entryCount = readS.readUint16();
-
- debug(3, "PalAnim::loadPalAnim(): Loading %d PALANIM entries.", _entryCount);
+ _entries.resize(readS.readUint16());
- test_p = malloc(_entryCount * sizeof(PalanimEntry));
- _entries = (PalanimEntry *)test_p;
+ debug(3, "PalAnim::loadPalAnim(): Loading %d PALANIM entries.", _entries.size());
- for (i = 0; i < _entryCount; i++) {
- int color_count;
- int pal_count;
- int p, c;
+ for (Common::Array<PalanimEntry>::iterator i = _entries.begin(); i != _entries.end(); ++i) {
+
+ i->cycle = 0;
- _entries[i].cycle = 0;
+ i->colors.resize(readS.readUint16());
+ debug(2, "PalAnim::loadPalAnim(): Loading %d SAGA_COLOR structures.", i->colors.size());
- color_count = readS.readUint16();
- pal_count = readS.readUint16();
+ i->palIndex.resize(readS.readUint16());
+ debug(2, "PalAnim::loadPalAnim(): Loading %d palette indices.\n", i->palIndex.size());
- _entries[i].pal_count = pal_count;
- _entries[i].color_count = color_count;
- debug(2, "PalAnim::loadPalAnim(): Entry %d: Loading %d palette indices.\n", i, pal_count);
-
- test_p = malloc(sizeof(char) * pal_count);
- _entries[i].pal_index = (byte *)test_p;
-
- debug(2, "PalAnim::loadPalAnim(): Entry %d: Loading %d SAGA_COLOR structures.", i, color_count);
-
- test_p = malloc(sizeof(Color) * color_count);
- _entries[i].colors = (Color *)test_p;
-
- for (p = 0; p < pal_count; p++) {
- _entries[i].pal_index[p] = readS.readByte();
+ for (uint j = 0; j < i->palIndex.size(); j++) {
+ i->palIndex[j] = readS.readByte();
}
- for (c = 0; c < color_count; c++) {
- _entries[i].colors[c].red = readS.readByte();
- _entries[i].colors[c].green = readS.readByte();
- _entries[i].colors[c].blue = readS.readByte();
+ for (Common::Array<Color>::iterator j = i->colors.begin(); j != i->colors.end(); ++j) {
+ j->red = readS.readByte();
+ j->green = readS.readByte();
+ j->blue = readS.readByte();
}
}
-
- _loaded = true;
- return SUCCESS;
}
-int PalAnim::cycleStart() {
+void PalAnim::cycleStart() {
Event event;
- if (!_loaded) {
- return FAILURE;
+ if (_entries.empty()) {
+ return;
}
event.type = kEvTOneshot;
@@ -119,42 +90,40 @@ int PalAnim::cycleStart() {
event.op = kEventCycleStep;
event.time = PALANIM_CYCLETIME;
_vm->_events->queue(&event);
-
- return SUCCESS;
}
-int PalAnim::cycleStep(int vectortime) {
+void PalAnim::cycleStep(int vectortime) {
static PalEntry pal[256];
- uint16 pal_index;
- uint16 col_index;
+ uint16 palIndex;
+ uint16 colIndex;
- uint16 i, j;
+ uint16 j;
uint16 cycle;
- uint16 cycle_limit;
+ uint16 cycleLimit;
Event event;
- if (!_loaded) {
- return FAILURE;
+ if (_entries.empty()) {
+ return;
}
_vm->_gfx->getCurrentPal(pal);
- for (i = 0; i < _entryCount; i++) {
- cycle = _entries[i].cycle;
- cycle_limit = _entries[i].color_count;
- for (j = 0; j < _entries[i].pal_count; j++) {
- pal_index = (unsigned char)_entries[i].pal_index[j];
- col_index = (cycle + j) % cycle_limit;
- pal[pal_index].red = (byte) _entries[i].colors[col_index].red;
- pal[pal_index].green = (byte) _entries[i].colors[col_index].green;
- pal[pal_index].blue = (byte) _entries[i].colors[col_index].blue;
+ for (Common::Array<PalanimEntry>::iterator i = _entries.begin(); i != _entries.end(); ++i) {
+ cycle = i->cycle;
+ cycleLimit = i->colors.size();
+ for (j = 0; j < i->palIndex.size(); j++) {
+ palIndex = i->palIndex[j];
+ colIndex = (cycle + j) % cycleLimit;
+ pal[palIndex].red = (byte) i->colors[colIndex].red;
+ pal[palIndex].green = (byte) i->colors[colIndex].green;
+ pal[palIndex].blue = (byte) i->colors[colIndex].blue;
}
- _entries[i].cycle++;
+ i->cycle++;
- if (_entries[i].cycle == cycle_limit) {
- _entries[i].cycle = 0;
+ if (i->cycle == cycleLimit) {
+ i->cycle = 0;
}
}
@@ -169,30 +138,12 @@ int PalAnim::cycleStep(int vectortime) {
event.time = vectortime + PALANIM_CYCLETIME;
_vm->_events->queue(&event);
- return SUCCESS;
}
-int PalAnim::freePalAnim() {
- uint16 i;
-
- if (!_loaded) {
- return FAILURE;
- }
-
- for (i = 0; i < _entryCount; i++) {
- debug(2, "PalAnim::freePalAnim(): Entry %d: Freeing colors.", i);
- free(_entries[i].colors);
- debug(2, "PalAnim::freePalAnim(): Entry %d: Freeing indices.", i);
- free(_entries[i].pal_index);
- }
-
- debug(3, "PalAnim::freePalAnim(): Freeing entries.");
-
- free(_entries);
-
- _loaded = false;
-
- return SUCCESS;
+void PalAnim::clear() {
+ debug(3, "PalAnim::clear()");
+
+ _entries.clear();
}
} // End of namespace Saga
diff --git a/engines/saga/palanim.h b/engines/saga/palanim.h
index 52002e01c3..3767f0367d 100644
--- a/engines/saga/palanim.h
+++ b/engines/saga/palanim.h
@@ -33,29 +33,24 @@ namespace Saga {
#define PALANIM_CYCLETIME 100
struct PalanimEntry {
- uint16 pal_count;
- uint16 color_count;
uint16 cycle;
- byte *pal_index;
- Color *colors;
+ ByteArray palIndex;
+ Common::Array<Color> colors;
};
class PalAnim {
public:
PalAnim(SagaEngine *vm);
- ~PalAnim();
- int loadPalAnim(const byte *, size_t);
- int cycleStart();
- int cycleStep(int vectortime);
- int freePalAnim();
+ void loadPalAnim(const byte *, size_t);
+ void cycleStart();
+ void cycleStep(int vectortime);
+ void clear();
private:
SagaEngine *_vm;
- bool _loaded;
- uint16 _entryCount;
- PalanimEntry *_entries;
+ Common::Array<PalanimEntry> _entries;
};
} // End of namespace Saga
diff --git a/engines/saga/resource.cpp b/engines/saga/resource.cpp
index 7d82aa4bda..028164158f 100644
--- a/engines/saga/resource.cpp
+++ b/engines/saga/resource.cpp
@@ -43,8 +43,7 @@ bool ResourceContext::loadResV1(uint32 contextOffset, uint32 contextSize) {
size_t i;
bool result;
byte tableInfo[RSC_TABLEINFO_SIZE];
- byte *tableBuffer;
- size_t tableSize;
+ ByteArray tableBuffer;
uint32 count;
uint32 resourceTableOffset;
ResourceData *resourceData;
@@ -70,17 +69,15 @@ bool ResourceContext::loadResV1(uint32 contextOffset, uint32 contextSize) {
}
// Load resource table
- tableSize = RSC_TABLEENTRY_SIZE * count;
-
- tableBuffer = (byte *)malloc(tableSize);
+ tableBuffer.resize(RSC_TABLEENTRY_SIZE * count);
_file.seek(resourceTableOffset + contextOffset, SEEK_SET);
- result = (_file.read(tableBuffer, tableSize) == tableSize);
+ result = (_file.read(tableBuffer.getBuffer(), tableBuffer.size()) == tableBuffer.size());
if (result) {
_table.resize(count);
- MemoryReadStreamEndian readS1(tableBuffer, tableSize, _isBigEndian);
+ MemoryReadStreamEndian readS1(tableBuffer.getBuffer(), tableBuffer.size(), _isBigEndian);
for (i = 0; i < count; i++) {
resourceData = &_table[i];
@@ -94,7 +91,6 @@ bool ResourceContext::loadResV1(uint32 contextOffset, uint32 contextSize) {
}
}
- free(tableBuffer);
return result;
}
@@ -375,7 +371,6 @@ void Resource::loadResource(ResourceContext *context, uint32 resourceId, byte*&r
uint32 resourceOffset;
ResourceData *resourceData;
- debug(8, "loadResource %d", resourceId);
resourceData = context->getResourceData(resourceId);
@@ -384,6 +379,8 @@ void Resource::loadResource(ResourceContext *context, uint32 resourceId, byte*&r
resourceOffset = resourceData->offset;
resourceSize = resourceData->size;
+ debug(8, "loadResource %d 0x%X:0x%X", resourceId, resourceOffset, resourceSize);
+
resourceBuffer = (byte*)malloc(resourceSize);
file->seek((long)resourceOffset, SEEK_SET);
diff --git a/engines/saga/resource_res.cpp b/engines/saga/resource_res.cpp
index 7e3e4e5b25..343f3b2ae2 100644
--- a/engines/saga/resource_res.cpp
+++ b/engines/saga/resource_res.cpp
@@ -54,7 +54,7 @@ void Resource_RES::loadGlobalResources(int chapter, int actorsEntrance) {
ResourceContext *resourceContext;
ResourceContext *soundContext;
- int i;
+ uint i;
resourceContext = _vm->_resource->getContext(GAME_RESOURCEFILE);
if (resourceContext == NULL) {
@@ -114,7 +114,7 @@ void Resource_RES::loadGlobalResources(int chapter, int actorsEntrance) {
_vm->loadStrings(_vm->_actor->_objectsStrings, resourcePointer, resourceLength);
free(resourcePointer);
- if (chapter >= _vm->_sndRes->_fxTableIDsLen) {
+ if (uint(chapter) >= _vm->_sndRes->_fxTableIDs.size()) {
error("Chapter ID exceeds fxTableIDs length");
}
@@ -126,14 +126,11 @@ void Resource_RES::loadGlobalResources(int chapter, int actorsEntrance) {
error("Resource::loadGlobalResources Can't load sound effects for current track");
}
- free(_vm->_sndRes->_fxTable);
-
- _vm->_sndRes->_fxTableLen = resourceLength / 4;
- _vm->_sndRes->_fxTable = (FxTable *)malloc(sizeof(FxTable) * _vm->_sndRes->_fxTableLen);
-
+ _vm->_sndRes->_fxTable.resize(resourceLength / 4);
+
MemoryReadStream fxS(resourcePointer, resourceLength);
- for (i = 0; i < _vm->_sndRes->_fxTableLen; i++) {
+ for (i = 0; i < _vm->_sndRes->_fxTable.size(); i++) {
_vm->_sndRes->_fxTable[i].res = fxS.readSint16LE();
_vm->_sndRes->_fxTable[i].vol = fxS.readSint16LE();
}
@@ -177,14 +174,11 @@ void Resource_RES::loadGlobalResources(int chapter, int actorsEntrance) {
error("Resource::loadGlobalResources Can't load songs list for current track");
}
- free(_vm->_music->_songTable);
-
- _vm->_music->_songTableLen = resourceLength / 4;
- _vm->_music->_songTable = (int32 *)malloc(sizeof(int32) * _vm->_music->_songTableLen);
+ _vm->_music->_songTable.resize(resourceLength / 4);
MemoryReadStream songS(resourcePointer, resourceLength);
- for (i = 0; i < _vm->_music->_songTableLen; i++)
+ for (i = 0; i < _vm->_music->_songTable.size(); i++)
_vm->_music->_songTable[i] = songS.readSint32LE();
free(resourcePointer);
} else {
diff --git a/engines/saga/saga.cpp b/engines/saga/saga.cpp
index 745414f0df..e7eac5e4fe 100644
--- a/engines/saga/saga.cpp
+++ b/engines/saga/saga.cpp
@@ -291,7 +291,7 @@ Common::Error SagaEngine::run() {
_sound = new Sound(this, _mixer);
if (!isSaga2()) {
- _interface->converseInit();
+ _interface->converseClear();
_script->setVerb(_script->getVerbType(kVerbWalkTo));
}
diff --git a/engines/saga/saga.h b/engines/saga/saga.h
index e391e662c3..8008cf7bdb 100644
--- a/engines/saga/saga.h
+++ b/engines/saga/saga.h
@@ -86,7 +86,7 @@ class ResourceContext;
using Common::MemoryReadStream;
using Common::MemoryReadStreamEndian;
-//#define SAGA_DEBUG 1 // define for test functions
+// #define SAGA_DEBUG 1 // define for test functions
#define SAGA_IMAGE_DATA_OFFSET 776
#define SAGA_IMAGE_HEADER_LEN 8
@@ -458,6 +458,14 @@ inline uint16 objectIndexToId(int type, int index) {
return (type << OBJECT_TYPE_SHIFT) | (OBJECT_TYPE_MASK & index);
}
+class ByteArray : public Common::Array<byte> {
+public:
+
+ byte * getBuffer() { // call this method instead of "&front()" if you insure of array emptyness state
+ return empty() ? NULL : &front();
+ }
+};
+
class SagaEngine : public Engine {
friend class Scene;
@@ -537,7 +545,7 @@ public:
Common::RandomSource _rnd;
private:
- int decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len);
+ int decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray &outbuf);
int flipImage(byte *img_buf, int columns, int scanlines);
int unbankBGImage(byte *dest_buf, const byte *src_buf, int columns, int scanlines);
uint32 _previousTicks;
diff --git a/engines/saga/saveload.cpp b/engines/saga/saveload.cpp
index 23ab43bdd7..24acefa910 100644
--- a/engines/saga/saveload.cpp
+++ b/engines/saga/saveload.cpp
@@ -242,7 +242,7 @@ void SagaEngine::save(const char *fileName, const char *saveName) {
out->writeSint16LE(_script->_commonBuffer.size());
- out->write(&_script->_commonBuffer.front(), _script->_commonBuffer.size());
+ out->write(_script->_commonBuffer.getBuffer(), _script->_commonBuffer.size());
// ISO map x, y coordinates for ITE
if (getGameId() == GID_ITE) {
@@ -282,7 +282,7 @@ void SagaEngine::load(const char *fileName) {
_saveHeader.version = SWAP_BYTES_32(_saveHeader.version);
}
- debug(2, "Save version: %x", _saveHeader.version);
+ debug(2, "Save version: 0x%X", _saveHeader.version);
if (_saveHeader.version < 4)
warning("This savegame is not endian-safe. There may be problems");
@@ -352,7 +352,7 @@ void SagaEngine::load(const char *fileName) {
commonBufferSize = in->readSint16LE();
_script->_commonBuffer.resize(commonBufferSize);
- in->read(&_script->_commonBuffer.front(), commonBufferSize);
+ in->read(_script->_commonBuffer.getBuffer(), commonBufferSize);
if (getGameId() == GID_ITE) {
mapx = in->readSint16LE();
diff --git a/engines/saga/scene.cpp b/engines/saga/scene.cpp
index 9750cf308a..f745fbddcc 100644
--- a/engines/saga/scene.cpp
+++ b/engines/saga/scene.cpp
@@ -140,7 +140,7 @@ Scene::Scene(SagaEngine *vm) : _vm(vm) {
byte *sceneLUTPointer;
size_t sceneLUTLength;
uint32 resourceId;
- int i;
+ uint i;
// Do nothing for SAGA2 games for now
if (_vm->isSaga2()) {
@@ -162,15 +162,11 @@ Scene::Scene(SagaEngine *vm) : _vm(vm) {
if (sceneLUTLength == 0) {
error("Scene::Scene() sceneLUTLength == 0");
}
- _sceneCount = sceneLUTLength / 2;
- _sceneLUT = (int *)malloc(_sceneCount * sizeof(*_sceneLUT));
- if (_sceneLUT == NULL) {
- memoryError("Scene::Scene()");
- }
+ _sceneLUT.resize(sceneLUTLength / 2);
MemoryReadStreamEndian readS(sceneLUTPointer, sceneLUTLength, _sceneContext->isBigEndian());
- for (i = 0; i < _sceneCount; i++) {
+ for (i = 0; i < _sceneLUT.size(); i++) {
_sceneLUT[i] = readS.readUint16();
debug(8, "sceneNumber %i has resourceId %i", i, _sceneLUT[i]);
}
@@ -190,7 +186,7 @@ Scene::Scene(SagaEngine *vm) : _vm(vm) {
getResourceTypes(types, typesCount);
- for (i = 0; i < _sceneCount; i++) {
+ for (i = 0; i < _sceneLUT.size(); i++) {
gDebugLevel = -1;
loadSceneDescriptor(_sceneLUT[i]);
loadSceneResourceList(_sceneDescription.resourceListResourceId);
@@ -210,7 +206,7 @@ Scene::Scene(SagaEngine *vm) : _vm(vm) {
}
#endif
- debug(3, "LUT has %d entries.", _sceneCount);
+ debug(3, "LUT has %d entries.", _sceneLUT.size());
_sceneLoaded = false;
_sceneNumber = 0;
@@ -236,7 +232,6 @@ Scene::~Scene() {
delete _actionMap;
delete _objectMap;
- free(_sceneLUT);
}
void Scene::getResourceTypes(SAGAResourceTypes *&types, int &typesCount) {
@@ -623,7 +618,7 @@ void Scene::loadScene(LoadSceneParams &loadSceneParams) {
if (loadSceneParams.chapter == 6 || loadSceneParams.chapter == 8)
_vm->_interface->setLeftPortrait(0);
- _vm->_anim->freeCutawayList();
+ _vm->_anim->clearCutawayList();
_vm->_script->clearModules();
// deleteAllScenes();
@@ -1244,15 +1239,15 @@ void Scene::endScene() {
// Free animation info list
_vm->_anim->reset();
- _vm->_palanim->freePalAnim();
+ _vm->_palanim->clear();
- _objectMap->freeMem();
- _actionMap->freeMem();
- _entryList.freeMem();
+ _objectMap->clear();
+ _actionMap->clear();
+ _entryList.clear();
_sceneStrings.clear();
if (_vm->getGameId() == GID_ITE)
- _vm->_isoMap->freeMem();
+ _vm->_isoMap->clear();
_vm->_events->clearList();
_textList.clear();
@@ -1285,7 +1280,7 @@ void Scene::cmdSceneChange(int argc, const char **argv) {
scene_num = atoi(argv[1]);
- if ((scene_num < 1) || (scene_num >= _sceneCount)) {
+ if ((scene_num < 1) || (uint(scene_num) >= _sceneLUT.size())) {
_vm->_console->DebugPrintf("Invalid scene number.\n");
return;
}
@@ -1304,26 +1299,21 @@ void Scene::cmdObjectMapInfo() {
}
void Scene::loadSceneEntryList(const byte* resourcePointer, size_t resourceLength) {
- int i;
-
- _entryList.entryListCount = resourceLength / 8;
-
- MemoryReadStreamEndian readS(resourcePointer, resourceLength, _sceneContext->isBigEndian());
+ uint i;
+ if (!_entryList.empty()) {
+ error("Scene::loadSceneEntryList entryList not empty");
+ }
- if (_entryList.entryList)
- error("Scene::loadSceneEntryList entryList != NULL");
+ _entryList.resize(resourceLength / 8);
- _entryList.entryList = (SceneEntry *) malloc(_entryList.entryListCount * sizeof(*_entryList.entryList));
- if (_entryList.entryList == NULL) {
- memoryError("Scene::loadSceneEntryList");
- }
+ MemoryReadStreamEndian readS(resourcePointer, resourceLength, _sceneContext->isBigEndian());
- for (i = 0; i < _entryList.entryListCount; i++) {
- _entryList.entryList[i].location.x = readS.readSint16();
- _entryList.entryList[i].location.y = readS.readSint16();
- _entryList.entryList[i].location.z = readS.readSint16();
- _entryList.entryList[i].facing = readS.readUint16();
+ for (i = 0; i < _entryList.size(); i++) {
+ _entryList[i].location.x = readS.readSint16();
+ _entryList[i].location.y = readS.readSint16();
+ _entryList[i].location.z = readS.readSint16();
+ _entryList[i].facing = readS.readUint16();
}
}
diff --git a/engines/saga/scene.h b/engines/saga/scene.h
index 0131e01abb..f7c6c39ec5 100644
--- a/engines/saga/scene.h
+++ b/engines/saga/scene.h
@@ -134,29 +134,10 @@ struct SceneDescription {
struct SceneEntry {
Location location;
- int facing;
+ uint16 facing;
};
-struct SceneEntryList {
- SceneEntry *entryList;
- int entryListCount;
-
- const SceneEntry * getEntry(int index) {
- if ((index < 0) || (index >= entryListCount)) {
- error("SceneEntryList::getEntry wrong index (%d)", index);
- }
- return &entryList[index];
- }
- void freeMem() {
- free(entryList);
- memset(this, 0, sizeof(*this));
- }
- SceneEntryList() {
- memset(this, 0, sizeof(*this));
- }
- ~SceneEntryList() {
- freeMem();
- }
+class SceneEntryList : public Common::Array<SceneEntry> {
};
struct SceneImage {
@@ -325,7 +306,7 @@ class Scene {
bool isSceneLoaded() const { return _sceneLoaded; }
- int getSceneResourceId(int sceneNumber) {
+ uint16 getSceneResourceId(int sceneNumber) {
#ifdef SCENE_DEBUG
if ((sceneNumber < 0) || (sceneNumber >= _sceneCount)) {
error("getSceneResourceId: wrong sceneNumber %i", sceneNumber);
@@ -385,8 +366,7 @@ class Scene {
SagaEngine *_vm;
ResourceContext *_sceneContext;
- int *_sceneLUT;
- int _sceneCount;
+ Common::Array<uint16> _sceneLUT;
SceneQueueList _sceneQueue;
bool _sceneLoaded;
int _currentProtag;
diff --git a/engines/saga/script.cpp b/engines/saga/script.cpp
index 5d3b90005c..b35e13ed8f 100644
--- a/engines/saga/script.cpp
+++ b/engines/saga/script.cpp
@@ -1112,9 +1112,9 @@ void Script::loadModuleBase(ModuleData &module, const byte *resourcePointer, siz
module.moduleBase.resize(resourceLength);
- memcpy(&module.moduleBase.front(), resourcePointer, resourceLength);
+ memcpy(module.moduleBase.getBuffer(), resourcePointer, resourceLength);
- MemoryReadStreamEndian scriptS(&module.moduleBase.front(), module.moduleBase.size(), _scriptContext->isBigEndian());
+ MemoryReadStreamEndian scriptS(module.moduleBase.getBuffer(), module.moduleBase.size(), _scriptContext->isBigEndian());
uint entryPointsCount = scriptS.readUint16();
scriptS.readUint16(); //skip
diff --git a/engines/saga/script.h b/engines/saga/script.h
index 10fa69315b..3423ddd05c 100644
--- a/engines/saga/script.h
+++ b/engines/saga/script.h
@@ -138,7 +138,7 @@ struct ModuleData {
int stringsResourceId;
int voicesResourceId;
- Common::Array<byte> moduleBase; // all base module
+ ByteArray moduleBase; // all base module
uint16 staticSize; // size of static data
uint staticOffset; // offset of static data begining in _commonBuffer
Common::Array<EntryPoint> entryPoints;
@@ -354,7 +354,7 @@ protected:
TextListEntry *_placardTextEntry;
friend class SagaEngine;
- Common::Array<byte> _commonBuffer;
+ ByteArray _commonBuffer;
uint _staticSize;
ScriptThreadList _threadList;
diff --git a/engines/saga/sfuncs.cpp b/engines/saga/sfuncs.cpp
index 17dbc9dbab..463adc76e8 100644
--- a/engines/saga/sfuncs.cpp
+++ b/engines/saga/sfuncs.cpp
@@ -953,7 +953,7 @@ void Script::sfPlaceActor(SCRIPTFUNC_PARAMS) {
int frameOffset = thread->pop();
ActorFrameRange *frameRange;
- debug(1, "sfPlaceActor(id = 0x%x, x=%d, y=%d, dir=%d, frameType=%d, frameOffset=%d)", actorId, actor->_location.x,
+ debug(1, "sfPlaceActor(id = 0x%X, x=%d, y=%d, dir=%d, frameType=%d, frameOffset=%d)", actorId, actor->_location.x,
actor->_location.y, actor->_facingDirection, frameType, frameOffset);
if (frameType >= 0) {
@@ -1349,8 +1349,8 @@ void Script::sfPlayMusic(SCRIPTFUNC_PARAMS) {
return;
}
- if (param1 >= _vm->_music->_songTableLen) {
- warning("sfPlayMusic: Wrong song number (%d > %d)", param1, _vm->_music->_songTableLen - 1);
+ if (uint(param1) >= _vm->_music->_songTable.size()) {
+ warning("sfPlayMusic: Wrong song number (%d > %d)", param1, _vm->_music->_songTable.size() - 1);
} else {
_vm->_music->setVolume(_vm->_musicVolume, 1);
_vm->_music->play(_vm->_music->_songTable[param1], param2 ? MUSIC_LOOP : MUSIC_NORMAL);
@@ -1440,7 +1440,7 @@ void Script::sfPlaySound(SCRIPTFUNC_PARAMS) {
int16 param = thread->pop();
int res;
- if (param >= 0 && param < _vm->_sndRes->_fxTableLen) {
+ if (uint(param) < _vm->_sndRes->_fxTable.size()) {
res = _vm->_sndRes->_fxTable[param].res;
if (_vm->getGameId() == GID_ITE && !(_vm->getFeatures() & GF_ITE_FLOPPY))
res -= 14;
@@ -1455,7 +1455,7 @@ void Script::sfPlayLoopedSound(SCRIPTFUNC_PARAMS) {
int16 param = thread->pop();
int res;
- if (param >= 0 && param < _vm->_sndRes->_fxTableLen) {
+ if (uint(param) < _vm->_sndRes->_fxTable.size()) {
res = _vm->_sndRes->_fxTable[param].res;
if (_vm->getGameId() == GID_ITE && !(_vm->getFeatures() & GF_ITE_FLOPPY))
res -= 14;
diff --git a/engines/saga/sfuncs_ihnm.cpp b/engines/saga/sfuncs_ihnm.cpp
index b98c1cb852..6637c861cb 100644
--- a/engines/saga/sfuncs_ihnm.cpp
+++ b/engines/saga/sfuncs_ihnm.cpp
@@ -413,8 +413,8 @@ void Script::sfQueueMusic(SCRIPTFUNC_PARAMS) {
return;
}
- if (param1 >= _vm->_music->_songTableLen) {
- warning("sfQueueMusic: Wrong song number (%d > %d)", param1, _vm->_music->_songTableLen - 1);
+ if (uint(param1) >= _vm->_music->_songTable.size()) {
+ warning("sfQueueMusic: Wrong song number (%d > %d)", param1, _vm->_music->_songTable.size() - 1);
} else {
_vm->_music->setVolume(_vm->_musicVolume, 1);
event.type = kEvTOneshot;
diff --git a/engines/saga/sndres.cpp b/engines/saga/sndres.cpp
index 9322918db5..bd33bc070f 100644
--- a/engines/saga/sndres.cpp
+++ b/engines/saga/sndres.cpp
@@ -60,8 +60,11 @@ SndRes::SndRes(SagaEngine *vm) : _vm(vm), _sfxContext(NULL), _voiceContext(NULL)
setVoiceBank(0);
if (_vm->getGameId() == GID_ITE) {
- _fxTable = ITE_SfxTable;
- _fxTableLen = ITE_SFXCOUNT;
+ _fxTable.resize(ITE_SFXCOUNT);
+ for (uint i = 0; i < _fxTable.size(); i++) {
+ _fxTable[i].res = ITE_SfxTable[i].res;
+ _fxTable[i].vol = ITE_SfxTable[i].vol;
+ }
#ifdef ENABLE_IHNM
} else if (_vm->getGameId() == GID_IHNM) {
ResourceContext *resourceContext;
@@ -86,17 +89,14 @@ SndRes::SndRes(SagaEngine *vm) : _vm(vm), _sfxContext(NULL), _voiceContext(NULL)
error("Sndres::SndRes can't read SfxIDs table");
}
- _fxTableIDsLen = resourceLength / 2;
- _fxTableIDs = (int16 *)malloc(_fxTableIDsLen * sizeof(int16));
+ _fxTableIDs.resize(resourceLength / 2);
MemoryReadStream metaS(resourcePointer, resourceLength);
- for (int i = 0; i < _fxTableIDsLen; i++)
+ for (uint i = 0; i < _fxTableIDs.size(); i++) {
_fxTableIDs[i] = metaS.readSint16LE();
+ }
free(resourcePointer);
-
- _fxTable = 0;
- _fxTableLen = 0;
#endif
#ifdef ENABLE_SAGA2
} else if (_vm->getGameId() == GID_DINO) {
@@ -108,12 +108,6 @@ SndRes::SndRes(SagaEngine *vm) : _vm(vm), _sfxContext(NULL), _voiceContext(NULL)
}
SndRes::~SndRes() {
-#ifdef ENABLE_IHNM
- if (_vm->getGameId() == GID_IHNM) {
- free(_fxTable);
- free(_fxTableIDs);
- }
-#endif
}
void SndRes::setVoiceBank(int serial) {
diff --git a/engines/saga/sndres.h b/engines/saga/sndres.h
index d5507ebc55..e4bae1b143 100644
--- a/engines/saga/sndres.h
+++ b/engines/saga/sndres.h
@@ -33,6 +33,11 @@
namespace Saga {
+struct FxTable {
+ int16 res;
+ int16 vol;
+};
+
class SndRes {
public:
@@ -44,11 +49,9 @@ public:
int getVoiceLength(uint32 resourceId);
void setVoiceBank(int serial);
- FxTable *_fxTable;
- int _fxTableLen;
+ Common::Array<FxTable> _fxTable;
- int16 *_fxTableIDs;
- int _fxTableIDsLen;
+ Common::Array<int16> _fxTableIDs;
private:
bool load(ResourceContext *context, uint32 resourceId, SoundBuffer &buffer, bool onlyHeader);
diff --git a/engines/saga/sprite.cpp b/engines/saga/sprite.cpp
index 53ec170914..df387f4fff 100644
--- a/engines/saga/sprite.cpp
+++ b/engines/saga/sprite.cpp
@@ -148,7 +148,7 @@ void Sprite::loadList(int resourceId, SpriteList &spriteList) {
spriteInfo->decodedBuffer.resize(outputLength);
if (outputLength > 0) {
decodeRLEBuffer(spriteDataPointer, inputLength, outputLength);
- byte *dst = spriteInfo->getBuffer();
+ byte *dst = &spriteInfo->decodedBuffer.front();
#ifdef ENABLE_IHNM
// IHNM sprites are upside-down, for reasons which i can only
// assume are perverse. To simplify things, flip them now. Not
@@ -183,13 +183,13 @@ void Sprite::getScaledSpriteBuffer(SpriteList &spriteList, uint spriteNumber, in
spriteInfo = &spriteList[spriteNumber];
if (scale < 256) {
- xAlign = (spriteInfo->xAlign * scale) >> 8;
- yAlign = (spriteInfo->yAlign * scale) >> 8;
+ xAlign = (spriteInfo->xAlign * scale) >> 8; //TODO: do we need to take in account sprite x&y aligns ?
+ yAlign = (spriteInfo->yAlign * scale) >> 8; // ????
height = (spriteInfo->height * scale + 0x7f) >> 8;
width = (spriteInfo->width * scale + 0x7f) >> 8;
size_t outLength = width * height;
if (outLength > 0) {
- scaleBuffer(spriteInfo->getBuffer(), spriteInfo->width, spriteInfo->height, scale, outLength);
+ scaleBuffer(&spriteInfo->decodedBuffer.front(), spriteInfo->width, spriteInfo->height, scale, outLength);
buffer = &_decodeBuf.front();
} else {
buffer = NULL;
@@ -199,7 +199,7 @@ void Sprite::getScaledSpriteBuffer(SpriteList &spriteList, uint spriteNumber, in
yAlign = spriteInfo->yAlign;
height = spriteInfo->height;
width = spriteInfo->width;
- buffer = spriteInfo->getBuffer();
+ buffer = spriteInfo->decodedBuffer.getBuffer();
}
}
diff --git a/engines/saga/sprite.h b/engines/saga/sprite.h
index f1eae3811f..4e463cdd88 100644
--- a/engines/saga/sprite.h
+++ b/engines/saga/sprite.h
@@ -34,20 +34,12 @@ namespace Saga {
#define SPRITE_ZMASK 0x0F
struct SpriteInfo {
- Common::Array<byte> decodedBuffer;
+ ByteArray decodedBuffer;
int width;
int height;
int xAlign;
int yAlign;
- byte * getBuffer() {
- if (decodedBuffer.empty()) {
- return NULL;
- } else {
- return &decodedBuffer.front();
- }
- }
-
SpriteInfo() : width(0), height(0), xAlign(0), yAlign(0) {
}
};
@@ -88,7 +80,7 @@ private:
SagaEngine *_vm;
ResourceContext *_spriteContext;
- Common::Array<byte> _decodeBuf;
+ ByteArray _decodeBuf;
};
} // End of namespace Saga
diff --git a/engines/saga/sthread.cpp b/engines/saga/sthread.cpp
index 1e0fe52618..098970f4e8 100644
--- a/engines/saga/sthread.cpp
+++ b/engines/saga/sthread.cpp
@@ -47,9 +47,9 @@ ScriptThread &Script::createThread(uint16 scriptModuleNumber, uint16 scriptEntry
_threadList.push_front(tmp);
ScriptThread &newThread = _threadList.front();
newThread._instructionOffset = _modules[scriptModuleNumber].entryPoints[scriptEntryPointNumber].offset;
- newThread._commonBase = &_commonBuffer.front();
- newThread._staticBase = &_commonBuffer.front() + _modules[scriptModuleNumber].staticOffset;
- newThread._moduleBase = &_modules[scriptModuleNumber].moduleBase.front();
+ newThread._commonBase = _commonBuffer.getBuffer();
+ newThread._staticBase = _commonBuffer.getBuffer() + _modules[scriptModuleNumber].staticOffset;
+ newThread._moduleBase = _modules[scriptModuleNumber].moduleBase.getBuffer();
newThread._moduleBaseSize = _modules[scriptModuleNumber].moduleBase.size();
newThread._strings = &_modules[scriptModuleNumber].strings;
@@ -209,7 +209,7 @@ bool Script::runThread(ScriptThread &thread) {
savedInstructionOffset = thread._instructionOffset;
operandChar = scriptS.readByte();
- debug(8, "Executing thread offset: %u (%x) stack: %d", thread._instructionOffset, operandChar, thread.pushedSize());
+ debug(8, "Executing thread offset: %u (0x%X) stack: %d", thread._instructionOffset, operandChar, thread.pushedSize());
stopParsing = false;
debug(4, "Calling op %s", this->_scriptOpsList[operandChar].scriptOpName);