From 8515164117c8a4b301c465008a771d50117cef02 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 4 Jan 2014 17:06:23 +0200 Subject: FULLPIPE: Proper use of copying consturctor for ExCommand --- engines/fullpipe/messages.cpp | 15 +++++---------- engines/fullpipe/messages.h | 4 ++-- engines/fullpipe/motion.cpp | 2 +- engines/fullpipe/scenes/scene04.cpp | 12 ++++++------ engines/fullpipe/scenes/scene08.cpp | 2 +- engines/fullpipe/scenes/scene22.cpp | 6 +++--- engines/fullpipe/statics.cpp | 8 ++++---- 7 files changed, 22 insertions(+), 27 deletions(-) diff --git a/engines/fullpipe/messages.cpp b/engines/fullpipe/messages.cpp index dcca925226..68ec3dcd04 100644 --- a/engines/fullpipe/messages.cpp +++ b/engines/fullpipe/messages.cpp @@ -43,8 +43,8 @@ ExCommand::ExCommand(ExCommand *src) : Message(src) { _parId = src->_parId; } -ExCommand *ExCommand::createClone(ExCommand *src) { - return new ExCommand(src); +ExCommand *ExCommand::createClone() { + return new ExCommand(this); } ExCommand::ExCommand(int16 parentId, int messageKind, int messageNum, int x, int y, int a7, int a8, int sceneClickX, int sceneClickY, int a11) : @@ -176,13 +176,8 @@ ExCommand2::~ExCommand2() { free(_points); } -ExCommand *ExCommand2::createClone(ExCommand *src) { - if (_objtype == kObjTypeExCommand) - return new ExCommand(src); - else if (_objtype == kObjTypeExCommand2) - return new ExCommand2((ExCommand2 *)src); - - error("ExCommand2::createClone(): Wrong object type: %d", _objtype); +ExCommand2 *ExCommand2::createClone() { + return new ExCommand2(this); } Message::Message() { @@ -284,7 +279,7 @@ MessageQueue::MessageQueue(MessageQueue *src, int parId, int field_38) { _field_38 = (field_38 == 0); for (Common::List::iterator it = src->_exCommands.begin(); it != src->_exCommands.end(); ++it) { - ExCommand *ex = new ExCommand(*it); + ExCommand *ex = (*it)->createClone(); ex->_excFlags |= 2; _exCommands.push_back(ex); diff --git a/engines/fullpipe/messages.h b/engines/fullpipe/messages.h index 653bd9625e..04355b2f90 100644 --- a/engines/fullpipe/messages.h +++ b/engines/fullpipe/messages.h @@ -69,7 +69,7 @@ class ExCommand : public Message { virtual bool load(MfcArchive &file); - virtual ExCommand *createClone(ExCommand *src); + virtual ExCommand *createClone(); bool handleMessage(); void sendMessage(); @@ -89,7 +89,7 @@ class ExCommand2 : public ExCommand { ExCommand2(ExCommand2 *src); virtual ~ExCommand2(); - virtual ExCommand *createClone(ExCommand *src); + virtual ExCommand2 *createClone(); }; class ObjstateCommand : public CObject { diff --git a/engines/fullpipe/motion.cpp b/engines/fullpipe/motion.cpp index 960ff45904..b7af4ca1f8 100644 --- a/engines/fullpipe/motion.cpp +++ b/engines/fullpipe/motion.cpp @@ -210,7 +210,7 @@ MessageQueue *MctlCompound::doWalkTo(StaticANIObject *subj, int xpos, int ypos, if (mq) { for (uint i = 0; i < closestP->_messageQueueObj->getCount(); i++) { - ex = new ExCommand(closestP->_messageQueueObj->getExCommandByIndex(i)); + ex = closestP->_messageQueueObj->getExCommandByIndex(i)->createClone() ex->_excFlags |= 2; mq->addExCommandToEnd(ex); } diff --git a/engines/fullpipe/scenes/scene04.cpp b/engines/fullpipe/scenes/scene04.cpp index fa9f4ceef0..332935072c 100644 --- a/engines/fullpipe/scenes/scene04.cpp +++ b/engines/fullpipe/scenes/scene04.cpp @@ -298,7 +298,7 @@ void sceneHandler04_walkClimbLadder(ExCommand *ex) { ExCommand *ex3; if (ex) { - ex3 = new ExCommand(ex); + ex3 = ex->createClone(); } else { ex3 = new ExCommand(0, 17, MSG_SC4_CLICKLADDER, 0, 0, 0, 1, 0, 0, 0); ex3->_excFlags |= 3; @@ -498,7 +498,7 @@ void sceneHandler04_gotoLadder(ExCommand *ex) { mq->addExCommandToEnd(ex3); if (ex) { - ExCommand *ex4 = new ExCommand(ex); + ExCommand *ex4 = ex->createClone(); mq->addExCommandToEnd(ex4); } @@ -630,7 +630,7 @@ MessageQueue *sceneHandler04_kozFly5(StaticANIObject *ani, double phase) { MessageQueue *mq2 = mgm.genMovement(&mgminfo); if (mq1 && mq2) { - mq1->addExCommandToEnd(new ExCommand(mq2->getExCommandByIndex(0))); + mq1->addExCommandToEnd(mq2->getExCommandByIndex(0)->createClone()); delete mq2; @@ -890,7 +890,7 @@ void sceneHandler04_animOutOfBottle(ExCommand *ex) { MessageQueue *mq = new MessageQueue(g_fp->_currentScene->getMessageQueueById(QU_SC4_MANFROMBOTTLE), 0, 0); if (ex) { - ExCommand *newex = new ExCommand(ex); + ExCommand *newex = ex->createClone(); mq->addExCommandToEnd(newex); } @@ -1066,7 +1066,7 @@ void sceneHandler04_leaveLadder(ExCommand *ex) { MessageQueue *mq = g_vars->scene04_ladder->controllerWalkTo(g_fp->_aniMan, 0); if (mq) { - mq->addExCommandToEnd(new ExCommand(ex)); + mq->addExCommandToEnd(ex->createClone()); if (mq->chain(g_fp->_aniMan) ) ex->_messageKind = 0; @@ -1099,7 +1099,7 @@ void sceneHandler04_leaveLadder(ExCommand *ex) { ex1->_excFlags |= 2; mq->addExCommandToEnd(ex1); - ex1 = new ExCommand(ex); + ex1 = ex->createClone(); mq->addExCommandToEnd(ex1); mq->setFlags(mq->getFlags() | 1); diff --git a/engines/fullpipe/scenes/scene08.cpp b/engines/fullpipe/scenes/scene08.cpp index ada63ef22d..716ca1f593 100644 --- a/engines/fullpipe/scenes/scene08.cpp +++ b/engines/fullpipe/scenes/scene08.cpp @@ -282,7 +282,7 @@ void sceneHandler08_finishArcade() { void sceneHandler08_jumpOff(ExCommand *cmd) { MessageQueue *mq = new MessageQueue(g_fp->_globalMessageQueueList->compact()); - mq->addExCommandToEnd(new ExCommand(cmd)); + mq->addExCommandToEnd(cmd->createClone()); mq->setFlags(mq->getFlags() | 1); g_fp->_globalMessageQueueList->addMessageQueue(mq); diff --git a/engines/fullpipe/scenes/scene22.cpp b/engines/fullpipe/scenes/scene22.cpp index 5df2b6e795..d7ac6d4cb2 100644 --- a/engines/fullpipe/scenes/scene22.cpp +++ b/engines/fullpipe/scenes/scene22.cpp @@ -153,7 +153,7 @@ void sceneHandler22_fromStool(ExCommand *cmd) { if (g_fp->_aniMan->isIdle() && !(g_fp->_aniMan->_flags & 0x100)) { MessageQueue *mq = new MessageQueue(g_fp->_currentScene->getMessageQueueById(QU_SC22_FROMSTOOL), 0, 0); - mq->addExCommandToEnd(new ExCommand(cmd)); + mq->addExCommandToEnd(cmd->createClone()); mq->setFlags(mq->getFlags() | 1); mq->chain(0); } @@ -196,7 +196,7 @@ void sceneHandler22_stoolLogic(ExCommand *cmd) { if (!mq) return; - mq->addExCommandToEnd(new ExCommand(cmd)); + mq->addExCommandToEnd(cmd->createClone)); postExCommand(g_fp->_aniMan->_id, 2, 841, 449, 0, -1); return; @@ -282,7 +282,7 @@ void sceneHandler22_stoolLogic(ExCommand *cmd) { mq = getCurrSceneSc2MotionController()->method34(g_fp->_aniMan, 1010, 443, 1, ST_MAN_UP); if (mq) { - mq->addExCommandToEnd(new ExCommand(cmd)); + mq->addExCommandToEnd(cmd->createClone()); postExCommand(g_fp->_aniMan->_id, 2, 1010, 443, 0, -1); return; diff --git a/engines/fullpipe/statics.cpp b/engines/fullpipe/statics.cpp index 1c3d11ac54..7178538823 100644 --- a/engines/fullpipe/statics.cpp +++ b/engines/fullpipe/statics.cpp @@ -708,7 +708,7 @@ void StaticANIObject::update(int counterdiff) { ex = dyn->getExCommand(); if (ex && ex->_messageKind != 35) { - newex = new ExCommand(ex); + newex = ex->createClone(); newex->_excFlags |= 2; if (newex->_messageKind == 17) { newex->_parentId = _id; @@ -741,7 +741,7 @@ void StaticANIObject::update(int counterdiff) { ex = dyn->getExCommand(); if (ex) { if (ex->_messageKind == 35) { - newex = new ExCommand(ex); + newex = ex->createClone(); newex->_excFlags |= 2; newex->sendMessage(); } @@ -1048,7 +1048,7 @@ bool StaticANIObject::startAnim(int movementId, int messageQueueId, int dynPhase ExCommand *ex = _movement->_currDynamicPhase->getExCommand(); if (ex) { if (ex->_messageKind == 35) { - ExCommand *newex = new ExCommand(ex); + ExCommand *newex = ex->createClone(); newex->_excFlags |= 2; newex->sendMessage(); } @@ -1858,7 +1858,7 @@ DynamicPhase::DynamicPhase(DynamicPhase *src, bool reverse) { _field_7C = src->_field_7C; if (src->getExCommand()) - _exCommand = new ExCommand(src->getExCommand()); + _exCommand = src->getExCommand()->createClone(); else _exCommand = 0; -- cgit v1.2.3