diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/fullpipe/anihandler.cpp | 37 | ||||
-rw-r--r-- | engines/fullpipe/anihandler.h | 2 | ||||
-rw-r--r-- | engines/fullpipe/floaters.cpp | 162 | ||||
-rw-r--r-- | engines/fullpipe/floaters.h | 13 | ||||
-rw-r--r-- | engines/fullpipe/fullpipe.h | 1 | ||||
-rw-r--r-- | engines/fullpipe/gfx.cpp | 3 | ||||
-rw-r--r-- | engines/fullpipe/gfx.h | 1 | ||||
-rw-r--r-- | engines/fullpipe/messagehandlers.cpp | 4 | ||||
-rw-r--r-- | engines/fullpipe/messages.cpp | 33 | ||||
-rw-r--r-- | engines/fullpipe/messages.h | 7 | ||||
-rw-r--r-- | engines/fullpipe/motion.cpp | 449 | ||||
-rw-r--r-- | engines/fullpipe/motion.h | 30 | ||||
-rw-r--r-- | engines/fullpipe/scenes/scene02.cpp | 4 | ||||
-rw-r--r-- | engines/fullpipe/scenes/scene05.cpp | 6 | ||||
-rw-r--r-- | engines/fullpipe/scenes/scene12.cpp | 6 | ||||
-rw-r--r-- | engines/fullpipe/scenes/scene17.cpp | 6 | ||||
-rw-r--r-- | engines/fullpipe/scenes/scene20.cpp | 20 | ||||
-rw-r--r-- | engines/fullpipe/scenes/scene28.cpp | 12 | ||||
-rw-r--r-- | engines/fullpipe/scenes/scene34.cpp | 6 | ||||
-rw-r--r-- | engines/fullpipe/scenes/scene35.cpp | 6 | ||||
-rw-r--r-- | engines/fullpipe/statics.cpp | 146 | ||||
-rw-r--r-- | engines/fullpipe/statics.h | 23 |
22 files changed, 421 insertions, 556 deletions
diff --git a/engines/fullpipe/anihandler.cpp b/engines/fullpipe/anihandler.cpp index b847986047..e556a8e5f2 100644 --- a/engines/fullpipe/anihandler.cpp +++ b/engines/fullpipe/anihandler.cpp @@ -356,7 +356,7 @@ MessageQueue *AniHandler::makeRunQueue(MakeQueueStruct *mkQueue) { for (int i = subIdx; i != st2idx;) { const MGMSubItem &s = _items[itemIdx].subItems[i + st2idx * _items[itemIdx].statics.size()]; - ex2 = createCommand(s.movement, mkQueue->ani->_id, x1, y1, &x2, &y2, -1); + ex2 = createCommand(s.movement, mkQueue->ani->_id, x1, y1, x2, y2, -1); ex2->_parId = mq->_id; ex2->_param = mkQueue->ani->_odelay; @@ -373,7 +373,7 @@ MessageQueue *AniHandler::makeRunQueue(MakeQueueStruct *mkQueue) { else plen = -1; - ex2 = createCommand(mov, mkQueue->ani->_id, x1, y1, &x2, &y2, plen); + ex2 = createCommand(mov, mkQueue->ani->_id, x1, y1, x2, y2, plen); ex2->_parId = mq->_id; ex2->_param = mkQueue->ani->_odelay; @@ -383,7 +383,7 @@ MessageQueue *AniHandler::makeRunQueue(MakeQueueStruct *mkQueue) { for (int j = st1idx; j != subOffset;) { const MGMSubItem &s = _items[itemIdx].subItems[j + subOffset * _items[itemIdx].statics.size()]; - ex2 = createCommand(s.movement, mkQueue->ani->_id, x1, y1, &x2, &y2, -1); + ex2 = createCommand(s.movement, mkQueue->ani->_id, x1, y1, x2, y2, -1); ex2->_parId = mq->_id; ex2->_param = mkQueue->ani->_odelay; @@ -701,8 +701,8 @@ Common::Point AniHandler::getNumCycles(Movement *mov, int x, int y, int *mult, i return Common::Point(p2x + p1x * newmult, p2y + p1y * newmult); } -ExCommand2 *AniHandler::createCommand(Movement *mov, int objId, int x1, int y1, Common::Point *x2, Common::Point *y2, int len) { - debugC(2, kDebugPathfinding, "AniHandler::createCommand(mov, %d, %d, %d, [%d, %d], [%d, %d], %d)", objId, x1, y1, x2->x, x2->y, y2->x, y2->y, len); +ExCommand2 *AniHandler::createCommand(Movement *mov, int objId, int x1, int y1, Common::Point &x2, Common::Point &y2, int len) { + debugC(2, kDebugPathfinding, "AniHandler::createCommand(mov, %d, %d, %d, [%d, %d], [%d, %d], %d)", objId, x1, y1, x2.x, x2.y, y2.x, y2.y, len); uint cnt; @@ -714,44 +714,37 @@ ExCommand2 *AniHandler::createCommand(Movement *mov, int objId, int x1, int y1, if (len > 0 && cnt > (uint)len) cnt = len; - Common::Point **points = (Common::Point **)malloc(sizeof(Common::Point *) * cnt); + PointList points(cnt); for (uint i = 0; i < cnt; i++) { int flags = mov->getDynamicPhaseByIndex(i)->getDynFlags(); - points[i] = new Common::Point; - if (flags & 1) { - points[i]->x = x1 + x2->x; + points[i].x = x1 + x2.x; - y2->x -= x2->x; + y2.x -= x2.x; - if (!y2->x) - x2->x = 0; + if (!y2.x) + x2.x = 0; } if (flags & 2) { - points[i]->y = y1 + x2->y; + points[i].y = y1 + x2.y; - y2->y -= x2->y; + y2.y -= x2.y; - if (!y2->y) - x2->y = 0; + if (!y2.y) + x2.y = 0; } } - ExCommand2 *ex = new ExCommand2(20, objId, points, cnt); + ExCommand2 *ex = new ExCommand2(20, objId, points); ex->_excFlags = 2; ex->_messageNum = mov->_id; ex->_field_14 = len; ex->_field_24 = 1; ex->_param = -1; - for (uint i = 0; i < cnt; i++) - delete points[i]; - - free(points); - return ex; } diff --git a/engines/fullpipe/anihandler.h b/engines/fullpipe/anihandler.h index 5bc771a0e8..f73d755aa9 100644 --- a/engines/fullpipe/anihandler.h +++ b/engines/fullpipe/anihandler.h @@ -84,7 +84,7 @@ public: void clearVisitsList(int idx); int seekWay(int idx, int st1idx, int st2idx, bool flip, bool flop); Common::Point getNumCycles(Movement *mov, int x, int y, int *mult, int *len, int flag); - ExCommand2 *createCommand(Movement *mov, int objId, int x1, int y1, Common::Point *x2, Common::Point *y2, int len); + ExCommand2 *createCommand(Movement *mov, int objId, int x1, int y1, Common::Point &x2, Common::Point &y2, int len); MessageQueue *makeQueue(StaticANIObject *ani, int staticsIndex, int staticsId, int *resStatId, Common::Point **pointArr); int getFramesCount(int idx, int subIdx, int subOffset, int flag); int getNumMovements(int objectId, int idx1, int idx2); diff --git a/engines/fullpipe/floaters.cpp b/engines/fullpipe/floaters.cpp index 01afa240cc..284e8b7205 100644 --- a/engines/fullpipe/floaters.cpp +++ b/engines/fullpipe/floaters.cpp @@ -32,10 +32,6 @@ namespace Fullpipe { -Floaters::~Floaters() { - delete _hRgn; -} - void Floaters::init(GameVar *var) { _array1.clear(); _array2.clear(); @@ -48,21 +44,16 @@ void Floaters::init(GameVar *var) { GameVar *sub = varFliers->getSubVarByName("flyIdleRegion"); if (sub) { - _hRgn = new ReactPolygonal(); + _hRgn.reset(new ReactPolygonal()); - _hRgn->_pointCount = sub->getSubVarsCount(); - _hRgn->_points = (Common::Point **)malloc(sizeof(Common::Point *) * _hRgn->_pointCount); + _hRgn->_points.resize(sub->getSubVarsCount()); sub = sub->_subVars; - - int idx = 0; - + uint idx = 0; while (sub) { - _hRgn->_points[idx] = new Common::Point; - _hRgn->_points[idx]->x = sub->_subVars->_value.intValue; - _hRgn->_points[idx]->y = sub->_subVars->_nextVarObj->_value.intValue; - - idx++; + _hRgn->_points[idx].x = sub->_subVars->_value.intValue; + _hRgn->_points[idx].y = sub->_subVars->_nextVarObj->_value.intValue; + ++idx; sub = sub->_nextVarObj; } } @@ -70,24 +61,20 @@ void Floaters::init(GameVar *var) { sub = varFliers->getSubVarByName("flyIdlePath"); if (sub) { - _array1.reserve(sub->getSubVarsCount()); + _array1.resize(sub->getSubVarsCount()); sub = sub->_subVars; - int idx = 0; - + uint idx = 0; while (sub) { - FloaterArray1 *f = new FloaterArray1; - - f->val1 = sub->_subVars->_value.intValue; - f->val2 = sub->_subVars->_nextVarObj->_value.intValue; + FloaterArray1 &f = _array1[idx]; - _array1.push_back(f); + f.val1 = sub->_subVars->_value.intValue; + f.val2 = sub->_subVars->_nextVarObj->_value.intValue; - idx++; + ++idx; sub = sub->_nextVarObj; } - } } @@ -113,65 +100,64 @@ void Floaters::genFlies(Scene *sc, int x, int y, int priority, int flags) { ani->_movement->setDynamicPhaseIndex(g_fp->_rnd.getRandomNumber(nummoves - 1)); - FloaterArray2 *arr2 = new FloaterArray2; - - arr2->ani = ani; - arr2->val11 = 15.0; - arr2->val3 = y; - arr2->val5 = y; - arr2->val2 = x; - arr2->val4 = x; - arr2->fflags = flags; - - _array2.push_back(arr2); + _array2.push_back(FloaterArray2()); + FloaterArray2 &arr2 = _array2.back(); + arr2.ani = ani; + arr2.val11 = 15.0; + arr2.val3 = y; + arr2.val5 = y; + arr2.val2 = x; + arr2.val4 = x; + arr2.fflags = flags; } void Floaters::update() { for (uint i = 0; i < _array2.size(); ++i) { - if (_array2[i]->val13 <= 0) { - if (_array2[i]->val4 != _array2[i]->val2 || _array2[i]->val5 != _array2[i]->val3) { - if (_array2[i]->val9 < 2.0) - _array2[i]->val9 = 2.0; - - int dy = _array2[i]->val3 - _array2[i]->val5; - int dx = _array2[i]->val2 - _array2[i]->val4; + FloaterArray2 &a2 = _array2[i]; + if (_array2[i].val13 <= 0) { + if (_array2[i].val4 != a2.val2 || a2.val5 != a2.val3) { + if (_array2[i].val9 < 2.0) + _array2[i].val9 = 2.0; + + int dy = a2.val3 - a2.val5; + int dx = a2.val2 - a2.val4; double dst = sqrt((double)(dy * dy + dx * dx)); double at = atan2((double)dy, (double)dx); - int newX = (int)(cos(at) * _array2[i]->val9); - int newY = (int)(sin(at) * _array2[i]->val9); + int newX = (int)(cos(at) * a2.val9); + int newY = (int)(sin(at) * a2.val9); - if (dst < _array2[i]->val9) { - newX = _array2[i]->val2 - _array2[i]->val4; - newY = _array2[i]->val3 - _array2[i]->val5; + if (dst < a2.val9) { + newX = a2.val2 - a2.val4; + newY = a2.val3 - a2.val5; } if (dst <= 30.0) { if (dst < 30.0) { - _array2[i]->val9 = _array2[i]->val9 - _array2[i]->val9 * 0.5; + a2.val9 = a2.val9 - a2.val9 * 0.5; - if (_array2[i]->val9 < 2.0) - _array2[i]->val9 = 2.0; + if (a2.val9 < 2.0) + a2.val9 = 2.0; } } else { - _array2[i]->val9 = _array2[i]->val9 * 0.5 + _array2[i]->val9; + a2.val9 = a2.val9 * 0.5 + a2.val9; - if (_array2[i]->val9 > _array2[i]->val11) - _array2[i]->val9 = _array2[i]->val11; + if (a2.val9 > a2.val11) + a2.val9 = a2.val11; } - _array2[i]->val4 += newX; - _array2[i]->val5 += newY; - _array2[i]->ani->setOXY(newX + _array2[i]->ani->_ox, newY + _array2[i]->ani->_oy); + a2.val4 += newX; + a2.val5 += newY; + a2.ani->setOXY(newX + a2.ani->_ox, newY + a2.ani->_oy); - if (_array2[i]->val4 == _array2[i]->val2 && _array2[i]->val5 == _array2[i]->val3) { - _array2[i]->val9 = 0.0; + if (a2.val4 == a2.val2 && a2.val5 == a2.val3) { + a2.val9 = 0.0; - _array2[i]->val13 = g_fp->_rnd.getRandomNumber(200) + 20; + a2.val13 = g_fp->_rnd.getRandomNumber(200) + 20; - if (_array2[i]->fflags & 1) { - g_fp->_currentScene->deleteStaticANIObject(_array2[i]->ani); + if (a2.fflags & 1) { + g_fp->_currentScene->deleteStaticANIObject(a2.ani); - if (_array2[i]->ani) - delete _array2[i]->ani; + if (a2.ani) + delete a2.ani; _array2.remove_at(i); @@ -184,66 +170,64 @@ void Floaters::update() { } } } else { - if ((_array2[i]->fflags & 4) && _array2[i]->countdown < 1) { - _array2[i]->fflags |= 1; - _array2[i]->val2 = _array2[i]->val6; - _array2[i]->val3 = _array2[i]->val7; + if ((a2.fflags & 4) && a2.countdown < 1) { + a2.fflags |= 1; + a2.val2 = a2.val6; + a2.val3 = a2.val7; } else { - if (_array2[i]->fflags & 2) { + if (a2.fflags & 2) { int idx1 = g_fp->_rnd.getRandomNumber(_array1.size() - 1); - _array2[i]->val2 = _array1[idx1]->val1; - _array2[i]->val3 = _array1[idx1]->val2; + a2.val2 = _array1[idx1].val1; + a2.val3 = _array1[idx1].val2; } else { - Common::Rect rect; - if (!_hRgn) error("Floaters::update(): empty fliers region"); - _hRgn->getBBox(&rect); + const Common::Rect rect = _hRgn->getBBox(); int x2 = rect.left + g_fp->_rnd.getRandomNumber(rect.right - rect.left); int y2 = rect.top + g_fp->_rnd.getRandomNumber(rect.bottom - rect.top); if (_hRgn->pointInRegion(x2, y2)) { - int dx = _array2[i]->val2 - x2; - int dy = _array2[i]->val3 - y2; + int dx = a2.val2 - x2; + int dy = a2.val3 - y2; double dst = sqrt((double)(dy * dy + dx * dx)); - if (dst < 300.0 || !_hRgn->pointInRegion(_array2[i]->val4, _array2[i]->val5)) { - _array2[i]->val2 = x2; - _array2[i]->val3 = y2; + if (dst < 300.0 || !_hRgn->pointInRegion(a2.val4, a2.val5)) { + a2.val2 = x2; + a2.val3 = y2; } } } g_fp->playSound(SND_CMN_061, 0); - if (_array2[i]->fflags & 4) - _array2[i]->countdown--; + if (a2.fflags & 4) + a2.countdown--; } } } else { - _array2[i]->val13--; + a2.val13--; } - if (!_array2[i]->ani->_movement && _array2[i]->ani->_statics->_staticsId == ST_FLY_FLY) { - if (!_array2[i]->val15) { + if (!a2.ani->_movement && a2.ani->_statics->_staticsId == ST_FLY_FLY) { + if (!a2.val15) { g_fp->playSound(SND_CMN_060, 1); - _array2[i]->val15 = 1; + a2.val15 = 1; } - _array2[i]->ani->startAnim(MV_FLY_FLY, 0, -1); + a2.ani->startAnim(MV_FLY_FLY, 0, -1); } } } void Floaters::stopAll() { for (uint i = 0; i < _array2.size(); i++) { - g_fp->_currentScene->deleteStaticANIObject(_array2[i]->ani); - - delete _array2[i]->ani; + FloaterArray2 &a2 = _array2[i]; + g_fp->_currentScene->deleteStaticANIObject(a2.ani); + delete a2.ani; } _array2.clear(); diff --git a/engines/fullpipe/floaters.h b/engines/fullpipe/floaters.h index bd7b7ffd2c..161a34282c 100644 --- a/engines/fullpipe/floaters.h +++ b/engines/fullpipe/floaters.h @@ -23,6 +23,9 @@ #ifndef FULLPIPE_FLOATERS_H #define FULLPIPE_FLOATERS_H +#include "common/array.h" +#include "common/ptr.h" + namespace Fullpipe { class StaticANIObject; @@ -52,18 +55,16 @@ struct FloaterArray2 { int val15; int fflags; - FloaterArray2() : ani(0), val2(0), val3(0), val4(0), val5(0), val6(0), val7(0), val8(0), + FloaterArray2() : ani(nullptr), val2(0), val3(0), val4(0), val5(0), val6(0), val7(0), val8(0), val9(0.0), val11(0.0), val13(0), countdown(0), val15(0), fflags(0) {} }; class Floaters { public: - ReactPolygonal *_hRgn; - Common::Array<FloaterArray1 *> _array1; - Common::Array<FloaterArray2 *> _array2; + Common::ScopedPtr<ReactPolygonal> _hRgn; + Common::Array<FloaterArray1> _array1; + Common::Array<FloaterArray2> _array2; - Floaters() { _hRgn = 0; } - ~Floaters(); void init(GameVar *var); void genFlies(Scene *sc, int x, int y, int priority, int flags); void update(); diff --git a/engines/fullpipe/fullpipe.h b/engines/fullpipe/fullpipe.h index fefe24cf81..a24f11e889 100644 --- a/engines/fullpipe/fullpipe.h +++ b/engines/fullpipe/fullpipe.h @@ -87,6 +87,7 @@ class StaticANIObject; class Vars; typedef Common::Array<int16> MovTable; typedef Common::Array<int32> Palette; +typedef Common::Array<Common::Point> PointList; int global_messageHandler1(ExCommand *cmd); int global_messageHandler2(ExCommand *cmd); diff --git a/engines/fullpipe/gfx.cpp b/engines/fullpipe/gfx.cpp index b5614fdbc1..ae2ddace22 100644 --- a/engines/fullpipe/gfx.cpp +++ b/engines/fullpipe/gfx.cpp @@ -266,9 +266,6 @@ GameObject::GameObject(GameObject *src) { _field_8 = src->_field_8; } -GameObject::~GameObject() { -} - bool GameObject::load(MfcArchive &file) { debugC(5, kDebugLoading, "GameObject::load()"); _odelay = 0; diff --git a/engines/fullpipe/gfx.h b/engines/fullpipe/gfx.h index af3ce8abd4..252f855691 100644 --- a/engines/fullpipe/gfx.h +++ b/engines/fullpipe/gfx.h @@ -153,7 +153,6 @@ class GameObject : public CObject { public: GameObject(); GameObject(GameObject *src); - ~GameObject(); virtual bool load(MfcArchive &file); void setOXY(int x, int y); diff --git a/engines/fullpipe/messagehandlers.cpp b/engines/fullpipe/messagehandlers.cpp index 55edae7826..de226852b3 100644 --- a/engines/fullpipe/messagehandlers.cpp +++ b/engines/fullpipe/messagehandlers.cpp @@ -599,9 +599,9 @@ int global_messageHandler4(ExCommand *cmd) { ExCommand2 *cmd2 = static_cast<ExCommand2 *>(cmd); if (cmd->_excFlags & 1) { - ani->startAnimSteps(cmd->_messageNum, 0, cmd->_x, cmd->_y, cmd2->_points, cmd2->_pointsSize, flags); + ani->startAnimSteps(cmd->_messageNum, 0, cmd->_x, cmd->_y, cmd2->_points, flags); } else { - ani->startAnimSteps(cmd->_messageNum, cmd->_parId, cmd->_x, cmd->_y, cmd2->_points, cmd2->_pointsSize, flags); + ani->startAnimSteps(cmd->_messageNum, cmd->_parId, cmd->_x, cmd->_y, cmd2->_points, flags); } } break; diff --git a/engines/fullpipe/messages.cpp b/engines/fullpipe/messages.cpp index c8656906e0..632e0546cf 100644 --- a/engines/fullpipe/messages.cpp +++ b/engines/fullpipe/messages.cpp @@ -146,36 +146,12 @@ void ExCommand::firef34() { } } -ExCommand2::ExCommand2(int messageKind, int parentId, Common::Point **points, int pointsSize) : ExCommand(parentId, messageKind, 0, 0, 0, 0, 1, 0, 0, 0) { +ExCommand2::ExCommand2(int messageKind, int parentId, const PointList &points) : ExCommand(parentId, messageKind, 0, 0, 0, 0, 1, 0, 0, 0) { _objtype = kObjTypeExCommand2; - - _pointsSize = pointsSize; - _points = (Common::Point **)malloc(sizeof(Common::Point *) * pointsSize); - - for (int i = 0; i < pointsSize; i++) { - _points[i] = new Common::Point; - - *_points[i] = *points[i]; - } + _points = points; } -ExCommand2::ExCommand2(ExCommand2 *src) : ExCommand(src) { - _pointsSize = src->_pointsSize; - _points = (Common::Point **)malloc(sizeof(Common::Point *) * _pointsSize); - - for (int i = 0; i < _pointsSize; i++) { - _points[i] = new Common::Point; - - *_points[i] = *src->_points[i]; - } -} - -ExCommand2::~ExCommand2() { - for (int i = 0; i < _pointsSize; i++) - delete _points[i]; - - free(_points); -} +ExCommand2::ExCommand2(ExCommand2 *src) : ExCommand(src), _points(src->_points) {} ExCommand2 *ExCommand2::createClone() { return new ExCommand2(this); @@ -242,9 +218,6 @@ ObjstateCommand::ObjstateCommand(ObjstateCommand *src) : ExCommand(src) { _objCommandName = src->_objCommandName; } -ObjstateCommand::~ObjstateCommand() { -} - bool ObjstateCommand::load(MfcArchive &file) { debugC(5, kDebugLoading, "ObjStateCommand::load()"); diff --git a/engines/fullpipe/messages.h b/engines/fullpipe/messages.h index 65c5e9b372..74af61ca5d 100644 --- a/engines/fullpipe/messages.h +++ b/engines/fullpipe/messages.h @@ -86,12 +86,10 @@ class ExCommand : public Message { class ExCommand2 : public ExCommand { public: - Common::Point **_points; - int _pointsSize; + PointList _points; - ExCommand2(int messageKind, int parentId, Common::Point **points, int pointsSize); + ExCommand2(int messageKind, int parentId, const PointList &points); ExCommand2(ExCommand2 *src); - virtual ~ExCommand2(); virtual ExCommand2 *createClone(); }; @@ -104,7 +102,6 @@ class ObjstateCommand : public ExCommand { public: ObjstateCommand(); ObjstateCommand(ObjstateCommand *src); - virtual ~ObjstateCommand(); virtual bool load(MfcArchive &file); diff --git a/engines/fullpipe/motion.cpp b/engines/fullpipe/motion.cpp index 99637769f2..005ed707c0 100644 --- a/engines/fullpipe/motion.cpp +++ b/engines/fullpipe/motion.cpp @@ -735,7 +735,6 @@ void MctlMQ::clear() { subIndex = 0; item1Index = 0; items.clear(); - itemsCount = 0; flags = 0; } @@ -1531,7 +1530,7 @@ Common::Array<MovArr *> *MovGraph::getHitPoints(int x, int y, int *arrSize, int return arr; } -void MovGraph::findAllPaths(MovGraphLink *lnk, MovGraphLink *lnk2, Common::Array<MovGraphLink *> &tempObList1, Common::Array<MovGraphLink *> &allPaths) { +void MovGraph::findAllPaths(MovGraphLink *lnk, MovGraphLink *lnk2, MovGraphLinkList &tempObList1, MovGraphLinkList &allPaths) { debugC(4, kDebugPathfinding, "MovGraph::findAllPaths(...)"); if (lnk == lnk2) { @@ -1566,8 +1565,8 @@ void MovGraph::findAllPaths(MovGraphLink *lnk, MovGraphLink *lnk2, Common::Array Common::Array<MovItem *> *MovGraph::getPaths(MovArr *currPos, MovArr *destPos, int *pathCount) { debugC(4, kDebugPathfinding, "MovGraph::getPaths(...)"); - Common::Array<MovGraphLink *> tempObList1; - Common::Array<MovGraphLink *> allPaths; + MovGraphLinkList tempObList1; + MovGraphLinkList allPaths; // Get all paths between two edges of the graph findAllPaths(currPos->_link, destPos->_link, tempObList1, allPaths); @@ -1677,7 +1676,7 @@ void MovGraph::setEnds(MovStep *step1, MovStep *step2) { int MctlGraph::getObjIndex(int objectId) { for (uint i = 0; i < _items2.size(); i++) - if (_items2[i]->_objectId == objectId) + if (_items2[i]._objectId == objectId) return i; return -1; @@ -1685,7 +1684,7 @@ int MctlGraph::getObjIndex(int objectId) { int MctlGraph::getDirByStatics(int idx, int staticsId) { for (int i = 0; i < 4; i++) - if (_items2[idx]->_subItems[i]._staticsId1 == staticsId || _items2[idx]->_subItems[i]._staticsId2 == staticsId) + if (_items2[idx]._subItems[i]._staticsId1 == staticsId || _items2[idx]._subItems[i]._staticsId2 == staticsId) return i; return -1; @@ -1693,9 +1692,9 @@ int MctlGraph::getDirByStatics(int idx, int staticsId) { int MctlGraph::getDirByMovement(int idx, int movId) { for (int i = 0; i < 4; i++) - if (_items2[idx]->_subItems[i]._walk[0]._movementId == movId - || _items2[idx]->_subItems[i]._walk[1]._movementId == movId - || _items2[idx]->_subItems[i]._walk[2]._movementId == movId) + if (_items2[idx]._subItems[i]._walk[0]._movementId == movId + || _items2[idx]._subItems[i]._walk[1]._movementId == movId + || _items2[idx]._subItems[i]._walk[2]._movementId == movId) return i; return -1; @@ -1708,7 +1707,7 @@ int MctlGraph::getDirByPoint(int index, StaticANIObject *ani) { for (int i = 0; i < 4; i++) { debugC(1, kDebugPathfinding, "WWW 5"); - int tmp = _aniHandler.getNumMovements(ani->_id, ani->_statics->_staticsId, _items2[index]->_subItems[i]._staticsId1); + int tmp = _aniHandler.getNumMovements(ani->_id, ani->_statics->_staticsId, _items2[index]._subItems[i]._staticsId1); if (tmp >= 0 && (minidx == -1 || tmp < min)) { minidx = i; @@ -1722,11 +1721,11 @@ int MctlGraph::getDirByPoint(int index, StaticANIObject *ani) { return -1; } -bool MctlGraph::fillData(StaticANIObject *obj, MctlAni *item) { +bool MctlGraph::fillData(StaticANIObject *obj, MctlAni &item) { debugC(4, kDebugPathfinding, "MovGraph::fillData(%d, ...)", obj->_id); - item->_obj = obj; - item->_objectId = obj->_id; + item._obj = obj; + item._objectId = obj->_id; GameVar *var = g_fp->getGameLoaderGameVar()->getSubVarByName(obj->_objectName); if (!var) @@ -1774,15 +1773,15 @@ bool MctlGraph::fillData(StaticANIObject *obj, MctlAni *item) { break; } - item->_subItems[dir]._walk[act]._movementId = idx; + item._subItems[dir]._walk[act]._movementId = idx; Movement *mov = obj->getMovementById(idx); - item->_subItems[dir]._walk[act]._mov = mov; + item._subItems[dir]._walk[act]._mov = mov; if (mov) { point = mov->calcSomeXY(0, -1); - item->_subItems[dir]._walk[act]._mx = point.x; - item->_subItems[dir]._walk[act]._my = point.y; + item._subItems[dir]._walk[act]._mx = point.x; + item._subItems[dir]._walk[act]._my = point.y; } } @@ -1804,15 +1803,15 @@ bool MctlGraph::fillData(StaticANIObject *obj, MctlAni *item) { break; } - item->_subItems[dir]._turn[act]._movementId = idx; + item._subItems[dir]._turn[act]._movementId = idx; Movement *mov = obj->getMovementById(idx); - item->_subItems[dir]._turn[act]._mov = mov; + item._subItems[dir]._turn[act]._mov = mov; if (mov) { point = mov->calcSomeXY(0, -1); - item->_subItems[dir]._turn[act]._mx = point.x; - item->_subItems[dir]._turn[act]._my = point.y; + item._subItems[dir]._turn[act]._mx = point.x; + item._subItems[dir]._turn[act]._my = point.y; } } @@ -1834,20 +1833,20 @@ bool MctlGraph::fillData(StaticANIObject *obj, MctlAni *item) { break; } - item->_subItems[dir]._turnS[act]._movementId = idx; + item._subItems[dir]._turnS[act]._movementId = idx; Movement *mov = obj->getMovementById(idx); - item->_subItems[dir]._turnS[act]._mov = mov; + item._subItems[dir]._turnS[act]._mov = mov; if (mov) { point = mov->calcSomeXY(0, -1); - item->_subItems[dir]._turnS[act]._mx = point.x; - item->_subItems[dir]._turnS[act]._my = point.y; + item._subItems[dir]._turnS[act]._mx = point.x; + item._subItems[dir]._turnS[act]._my = point.y; } } - item->_subItems[dir]._staticsId1 = item->_subItems[dir]._walk[0]._mov->_staticsObj1->_staticsId; - item->_subItems[dir]._staticsId2 = item->_subItems[dir]._walk[0]._mov->_staticsObj2->_staticsId; + item._subItems[dir]._staticsId1 = item._subItems[dir]._walk[0]._mov->_staticsObj1->_staticsId; + item._subItems[dir]._staticsId2 = item._subItems[dir]._walk[0]._mov->_staticsObj2->_staticsId; } return true; @@ -1861,47 +1860,44 @@ void MctlGraph::attachObject(StaticANIObject *obj) { int id = getObjIndex(obj->_id); if (id >= 0) { - _items2[id]->_obj = obj; + _items2[id]._obj = obj; } else { - MctlAni *item = new MctlAni; - - if (fillData(obj, item)) { - _items2.push_back(item); - } else { - delete item; + // this is a little dumb due to no move semantics + _items2.push_back(MctlAni()); + if (!fillData(obj, _items2.back())) { + _items2.pop_back(); } } } -void MctlGraph::generateList(MctlMQ *movinfo, Common::Array<MovGraphLink *> *linkList, LinkInfo *lnkSrc, LinkInfo *lnkDst) { +void MctlGraph::generateList(MctlMQ &movinfo, MovGraphLinkList *linkList, LinkInfo *lnkSrc, LinkInfo *lnkDst) { debugC(4, kDebugPathfinding, "MctlGraph::generateList(...)"); MctlMQSub *elem; Common::Point point; Common::Rect rect; - int subIndex = movinfo->subIndex; + int subIndex = movinfo.subIndex; - movinfo->items.clear(); + movinfo.items.clear(); - elem = new MctlMQSub; + movinfo.items.push_back(MctlMQSub()); + elem = &movinfo.items.back(); elem->subIndex = subIndex; - elem->x = movinfo->pt1.x; - elem->y = movinfo->pt1.y; + elem->x = movinfo.pt1.x; + elem->y = movinfo.pt1.y; elem->distance = -1; - movinfo->items.push_back(elem); - - int prevSubIndex = movinfo->subIndex; + int prevSubIndex = movinfo.subIndex; for (uint i = 0; i < linkList->size(); i++) { int idx1; if (linkList->size() <= 1) { if (linkList->size() == 1) - idx1 = getDirBySize((*linkList)[0], movinfo->pt2.x - movinfo->pt1.x, movinfo->pt2.y - movinfo->pt1.y); + idx1 = getDirBySize((*linkList)[0], movinfo.pt2.x - movinfo.pt1.x, movinfo.pt2.y - movinfo.pt1.y); else - idx1 = getDirBySize(0, movinfo->pt2.x - movinfo->pt1.x, movinfo->pt2.y - movinfo->pt1.y); + idx1 = getDirBySize(0, movinfo.pt2.x - movinfo.pt1.x, movinfo.pt2.y - movinfo.pt1.y); point.y = -1; rect.bottom = -1; @@ -1916,17 +1912,16 @@ void MctlGraph::generateList(MctlMQ *movinfo, Common::Array<MovGraphLink *> *lin prevSubIndex = idx1; subIndex = idx1; - elem = new MctlMQSub; + movinfo.items.push_back(MctlMQSub()); + elem = &movinfo.items.back(); elem->subIndex = subIndex; elem->x = rect.left; elem->y = rect.top; elem->distance = -1; - - movinfo->items.push_back(elem); } if (i != linkList->size() - 1) { - while (1) { + for (;;) { i++; if (getLinkDir(linkList, i, &rect, 0) != prevSubIndex) { i--; @@ -1940,84 +1935,77 @@ void MctlGraph::generateList(MctlMQ *movinfo, Common::Array<MovGraphLink *> *lin } } - if (movinfo->items.back()->subIndex != 10) { + if (movinfo.items.back().subIndex != 10) { subIndex = prevSubIndex; - elem = new MctlMQSub; + movinfo.items.push_back(MctlMQSub()); + elem = &movinfo.items.back(); elem->subIndex = 10; elem->x = -1; elem->y = -1; elem->distance = -1; - movinfo->items.push_back(elem); - + movinfo.items.push_back(MctlMQSub()); + elem = &movinfo.items.back(); + elem->subIndex = prevSubIndex; if (i == linkList->size() - 1) { - elem = new MctlMQSub; - elem->subIndex = prevSubIndex; - elem->x = movinfo->pt2.x; - elem->y = movinfo->pt2.y; - elem->distance = movinfo->distance2; - - movinfo->items.push_back(elem); + elem->x = movinfo.pt2.x; + elem->y = movinfo.pt2.y; + elem->distance = movinfo.distance2; } else { - elem = new MctlMQSub; - elem->subIndex = prevSubIndex; elem->x = rect.right; elem->y = rect.bottom; elem->distance = point.y; - - movinfo->items.push_back(elem); } } } - if (subIndex != movinfo->item1Index) { - elem = new MctlMQSub; - elem->subIndex = movinfo->item1Index; - elem->x = movinfo->pt2.x; - elem->y = movinfo->pt2.y; - elem->distance = movinfo->distance2; - - movinfo->items.push_back(elem); + if (subIndex != movinfo.item1Index) { + movinfo.items.push_back(MctlMQSub()); + elem = &movinfo.items.back(); + elem->subIndex = movinfo.item1Index; + elem->x = movinfo.pt2.x; + elem->y = movinfo.pt2.y; + elem->distance = movinfo.distance2; } - - movinfo->itemsCount = movinfo->items.size(); } -MessageQueue *MctlGraph::makeWholeQueue(MctlMQ *mctlMQ) { +MessageQueue *MctlGraph::makeWholeQueue(MctlMQ &mctlMQ) { debugC(4, kDebugPathfinding, "MctlGraph::makeWholeQueue(...)"); MctlMQ movinfo(mctlMQ); - int curX = mctlMQ->pt1.x; - int curY = mctlMQ->pt1.y; - int curDistance = mctlMQ->distance1; + int curX = mctlMQ.pt1.x; + int curY = mctlMQ.pt1.y; + int curDistance = mctlMQ.distance1; MessageQueue *mq = new MessageQueue(g_fp->_globalMessageQueueList->compact()); - for (int i = 0; i < mctlMQ->itemsCount - 1; i++) { - if (mctlMQ->items[i + 1]->subIndex != 10) { + int numItems = mctlMQ.items.size(); + + for (int i = 0; i < numItems - 1; i++) { + if (mctlMQ.items[i + 1].subIndex != 10) { MG2I *mg2i; - if (i >= mctlMQ->itemsCount - 2 || mctlMQ->items[i + 2]->subIndex != 10) { + if (i >= numItems - 2 || mctlMQ.items[i + 2].subIndex != 10) { movinfo.flags = 0; - mg2i = &_items2[mctlMQ->index]->_subItems[mctlMQ->items[i]->subIndex]._turnS[mctlMQ->items[i + 1]->subIndex]; + mg2i = &_items2[mctlMQ.index]._subItems[mctlMQ.items[i].subIndex]._turnS[mctlMQ.items[i + 1].subIndex]; } else { movinfo.flags = 2; - mg2i = &_items2[mctlMQ->index]->_subItems[mctlMQ->items[i]->subIndex]._turn[mctlMQ->items[i + 1]->subIndex]; + mg2i = &_items2[mctlMQ.index]._subItems[mctlMQ.items[i].subIndex]._turn[mctlMQ.items[i + 1].subIndex]; } - if (i < mctlMQ->itemsCount - 2 - || (mctlMQ->items[i]->x == mctlMQ->items[i + 1]->x - && mctlMQ->items[i]->y == mctlMQ->items[i + 1]->y) - || mctlMQ->items[i]->x == -1 - || mctlMQ->items[i]->y == -1 - || mctlMQ->items[i + 1]->x == -1 - || mctlMQ->items[i + 1]->y == -1) { + if (i < numItems - 2 + || (mctlMQ.items[i].x == mctlMQ.items[i + 1].x + && mctlMQ.items[i].y == mctlMQ.items[i + 1].y) + || mctlMQ.items[i].x == -1 + || mctlMQ.items[i].y == -1 + || mctlMQ.items[i + 1].x == -1 + || mctlMQ.items[i + 1].y == -1) { - ExCommand *ex = new ExCommand(_items2[mctlMQ->index]->_objectId, 1, mg2i->_movementId, 0, 0, 0, 1, 0, 0, 0); + ExCommand *ex = new ExCommand(_items2[mctlMQ.index]._objectId, 1, mg2i->_movementId, 0, 0, 0, 1, 0, 0, 0); ex->_excFlags |= 2; - ex->_param = _items2[mctlMQ->index]->_obj->_odelay; + ex->_param = _items2[mctlMQ.index]._obj->_odelay; ex->_field_24 = 1; ex->_field_14 = -1; mq->addExCommandToEnd(ex); @@ -2029,45 +2017,43 @@ MessageQueue *MctlGraph::makeWholeQueue(MctlMQ *mctlMQ) { memset(&mkQueue, 0, sizeof(mkQueue)); - mkQueue.ani = _items2[mctlMQ->index]->_obj; + mkQueue.ani = _items2[mctlMQ.index]._obj; mkQueue.staticsId2 = mg2i->_mov->_staticsObj2->_staticsId; - mkQueue.x1 = mctlMQ->items[i + 1]->x; - mkQueue.y1 = mctlMQ->items[i + 1]->y; - mkQueue.field_1C = mctlMQ->items[i + 1]->distance; + mkQueue.x1 = mctlMQ.items[i + 1].x; + mkQueue.y1 = mctlMQ.items[i + 1].y; + mkQueue.field_1C = mctlMQ.items[i + 1].distance; mkQueue.staticsId1 = mg2i->_mov->_staticsObj1->_staticsId; - mkQueue.x2 = mctlMQ->items[i]->x; - mkQueue.y2 = mctlMQ->items[i]->y; + mkQueue.x2 = mctlMQ.items[i].x; + mkQueue.y2 = mctlMQ.items[i].y; mkQueue.field_10 = 1; mkQueue.flags = 0x7f; mkQueue.movementId = mg2i->_movementId; - MessageQueue *mq2 = _aniHandler.makeRunQueue(&mkQueue); - mq->mergeQueue(mq2); + Common::ScopedPtr<MessageQueue> mq2(_aniHandler.makeRunQueue(&mkQueue)); + mq->mergeQueue(mq2.get()); - delete mq2; - - curX = mctlMQ->items[i + 1]->x; - curY = mctlMQ->items[i + 1]->y; + curX = mctlMQ.items[i + 1].x; + curY = mctlMQ.items[i + 1].y; } } else { - movinfo.item1Index = mctlMQ->items[i]->subIndex; + movinfo.item1Index = mctlMQ.items[i].subIndex; movinfo.subIndex = movinfo.item1Index; movinfo.pt1.y = curY; movinfo.pt1.x = curX; movinfo.distance1 = curDistance; - movinfo.pt2.x = mctlMQ->items[i + 2]->x; - movinfo.pt2.y = mctlMQ->items[i + 2]->y; - movinfo.distance2 = mctlMQ->items[i + 2]->distance; + movinfo.pt2.x = mctlMQ.items[i + 2].x; + movinfo.pt2.y = mctlMQ.items[i + 2].y; + movinfo.distance2 = mctlMQ.items[i + 2].distance; - if (i < mctlMQ->itemsCount - 4 - && mctlMQ->items[i + 2]->subIndex != 10 - && mctlMQ->items[i + 3]->subIndex != 10 - && mctlMQ->items[i + 2]->subIndex != mctlMQ->items[i + 3]->subIndex - && mctlMQ->items[i + 4]->subIndex == 10) { + if (i < numItems - 4 + && mctlMQ.items[i + 2].subIndex != 10 + && mctlMQ.items[i + 3].subIndex != 10 + && mctlMQ.items[i + 2].subIndex != mctlMQ.items[i + 3].subIndex + && mctlMQ.items[i + 4].subIndex == 10) { - MG2I *m = &_items2[mctlMQ->index]->_subItems[mctlMQ->items[i + 2]->subIndex]._turn[mctlMQ->items[i + 3]->subIndex]; + MG2I *m = &_items2[mctlMQ.index]._subItems[mctlMQ.items[i + 2].subIndex]._turn[mctlMQ.items[i + 3].subIndex]; if (movinfo.item1Index && movinfo.item1Index != 1) { movinfo.pt2.y -= m->_my; @@ -2077,18 +2063,18 @@ MessageQueue *MctlGraph::makeWholeQueue(MctlMQ *mctlMQ) { movinfo.flags = (movinfo.flags & 2) | 1; } - } else if (i < mctlMQ->itemsCount - 3 - && mctlMQ->items[i + 2]->subIndex != 10 - && mctlMQ->items[i + 3]->subIndex != 10 - && mctlMQ->items[i + 2]->subIndex != mctlMQ->items[i + 3]->subIndex) { + } else if (i < numItems - 3 + && mctlMQ.items[i + 2].subIndex != 10 + && mctlMQ.items[i + 3].subIndex != 10 + && mctlMQ.items[i + 2].subIndex != mctlMQ.items[i + 3].subIndex) { - MG2I *m = &_items2[mctlMQ->index]->_subItems[mctlMQ->items[i + 2]->subIndex]._turnS[mctlMQ->items[i + 3]->subIndex]; + MG2I *m = &_items2[mctlMQ.index]._subItems[mctlMQ.items[i + 2].subIndex]._turnS[mctlMQ.items[i + 3].subIndex]; movinfo.pt2.x -= m->_mx; movinfo.pt2.y -= m->_my; - movinfo.flags = (movinfo.flags & 2) | (mctlMQ->flags & 1); + movinfo.flags = (movinfo.flags & 2) | (mctlMQ.flags & 1); } else { - movinfo.flags = (movinfo.flags & 2) | (mctlMQ->flags & 1); + movinfo.flags = (movinfo.flags & 2) | (mctlMQ.flags & 1); } i++; // intentional @@ -2110,8 +2096,8 @@ MessageQueue *MctlGraph::makeWholeQueue(MctlMQ *mctlMQ) { } } - mctlMQ->pt2.x = movinfo.pt2.x; - mctlMQ->pt2.y = movinfo.pt2.y; + mctlMQ.pt2.x = movinfo.pt2.x; + mctlMQ.pt2.y = movinfo.pt2.y; return mq; } @@ -2124,10 +2110,6 @@ int MctlGraph::detachObject(StaticANIObject *obj) { void MctlGraph::detachAllObjects() { debugC(4, kDebugPathfinding, "MctlGraph::detachAllObjects()"); - - for (uint i = 0; i < _items2.size(); i++) - delete _items2[i]; - _items2.clear(); } @@ -2222,7 +2204,7 @@ MessageQueue *MctlGraph::makeQueue(StaticANIObject *obj, int xpos, int ypos, int if (subMgm) { obj->_messageQueueId = 0; - obj->changeStatics2(_items2[idx]->_subItems[idxsub]._staticsId1); + obj->changeStatics2(_items2[idx]._subItems[idxsub]._staticsId1); newx = obj->_ox; newy = obj->_oy; } else { @@ -2255,7 +2237,7 @@ MessageQueue *MctlGraph::makeQueue(StaticANIObject *obj, int xpos, int ypos, int return 0; } - ExCommand *ex = new ExCommand(picAniInfo.objectId, 1, _items2[idx]->_subItems[idxsub]._turnS[idxwalk]._movementId, 0, 0, 0, 1, 0, 0, 0); + ExCommand *ex = new ExCommand(picAniInfo.objectId, 1, _items2[idx]._subItems[idxsub]._turnS[idxwalk]._movementId, 0, 0, 0, 1, 0, 0, 0); ex->_field_24 = 1; ex->_param = picAniInfo.field_8; @@ -2310,7 +2292,7 @@ MessageQueue *MctlGraph::makeQueue(StaticANIObject *obj, int xpos, int ypos, int } } - Common::Array<MovGraphLink *> tempLinkList; + MovGraphLinkList tempLinkList; double minPath = iterate(&linkInfoSource, &linkInfoDest, &tempLinkList); debugC(0, kDebugPathfinding, "MctlGraph::makeQueue(): path: %g parts: %d", minPath, tempLinkList.size()); @@ -2372,12 +2354,12 @@ MessageQueue *MctlGraph::makeQueue(StaticANIObject *obj, int xpos, int ypos, int mctlMQ1.flags = fuzzyMatch != 0; - if (_items2[idx]->_subItems[idxsub]._staticsId1 != obj->_statics->_staticsId) + if (_items2[idx]._subItems[idxsub]._staticsId1 != obj->_statics->_staticsId) mctlMQ1.flags |= 2; - generateList(&mctlMQ1, &tempLinkList, &linkInfoSource, &linkInfoDest); + generateList(mctlMQ1, &tempLinkList, &linkInfoSource, &linkInfoDest); - MessageQueue *mq = makeWholeQueue(&mctlMQ1); + MessageQueue *mq = makeWholeQueue(mctlMQ1); linkInfoDest.node = getHitNode(mctlMQ1.pt2.x, mctlMQ1.pt2.y, fuzzyMatch); @@ -2399,7 +2381,7 @@ MessageQueue *MctlGraph::makeQueue(StaticANIObject *obj, int xpos, int ypos, int ex->_excFlags |= 2; mq->addExCommand(ex); - ex = new ExCommand(picAniInfo.objectId, 22, _items2[idx]->_subItems[idxsub]._staticsId1, 0, 0, 0, 1, 0, 0, 0); + ex = new ExCommand(picAniInfo.objectId, 22, _items2[idx]._subItems[idxsub]._staticsId1, 0, 0, 0, 1, 0, 0, 0); ex->_param = picAniInfo.field_8; ex->_excFlags |= 3; @@ -2407,9 +2389,8 @@ MessageQueue *MctlGraph::makeQueue(StaticANIObject *obj, int xpos, int ypos, int } } } else { - if (mq) - delete mq; - mq = 0; + delete mq; + mq = nullptr; } obj->setPicAniInfo(picAniInfo); @@ -2449,7 +2430,7 @@ int MctlGraph::getDirBySize(MovGraphLink *lnk, int x, int y) { return ((y > 0) + 2); } -int MctlGraph::getLinkDir(Common::Array<MovGraphLink *> *linkList, int idx, Common::Rect *rect, Common::Point *point) { +int MctlGraph::getLinkDir(MovGraphLinkList *linkList, int idx, Common::Rect *rect, Common::Point *point) { debugC(4, kDebugPathfinding, "MctlGraph::getLinkDir(...)"); MovGraphNode *node1 = (*linkList)[idx]->_graphSrc; @@ -2505,16 +2486,16 @@ MessageQueue *MctlGraph::makeLineQueue(MctlMQ *info) { int my1 = 0; if (!(info->flags & 2)) { - mx1 = _items2[info->index]->_subItems[info->subIndex]._walk[0]._mx; - my1 = _items2[info->index]->_subItems[info->subIndex]._walk[0]._my; + mx1 = _items2[info->index]._subItems[info->subIndex]._walk[0]._mx; + my1 = _items2[info->index]._subItems[info->subIndex]._walk[0]._my; } int mx2 = 0; int my2 = 0; if (!(info->flags & 4)) { - mx2 = _items2[info->index]->_subItems[info->subIndex]._walk[2]._mx; - my2 = _items2[info->index]->_subItems[info->subIndex]._walk[2]._my; + mx2 = _items2[info->index]._subItems[info->subIndex]._walk[2]._mx; + my2 = _items2[info->index]._subItems[info->subIndex]._walk[2]._my; } Common::Point point; @@ -2524,7 +2505,7 @@ MessageQueue *MctlGraph::makeLineQueue(MctlMQ *info) { int a2 = 0; int mgmLen; - point = _aniHandler.getNumCycles(_items2[info->index]->_subItems[info->subIndex]._walk[1]._mov, x, y, &mgmLen, &a2, info->flags & 1); + point = _aniHandler.getNumCycles(_items2[info->index]._subItems[info->subIndex]._walk[1]._mov, x, y, &mgmLen, &a2, info->flags & 1); int x1 = point.x; int y1 = point.y; @@ -2532,7 +2513,7 @@ MessageQueue *MctlGraph::makeLineQueue(MctlMQ *info) { if (!(info->flags & 1)) { if (info->subIndex == 1 || info->subIndex == 0) { a2 = -1; - x1 = mgmLen * _items2[info->index]->_subItems[info->subIndex]._walk[1]._mx; + x1 = mgmLen * _items2[info->index]._subItems[info->subIndex]._walk[1]._mx; x = x1; info->pt2.x = x1 + info->pt1.x + mx1 + mx2; } @@ -2541,7 +2522,7 @@ MessageQueue *MctlGraph::makeLineQueue(MctlMQ *info) { if (!(info->flags & 1)) { if (info->subIndex == 2 || info->subIndex == 3) { a2 = -1; - y1 = mgmLen * _items2[info->index]->_subItems[info->subIndex]._walk[1]._my; + y1 = mgmLen * _items2[info->index]._subItems[info->subIndex]._walk[1]._my; y = y1; info->pt2.y = y1 + info->pt1.y + my1 + my2; } @@ -2551,23 +2532,23 @@ MessageQueue *MctlGraph::makeLineQueue(MctlMQ *info) { int cntY = 0; if (!(info->flags & 2)) { - cntX = _items2[info->index]->_subItems[info->subIndex]._walk[0]._mov->countPhasesWithFlag(-1, 1); - cntY = _items2[info->index]->_subItems[info->subIndex]._walk[0]._mov->countPhasesWithFlag(-1, 2); + cntX = _items2[info->index]._subItems[info->subIndex]._walk[0]._mov->countPhasesWithFlag(-1, 1); + cntY = _items2[info->index]._subItems[info->subIndex]._walk[0]._mov->countPhasesWithFlag(-1, 2); } if (mgmLen > 1) { - cntX += (mgmLen - 1) * _items2[info->index]->_subItems[info->subIndex]._walk[1]._mov->countPhasesWithFlag(-1, 1); - cntY += (mgmLen - 1) * _items2[info->index]->_subItems[info->subIndex]._walk[1]._mov->countPhasesWithFlag(-1, 2); + cntX += (mgmLen - 1) * _items2[info->index]._subItems[info->subIndex]._walk[1]._mov->countPhasesWithFlag(-1, 1); + cntY += (mgmLen - 1) * _items2[info->index]._subItems[info->subIndex]._walk[1]._mov->countPhasesWithFlag(-1, 2); } if (mgmLen > 0) { - cntX += _items2[info->index]->_subItems[info->subIndex]._walk[1]._mov->countPhasesWithFlag(a2, 1); - cntY += _items2[info->index]->_subItems[info->subIndex]._walk[1]._mov->countPhasesWithFlag(a2, 2); + cntX += _items2[info->index]._subItems[info->subIndex]._walk[1]._mov->countPhasesWithFlag(a2, 1); + cntY += _items2[info->index]._subItems[info->subIndex]._walk[1]._mov->countPhasesWithFlag(a2, 2); } if (!(info->flags & 4)) { - cntX += _items2[info->index]->_subItems[info->subIndex]._walk[2]._mov->countPhasesWithFlag(-1, 1); - cntY += _items2[info->index]->_subItems[info->subIndex]._walk[2]._mov->countPhasesWithFlag(-1, 2); + cntX += _items2[info->index]._subItems[info->subIndex]._walk[2]._mov->countPhasesWithFlag(-1, 1); + cntY += _items2[info->index]._subItems[info->subIndex]._walk[2]._mov->countPhasesWithFlag(-1, 2); } int dx1 = x - x1; @@ -2603,9 +2584,9 @@ MessageQueue *MctlGraph::makeLineQueue(MctlMQ *info) { if (info->flags & 2) { ex = new ExCommand( - _items2[info->index]->_objectId, + _items2[info->index]._objectId, 5, - _items2[info->index]->_subItems[info->subIndex]._walk[1]._movementId, + _items2[info->index]._subItems[info->subIndex]._walk[1]._movementId, info->pt1.x, info->pt1.y, 0, @@ -2616,14 +2597,14 @@ MessageQueue *MctlGraph::makeLineQueue(MctlMQ *info) { ex->_field_14 = info->distance1; - ex->_param = _items2[info->index]->_obj->_odelay; + ex->_param = _items2[info->index]._obj->_odelay; ex->_field_24 = 1; ex->_excFlags |= 2; } else { ex = new ExCommand( - _items2[info->index]->_objectId, + _items2[info->index]._objectId, 5, - _items2[info->index]->_subItems[info->subIndex]._walk[0]._movementId, + _items2[info->index]._subItems[info->subIndex]._walk[0]._movementId, info->pt1.x, info->pt1.y, 0, @@ -2634,21 +2615,21 @@ MessageQueue *MctlGraph::makeLineQueue(MctlMQ *info) { ex->_field_14 = info->distance1; - ex->_param = _items2[info->index]->_obj->_odelay; + ex->_param = _items2[info->index]._obj->_odelay; ex->_field_24 = 1; ex->_excFlags |= 2; mq->addExCommandToEnd(ex); ex = _aniHandler.createCommand( - _items2[info->index]->_subItems[info->subIndex]._walk[0]._mov, - _items2[info->index]->_objectId, + _items2[info->index]._subItems[info->subIndex]._walk[0]._mov, + _items2[info->index]._objectId, x1, y1, - &x2, - &y2, + x2, + y2, -1); ex->_parId = mq->_id; - ex->_param = _items2[info->index]->_obj->_odelay; + ex->_param = _items2[info->index]._obj->_odelay; } mq->addExCommandToEnd(ex); @@ -2662,37 +2643,37 @@ MessageQueue *MctlGraph::makeLineQueue(MctlMQ *info) { par = -1; ex = _aniHandler.createCommand( - _items2[info->index]->_subItems[info->subIndex]._walk[1]._mov, - _items2[info->index]->_objectId, + _items2[info->index]._subItems[info->subIndex]._walk[1]._mov, + _items2[info->index]._objectId, x1, y1, - &x2, - &y2, + x2, + y2, par); ex->_parId = mq->_id; - ex->_param = _items2[info->index]->_obj->_odelay; + ex->_param = _items2[info->index]._obj->_odelay; mq->addExCommandToEnd(ex); } if (!(info->flags & 4)) { ex = _aniHandler.createCommand( - _items2[info->index]->_subItems[info->subIndex]._walk[2]._mov, - _items2[info->index]->_objectId, + _items2[info->index]._subItems[info->subIndex]._walk[2]._mov, + _items2[info->index]._objectId, x1, y1, - &x2, - &y2, + x2, + y2, -1); ex->_parId = mq->_id; - ex->_param = _items2[info->index]->_obj->_odelay; + ex->_param = _items2[info->index]._obj->_odelay; mq->addExCommandToEnd(ex); } - ex = new ExCommand(_items2[info->index]->_objectId, 5, -1, info->pt2.x, info->pt2.y, 0, 1, 0, 0, 0); + ex = new ExCommand(_items2[info->index]._objectId, 5, -1, info->pt2.x, info->pt2.y, 0, 1, 0, 0, 0); ex->_field_14 = info->distance2; - ex->_param = _items2[info->index]->_obj->_odelay; + ex->_param = _items2[info->index]._obj->_odelay; ex->_field_24 = 0; ex->_excFlags |= 2; @@ -2781,7 +2762,7 @@ MovGraphLink *MctlGraph::getNearestLink(int x, int y) { return 0; } -double MctlGraph::iterate(LinkInfo *linkInfoSource, LinkInfo *linkInfoDest, Common::Array<MovGraphLink *> *listObj) { +double MctlGraph::iterate(LinkInfo *linkInfoSource, LinkInfo *linkInfoDest, MovGraphLinkList *listObj) { debugC(4, kDebugPathfinding, "MctlGraph::iterate(...)"); LinkInfo linkInfoWorkSource; @@ -2797,7 +2778,7 @@ double MctlGraph::iterate(LinkInfo *linkInfoSource, LinkInfo *linkInfoDest, Comm linkInfoWorkSource.node = 0; linkInfoWorkSource.link = lnk; - Common::Array<MovGraphLink *> tmpList; + MovGraphLinkList tmpList; lnk->_flags |= 0x80000000; @@ -2817,7 +2798,7 @@ double MctlGraph::iterate(LinkInfo *linkInfoSource, LinkInfo *linkInfoDest, Comm linkInfoWorkSource.node = linkInfoSource->link->_graphSrc; linkInfoWorkSource.link = 0; - Common::Array<MovGraphLink *> tmpList; + MovGraphLinkList tmpList; double newDistance = iterate(&linkInfoWorkSource, linkInfoDest, &tmpList); @@ -2966,28 +2947,24 @@ bool ReactParallel::load(MfcArchive &file) { } void ReactParallel::createRegion() { - _points = (Common::Point **)malloc(sizeof(Common::Point *) * 4); - - for (int i = 0; i < 4; i++) - _points[i] = new Common::Point; + _points.resize(4); double at = atan2((double)(_y1 - _y2), (double)(_x1 - _x2)) + 1.570796; // pi/2 double sn = sin(at); double cs = cos(at); - _points[0]->x = (int16)(_x1 - _dx * cs); - _points[0]->y = (int16)(_y1 - _dx * sn); + _points[0].x = _x1 - _dx * cs; + _points[0].y = _y1 - _dx * sn; - _points[1]->x = (int16)(_x2 - _dx * cs); - _points[1]->y = (int16)(_y2 - _dx * sn); + _points[1].x = _x2 - _dx * cs; + _points[1].y = _y2 - _dx * sn; - _points[2]->x = (int16)(_x2 + _dy * cs); - _points[2]->y = (int16)(_y2 + _dy * sn); + _points[2].x = _x2 + _dy * cs; + _points[2].y = _y2 + _dy * sn; - _points[3]->x = (int16)(_x1 + _dy * cs); - _points[3]->y = (int16)(_y1 + _dy * sn); + _points[3].x = _x1 + _dy * cs; + _points[3].y = _y1 + _dy * sn; - _pointCount = 4; // GdiObject::Attach(_rgn, CreatePolygonRgn(_points, 4, 2); } @@ -2999,13 +2976,12 @@ void ReactParallel::setCenter(int x1, int y1, int x2, int y2) { } ReactPolygonal::ReactPolygonal() { + // hack for using isValid to avoid creating another state variable for + // getBBox + _bbox.right = -1; + _centerX = 0; _centerY = 0; - _bbox = 0; -} - -ReactPolygonal::~ReactPolygonal() { - delete _bbox; } bool ReactPolygonal::load(MfcArchive &file) { @@ -3013,18 +2989,11 @@ bool ReactPolygonal::load(MfcArchive &file) { _centerX = file.readSint32LE(); _centerY = file.readSint32LE(); - _pointCount = file.readUint32LE(); - - if (_pointCount > 0) { - _points = (Common::Point **)malloc(sizeof(Common::Point *) * _pointCount); - - for (int i = 0; i < _pointCount; i++) { - _points[i] = new Common::Point; - - _points[i]->x = file.readUint32LE(); - _points[i]->y = file.readUint32LE(); - } + _points.resize(file.readUint32LE()); + for (uint i = 0; i < _points.size(); ++i) { + _points[i].x = file.readUint32LE(); + _points[i].y = file.readUint32LE(); } createRegion(); @@ -3033,7 +3002,7 @@ bool ReactPolygonal::load(MfcArchive &file) { } void ReactPolygonal::createRegion() { - if (_points) { + if (_points.size()) { // GdiObject::Attach(_rgn, CreatePolygonRgn(_points, _pointCount, 2); } @@ -3043,52 +3012,46 @@ void ReactPolygonal::setCenter(int x1, int y1, int x2, int y2) { int cX = (x2 + x1) / 2; int cY = (y2 + y1) / 2; - if (_points) { - for (int i = 0; i < _pointCount; i++) { - _points[i]->x += cX - _centerX; - _points[i]->y += cY - _centerY; - } + for (uint i = 0; i < _points.size(); ++i) { + _points[i].x += cX - _centerX; + _points[i].y += cY - _centerY; } _centerX = cX; _centerY = cY; } -void ReactPolygonal::getBBox(Common::Rect *rect) { - if (!_pointCount) - return; - - if (_bbox) { - *rect = *_bbox; - return; - } +Common::Rect ReactPolygonal::getBBox() { + if (!_points.size()) + return Common::Rect(); - rect->left = _points[0]->x; - rect->top = _points[0]->y; - rect->right = _points[0]->x; - rect->bottom = _points[0]->y; + if (!_bbox.isValidRect()) { + _bbox.left = _points[0].x; + _bbox.top = _points[0].y; + _bbox.right = _points[0].x; + _bbox.bottom = _points[0].y; - for (int i = 1; i < _pointCount; i++) { - if (rect->left > _points[i]->x) - rect->left = _points[i]->x; + for (uint i = 1; i < _points.size(); ++i) { + if (_bbox.left > _points[i].x) + _bbox.left = _points[i].x; - if (rect->top > _points[i]->y) - rect->top = _points[i]->y; + if (_bbox.top > _points[i].y) + _bbox.top = _points[i].y; - if (rect->right < _points[i]->x) - rect->right = _points[i]->x; + if (_bbox.right < _points[i].x) + _bbox.right = _points[i].x; - if (rect->bottom < _points[i]->y) - rect->bottom = _points[i]->y; + if (_bbox.bottom < _points[i].y) + _bbox.bottom = _points[i].y; + } } - _bbox = new Common::Rect; - *_bbox = *rect; + return _bbox; } bool MovGraphReact::pointInRegion(int x, int y) { - if (_pointCount < 3) { + if (_points.size() < 3) { return false; } @@ -3099,12 +3062,12 @@ bool MovGraphReact::pointInRegion(int x, int y) { p.x = x; p.y = y; - p1.x = _points[0]->x; - p1.y = _points[0]->y; + p1.x = _points[0].x; + p1.y = _points[0].y; - for (int i = 1; i <= _pointCount; i++) { - p2.x = _points[i % _pointCount]->x; - p2.y = _points[i % _pointCount]->y; + for (uint i = 1; i <= _points.size(); i++) { + p2.x = _points[i % _points.size()].x; + p2.y = _points[i % _points.size()].y; if (p.y > MIN(p1.y, p2.y)) { if (p.y <= MAX(p1.y, p2.y)) { diff --git a/engines/fullpipe/motion.h b/engines/fullpipe/motion.h index 2a1450eb71..b47cff9a13 100644 --- a/engines/fullpipe/motion.h +++ b/engines/fullpipe/motion.h @@ -70,13 +70,9 @@ public: class MovGraphReact : public CObject { public: - int _pointCount; - Common::Point **_points; + PointList _points; public: - MovGraphReact() : _pointCount(0), _points(0) {} - ~MovGraphReact() { free(_points); } - virtual void setCenter(int x1, int y1, int x2, int y2) {} virtual void createRegion() {} virtual bool pointInRegion(int x, int y); @@ -200,20 +196,19 @@ public: }; class ReactPolygonal : public MovGraphReact { - Common::Rect *_bbox; + Common::Rect _bbox; int _centerX; int _centerY; public: ReactPolygonal(); - ~ReactPolygonal(); virtual bool load(MfcArchive &file); virtual void setCenter(int x1, int y1, int x2, int y2); virtual void createRegion(); - void getBBox(Common::Rect *rect); + Common::Rect getBBox(); }; class MovGraphLink : public CObject { @@ -238,6 +233,7 @@ class MovGraphLink : public CObject { void recalcLength(); }; +typedef Common::Array<MovGraphLink *> MovGraphLinkList; struct MovStep { int sfield_0; @@ -315,7 +311,7 @@ public: MovGraphNode *calcOffset(int ox, int oy); int getObjectIndex(StaticANIObject *ani); Common::Array<MovArr *> *getHitPoints(int x, int y, int *arrSize, int flag1, int flag2); - void findAllPaths(MovGraphLink *lnk, MovGraphLink *lnk2, Common::Array<MovGraphLink *> &tempObList1, Common::Array<MovGraphLink *> &tempObList2); + void findAllPaths(MovGraphLink *lnk, MovGraphLink *lnk2, MovGraphLinkList &tempObList1, MovGraphLinkList &tempObList2); Common::Array<MovItem *> *getPaths(MovArr *movarr1, MovArr *movarr2, int *listCount); void genMovItem(MovItem *movitem, MovGraphLink *grlink, MovArr *movarr1, MovArr *movarr2); bool getHitPoint(int idx, int x, int y, MovArr *arr, int a6); @@ -361,12 +357,10 @@ struct MctlMQ { int distance2; int subIndex; int item1Index; - Common::Array<MctlMQSub *> items; - int itemsCount; + Common::Array<MctlMQSub> items; int flags; MctlMQ() { clear(); } - MctlMQ(MctlMQ *src); void clear(); }; @@ -378,7 +372,7 @@ struct MctlAni { // 744 class MctlGraph : public MovGraph { public: - Common::Array<MctlAni *> _items2; + Common::Array<MctlAni> _items2; public: virtual void attachObject(StaticANIObject *obj); @@ -393,16 +387,16 @@ public: int getDirByPoint(int idx, StaticANIObject *ani); int getDirBySize(MovGraphLink *lnk, int x, int y); - int getLinkDir(Common::Array<MovGraphLink *> *linkList, int idx, Common::Rect *a3, Common::Point *a4); + int getLinkDir(MovGraphLinkList *linkList, int idx, Common::Rect *a3, Common::Point *a4); - bool fillData(StaticANIObject *obj, MctlAni *item); - void generateList(MctlMQ *movinfo, Common::Array<MovGraphLink *> *linkList, LinkInfo *lnkSrc, LinkInfo *lnkDst); - MessageQueue *makeWholeQueue(MctlMQ *mctlMQ); + bool fillData(StaticANIObject *obj, MctlAni &item); + void generateList(MctlMQ &movinfo, MovGraphLinkList *linkList, LinkInfo *lnkSrc, LinkInfo *lnkDst); + MessageQueue *makeWholeQueue(MctlMQ &mctlMQ); MovGraphNode *getHitNode(int x, int y, int strictMatch); MovGraphLink *getHitLink(int x, int y, int idx, int fuzzyMatch); MovGraphLink *getNearestLink(int x, int y); - double iterate(LinkInfo *linkInfoSource, LinkInfo *linkInfoDest, Common::Array<MovGraphLink *> *listObj); + double iterate(LinkInfo *linkInfoSource, LinkInfo *linkInfoDest, MovGraphLinkList *listObj); MessageQueue *makeLineQueue(MctlMQ *movinfo); }; diff --git a/engines/fullpipe/scenes/scene02.cpp b/engines/fullpipe/scenes/scene02.cpp index e2350a958a..c503013190 100644 --- a/engines/fullpipe/scenes/scene02.cpp +++ b/engines/fullpipe/scenes/scene02.cpp @@ -113,12 +113,12 @@ int sceneHandler02(ExCommand *ex) { if (g_vars->scene02_boxDelay >= 1) { --g_vars->scene02_boxDelay; } else if (g_fp->_floaters->_array2.size() >= 1) { - if (g_fp->_floaters->_array2[0]->val5 == -50) { + if (g_fp->_floaters->_array2[0].val5 == -50) { g_fp->_floaters->stopAll(); g_vars->scene02_boxOpen = false; g_vars->scene02_boxDelay = 100 * g_fp->_rnd.getRandomNumber(32767) + 150; } else { - g_fp->_floaters->_array2[0]->val3 = -50; + g_fp->_floaters->_array2[0].val3 = -50; } } else { g_fp->_floaters->genFlies(g_fp->_currentScene, g_fp->_rnd.getRandomNumber(700) + 100, -50, 0, 0); diff --git a/engines/fullpipe/scenes/scene05.cpp b/engines/fullpipe/scenes/scene05.cpp index 35fd24eb99..e67e12ac3d 100644 --- a/engines/fullpipe/scenes/scene05.cpp +++ b/engines/fullpipe/scenes/scene05.cpp @@ -159,9 +159,9 @@ void sceneHandler05_genFlies() { int y = g_fp->_rnd.getRandomNumber(60) + i * 30 + 520; g_fp->_floaters->genFlies(g_fp->_currentScene, x, y, 5, 1); - g_fp->_floaters->_array2.back()->val2 = 585; - g_fp->_floaters->_array2.back()->val3 = -70; - g_fp->_floaters->_array2.back()->val11 = 8.0; + g_fp->_floaters->_array2.back().val2 = 585; + g_fp->_floaters->_array2.back().val3 = -70; + g_fp->_floaters->_array2.back().val11 = 8.0; } } diff --git a/engines/fullpipe/scenes/scene12.cpp b/engines/fullpipe/scenes/scene12.cpp index 23bab31912..81732bc067 100644 --- a/engines/fullpipe/scenes/scene12.cpp +++ b/engines/fullpipe/scenes/scene12.cpp @@ -50,9 +50,9 @@ void scene12_initScene(Scene *sc) { void sceneHandler12_updateFloaters() { g_fp->_floaters->genFlies(g_fp->_currentScene, 397, -50, 100, 6); - g_fp->_floaters->_array2[0]->countdown = g_fp->_rnd.getRandomNumber(6) + 4; - g_fp->_floaters->_array2[0]->val6 = 397; - g_fp->_floaters->_array2[0]->val7 = -50; + g_fp->_floaters->_array2[0].countdown = g_fp->_rnd.getRandomNumber(6) + 4; + g_fp->_floaters->_array2[0].val6 = 397; + g_fp->_floaters->_array2[0].val7 = -50; } int sceneHandler12(ExCommand *cmd) { diff --git a/engines/fullpipe/scenes/scene17.cpp b/engines/fullpipe/scenes/scene17.cpp index a830a8f985..7dd75ae5a2 100644 --- a/engines/fullpipe/scenes/scene17.cpp +++ b/engines/fullpipe/scenes/scene17.cpp @@ -157,9 +157,9 @@ void sceneHandler17_moonshineFill() { void sceneHandler17_updateFlies() { g_fp->_floaters->genFlies(g_fp->_currentScene, 239, -50, 20, 4); - g_fp->_floaters->_array2[0]->countdown = g_fp->_rnd.getRandomNumber(5) + 6; - g_fp->_floaters->_array2[0]->val6 = 239; - g_fp->_floaters->_array2[0]->val7 = -50; + g_fp->_floaters->_array2[0].countdown = g_fp->_rnd.getRandomNumber(5) + 6; + g_fp->_floaters->_array2[0].val6 = 239; + g_fp->_floaters->_array2[0].val7 = -50; } diff --git a/engines/fullpipe/scenes/scene20.cpp b/engines/fullpipe/scenes/scene20.cpp index 9085f02325..53c019b5e1 100644 --- a/engines/fullpipe/scenes/scene20.cpp +++ b/engines/fullpipe/scenes/scene20.cpp @@ -85,7 +85,7 @@ void scene20_initScene(Scene *sc) { for (int i = 0; i < 3; i++) { g_fp->_floaters->genFlies(sc, g_fp->_rnd.getRandomNumber(101) + 70, g_fp->_rnd.getRandomNumber(51) + 175, 100, 0); - g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1]->val13 = g_fp->_rnd.getRandomNumber(9); + g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1].val13 = g_fp->_rnd.getRandomNumber(9); } g_fp->_currentScene = oldsc; @@ -98,18 +98,18 @@ void sceneHandler20_updateFlies() { if (sz < 3) { g_fp->_floaters->genFlies(g_fp->_currentScene, 253, 650, 200, 0); - g_fp->_floaters->_array2[sz - 1]->val2 = 250; - g_fp->_floaters->_array2[sz - 1]->val3 = 200; + g_fp->_floaters->_array2[sz - 1].val2 = 250; + g_fp->_floaters->_array2[sz - 1].val3 = 200; } else { int idx = g_fp->_rnd.getRandomNumber(sz); - g_fp->_floaters->_array2[idx]->countdown = 0; - g_fp->_floaters->_array2[idx]->fflags |= 4u; - g_fp->_floaters->_array2[idx]->val2 = 250; - g_fp->_floaters->_array2[idx]->val3 = 200; - g_fp->_floaters->_array2[idx]->val6 = 253; - g_fp->_floaters->_array2[idx]->val7 = 650; - g_fp->_floaters->_array2[idx]->ani->_priority = 200; + g_fp->_floaters->_array2[idx].countdown = 0; + g_fp->_floaters->_array2[idx].fflags |= 4u; + g_fp->_floaters->_array2[idx].val2 = 250; + g_fp->_floaters->_array2[idx].val3 = 200; + g_fp->_floaters->_array2[idx].val6 = 253; + g_fp->_floaters->_array2[idx].val7 = 650; + g_fp->_floaters->_array2[idx].ani->_priority = 200; } g_vars->scene20_fliesCountdown = g_fp->_rnd.getRandomNumber(200) + 400; diff --git a/engines/fullpipe/scenes/scene28.cpp b/engines/fullpipe/scenes/scene28.cpp index 7cf683ac97..c5422bf42c 100644 --- a/engines/fullpipe/scenes/scene28.cpp +++ b/engines/fullpipe/scenes/scene28.cpp @@ -172,13 +172,13 @@ void sceneHandler28_turnOn2() { if (g_vars->scene28_fliesArePresent) { g_fp->_floaters->genFlies(g_fp->_currentScene, 1013, 329, 60, 4); - g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1]->val13 = 30; - g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1]->countdown = g_fp->_rnd.getRandomNumber(12) + 12; + g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1].val13 = 30; + g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1].countdown = g_fp->_rnd.getRandomNumber(12) + 12; g_fp->_floaters->genFlies(g_fp->_currentScene, 1074, 311, 60, 4); - g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1]->val13 = 30; - g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1]->countdown = g_fp->_rnd.getRandomNumber(12) + 12; + g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1].val13 = 30; + g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1].countdown = g_fp->_rnd.getRandomNumber(12) + 12; } g_vars->scene28_fliesArePresent = false; @@ -467,8 +467,8 @@ int sceneHandler28(ExCommand *cmd) { g_fp->_floaters->update(); for (uint i = 0; i < g_fp->_floaters->_array2.size(); i++) - if (g_fp->_floaters->_array2[i]->val13 == 1) - g_fp->_floaters->_array2[i]->ani->_priority = 15; + if (g_fp->_floaters->_array2[i].val13 == 1) + g_fp->_floaters->_array2[i].ani->_priority = 15; g_fp->_behaviorManager->updateBehaviors(); diff --git a/engines/fullpipe/scenes/scene34.cpp b/engines/fullpipe/scenes/scene34.cpp index 040d023bb9..b51715a43d 100644 --- a/engines/fullpipe/scenes/scene34.cpp +++ b/engines/fullpipe/scenes/scene34.cpp @@ -160,9 +160,9 @@ void sceneHandler34_climb() { void sceneHandler34_genFlies() { g_fp->_floaters->genFlies(g_fp->_currentScene, 1072, -50, 100, 4); - g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1]->countdown = 1; - g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1]->val6 = 1072; - g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1]->val7 = -50; + g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1].countdown = 1; + g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1].val6 = 1072; + g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1].val7 = -50; g_vars->scene34_fliesCountdown = g_fp->_rnd.getRandomNumber(500) + 500; } diff --git a/engines/fullpipe/scenes/scene35.cpp b/engines/fullpipe/scenes/scene35.cpp index ed2ab46caa..abeffbee7f 100644 --- a/engines/fullpipe/scenes/scene35.cpp +++ b/engines/fullpipe/scenes/scene35.cpp @@ -141,9 +141,9 @@ void sceneHandler35_genFlies() { xoff += 40; - g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1]->val2 = 1084; - g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1]->val3 = y; - g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1]->val11 = 8.0; + g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1].val2 = 1084; + g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1].val3 = y; + g_fp->_floaters->_array2[g_fp->_floaters->_array2.size() - 1].val11 = 8.0; } g_vars->scene35_fliesCounter = 0; diff --git a/engines/fullpipe/statics.cpp b/engines/fullpipe/statics.cpp index 8c2807fb08..c1daea0c64 100644 --- a/engines/fullpipe/statics.cpp +++ b/engines/fullpipe/statics.cpp @@ -35,56 +35,37 @@ namespace Fullpipe { StepArray::StepArray() { - _points = 0; - _maxPointIndex = 0; _currPointIndex = 0; - _pointsCount = 0; - _isEos = 0; -} - -StepArray::~StepArray() { - if (_pointsCount) { - for (int i = 0; i < _pointsCount; i++) - delete _points[i]; - - free(_points); - - _points = 0; - } + _isEos = false; } void StepArray::clear() { _currPointIndex = 0; - _maxPointIndex = 0; - _isEos = 0; - - for (int i = 0; i < _pointsCount; i++) { - _points[i]->x = 0; - _points[i]->y = 0; - } + _isEos = false; + _points.clear(); } Common::Point StepArray::getCurrPoint() const { - if (_isEos || _points == 0) { + if (_isEos || !_points.size()) { return Common::Point(); } - return Common::Point(_points[_currPointIndex]->x, - _points[_currPointIndex]->y); + return Common::Point(_points[_currPointIndex].x, + _points[_currPointIndex].y); } Common::Point StepArray::getPoint(int index, int offset) const { if (index == -1) index = _currPointIndex; - if (index + offset > _maxPointIndex - 1) - offset = _maxPointIndex - index; + if (index + offset > getPointsCount() - 1) + offset = getPointsCount() - index; Common::Point point; while (offset >= 1) { - point.x += _points[index]->x; - point.y += _points[index]->y; + point.x += _points[index].x; + point.y += _points[index].y; index++; offset--; @@ -94,33 +75,18 @@ Common::Point StepArray::getPoint(int index, int offset) const { } bool StepArray::gotoNextPoint() { - if (_currPointIndex < _maxPointIndex - 1) { + if (_currPointIndex < getPointsCount() - 1) { _currPointIndex++; return true; } else { - _isEos = 1; + _isEos = true; return false; } } -void StepArray::insertPoints(Common::Point **points, int pointsCount) { - if (_currPointIndex + pointsCount >= _pointsCount) { - _points = (Common::Point **)realloc(_points, sizeof(Common::Point *) * (_pointsCount + pointsCount)); - - if (!_points) { - error("Out of memory at StepArray::insertPoints()"); - } - - for(int i = 0; i < pointsCount; i++) - _points[_pointsCount + i] = new Common::Point; - - _pointsCount += pointsCount; - } - - _maxPointIndex = _currPointIndex + pointsCount; - - for (int i = 0; i < pointsCount; i++) - *_points[_currPointIndex + i] = *points[i]; +void StepArray::insertPoints(const PointList &points) { + _points.resize(_currPointIndex + points.size()); + Common::copy(points.begin(), points.end(), _points.begin() + _currPointIndex); } StaticANIObject::StaticANIObject() { @@ -179,7 +145,7 @@ StaticANIObject::StaticANIObject(StaticANIObject *src) : GameObject(src) { _objtype = kObjTypeStaticANIObject; for (uint i = 0; i < src->_staticsList.size(); i++) - _staticsList.push_back(new Statics(*src->_staticsList[i], false)); + _staticsList.push_back(new Statics(src->_staticsList[i], false)); _movement = 0; _statics = 0; @@ -427,7 +393,7 @@ Movement *StaticANIObject::getMovementById(int itemId) { return 0; } -int StaticANIObject::getMovementIdById(int itemId) { +int StaticANIObject::getMovementIdById(int itemId) const { for (uint i = 0; i < _movements.size(); i++) { Movement *mov = _movements[i]; @@ -581,7 +547,7 @@ Statics *StaticANIObject::addReverseStatics(Statics *st) { Statics *res = getStaticsById(st->_staticsId ^ 0x4000); if (!res) { - res = new Statics(*st, true); + res = new Statics(st, true); _staticsList.push_back(res); } @@ -1169,7 +1135,7 @@ void StaticANIObject::playIdle() { adjustSomeXY(); } -void StaticANIObject::startAnimSteps(int movementId, int messageQueueId, int x, int y, Common::Point **points, int pointsCount, int someDynamicPhaseIndex) { +void StaticANIObject::startAnimSteps(int movementId, int messageQueueId, int x, int y, const PointList &points, int someDynamicPhaseIndex) { Movement *mov = 0; if (!(_flags & 0x80)) { @@ -1205,7 +1171,7 @@ void StaticANIObject::startAnimSteps(int movementId, int messageQueueId, int x, _movement->gotoFirstFrame(); _stepArray.clear(); - _stepArray.insertPoints(points, pointsCount); + _stepArray.insertPoints(points); if (!(_flags & 0x40)) { if (!_movement->_currDynamicPhaseIndex) { @@ -1393,17 +1359,17 @@ Statics::Statics() { _data = nullptr; } -Statics::Statics(Statics &src, bool reverse) : DynamicPhase(src, reverse) { - _staticsId = src._staticsId; +Statics::Statics(Statics *src, bool reverse) : DynamicPhase(src, reverse) { + _staticsId = src->_staticsId; if (reverse) { _staticsId ^= 0x4000; - _staticsName = sO_MirroredTo + src._staticsName; + _staticsName = sO_MirroredTo + src->_staticsName; } else { - _staticsName = src._staticsName; + _staticsName = src->_staticsName; } - _memfilename = src._memfilename; + _memfilename = src->_memfilename; } bool Statics::load(MfcArchive &file) { @@ -1582,7 +1548,7 @@ Movement::Movement(Movement *src, int *oldIdxs, int newSize, StaticANIObject *an src->setDynamicPhaseIndex(i); if (i < newSize - 1) - _dynamicPhases.push_back(new DynamicPhase(*src->_currDynamicPhase, 0)); + _dynamicPhases.push_back(new DynamicPhase(src->_currDynamicPhase, 0)); _framePosOffsets[i].x = src->_framePosOffsets[i].x; _framePosOffsets[i].y = src->_framePosOffsets[i].y; @@ -2106,18 +2072,18 @@ DynamicPhase::DynamicPhase() { _data = nullptr; } -DynamicPhase::DynamicPhase(DynamicPhase &src, bool reverse) { - _field_7C = src._field_7C; +DynamicPhase::DynamicPhase(DynamicPhase *src, bool reverse) { + _field_7C = src->_field_7C; _field_7E = 0; debugC(1, kDebugAnimation, "DynamicPhase::DynamicPhase(src, %d)", reverse); if (reverse) { - if (!src._bitmap) - src.init(); + if (!src->_bitmap) + src->init(); - _bitmap.reset(src._bitmap->reverseImage()); - _dataSize = src._dataSize; + _bitmap.reset(src->_bitmap->reverseImage()); + _dataSize = src->_dataSize; if (g_fp->_currArchive) { _mfield_14 = 0; @@ -2126,45 +2092,45 @@ DynamicPhase::DynamicPhase(DynamicPhase &src, bool reverse) { _mflags |= 1; - _someX = src._someX; - _someY = src._someY; + _someX = src->_someX; + _someY = src->_someY; } else { - _mfield_14 = src._mfield_14; - _mfield_8 = src._mfield_8; - _mflags = src._mflags; + _mfield_14 = src->_mfield_14; + _mfield_8 = src->_mfield_8; + _mflags = src->_mflags; - _memfilename = src._memfilename; - _dataSize = src._dataSize; - _mfield_10 = src._mfield_10; - _libHandle = src._libHandle; + _memfilename = src->_memfilename; + _dataSize = src->_dataSize; + _mfield_10 = src->_mfield_10; + _libHandle = src->_libHandle; - if (src._bitmap) { + if (src->_bitmap) { _field_54 = 1; - _bitmap.reset(src._bitmap->reverseImage(false)); + _bitmap.reset(src->_bitmap->reverseImage(false)); } - _someX = src._someX; - _someY = src._someY; + _someX = src->_someX; + _someY = src->_someY; } - _rect = src._rect; + _rect = src->_rect; - _width = src._width; - _height = src._height; - _field_7C = src._field_7C; + _width = src->_width; + _height = src->_height; + _field_7C = src->_field_7C; - if (src.getExCommand()) - _exCommand = src.getExCommand()->createClone(); + if (src->getExCommand()) + _exCommand = src->getExCommand()->createClone(); else _exCommand = 0; - _initialCountdown = src._initialCountdown; - _field_6A = src._field_6A; - _dynFlags = src._dynFlags; + _initialCountdown = src->_initialCountdown; + _field_6A = src->_field_6A; + _dynFlags = src->_dynFlags; - setPaletteData(src.getPaletteData()); + setPaletteData(src->getPaletteData()); - copyMemoryObject2(src); + copyMemoryObject2(*src); } bool DynamicPhase::load(MfcArchive &file) { diff --git a/engines/fullpipe/statics.h b/engines/fullpipe/statics.h index 841c158065..124a293722 100644 --- a/engines/fullpipe/statics.h +++ b/engines/fullpipe/statics.h @@ -31,23 +31,20 @@ class ExCommand; class StepArray : public CObject { int _currPointIndex; - Common::Point **_points; - int _maxPointIndex; - int _pointsCount; - int _isEos; + PointList _points; + bool _isEos; public: StepArray(); - ~StepArray(); void clear(); - int getCurrPointIndex() { return _currPointIndex; } - int getPointsCount() { return _maxPointIndex; } + int getCurrPointIndex() const { return _currPointIndex; } + int getPointsCount() const { return _points.size(); } Common::Point getCurrPoint() const; Common::Point getPoint(int index, int offset) const; bool gotoNextPoint(); - void insertPoints(Common::Point **points, int pointsCount); + void insertPoints(const PointList &points); }; class StaticPhase : public Picture { @@ -78,7 +75,7 @@ class DynamicPhase : public StaticPhase { public: DynamicPhase(); - DynamicPhase(DynamicPhase &src, bool reverse); + DynamicPhase(DynamicPhase *src, bool reverse); virtual bool load(MfcArchive &file); @@ -93,7 +90,7 @@ class Statics : public DynamicPhase { public: Statics(); - Statics(Statics &src, bool reverse); + Statics(Statics *src, bool reverse); virtual bool load(MfcArchive &file); virtual void init(); @@ -122,7 +119,7 @@ class Movement : public GameObject { int _counter; Common::Array<DynamicPhase *> _dynamicPhases; int _field_78; - Common::Array<Common::Point> _framePosOffsets; + PointList _framePosOffsets; Movement *_currMovement; int _field_84; DynamicPhase *_currDynamicPhase; @@ -204,7 +201,7 @@ public: Statics *getStaticsById(int id); Statics *getStaticsByName(const Common::String &name); Movement *getMovementById(int id); - int getMovementIdById(int itemId); + int getMovementIdById(int itemId) const; Movement *getMovementByName(const Common::String &name); Common::Point getCurrDimensions() const; @@ -232,7 +229,7 @@ public: bool startAnim(int movementId, int messageQueueId, int dynPhaseIdx); bool startAnimEx(int movid, int parId, int flag1, int flag2); - void startAnimSteps(int movementId, int messageQueueId, int x, int y, Common::Point **points, int pointsCount, int someDynamicPhaseIndex); + void startAnimSteps(int movementId, int messageQueueId, int x, int y, const PointList &points, int someDynamicPhaseIndex); void hide(); void show1(int x, int y, int movementId, int mqId); |