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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Thu Nov 1 14:47:19 CET 2007


Revision: 29353
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29353&view=rev
Author:   peres001
Date:     2007-11-01 06:47:18 -0700 (Thu, 01 Nov 2007)

Log Message:
-----------
Added new LocationName class to simplify handling of location switches.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/menu.cpp
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/parallaction.h
    scummvm/trunk/engines/parallaction/parallaction_ns.cpp

Modified: scummvm/trunk/engines/parallaction/menu.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/menu.cpp	2007-11-01 11:22:11 UTC (rev 29352)
+++ scummvm/trunk/engines/parallaction/menu.cpp	2007-11-01 13:47:18 UTC (rev 29353)
@@ -142,7 +142,7 @@
 	if (_vm->getFeatures() & GF_DEMO) {
 		// character screen is not shown on demo
 		// so user warps to the playable intro
-		strcpy(_vm->_location._name, "fognedemo");
+		strcpy(_vm->_location._name, "fognedemo.dough");
 		return;
 	}
 
@@ -171,15 +171,12 @@
 	_vm->showCursor(true);
 
 	if (_mouseButtons != kMouseRightUp) {
-		strcpy(_vm->_location._name, "fogne");
+		strcpy(_vm->_location._name, "fogne.dough");
 		return;    // show intro
 	}
 
 	selectCharacter();
 
-	char *v4 = strchr(_vm->_location._name, '.') + 1;
-	_vm->_char.setName(v4);
-
 	return; // start game
 }
 
@@ -290,8 +287,7 @@
 	// game window without picking a savegame.
 	// The 2 strcpy's below act as workaround to prevent crashes for
 	// time being.
-	strcpy(_vm->_location._name, "fogne");
-	_vm->_char.setName("dough");
+	strcpy(_vm->_location._name, "fogne.dough");
 	_vm->loadGame();
 
 	return 1;  // load game

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2007-11-01 11:22:11 UTC (rev 29352)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2007-11-01 13:47:18 UTC (rev 29353)
@@ -172,8 +172,6 @@
 	_backgroundInfo = new BackgroundInfo;
 
 	strcpy(_characterName1, "null");
-//	strcpy(_char._name, "dough");
-	_char.setName("dough");
 
 	memset(_locationNames, 0, NUM_LOCATIONS * 32);
 

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2007-11-01 11:22:11 UTC (rev 29352)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2007-11-01 13:47:18 UTC (rev 29353)
@@ -597,6 +597,48 @@
 };
 
 
