[Scummvm-cvs-logs] scummvm master -> 2f0b35bbb51dc94c379d48ef336dcb8502bb2db5

Strangerke arnaud.boutonne at gmail.com
Tue Feb 15 19:30:25 CET 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
2f0b35bbb5 HUGO: Replace cypher by a global variable, clean engine destructor


Commit: 2f0b35bbb51dc94c379d48ef336dcb8502bb2db5
    https://github.com/scummvm/scummvm/commit/2f0b35bbb51dc94c379d48ef336dcb8502bb2db5
Author: strangerke (arnaud.boutonne at gmail.com)
Date: 2011-02-15T10:30:15-08:00

Commit Message:
HUGO: Replace cypher by a global variable, clean engine destructor

Changed paths:
    engines/hugo/display.cpp
    engines/hugo/display.h
    engines/hugo/file.cpp
    engines/hugo/hugo.cpp
    engines/hugo/object.cpp
    engines/hugo/object.h
    engines/hugo/parser.cpp
    engines/hugo/parser.h
    engines/hugo/schedule.cpp
    engines/hugo/schedule.h



diff --git a/engines/hugo/display.cpp b/engines/hugo/display.cpp
index 69ca064..f2c4990 100644
--- a/engines/hugo/display.cpp
+++ b/engines/hugo/display.cpp
@@ -585,17 +585,12 @@ void Screen::loadPalette(Common::ReadStream &in) {
 }
 
 /**
- * Free main and current palettes
+ * Free fonts, main and current palettes
  */
