[Scummvm-cvs-logs] SF.net SVN: scummvm:[34939] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Sat Nov 8 15:56:45 CET 2008


Revision: 34939
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34939&view=rev
Author:   peres001
Date:     2008-11-08 14:56:45 +0000 (Sat, 08 Nov 2008)

Log Message:
-----------
* removed the obsolete _quit flag
* refactored most cleanup code for locations and game

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/exec_ns.cpp
    scummvm/trunk/engines/parallaction/gui_br.cpp
    scummvm/trunk/engines/parallaction/gui_ns.cpp
    scummvm/trunk/engines/parallaction/input.cpp
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/parallaction.h
    scummvm/trunk/engines/parallaction/parallaction_br.cpp
    scummvm/trunk/engines/parallaction/parallaction_ns.cpp
    scummvm/trunk/engines/parallaction/saveload.cpp

Modified: scummvm/trunk/engines/parallaction/exec_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/exec_ns.cpp	2008-11-08 02:32:40 UTC (rev 34938)
+++ scummvm/trunk/engines/parallaction/exec_ns.cpp	2008-11-08 14:56:45 UTC (rev 34939)
@@ -278,7 +278,6 @@
 
 
 DECLARE_COMMAND_OPCODE(quit) {
-	_vm->_quit = true;
 	_vm->quitGame();
 }
 

Modified: scummvm/trunk/engines/parallaction/gui_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/gui_br.cpp	2008-11-08 02:32:40 UTC (rev 34938)
+++ scummvm/trunk/engines/parallaction/gui_br.cpp	2008-11-08 14:56:45 UTC (rev 34939)
@@ -171,7 +171,6 @@
 	void performChoice(int selectedItem) {
 		switch (selectedItem) {
 		case kMenuQuit: {
-			_vm->_quit = true;
 			_vm->quitGame();
 			break;
 		}

Modified: scummvm/trunk/engines/parallaction/gui_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/gui_ns.cpp	2008-11-08 02:32:40 UTC (rev 34938)
+++ scummvm/trunk/engines/parallaction/gui_ns.cpp	2008-11-08 14:56:45 UTC (rev 34939)
@@ -700,7 +700,6 @@
 		}
 
 		if (_isDemo) {
-			_vm->_quit = true;
 			_vm->quitGame();
 			return 0;
 		}

Modified: scummvm/trunk/engines/parallaction/input.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/input.cpp	2008-11-08 02:32:40 UTC (rev 34938)
+++ scummvm/trunk/engines/parallaction/input.cpp	2008-11-08 14:56:45 UTC (rev 34939)
@@ -133,7 +133,6 @@
 
 		case Common::EVENT_RTL:
 		case Common::EVENT_QUIT:
-			_vm->_quit = true;
 			return;
 
 		default:

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2008-11-08 02:32:40 UTC (rev 34938)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2008-11-08 14:56:45 UTC (rev 34939)
@@ -92,7 +92,6 @@
 	_gfx->clearGfxObjects(kGfxObjCharacter | kGfxObjNormal);
 	hideDialogueStuff();
 	delete _balloonMan;
-	freeLocation();
 
 	freeCharacter();
 	destroyInventory();
@@ -120,8 +119,6 @@
 	_location._comment = NULL;
 	_location._endComment = NULL;
 
-	_quit = false;
-
 	_pathBuffer = 0;
 
 	_screenSize = _screenWidth * _screenHeight;
@@ -200,12 +197,11 @@
 	return nullAnimationPtr;
 }
 