+class LocationName {
+
+	Common::String _slide;
+	Common::String _character;
+	Common::String _location;
+
+	bool _hasCharacter;
+	bool _hasSlide;
+	char *_buf;
+
+public:
+	LocationName();
+	~LocationName();
+
+	void bind(const char*);
+
+	const char *location() const {
+		return _location.c_str();
+	}
+
+	bool hasCharacter() const {
+		return _hasCharacter;
+	}
+
+	const char *character() const {
+		return _character.c_str();
+	}
+
+	bool hasSlide() const {
+		return _hasSlide;
+	}
+
+	const char *slide() const {
+		return _slide.c_str();
+	}
+
+	const char *c_str() const {
+		return _buf;
+	}
+};
+
+
 class Parallaction_ns : public Parallaction {
 
 public:

Modified: scummvm/trunk/engines/parallaction/parallaction_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction_ns.cpp	2007-11-01 11:22:11 UTC (rev 29352)
+++ scummvm/trunk/engines/parallaction/parallaction_ns.cpp	2007-11-01 13:47:18 UTC (rev 29353)
@@ -40,6 +40,76 @@
 #define MOUSECOMBO_WIDTH		32	// sizes for cursor + selected inventory item
 #define MOUSECOMBO_HEIGHT		32
 
+LocationName::LocationName() {
+	_buf = 0;
+	_hasSlide = false;
+	_hasCharacter = false;
+}
+
+LocationName::~LocationName() {
+	if (_buf)
+		free(_buf);
+}
+
+
+/*
+	bind accept the following input formats:
+
+    1 - [S].slide.[L]{.[C]}
+	2 - [L]{.[C]}
+
+    where:
+
+	[S] is the slide to be shown
+    [L] is the location to switch to (immediately in case 2, or right after slide [S] in case 1)
+    [C] is the character to be selected, and is optional
+
+    The routine tells one form from the other by searching for the '.slide.'
+
+    NOTE: there exists one script in which [L] is not used in the case 1, but its use
+		  is commented out, and would definitely crash the current implementation.
+*/
+void LocationName::bind(const char *s) {
+
+	if (_buf)
+		free(_buf);
+
+	_buf = strdup(s);
+	_hasSlide = false;
+	_hasCharacter = false;
+
+	Common::StringList list;
+	char *tok = strtok(_buf, ".");
+	while (tok) {
+		list.push_back(tok);
+		tok = strtok(NULL, ".");
+	}
+
+	if (list.size() < 1 || list.size() > 4)
+		error("changeLocation: ill-formed location name '%s'", s);
+
+	if (list.size() > 1) {
+		if (list[1] == "slide") {
+			_hasSlide = true;
+			_slide = list[0];
+
+			list.remove_at(0);		// removes slide name
+			list.remove_at(0);		// removes 'slide'
+		}
+
+		if (list.size() == 2) {
+			_hasCharacter = true;
+			_character = list[1];
+		}
+	}
+
+	_location = list[0];
+
+	strcpy(_buf, s);		// kept as reference
+}
+
+
+
 int Parallaction_ns::init() {
 
 	// Detect game
@@ -193,11 +263,12 @@
 	_menu = new Menu(this);
 	_menu->start();
 
-	char *v4 = strchr(_location._name, '.');
-	if (v4) {
-		*v4 = '\0';
-	}
+	LocationName locname;
+	locname.bind(_location._name);
 
+	_char.setName(locname.character());
+	strcpy(_location._name, locname.location());
+
 	_globalTable = _disk->loadTable("global");
 
 	_engineFlags &= ~kEngineChangeLocation;
@@ -221,25 +292,9 @@
 	return 0;
 }
 
-
-/*
-	changeLocation handles transitions between locations, and is able to display slides
-	between one and the other. The input parameter 'location' exists in some flavours:
-
-    1 - [S].slide.[L]{.[C]}
-	2 - [L]{.[C]}
-
-    where:
-
-	[S] is the slide to be shown
-    [L] is the location to switch to (immediately in case 2, or right after slide [S] in case 1)
-    [C] is the character to be selected, and is optional
-
-    The routine tells one form from the other by searching for the '.slide.'
-
-    NOTE: there exists one script in which [L] is not used in the case 1, but its use
-		  is commented out, and would definitely crash the current implementation.
-*/
+//	changeLocation handles transitions between locations, and is able to display slides
+//	between one and the other.
+//
 void Parallaction_ns::changeLocation(char *location) {
 	debugC(1, kDebugExec, "changeLocation(%s)", location);
 
@@ -264,41 +319,26 @@
 	runJobs();
 
 	freeLocation();
-	char buf[100];
-	strcpy(buf, location);
 
-	Common::StringList list;
-	char *tok = strtok(location, ".");
-	while (tok) {
-		list.push_back(tok);
-		tok = strtok(NULL, ".");
+	LocationName locname;
+	locname.bind(location);
+
+	if (locname.hasSlide()) {
+		showSlide(locname.slide());
+		_gfx->setFont(_menuFont);
+		_gfx->displayCenteredString(14, _slideText[0]); // displays text on screen
+		_gfx->updateScreen();
+		waitUntilLeftClick();
 	}
 
-	if (list.size() < 1 || list.size() > 4)
-		error("changeLocation: ill-formed location string '%s'", location);
-
-	if (list.size() > 1) {
-		if (list[1] == "slide") {
-			showSlide(list[0].c_str());
-			_gfx->setFont(_menuFont);
-			_gfx->displayCenteredString(14, _slideText[0]); // displays text on screen
-			_gfx->updateScreen();
-			waitUntilLeftClick();
-
-			list.remove_at(0);		// removes slide name
-			list.remove_at(0);		// removes 'slide'
-		}
-
-		// list is now only [L].{[C]} (see above comment)
-		if (list.size() == 2) {
-			changeCharacter(list[1].c_str());
-		}
+	if (locname.hasCharacter()) {
+		changeCharacter(locname.character());
 	}
 
 	_animations.push_front(&_char._ani);
 
-	strcpy(_saveData1, list[0].c_str());
-	parseLocation(list[0].c_str());
+	strcpy(_saveData1, locname.location());
+	parseLocation(_saveData1);
 
 	_char._ani._oldPos.x = -1000;
 	_char._ani._oldPos.y = -1000;


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