-void Screen::freePalette() {
+void Screen::freeScreen() {
 	free(_curPalette);
 	free(_mainPalette);
-}
 
-/**
- * Free fonts
- */
-void Screen::freeFonts() {
 	for (int i = 0; i < kNumFonts; i++) {
 		if (_arrayFont[i])
 			free(_arrayFont[i]);
diff --git a/engines/hugo/display.h b/engines/hugo/display.h
index 21e9fe2..b5a3c76 100644
--- a/engines/hugo/display.h
+++ b/engines/hugo/display.h
@@ -65,8 +65,7 @@ public:
 	void     drawRectangle(const bool filledFl, const int16 x1, const int16 y1, const int16 x2, const int16 y2, const int color);
 	void     drawShape(const int x, const int y, const int color1, const int color2);
 	void     drawStatusText();
-	void     freeFonts();
-	void     freePalette();
+	void     freeScreen();
 	void     hideCursor();
 	void     initDisplay();
 	void     initNewScreenDisplay();
diff --git a/engines/hugo/file.cpp b/engines/hugo/file.cpp
index 2e23247..a0602f0 100644
--- a/engines/hugo/file.cpp
+++ b/engines/hugo/file.cpp
@@ -369,14 +369,7 @@ bool FileManager::saveGame(const int16 slot, const Common::String &descrip) {
 	for (int i = 0; i < _vm->_numScreens; i++)
 		out->writeByte(_vm->_screenStates[i]);
 
-	_vm->_scheduler->savePoints(out);
-
-	// Now save current time and all current events in event queue
-	_vm->_scheduler->saveEvents(out);
-
-	// Now save current actions
-	_vm->_scheduler->saveActions(out);
-
+	_vm->_scheduler->saveSchedulerData(out);
 	// Save palette table
 	_vm->_screen->savePal(out);
 
@@ -471,14 +464,7 @@ bool FileManager::restoreGame(const int16 slot) {
 	for (int i = 0; i < _vm->_numScreens; i++)
 		_vm->_screenStates[i] = in->readByte();
 
-	_vm->_scheduler->restorePoints(in);
-	_vm->_object->restoreAllSeq();
-
-	// Now restore time of the save and the event queue
-	_vm->_scheduler->restoreEvents(in);
-
-	// Now restore actions
-	_vm->_scheduler->restoreActions(in);
+	_vm->_scheduler->restoreSchedulerData(in);
 
 	// Restore palette and change it if necessary
 	_vm->_screen->restorePal(in);
diff --git a/engines/hugo/hugo.cpp b/engines/hugo/hugo.cpp
index 76898c6..9f64db8 100644
--- a/engines/hugo/hugo.cpp
+++ b/engines/hugo/hugo.cpp
@@ -74,30 +74,22 @@ HugoEngine::HugoEngine(OSystem *syst, const HugoGameDescription *gd) : Engine(sy
 }
 
 HugoEngine::~HugoEngine() {
-	shutdown();
+	_file->closeDatabaseFiles();
 
-	_screen->freePalette();
-	_text->freeAllTexts();
 	_intro->freeIntroData();
-	_parser->freeArrayReqs();
-	_mouse->freeHotspots();
 	_inventory->freeInvent();
-	_object->freeObjectUses();
-	_parser->freeCatchallList();
-	_parser->freeBackgroundObjects();
-	_scheduler->freePoints();
-	_parser->freeCmdList();
-	_scheduler->freeScreenAct();
-	_object->freeObjectArr();
-	_scheduler->freeActListArr();
+	_mouse->freeHotspots();
+	_object->freeObjects();
+	_parser->freeParser();
+	_scheduler->freeScheduler();
+	_screen->freeScreen();
+	_text->freeAllTexts();
 
 	free(_defltTunes);
 	free(_screenStates);
 
-	_screen->freeFonts();
 
 	delete _topMenu;
-
 	delete _object;
 	delete _sound;
 	delete _route;
@@ -203,11 +195,12 @@ Common::Error HugoEngine::run() {
 	_screen->setCursorPal();
 	_screen->resetInventoryObjId();
 
+	_scheduler->initCypher();
+
 	initStatus();                                   // Initialize game status
 	initConfig();                                   // Initialize user's config
 	initialize();
 	resetConfig();                                  // Reset user's config
-
 	initMachine();
 
 	// Start the state machine
@@ -577,16 +570,6 @@ void HugoEngine::initialize() {
 }
 
 /**
- * Restore all resources before termination
- */
-void HugoEngine::shutdown() {
-	debugC(1, kDebugEngine, "shutdown");
-
-	_file->closeDatabaseFiles();
-	_object->freeObjects();
-}
-
-/**
  * Read scenery, overlay files for given screen number
  */
 void HugoEngine::readScreenFiles(const int screenNum) {
diff --git a/engines/hugo/object.cpp b/engines/hugo/object.cpp
index c2bcffb..786ea47 100644
--- a/engines/hugo/object.cpp
+++ b/engines/hugo/object.cpp
@@ -213,52 +213,54 @@ void ObjectHandler::lookObject(object_t *obj) {
 }
 
 /**
- * Free all object images
+ * Free all object images, uses and ObjArr (before exiting)
  */
 void ObjectHandler::freeObjects() {
 	debugC(1, kDebugObject, "freeObjects");
 
-	// Nothing to do if not allocated yet
-	if (_vm->_hero == 0 || _vm->_hero->seqList[0].seqPtr == 0)
-		return;
-
-	// Free all sequence lists and image data
-	for (int i = 0; i < _numObj; i++) {
-		object_t *obj = &_objects[i];
-		for (int j = 0; j < obj->seqNumb; j++) {
-			seq_t *seq = obj->seqList[j].seqPtr;
-			seq_t *next;
-			if (seq == 0) // Failure during database load
-				break;
-			if (seq->imagePtr != 0) {
-				free(seq->imagePtr);
-				seq->imagePtr = 0;
-			}
-			seq = seq->nextSeqPtr;
-			while (seq != obj->seqList[j].seqPtr) {
+	if (_vm->_hero != 0 && _vm->_hero->seqList[0].seqPtr != 0) {
+		// Free all sequence lists and image data
+		for (int16 i = 0; i < _numObj; i++) {
+			object_t *obj = &_objects[i];
+			for (int16 j = 0; j < obj->seqNumb; j++) {
+				seq_t *seq = obj->seqList[j].seqPtr;
+				seq_t *next;
+				if (seq == 0) // Failure during database load
+					break;
 				if (seq->imagePtr != 0) {
 					free(seq->imagePtr);
 					seq->imagePtr = 0;
 				}
-				next = seq->nextSeqPtr;
+				seq = seq->nextSeqPtr;
+				while (seq != obj->seqList[j].seqPtr) {
+					if (seq->imagePtr != 0) {
+						free(seq->imagePtr);
+						seq->imagePtr = 0;
+					}
+					next = seq->nextSeqPtr;
+					free(seq);
+					seq = next;
+				}
 				free(seq);
-				seq = next;
 			}
-			free(seq);
 		}
 	}
-}
 
-/**
- * Free all object uses
- */
-void ObjectHandler::freeObjectUses() {
 	if (_uses) {
-		for (int i = 0; i < _usesSize; i++)
+		for (int16 i = 0; i < _usesSize; i++)
 			free(_uses[i].targets);
 		free(_uses);
 	}
+
+	for(int16 i = 0; i < _objCount; i++) {
+		free(_objects[i].stateDataIndex);
+		_objects[i].stateDataIndex = 0;
+	}
+
+	free(_objects);
+	_objects = 0;
 }
+
 /**
  * Compare function for the quicksort.  The sort is to order the objects in
  * increasing vertical position, using y+y2 as the baseline
@@ -367,18 +369,6 @@ bool ObjectHandler::findObjectSpace(object_t *obj, int16 *destx, int16 *desty) {
 }
 
 /**
- * Free ObjectArr (before exiting)
- */
-void ObjectHandler::freeObjectArr() {
-	for(int16 i = 0; i < _objCount; i++) {
-		free(_objects[i].stateDataIndex);
-		_objects[i].stateDataIndex = 0;
-	}
-	free(_objects);
-	_objects = 0;
-}
-
-/**
  * Load _uses from Hugo.dat
  */
 void ObjectHandler::loadObjectUses(Common::ReadStream &in) {
diff --git a/engines/hugo/object.h b/engines/hugo/object.h
index 09dcfeb..ef60e62 100644
--- a/engines/hugo/object.h
+++ b/engines/hugo/object.h
@@ -73,10 +73,8 @@ public:
 	int   calcMaxScore();
 	int16 findObject(uint16 x, uint16 y);
 	void freeObjects();
-	void freeObjectUses();
 	void loadObjectArr(Common::ReadStream &in);
 	void loadObjectUses(Common::ReadStream &in);
-	void freeObjectArr();
 	void loadNumObj(Common::ReadStream &in);
 	void lookObject(object_t *obj);
 	void readObjectImages();
diff --git a/engines/hugo/parser.cpp b/engines/hugo/parser.cpp
index 5cc704e..c7e252b 100644
--- a/engines/hugo/parser.cpp
+++ b/engines/hugo/parser.cpp
@@ -105,14 +105,6 @@ void Parser::loadCmdList(Common::ReadStream &in) {
 	}
 }
 
-void Parser::freeCmdList() {
-	if (_cmdList) {
-		for (int i = 0; i < _cmdListSize; i++)
-			free(_cmdList[i]);
-		free(_cmdList);
-	}
-}
-
 /**
  * Read _backgrounObjects from Hugo.dat
  */
@@ -146,14 +138,6 @@ void Parser::loadBackgroundObjects(Common::ReadStream &in) {
 	}
 }
 
-void Parser::freeBackgroundObjects() {
-	if (_backgroundObjects) {
-		for (int i = 0; i < _backgroundObjectsSize; i++)
-			free(_backgroundObjects[i]);
-		free(_backgroundObjects);
-	}
-}
-
 /**
  * Read _catchallList from Hugo.dat
  */
@@ -178,10 +162,6 @@ void Parser::loadCatchallList(Common::ReadStream &in) {
 	}
 }
 
-void Parser::freeCatchallList() {
-	free(_catchallList);
-}
-
 void Parser::loadArrayReqs(Common::ReadStream &in) {
 	_arrayReqs = _vm->loadLongArray(in);
 }
@@ -204,12 +184,26 @@ const char *Parser::useBG(const char *name) {
 	return 0;
 }
 
-void Parser::freeArrayReqs() {
+void Parser::freeParser() {
 	if (_arrayReqs) {
 		for (int i = 0; _arrayReqs[i] != 0; i++)
 			free(_arrayReqs[i]);
 		free(_arrayReqs);
 	}
+
+	free(_catchallList);
+
+	if (_backgroundObjects) {
+		for (int i = 0; i < _backgroundObjectsSize; i++)
+			free(_backgroundObjects[i]);
+		free(_backgroundObjects);
+	}
+
+	if (_cmdList) {
+		for (int i = 0; i < _cmdListSize; i++)
+			free(_cmdList[i]);
+		free(_cmdList);
+	}
 }
 
 void Parser::switchTurbo() {
diff --git a/engines/hugo/parser.h b/engines/hugo/parser.h
index 283bcd4..5bc602f 100644
--- a/engines/hugo/parser.h
+++ b/engines/hugo/parser.h
@@ -53,10 +53,7 @@ public:
 	
 	void charHandler();
 	void command(const char *format, ...);
-	void freeArrayReqs();
-	void freeBackgroundObjects();
-	void freeCatchallList();
-	void freeCmdList();
+	void freeParser();
 	void keyHandler(Common::Event event);
 	void loadArrayReqs(Common::ReadStream &in);
 	void loadBackgroundObjects(Common::ReadStream &in);
diff --git a/engines/hugo/schedule.cpp b/engines/hugo/schedule.cpp
index 02f8e48..c5d1683 100644
--- a/engines/hugo/schedule.cpp
+++ b/engines/hugo/schedule.cpp
@@ -57,6 +57,10 @@ Scheduler::Scheduler(HugoEngine *vm) : _vm(vm), _actListArr(0), _curTick(0), _ol
 Scheduler::~Scheduler() {
 }
 
+void Scheduler::initCypher() {
+	_cypher = getCypher();
+}
+
 /**
  * Initialise the timer event queue
  */
@@ -840,21 +844,6 @@ void Scheduler::loadActListArr(Common::ReadStream &in) {
 	}
 }
 
-void Scheduler::freeActListArr() {
-	debugC(6, kDebugSchedule, "freeActListArr()");
-
-	if (_actListArr) {
-		for (int i = 0; i < _actListArrSize; i++) {
-			for (int j = 0; _actListArr[i][j].a0.actType != ANULL; j++) {
-				if (_actListArr[i][j].a0.actType == PROMPT)
-					free(_actListArr[i][j].a3.responsePtr);
-			}
-			free(_actListArr[i]);
-		}
-		free(_actListArr);
-	}
-}
-
 /**
  * Read _screenActs
  */
@@ -885,12 +874,27 @@ void Scheduler::loadScreenAct(Common::ReadStream &in) {
 	}
 }
 
-void Scheduler::freeScreenAct() {
+void Scheduler::freeScheduler() {
+	debugC(6, kDebugSchedule, "freeActListArr()");
+
+	free(_points);
+
 	if (_screenActs) {
 		for (int i = 0; i < _screenActsSize; i++)
 			free(_screenActs[i]);
 		free(_screenActs);
 	}
+
+	if (_actListArr) {
+		for (int i = 0; i < _actListArrSize; i++) {
+			for (int j = 0; _actListArr[i][j].a0.actType != ANULL; j++) {
+				if (_actListArr[i][j].a0.actType == PROMPT)
+					free(_actListArr[i][j].a3.responsePtr);
+			}
+			free(_actListArr[i]);
+		}
+		free(_actListArr);
+	}
 }
 
 /**
@@ -1020,7 +1024,6 @@ int16 Scheduler::calcMaxPoints() const {
 /*
 * Save the action data in the file with handle f
 */
-
 void Scheduler::saveActions(Common::WriteStream* f) const {
 	for (int i = 0; i < _actListArrSize; i++) {
 		// write all the sub elems data
@@ -1061,6 +1064,27 @@ void Scheduler::findAction(act* action, int16* index, int16* subElem) {
 	assert(0);
 }
 
+void Scheduler::saveSchedulerData(Common::WriteStream *out) {
+	savePoints(out);
+
+	// Now save current time and all current events in event queue
+	saveEvents(out);
+
+	// Now save current actions
+	saveActions(out);
+}
+
+void Scheduler::restoreSchedulerData(Common::ReadStream *in) {
+	restorePoints(in);
+	_vm->_object->restoreAllSeq();
+
+	// Now restore time of the save and the event queue
+	restoreEvents(in);
+
+	// Now restore actions
+	restoreActions(in);
+}
+
 /**
  * Restore the event list from file with handle f
  */
@@ -1455,7 +1479,7 @@ void Scheduler::delEventType(const action_t actTypeDel) {
 /**
  * Save the points table
  */
-void Scheduler::savePoints(Common::WriteStream *out) {
+void Scheduler::savePoints(Common::WriteStream *out) const {
 	for (int i = 0; i < _numBonuses; i++) {
 		out->writeByte(_points[i].score);
 		out->writeByte((_points[i].scoredFl) ? 1 : 0);
@@ -1533,11 +1557,9 @@ void Scheduler_v1d::promptAction(act *action) {
 void Scheduler_v1d::decodeString(char *line) {
 	debugC(1, kDebugSchedule, "decodeString(%s)", line);
 
-	static const Common::String cypher = getCypher();
-
 	uint16 linelength = strlen(line);
 	for(uint16 i = 0; i < linelength; i++) {
-		line[i] = (line[i] + cypher.c_str()[i % cypher.size()]) % '~';
+		line[i] = (line[i] + _cypher.c_str()[i % _cypher.size()]) % '~';
 		if (line[i] < ' ')
 			line[i] += ' ';
 	}
@@ -1586,11 +1608,10 @@ void Scheduler_v2d::promptAction(act *action) {
 void Scheduler_v2d::decodeString(char *line) {
 	debugC(1, kDebugSchedule, "decodeString(%s)", line);
 
-	static const Common::String cypher = getCypher();
-
 	int16 lineLength = strlen(line);
 	for (uint16 i = 0; i < lineLength; i++)
-		line[i] -= cypher.c_str()[i % cypher.size()];
+		line[i] -= _cypher.c_str()[i % _cypher.size()];
+
 	debugC(1, kDebugSchedule, "result : %s", line);
 }
 
diff --git a/engines/hugo/schedule.h b/engines/hugo/schedule.h
index c621a61..e2169a0 100644
--- a/engines/hugo/schedule.h
+++ b/engines/hugo/schedule.h
@@ -458,12 +458,10 @@ public:
 	virtual void decodeString(char *line) = 0;
 	virtual void runScheduler() = 0;
 
-	void freePoints() { free(_points); }
-
 	int16 calcMaxPoints() const;
 
-	void freeActListArr();
-	void freeScreenAct();
+	void freeScheduler();
+	void initCypher();
 	void initEventQueue();
 	void insertActionList(const uint16 actIndex);
 	void loadActListArr(Common::ReadStream &in);
@@ -473,24 +471,20 @@ public:
 	void newScreen(const int screenIndex);
 	void processBonus(const int bonusIndex);
 	void processMaze(const int x1, const int x2, const int y1, const int y2);
+	void restoreSchedulerData(Common::ReadStream *in);
 	void restoreScreen(const int screenIndex);
-	void restoreEvents(Common::ReadStream *f);
-	void restorePoints(Common::ReadStream *in);
-	void saveEvents(Common::WriteStream *f);
-	void savePoints(Common::WriteStream *out);
-	void screenActions(const int screenNum);
+	void saveSchedulerData(Common::WriteStream *out);
 	void waitForRefresh();
 
 	void findAction(act* action, int16* index, int16* subElem);
-	void saveActions(Common::WriteStream* f) const;
-	void restoreActions(Common::ReadStream *f);
-
 protected:
 	HugoEngine *_vm;
 	static const int kFilenameLength = 12;          // Max length of a DOS file name
 	static const int kMaxEvents = 50;               // Max events in event queue
 	static const int kShiftSize = 8;                // Place hero this far inside bounding box
 
+	Common::String _cypher;
+
 	uint16   _actListArrSize;
 	uint16   _alNewscrIndex;
 	uint16   _screenActsSize;
@@ -525,6 +519,14 @@ protected:
 	void delEventType(const action_t actTypeDel);
 	void delQueue(event_t *curEvent);
 	void insertAction(act *action);
+	void restoreActions(Common::ReadStream *f);
+	void restoreEvents(Common::ReadStream *f);
+	void restorePoints(Common::ReadStream *in);
+	void saveActions(Common::WriteStream* f) const;
+	void saveEvents(Common::WriteStream *f);
+	void savePoints(Common::WriteStream *out) const;
+	void screenActions(const int screenNum);
+
 };
 
 class Scheduler_v1d : public Scheduler {






More information about the Scummvm-git-logs mailing list