diff options
author | Nicola Mettifogo | 2007-04-07 09:31:24 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2007-04-07 09:31:24 +0000 |
commit | 93673711073bbf6947e83ca3ec9cd262036aa64a (patch) | |
tree | 9a27428dd46207725bee78af40fd1f32f33f3599 /engines/parallaction | |
parent | 83610641c7f866e218cf562b2abeb94619bc229a (diff) | |
download | scummvm-rg350-93673711073bbf6947e83ca3ec9cd262036aa64a.tar.gz scummvm-rg350-93673711073bbf6947e83ca3ec9cd262036aa64a.tar.bz2 scummvm-rg350-93673711073bbf6947e83ca3ec9cd262036aa64a.zip |
Turned free___() routines into proper destructors for Zone, Animation and Program, and added memo comments for porting the engine to Common::List<>.
svn-id: r26399
Diffstat (limited to 'engines/parallaction')
-rw-r--r-- | engines/parallaction/animation.cpp | 69 | ||||
-rw-r--r-- | engines/parallaction/callables.cpp | 6 | ||||
-rw-r--r-- | engines/parallaction/location.cpp | 8 | ||||
-rw-r--r-- | engines/parallaction/parallaction.cpp | 9 | ||||
-rw-r--r-- | engines/parallaction/parallaction.h | 5 | ||||
-rw-r--r-- | engines/parallaction/saveload.cpp | 4 | ||||
-rw-r--r-- | engines/parallaction/walk.cpp | 2 | ||||
-rw-r--r-- | engines/parallaction/zone.cpp | 137 | ||||
-rw-r--r-- | engines/parallaction/zone.h | 90 |
9 files changed, 185 insertions, 145 deletions
diff --git a/engines/parallaction/animation.cpp b/engines/parallaction/animation.cpp index 7102aa8136..2eedb9365d 100644 --- a/engines/parallaction/animation.cpp +++ b/engines/parallaction/animation.cpp @@ -151,27 +151,12 @@ Animation *Parallaction::parseAnimation(Script& script, Node *list, char *name) } - -void Parallaction::freeScript(Program *program) { - - if (!program) return; - - delete[] program->_locals; - freeNodeList(&program->_start); - - return; -} - - - void Parallaction::freeAnimations() { Animation *v4 = (Animation*)_animations._next; while (v4) { - freeScript(v4->_program); - if (v4->_cnv) delete v4->_cnv; - v4 = (Animation*)v4->_next; - - // TODO: delete Animation + Animation *v = (Animation*)v4->_next; + delete v4; + v4 = (Animation*)v; } return; @@ -683,5 +668,53 @@ void Parallaction::sortAnimations() { return; } +Animation::Animation() { + _cnv = NULL; + _program = NULL; + _frame = 0; + _z = 0; +} + +Animation::~Animation() { + if (_program) + delete _program; + + if (_cnv) + delete _cnv; +} + +uint16 Animation::width() const { + if (!_cnv) return 0; + return _cnv->_width; +} + +uint16 Animation::height() const { + if (!_cnv) return 0; + return _cnv->_height; +} + +uint16 Animation::getFrameNum() const { + if (!_cnv) return 0; + return _cnv->_count; +} + +byte* Animation::getFrameData(uint32 index) const { + if (!_cnv) return NULL; + return _cnv->getFramePtr(index); +} + + +Program::Program() { + _locals = NULL; + _loopCounter = 0; + _ip = NULL; + _loopStart = NULL; +} + +Program::~Program() { + delete[] _locals; + freeNodeList(&_start); +} + } // namespace Parallaction diff --git a/engines/parallaction/callables.cpp b/engines/parallaction/callables.cpp index 760c633204..faf7c71280 100644 --- a/engines/parallaction/callables.cpp +++ b/engines/parallaction/callables.cpp @@ -398,23 +398,29 @@ void _c_finito(void *parm) { _vm->_menu->selectCharacter(); } + // this code saves main character animation from being removed from the following code removeNode(&_vm->_char._ani); _vm->_locationNames[0][0] = '\0'; _vm->_numLocations = 0; _commandFlags = 0; + // this flag tells freeZones to unconditionally remove *all* Zones _engineFlags |= kEngineQuit; + // TODO (LIST): this sequence should be just _zones.clear() _vm->freeZones(_vm->_zones._next); freeNodeList(_vm->_zones._next); _vm->_zones._next = NULL; + // TODO (LIST): this sequence should be just _animations.clear() _vm->freeZones(_vm->_animations._next); freeNodeList(_vm->_animations._next); _vm->_animations._next = NULL; + // this dangerous flag can now be cleared _engineFlags &= ~kEngineQuit; + // main character animation is restored addNode(&_vm->_animations, &_vm->_char._ani); _score = 0; diff --git a/engines/parallaction/location.cpp b/engines/parallaction/location.cpp index 42e4ffeb4b..a41006fc91 100644 --- a/engines/parallaction/location.cpp +++ b/engines/parallaction/location.cpp @@ -185,10 +185,14 @@ void Parallaction::freeLocation() { debugC(7, kDebugLocation, "freeLocation: localflags names freed"); + // TODO (LIST): this should be replaced by a call to _location._walkNodes.clear() freeNodeList(_vm->_location._walkNodes._next); _vm->_location._walkNodes._next = NULL; debugC(7, kDebugLocation, "freeLocation: walk nodes freed"); + // TODO (LIST): helperNode should be rendered useless by the use of a Common::List<> + // to store Zones and Animations. Right now, it holds a list of Zones to be preserved + // but that'll pretty meaningless with a single list approach. helperNode._prev = helperNode._next = NULL; _vm->freeZones(_zones._next); freeNodeList(_zones._next); @@ -197,6 +201,9 @@ void Parallaction::freeLocation() { // memcpy(&_zones, &helperNode, sizeof(Node)); debugC(7, kDebugLocation, "freeLocation: zones freed"); + // TODO (LIST): helperNode should be rendered useless by the use of a Common::List<> + // to store Zones and Animations. Right now, it holds a list of Zones to be preserved + // but that'll pretty meaningless with a single list approach. helperNode._prev = helperNode._next = NULL; _vm->freeZones(_animations._next); _vm->freeAnimations(); @@ -212,6 +219,7 @@ void Parallaction::freeLocation() { _vm->_location._comment = NULL; debugC(7, kDebugLocation, "freeLocation: comments freed"); + // TODO (LIST): this should be _location._commands.clear(); if (_vm->_location._commands) { freeNodeList(_vm->_location._commands); } diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index 9bda9583da..cbb610abec 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -811,6 +811,8 @@ void Parallaction::changeCharacter(const char *name) { return; } +// TODO (LIST): this rouinte basically performs List<>::clear() +// so it will become useless void freeNodeList(Node *list) { while (list) { @@ -822,7 +824,7 @@ void freeNodeList(Node *list) { return; } - +// TODO (LIST): this routine will be removed void addNode(Node *list, Node *n) { Node *v4 = list->_next; @@ -838,6 +840,7 @@ void addNode(Node *list, Node *n) { return; } +// TODO (LIST): this routine will be removed void removeNode(Node *n) { Node *v4 = n->_next; @@ -863,11 +866,13 @@ Job *Parallaction::addJob(JobFn fn, void *parm, uint16 tag) { Job *v4 = &_jobs; + // TODO (LIST): the loop will be useless once we have an ordered + // list _jobs. So this code will just be: _jobs.insert(v8) while (v4->_next && ((Job*)(v4->_next))->_tag > tag) { v4 = (Job*)v4->_next; } - addNode(v4, v8); + return v8; } diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index f5c006ece5..26485b6b41 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -293,6 +293,7 @@ public: // static void initTable(const char *path, char **table); // static void freeTable(char** table); // static int16 searchTable(const char *s, const char **table); + void freeCommands(Command*); void parseLocation(const char *filename); void changeCursor(int32 index); @@ -430,12 +431,10 @@ protected: // members void pickMusic(const char *location); void selectCharacterMusic(const char *name); - void freeScript(Program*); - Command *parseCommands(Script &script); - void freeCommands(Command*); void freeCharacter(); + void initResources(); }; diff --git a/engines/parallaction/saveload.cpp b/engines/parallaction/saveload.cpp index 13a75bf4a2..a518e76a24 100644 --- a/engines/parallaction/saveload.cpp +++ b/engines/parallaction/saveload.cpp @@ -81,10 +81,14 @@ void Parallaction::doLoadGame(uint16 slot) { f->readLine(s, 15); + // TODO (LIST): the very same code can be found in _c_finito(). + // Why aren't we clearing Animations too, anyway? _engineFlags |= kEngineQuit; + freeZones(_zones._next); freeNodeList(_zones._next); _zones._next = NULL; + _engineFlags &= ~kEngineQuit; _numLocations = atoi(s); diff --git a/engines/parallaction/walk.cpp b/engines/parallaction/walk.cpp index 130fa57e78..ce9ec11af2 100644 --- a/engines/parallaction/walk.cpp +++ b/engines/parallaction/walk.cpp @@ -188,6 +188,7 @@ WalkNode *buildWalkPath(uint16 x, uint16 y) { uint32 v34 = buildSubPath(pos, stop, v48); if (v38 != 0 && v34 > v38) { // no alternative path (gap?) + // TODO (LIST): tempPath.clear() freeNodeList(dummy._next); return v44; } @@ -370,6 +371,7 @@ void jobWalk(void *parm, Job *j) { if (pos == _vm->_char._ani._oldPos) { j->_finished = 1; checkDoor(); + //TODO (LIST): this should become path.clear() freeNodeList(node); } else { _vm->_char._ani._frame = v16 + walkData2 + 1; diff --git a/engines/parallaction/zone.cpp b/engines/parallaction/zone.cpp index 53adb3b885..2f31c8e9d7 100644 --- a/engines/parallaction/zone.cpp +++ b/engines/parallaction/zone.cpp @@ -133,62 +133,15 @@ void Parallaction::freeZones(Node *list) { debugC(1, kDebugLocation, "freeZones preserving zone '%s'", z->_label._text); v8 = (Zone*)z->_next; - removeNode(z); - addNode(&helperNode, z); + removeNode(z); // HelperNode holds a list of zones to be preserved. There's code in freeLocation to deal with this too. + addNode(&helperNode, z); // Can't we simply delete the other zones in the list and keep the good ones? z = v8; continue; } - - switch (z->_type & 0xFFFF) { - case kZoneExamine: - free(z->u.examine->_filename); - free(z->u.examine->_description); - delete z->u.examine; - break; - - case kZoneDoor: - free(z->u.door->_location); - free(z->u.door->_background); - if (z->u.door->_cnv) - delete z->u.door->_cnv; - delete z->u.door; - break; - - case kZoneSpeak: - freeDialogue(z->u.speak->_dialogue); - delete z->u.speak; - break; - - case kZoneGet: - free(z->u.get->_backup); - _vm->_gfx->freeStaticCnv(z->u.get->_cnv); - if (z->u.get->_cnv) - delete z->u.get->_cnv; - delete z->u.get; - break; - - case kZoneHear: - delete z->u.hear; - break; - - case kZoneMerge: - delete z->u.merge; - break; - - default: - break; - } - - free(z->_label._text); - z->_label._text = NULL; - _vm->_gfx->freeStaticCnv(&z->_label._cnv); - freeCommands(z->_commands); - - // TODO: delete Zone - - z=(Zone*)z->_next; - + Zone *z2 = (Zone*)z->_next; + delete z; + z = z2; } return; @@ -642,7 +595,87 @@ Zone *Parallaction::hitZone(uint32 type, uint16 x, uint16 y) { } return NULL; +} + + +Zone::Zone() { + _left = _top = _right = _bottom = 0; + + _type = 0; + _flags = 0; + _commands = NULL; +} + +Zone::~Zone() { + + switch (_type & 0xFFFF) { + case kZoneExamine: + free(u.examine->_filename); + free(u.examine->_description); + delete u.examine; + break; + + case kZoneDoor: + free(u.door->_location); + free(u.door->_background); + if (u.door->_cnv) + delete u.door->_cnv; + delete u.door; + break; + + case kZoneSpeak: + _vm->freeDialogue(u.speak->_dialogue); + delete u.speak; + break; + + case kZoneGet: + free(u.get->_backup); + _vm->_gfx->freeStaticCnv(u.get->_cnv); + if (u.get->_cnv) + delete u.get->_cnv; + delete u.get; + break; + + case kZoneHear: + delete u.hear; + break; + + case kZoneMerge: + delete u.merge; + break; + + default: + break; + } + + free(_label._text); + _label._text = NULL; + _vm->_gfx->freeStaticCnv(&_label._cnv); + _vm->freeCommands(_commands); + +} +void Zone::getRect(Common::Rect& r) const { + r.left = _left; + r.right = _right; + r.top = _top; + r.bottom = _bottom; } +void Zone::translate(int16 x, int16 y) { + _left += x; + _right += x; + _top += y; + _bottom += y; +} + +uint16 Zone::width() const { + return _right - _left; +} + +uint16 Zone::height() const { + return _bottom - _top; +} + + } // namespace Parallaction diff --git a/engines/parallaction/zone.h b/engines/parallaction/zone.h index 8d33963951..ae9977b5e8 100644 --- a/engines/parallaction/zone.h +++ b/engines/parallaction/zone.h @@ -184,50 +184,26 @@ struct Label { }; struct Zone : public Node { - int16 _left; - int16 _top; - int16 _right; - int16 _bottom; + int16 _left; + int16 _top; + int16 _right; + int16 _bottom; uint32 _type; uint32 _flags; - Label _label; + Label _label; uint16 field_2C; // unused uint16 field_2E; // unused - TypeData u; + TypeData u; Command *_commands; Common::Point _moveTo; - Zone() { - _left = _top = _right = _bottom = 0; + Zone(); + virtual ~Zone(); - _type = 0; - _flags = 0; - _commands = NULL; - } - - virtual ~Zone() {} - - void getRect(Common::Rect& r) const { - r.left = _left; - r.right = _right; - r.top = _top; - r.bottom = _bottom; - } - - void translate(int16 x, int16 y) { - _left += x; - _right += x; - _top += y; - _bottom += y; - } - - virtual uint16 width() const { - return _right - _left; - } - - virtual uint16 height() const { - return _bottom - _top; - } + void getRect(Common::Rect& r) const; + void translate(int16 x, int16 y); + virtual uint16 width() const; + virtual uint16 height() const; }; struct LocalVariable { @@ -286,12 +262,8 @@ struct Program { Instruction *_loopStart; Instruction _start; - Program() { - _locals = NULL; - _loopCounter = 0; - _ip = NULL; - _loopStart = NULL; - } + Program(); + ~Program(); }; @@ -311,34 +283,12 @@ struct Animation : public Zone { uint16 field_5C; // unused uint16 field_5E; // unused - Animation() { - _cnv = NULL; - _program = NULL; - _frame = 0; - _z = 0; - } - - virtual ~Animation() {} - - virtual uint16 width() const { - if (!_cnv) return 0; - return _cnv->_width; - } - - virtual uint16 height() const { - if (!_cnv) return 0; - return _cnv->_height; - } - - uint16 getFrameNum() const { - if (!_cnv) return 0; - return _cnv->_count; - } - - byte* getFrameData(uint32 index) const { - if (!_cnv) return NULL; - return _cnv->getFramePtr(index); - } + Animation(); + virtual ~Animation(); + virtual uint16 width() const; + virtual uint16 height() const; + uint16 getFrameNum() const; + byte* getFrameData(uint32 index) const; }; |