-void Parallaction::freeAnimations() {
-	for (AnimationList::iterator it = _location._animations.begin(); it != _location._animations.end(); it++) {
+void Location::freeAnimations() {
+	for (AnimationList::iterator it = _animations.begin(); it != _animations.end(); it++) {
 		(*it)->_commands.clear();	// See comment for freeZones(), about circular references.
 	}
-	_location._animations.clear();
-	return;
+	_animations.clear();
 }
 
 
@@ -241,33 +237,36 @@
 }
 
 
+Location::Location() : _comment(0), _endComment(0) {
+	cleanup(true);
+}
 
-void Parallaction::freeLocation() {
-	debugC(2, kDebugExec, "freeLocation");
+Location::~Location() {
+	cleanup(true);
+}
 
-	_soundMan->stopSfx(0);
-	_soundMan->stopSfx(1);
-	_soundMan->stopSfx(2);
-	_soundMan->stopSfx(3);
+void Location::cleanup(bool removeAll) {
+	free(_comment); _comment = 0;
+	free(_endComment); _endComment = 0;
 
-	_localFlagNames->clear();
+	freeZones(removeAll);
+	freeAnimations();
 
-	_location._walkPoints.clear();
+	_programs.clear();
+	_commands.clear();
+	_aCommands.clear();
 
-	_gfx->clearGfxObjects(kGfxObjNormal);
+	_hasSound = false;
 
-	_location._programs.clear();
-	freeZones();
-	freeAnimations();
+	// NS specific
+	_walkPoints.clear();
 
-	free(_location._comment);
-	_location._comment = 0;
+	// BRA specific
+	_zeta0 = _zeta1 = _zeta2 = 0;
+	_escapeCommands.clear();
+}
 
-	_location._commands.clear();
-	_location._aCommands.clear();
 
-	return;
-}
 
 void Parallaction::showSlide(const char *name, int x, int y) {
 	BackgroundInfo *info = new BackgroundInfo;
@@ -819,24 +818,24 @@
 }
 
 
-void Parallaction::freeZones() {
-	debugC(2, kDebugExec, "freeZones: _vm->_quit = %i", _vm->_quit);
+void Location::freeZones(bool removeAll) {
+	debugC(2, kDebugExec, "freeZones: removeAll = %i", removeAll);
 
-	ZoneList::iterator it = _location._zones.begin();
+	ZoneList::iterator it = _zones.begin();
 
-	while ( it != _location._zones.end() ) {
+	while ( it != _zones.end() ) {
 
 		// NOTE : this condition has been relaxed compared to the original, to allow the engine
 		// to retain special - needed - zones that were lost across location switches.
 		ZonePtr z = *it;
-		if (((z->getY() == -1) || (z->getX() == -2)) && (_quit == 0)) {
+		if (((z->getY() == -1) || (z->getX() == -2)) && (!removeAll)) {
 			debugC(2, kDebugExec, "freeZones preserving zone '%s'", z->_name);
 			it++;
 		} else {
 			(*it)->_commands.clear();	// Since commands may reference zones, and both commands and zones are kept stored into
 										// SharedPtr's, we need to kill commands explicitly to destroy any potential circular
 										// reference.
-			it = _location._zones.erase(it);
+			it = _zones.erase(it);
 		}
 	}
 

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2008-11-08 02:32:40 UTC (rev 34938)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2008-11-08 14:56:45 UTC (rev 34939)
@@ -150,6 +150,16 @@
 	int			_zeta1;
 	int			_zeta2;
 	CommandList		_escapeCommands;
+
+protected:
+	void freeAnimations();
+	void freeZones(bool removeAll);
+
+public:
+	Location();
+	~Location();
+
+	void cleanup(bool removeAll);
 };
 
 
@@ -277,11 +287,6 @@
 	ZonePtr			_zoneTrap;
 	ZonePtr			_commentZone;
 
-	bool _quit;   /* The only reason this flag exists is for freeZones() to properly
-		       * delete all zones when necessary. THIS FLAG IS NOT THE ENGINE QUIT FLAG,
-		       * use _eventMan->shouldQuit() for that.
-		       */
-
 protected:
 	void	runGame();
 	void 	runGuiFrame();
@@ -295,7 +300,6 @@
 	void	updateView();
 	void 	drawAnimations();
 	void	freeCharacter();
-	void	freeLocation();
 	void	doLocationEnterTransition();
 	void	allocateLocationSlot(const char *name);
 	void	finalizeLocationParsing();
@@ -324,7 +328,7 @@
 	ZonePtr		findZone(const char *name);
 	ZonePtr		hitZone(uint32 type, uint16 x, uint16 y);
 	void		runZone(ZonePtr z);
-	void		freeZones();
+	void		freeZones(bool removeAll);
 	bool		pickupItem(ZonePtr z);
 	void 		updateDoor(ZonePtr z, bool close);
 	void 		showZone(ZonePtr z, bool visible);
@@ -390,6 +394,7 @@
 	void	startCreditSequence();
 	void	startEndPartSequence();
 	void	loadProgram(AnimationPtr a, const char *filename);
+	void	freeLocation(bool removeAll);
 
 
 	//  callables data
@@ -489,7 +494,7 @@
 	void	initResources();
 	void	initFonts();
 	void	freeFonts();
-	void	freeLocation();
+	void	freeLocation(bool removeAll);
 	void 	loadProgram(AnimationPtr a, const char *filename);
 	void 	startGui(bool showSplash);
 

Modified: scummvm/trunk/engines/parallaction/parallaction_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction_br.cpp	2008-11-08 02:32:40 UTC (rev 34938)
+++ scummvm/trunk/engines/parallaction/parallaction_br.cpp	2008-11-08 14:56:45 UTC (rev 34939)
@@ -169,7 +169,7 @@
 	}
 }
 
-void Parallaction_br::freeLocation() {
+void Parallaction_br::freeLocation(bool removeAll) {
 
 	// free open location stuff
 	clearSubtitles();
@@ -178,24 +178,14 @@
 	_gfx->freeLabels();
 	_subtitle[0] = _subtitle[1] = -1;
 
-	_location._programs.clear();
-
 	_location._animations.remove(_char._ani);
-
-	freeZones();
-	freeAnimations();
-
+	_location.cleanup(removeAll);
 	_location._animations.push_front(_char._ani);
 
-	free(_location._comment);
-	_location._comment = 0;
-	_location._commands.clear();
-	_location._aCommands.clear();
-
 }
 
 void Parallaction_br::cleanupGame() {
-	freeLocation();
+	freeLocation(true);
 
 //		freeCharacter();
 
@@ -241,7 +231,7 @@
 		parseLocation("common.slf");
 	}
 
-	freeLocation();
+	freeLocation(false);
 	// load new location
 	parseLocation(location);
 	// kFlagsRemove is cleared because the character is visible by default.

Modified: scummvm/trunk/engines/parallaction/parallaction_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction_ns.cpp	2008-11-08 02:32:40 UTC (rev 34938)
+++ scummvm/trunk/engines/parallaction/parallaction_ns.cpp	2008-11-08 14:56:45 UTC (rev 34939)
@@ -202,6 +202,7 @@
 
 	delete _locationParser;
 	delete _programParser;
+	freeLocation(true);
 
 	_location._animations.remove(_char._ani);
 
@@ -294,9 +295,8 @@
 	_input->setArrowCursor();
 
 	_gfx->showGfxObj(_char._ani->gfxobj, false);
-	_location._animations.remove(_char._ani);
 
-	freeLocation();
+	freeLocation(false);
 
 	LocationName locname;
 	locname.bind(location);
@@ -316,7 +316,6 @@
 		changeCharacter(locname.character());
 	}
 
-	_location._animations.push_front(_char._ani);
 	_gfx->showGfxObj(_char._ani->gfxobj, true);
 
 	strcpy(_saveData1, locname.location());
@@ -423,37 +422,39 @@
 	return;
 }
 
+void Parallaction_ns::freeLocation(bool removeAll) {
+	debugC(2, kDebugExec, "freeLocation");
+
+	_soundMan->stopSfx(0);
+	_soundMan->stopSfx(1);
+	_soundMan->stopSfx(2);
+	_soundMan->stopSfx(3);
+
+	_localFlagNames->clear();
+
+	_gfx->clearGfxObjects(kGfxObjNormal);
+
+	_location._animations.remove(_char._ani);
+	_location.cleanup(removeAll);
+	_location._animations.push_front(_char._ani);
+}
+
 void Parallaction_ns::cleanupGame() {
+	_soundMan->stopMusic();
+
 	_inTestResult = false;
-
 	_engineFlags &= ~kEngineTransformedDonna;
 
-	// this code saves main character animation from being removed from the following code
-	_location._animations.remove(_char._ani);
 	_numLocations = 0;
 	_globalFlags = 0;
-
 	memset(_localFlags, 0, sizeof(_localFlags));
 	memset(_locationNames, 0, sizeof(_locationNames));
 
-	// this flag tells freeZones to unconditionally remove *all* Zones
-	_vm->_quit = true;
+	freeLocation(true);
 
-	freeZones();
-	freeAnimations();
-
-	// this dangerous flag can now be cleared
-	_vm->_quit = false;
-
-	// main character animation is restored
-	_location._animations.push_front(_char._ani);
 	_score = 0;
-
-	_soundMan->stopMusic();
 	_introSarcData3 = 200;
 	_introSarcData2 = 1;
-
-	return;
 }
 
 } // namespace Parallaction

Modified: scummvm/trunk/engines/parallaction/saveload.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/saveload.cpp	2008-11-08 02:32:40 UTC (rev 34938)
+++ scummvm/trunk/engines/parallaction/saveload.cpp	2008-11-08 14:56:45 UTC (rev 34939)
@@ -134,15 +134,6 @@
 
 	f->readLine_OLD(s, 15);
 
-	// TODO (LIST): unify (and parametrize) calls to freeZones.
-	// We aren't calling freeAnimations because it is not needed, since
-	// kChangeLocation will trigger a complete deletion. Anyway, we still
-	// need to invoke freeZones here with _quit set, because the
-	// call in changeLocation preserve certain zones.
-	_vm->_quit = true;
-	_vm->freeZones();
-	_vm->_quit = false;
-
 	_vm->_numLocations = atoi(s);
 
 	uint16 _si;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list