aboutsummaryrefslogtreecommitdiff
path: root/engines/saga
diff options
context:
space:
mode:
authorAndrew Kurushin2010-10-19 21:40:24 +0000
committerAndrew Kurushin2010-10-19 21:40:24 +0000
commitbfb0986cd4f73e564384f513daeba9e7938dcb4d (patch)
tree422ccde8fa472ac4a30b195caa53af96c4c87ce8 /engines/saga
parent6629efc676ca48e958dcfa0ee4e66e6aba1c6597 (diff)
downloadscummvm-rg350-bfb0986cd4f73e564384f513daeba9e7938dcb4d.tar.gz
scummvm-rg350-bfb0986cd4f73e564384f513daeba9e7938dcb4d.tar.bz2
scummvm-rg350-bfb0986cd4f73e564384f513daeba9e7938dcb4d.zip
SAGA: replace Actors "::realloc" with Common::Array
svn-id: r53627
Diffstat (limited to 'engines/saga')
-rw-r--r--engines/saga/actor.cpp52
-rw-r--r--engines/saga/actor.h8
-rw-r--r--engines/saga/interface.cpp12
-rw-r--r--engines/saga/isomap.cpp8
4 files changed, 27 insertions, 53 deletions
diff --git a/engines/saga/actor.cpp b/engines/saga/actor.cpp
index 6e6707c2b5..70ca8b5fef 100644
--- a/engines/saga/actor.cpp
+++ b/engines/saga/actor.cpp
@@ -48,12 +48,10 @@ ActorData::ActorData() {
ActorData::~ActorData() {
if (!_shareFrames)
free(_frames);
- free(_tileDirections);
- free(_walkStepsPoints);
freeSpriteList();
}
void ActorData::saveState(Common::OutSaveFile *out) {
- int i = 0;
+ uint i = 0;
CommonObjectData::saveState(out);
out->writeUint16LE(_actorFlags);
out->writeSint32LE(_currentAction);
@@ -74,13 +72,13 @@ void ActorData::saveState(Common::OutSaveFile *out) {
out->writeByte(_dragonMoveType);
out->writeSint32LE(_frameNumber);
- out->writeSint32LE(_tileDirectionsAlloced);
- for (i = 0; i < _tileDirectionsAlloced; i++) {
+ out->writeSint32LE(_tileDirections.size());
+ for (i = 0; i < _tileDirections.size(); i++) {
out->writeByte(_tileDirections[i]);
}
- out->writeSint32LE(_walkStepsAlloced);
- for (i = 0; i < _walkStepsAlloced; i++) {
+ out->writeSint32LE(_walkStepsPoints.size());
+ for (i = 0; i < _walkStepsPoints.size(); i++) {
out->writeSint16LE(_walkStepsPoints[i].x);
out->writeSint16LE(_walkStepsPoints[i].y);
}
@@ -93,7 +91,7 @@ void ActorData::saveState(Common::OutSaveFile *out) {
}
void ActorData::loadState(uint32 version, Common::InSaveFile *in) {
- int i = 0;
+ uint i = 0;
CommonObjectData::loadState(in);
_actorFlags = in->readUint16LE();
_currentAction = in->readSint32LE();
@@ -125,13 +123,13 @@ void ActorData::loadState(uint32 version, Common::InSaveFile *in) {
_frameNumber = in->readSint32LE();
- setTileDirectionsSize(in->readSint32LE(), true);
- for (i = 0; i < _tileDirectionsAlloced; i++) {
+ _tileDirections.resize(in->readSint32LE());
+ for (i = 0; i < _tileDirections.size(); i++) {
_tileDirections[i] = in->readByte();
}
- setWalkStepsPointsSize(in->readSint32LE(), true);
- for (i = 0; i < _walkStepsAlloced; i++) {
+ _walkStepsPoints.resize(in->readSint32LE());
+ for (i = 0; i < _walkStepsPoints.size(); i++) {
_walkStepsPoints[i].x = in->readSint16LE();
_walkStepsPoints[i].y = in->readSint16LE();
}
@@ -143,39 +141,13 @@ void ActorData::loadState(uint32 version, Common::InSaveFile *in) {
_walkFrameSequence = in->readSint32LE();
}
-void ActorData::setTileDirectionsSize(int size, bool forceRealloc) {
- if ((size <= _tileDirectionsAlloced) && !forceRealloc) {
- return;
- }
- _tileDirectionsAlloced = size;
- byte *tmp = (byte*)realloc(_tileDirections, _tileDirectionsAlloced * sizeof(*_tileDirections));
- if ((tmp != NULL) || (_tileDirectionsAlloced == 0)) {
- _tileDirections = tmp;
- } else {
- error("ActorData::setTileDirectionsSize(): Error while reallocating memory");
- }
-}
-
void ActorData::cycleWrap(int cycleLimit) {
if (_actionCycle >= cycleLimit)
_actionCycle = 0;
}
-void ActorData::setWalkStepsPointsSize(int size, bool forceRealloc) {
- if ((size <= _walkStepsAlloced) && !forceRealloc) {
- return;
- }
- _walkStepsAlloced = size;
- Point *tmp = (Point*)realloc(_walkStepsPoints, _walkStepsAlloced * sizeof(*_walkStepsPoints));
- if ((tmp != NULL) || (_walkStepsAlloced == 0)) {
- _walkStepsPoints = tmp;
- } else {
- error("ActorData::setWalkStepsPointsSize(): Error while reallocating memory");
- }
-}
-
void ActorData::addWalkStepPoint(const Point &point) {
- setWalkStepsPointsSize(_walkStepsCount + 1, false);
+ _walkStepsPoints.resize(_walkStepsCount + 1);
_walkStepsPoints[_walkStepsCount++] = point;
}
@@ -183,8 +155,6 @@ void ActorData::freeSpriteList() {
_spriteList.freeMem();
}
-
-
static int commonObjectCompare(const CommonObjectDataPointer& obj1, const CommonObjectDataPointer& obj2) {
int p1 = obj1->_location.y - obj1->_location.z;
int p2 = obj2->_location.y - obj2->_location.z;
diff --git a/engines/saga/actor.h b/engines/saga/actor.h
index 2f8fdea8ec..7073adcdcc 100644
--- a/engines/saga/actor.h
+++ b/engines/saga/actor.h
@@ -376,11 +376,9 @@ public:
int32 _frameNumber; // current frame number
- int32 _tileDirectionsAlloced;
- byte *_tileDirections;
+ Common::Array<byte> _tileDirections;
- int32 _walkStepsAlloced;
- Point *_walkStepsPoints;
+ Common::Array<Point> _walkStepsPoints;
int32 _walkStepsCount;
int32 _walkStepIndex;
@@ -396,9 +394,7 @@ public:
void saveState(Common::OutSaveFile *out);
void loadState(uint32 version, Common::InSaveFile *in);
- void setTileDirectionsSize(int size, bool forceRealloc);
void cycleWrap(int cycleLimit);
- void setWalkStepsPointsSize(int size, bool forceRealloc);
void addWalkStepPoint(const Point &point);
void freeSpriteList();
};
diff --git a/engines/saga/interface.cpp b/engines/saga/interface.cpp
index a77ec1c140..8d89a6fbdb 100644
--- a/engines/saga/interface.cpp
+++ b/engines/saga/interface.cpp
@@ -2281,14 +2281,22 @@ void Interface::drawPanelButtonText(InterfacePanel *panel, PanelButton *panelBut
}
break;
case kTextMusic:
- if (_vm->_musicVolume)
+ if (_vm->_musicVolume) {
textId = kText10Percent + _vm->_musicVolume / 25 - 1;
+ if (textId > kTextMax) {
+ textId = kTextMax;
+ }
+ }
else
textId = kTextOff;
break;
case kTextSound:
- if (_vm->_soundVolume)
+ if (_vm->_soundVolume) {
textId = kText10Percent + _vm->_soundVolume / 25 - 1;
+ if (textId > kTextMax) {
+ textId = kTextMax;
+ }
+ }
else
textId = kTextOff;
break;
diff --git a/engines/saga/isomap.cpp b/engines/saga/isomap.cpp
index f0ad9bbd5e..87c49047c5 100644
--- a/engines/saga/isomap.cpp
+++ b/engines/saga/isomap.cpp
@@ -1452,8 +1452,8 @@ void IsoMap::findDragonTilePath(ActorData* actor,const Location &start, const Lo
actor->_walkStepsCount = i;
if (i) {
- actor->setTileDirectionsSize(i, false);
- memcpy(actor->_tileDirections, res, i);
+ actor->_tileDirections.resize(i);
+ memcpy(&actor->_tileDirections.front(), res, i);
}
}
@@ -1585,8 +1585,8 @@ void IsoMap::findTilePath(ActorData* actor, const Location &start, const Locatio
actor->_walkStepsCount = i;
if (i) {
- actor->setTileDirectionsSize(i, false);
- memcpy(actor->_tileDirections, res, i);
+ actor->_tileDirections.resize(i);
+ memcpy(&actor->_tileDirections.front(), res, i);
}
}