aboutsummaryrefslogtreecommitdiff
path: root/engines/parallaction
diff options
context:
space:
mode:
authorNicola Mettifogo2007-04-07 17:18:16 +0000
committerNicola Mettifogo2007-04-07 17:18:16 +0000
commitedd226d1b646470780a785d32c06876697f75e7e (patch)
tree11545dfe20ffbecc5de86c5ca004dca5992b6970 /engines/parallaction
parent5a8b8ca92dc95ced8df2a7f6a46412c04ebfe757 (diff)
downloadscummvm-rg350-edd226d1b646470780a785d32c06876697f75e7e.tar.gz
scummvm-rg350-edd226d1b646470780a785d32c06876697f75e7e.tar.bz2
scummvm-rg350-edd226d1b646470780a785d32c06876697f75e7e.zip
Added new ManagedList class to handle Instruction and Command lists. The same class will be used to hold Zone, Animation and WalkNode lists.
svn-id: r26410
Diffstat (limited to 'engines/parallaction')
-rw-r--r--engines/parallaction/animation.cpp6
-rw-r--r--engines/parallaction/commands.cpp16
-rw-r--r--engines/parallaction/commands.h3
-rw-r--r--engines/parallaction/defs.h30
-rw-r--r--engines/parallaction/dialogue.cpp2
-rw-r--r--engines/parallaction/location.cpp5
-rw-r--r--engines/parallaction/parallaction.h1
-rw-r--r--engines/parallaction/zone.cpp1
-rw-r--r--engines/parallaction/zone.h6
9 files changed, 38 insertions, 32 deletions
diff --git a/engines/parallaction/animation.cpp b/engines/parallaction/animation.cpp
index f59dcbdd3d..d084e85567 100644
--- a/engines/parallaction/animation.cpp
+++ b/engines/parallaction/animation.cpp
@@ -704,12 +704,6 @@ Program::Program() {
Program::~Program() {
delete[] _locals;
-
- InstructionList::iterator it = _instructions.begin();
- for (; it != _instructions.end(); it++)
- delete *it;
-
- _instructions.clear();
}
diff --git a/engines/parallaction/commands.cpp b/engines/parallaction/commands.cpp
index 50fbeb20da..340019491f 100644
--- a/engines/parallaction/commands.cpp
+++ b/engines/parallaction/commands.cpp
@@ -189,22 +189,6 @@ void Parallaction::parseCommands(Script &script, CommandList& list) {
}
-void Parallaction::freeCommands(CommandList &list) {
-
- CommandList::iterator it = list.begin();
-
- while ( it != list.end() ) {
- delete *it;
- it++;
- }
-
- list.clear();
-
- return;
-}
-
-
-
void Parallaction::runCommands(CommandList& list, Zone *z) {
debugC(1, kDebugLocation, "runCommands");
diff --git a/engines/parallaction/commands.h b/engines/parallaction/commands.h
index a1778b5d16..35ad6c15f3 100644
--- a/engines/parallaction/commands.h
+++ b/engines/parallaction/commands.h
@@ -73,6 +73,9 @@ struct Command : public Node {
~Command();
};
+//typedef Common::List<Command*> CommandList;
+typedef ManagedList<Command*> CommandList;
+
} // namespace Parallaction
#endif
diff --git a/engines/parallaction/defs.h b/engines/parallaction/defs.h
index cab8f14be0..09628f6685 100644
--- a/engines/parallaction/defs.h
+++ b/engines/parallaction/defs.h
@@ -23,6 +23,9 @@
#ifndef PARALLACTION_DEFS_H
#define PARALLACTION_DEFS_H
+#include "common/stdafx.h"
+#include "common/list.h"
+
namespace Parallaction {
// TODO (LIST): this struct won't be used anymore as soon as List<> is enforced throughout the code.
@@ -40,6 +43,33 @@ struct Node {
}
};
+template <class T>
+class ManagedList : public Common::List<T> {
+
+public:
+
+ typedef typename Common::List<T> Common_List;
+ typedef typename Common::List<T>::iterator iterator;
+
+ ~ManagedList() {
+ clear();
+ }
+
+ void clear() {
+ erase(Common_List::begin(), Common_List::end());
+ }
+
+ iterator erase(iterator pos) {
+ return erase(pos, pos);
+ }
+
+ iterator erase(iterator first, iterator last) {
+ for (iterator it = first; it != last; it++)
+ delete *it;
+ return Common_List::erase(first, last);
+ }
+
+};
} // namespace Parallaction
diff --git a/engines/parallaction/dialogue.cpp b/engines/parallaction/dialogue.cpp
index e6526db9f0..aeaa9f0579 100644
--- a/engines/parallaction/dialogue.cpp
+++ b/engines/parallaction/dialogue.cpp
@@ -497,8 +497,6 @@ Answer::~Answer() {
if (_mood & 0x10)
delete _following._question;
- _vm->freeCommands(_commands);
-
if (_text)
free(_text);
diff --git a/engines/parallaction/location.cpp b/engines/parallaction/location.cpp
index 5540d79785..d35739e299 100644
--- a/engines/parallaction/location.cpp
+++ b/engines/parallaction/location.cpp
@@ -219,11 +219,10 @@ void Parallaction::freeLocation() {
_location._comment = NULL;
debugC(7, kDebugLocation, "freeLocation: comments freed");
- // TODO (LIST): this should be _location._commands.clear();
- freeCommands(_location._commands);
+ _location._commands.clear();
debugC(7, kDebugLocation, "freeLocation: commands freed");
- freeCommands(_location._aCommands);
+ _location._aCommands.clear();
debugC(7, kDebugLocation, "freeLocation: acommands freed");
return;
diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h
index 3dafbd4e74..c311aa93a9 100644
--- a/engines/parallaction/parallaction.h
+++ b/engines/parallaction/parallaction.h
@@ -319,7 +319,6 @@ public:
void runDialogue(SpeakData*);
void runCommands(CommandList& list, Zone *z = NULL);
- void freeCommands(CommandList& list); // to be phased out soon
Animation *findAnimation(const char *name);
void sortAnimations();
diff --git a/engines/parallaction/zone.cpp b/engines/parallaction/zone.cpp
index 10eacbb803..e36d2b327f 100644
--- a/engines/parallaction/zone.cpp
+++ b/engines/parallaction/zone.cpp
@@ -650,7 +650,6 @@ Zone::~Zone() {
free(_label._text);
_label._text = NULL;
_vm->_gfx->freeStaticCnv(&_label._cnv);
- _vm->freeCommands(_commands);
}
diff --git a/engines/parallaction/zone.h b/engines/parallaction/zone.h
index 6ad5c6c296..7689f216a4 100644
--- a/engines/parallaction/zone.h
+++ b/engines/parallaction/zone.h
@@ -26,6 +26,7 @@
#include "common/list.h"
#include "parallaction/defs.h"
+#include "parallaction/commands.h"
#include "parallaction/graphics.h"
@@ -68,8 +69,6 @@ enum ZoneFlags {
struct Command;
struct Question;
-typedef Common::List<Command*> CommandList;
-
struct Answer {
char* _text;
uint16 _mood;
@@ -263,7 +262,8 @@ struct Instruction : public Node {
}
};
-typedef Common::List<Instruction*> InstructionList;
+//typedef Common::List<Instruction*> InstructionList;
+typedef ManagedList<Instruction*> InstructionList;
struct Program {
LocalVariable *_locals;