[Scummvm-cvs-logs] CVS: scummvm/sword2 save_rest.cpp,1.58,1.59 sword2.cpp,1.118,1.119 sword2.h,1.66,1.67

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Mon Nov 15 00:23:02 CET 2004


Update of /cvsroot/scummvm/scummvm/sword2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31534

Modified Files:
	save_rest.cpp sword2.cpp sword2.h 
Log Message:
I think this is the kind of constructor/go changes _sev was talking about
in his mail to scummvm-devel. (Though "a discussed a while ago change"
sounds like sort of thing Robert Jordan writes whenever there is danger of
anything actually happening in any of his more recent books. Tantalizing,
yet non-informative. ;-)

It's still rather messy. I'll look into cleaning it up later.


Index: save_rest.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/save_rest.cpp,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- save_rest.cpp	14 Nov 2004 15:00:01 -0000	1.58
+++ save_rest.cpp	15 Nov 2004 08:22:16 -0000	1.59
@@ -163,7 +163,7 @@
 uint32 Sword2Engine::saveData(uint16 slotNo, byte *buffer, uint32 bufferSize) {
 	char saveFileName[MAX_FILENAME_LEN];
 
-	sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
+	sprintf(saveFileName, "%s.%.3d", _targetName.c_str(), slotNo);
 
 	SaveFile *out;
 
@@ -210,7 +210,7 @@
 uint32 Sword2Engine::restoreData(uint16 slotNo, byte *buffer, uint32 bufferSize) {
 	char saveFileName[MAX_FILENAME_LEN];
 
-	sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
+	sprintf(saveFileName, "%s.%.3d", _targetName.c_str(), slotNo);
 
 	SaveFile *in;
 
@@ -355,7 +355,7 @@
 uint32 Sword2Engine::getSaveDescription(uint16 slotNo, byte *description) {
 	char saveFileName[MAX_FILENAME_LEN];
 
-	sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
+	sprintf(saveFileName, "%s.%.3d", _targetName.c_str(), slotNo);
 
 	SaveFile *in;
 
@@ -382,7 +382,7 @@
 bool Sword2Engine::saveExists(uint16 slotNo) {
 	char saveFileName[MAX_FILENAME_LEN];
 
-	sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
+	sprintf(saveFileName, "%s.%.3d", _targetName.c_str(), slotNo);
 
 	SaveFile *in;
 

Index: sword2.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sword2.cpp,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- sword2.cpp	14 Nov 2004 15:00:01 -0000	1.118
+++ sword2.cpp	15 Nov 2004 08:22:16 -0000	1.119
@@ -102,9 +102,7 @@
 
 Sword2Engine *g_sword2 = NULL;
 
-Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
-	: Engine(syst) {
-
+Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) : Engine(syst) {
 	// Add default file directories
 	File::addDefaultDirectory(_gameDataPath + "CLUSTERS/");
 	File::addDefaultDirectory(_gameDataPath + "SWORD2/");
@@ -118,43 +116,15 @@
 	_sound = NULL;
 	_graphics = NULL;
 	_features = detector->_game.features;
-	_targetName = strdup(detector->_targetName.c_str());
+	_targetName = detector->_targetName;
 	_bootParam = ConfMan.getInt("boot_param");
 	_saveSlot = ConfMan.getInt("save_slot");
 
-	// Setup mixer
-	if (!_mixer->isReady())
-		warning("Sound initialization failed");
-
-	// We have our own volume settings panel, so don't let ScummVM's mixer
-	// soften the sound in any way.
-
-	_mixer->setVolume(256);
-
 	_keyboardEvent.pending = false;
 	_mouseEvent.pending = false;
 
 	_mouseX = _mouseY = 0;
 
-	// get some falling RAM and put it in your pocket, never let it slip
-	// away
-
-	_graphics = new Graphics(this, 640, 480);
-
-	// Create the debugger as early as possible (but not before the
-	// graphics object!) so that errors can be displayed in it. In
-	// particular, we want errors about missing files to be clearly
-	// visible to the user.
-
-	_debugger = new Debugger(this);
-
-	_memory = new MemoryManager(this);
-	_resman = new ResourceManager(this);
-	_logic = new Logic(this);
-	_fontRenderer = new FontRenderer(this);
-	_gui = new Gui(this);
-	_sound = new Sound(this);
-
 	_lastPaletteRes = 0;
 
 	_largestLayerArea = 0;
@@ -176,9 +146,7 @@
 
 	_totalMasters = 0;
 	memset(_masterMenuList, 0, sizeof(_masterMenuList));
-
 	memset(&_thisScreen, 0, sizeof(_thisScreen));
-
 	memset(_mouseList, 0, sizeof(_mouseList));
 
 	_mouseTouching = 0;
@@ -202,10 +170,20 @@
 	_gamePaused = false;
 	_stepOneCycle = false;
 	_graphicsLevelFudged = false;
+
+	_debugger = NULL;
+	_graphics = NULL;
+	_sound = NULL;
+	_gui = NULL;
+	_fontRenderer = NULL;
+	_logic = NULL;
+	_resman = NULL;
+	_memory = NULL;
+
+	_quit = false;
 }
 
 Sword2Engine::~Sword2Engine() {
-	free(_targetName);
 	delete _debugger;
 	delete _graphics;
 	delete _sound;
@@ -239,12 +217,40 @@
  * the game, so that they are never expelled by the resource manager.
  */
 
-void Sword2Engine::setupPersistentResources(void) {
+void Sword2Engine::setupPersistentResources() {
 	Logic::_scriptVars = (uint32 *) (_resman->openResource(1) + sizeof(StandardHeader));
 	_resman->openResource(CUR_PLAYER_ID);
 }
     
-int32 Sword2Engine::initialiseGame(void) {
+void Sword2Engine::mainInit() {
+	// get some falling RAM and put it in your pocket, never let it slip
+	// away
+
+	_graphics = new Graphics(this, 640, 480);
+
+	// Create the debugger as early as possible (but not before the
+	// graphics object!) so that errors can be displayed in it. In
+	// particular, we want errors about missing files to be clearly
+	// visible to the user.
+
+	_debugger = new Debugger(this);
+
+	_memory = new MemoryManager(this);
+	_resman = new ResourceManager(this);
+	_logic = new Logic(this);
+	_fontRenderer = new FontRenderer(this);
+	_gui = new Gui(this);
+	_sound = new Sound(this);
+
+	// Setup mixer
+	if (!_mixer->isReady())
+		warning("Sound initialization failed");
+
+	// We have our own volume settings panel, so don't let ScummVM's mixer
+	// soften the sound in any way.
+
+	_mixer->setVolume(256);
+
 	// During normal gameplay, we care neither about mouse button releases
 	// nor the scroll wheel.
 	setEventFilter(RD_LEFTBUTTONUP | RD_RIGHTBUTTONUP | RD_WHEELUP | RD_WHEELDOWN);
@@ -268,18 +274,144 @@
 	else
 		Logic::_scriptVars[DEMO] = 0;
 
-	return 0;
+	debug(5, "CALLING: readOptionSettings");
+	_gui->readOptionSettings();
+
+	if (_saveSlot != -1) {
+		if (saveExists(_saveSlot))
+			restoreGame(_saveSlot);
+		else {
+			setMouse(NORMAL_MOUSE_ID);
+			if (!_gui->restoreControl())
+				startGame();
+		}
+	} else if (!_bootParam && saveExists()) {
+		int32 pars[2] = { 221, FX_LOOP };
+		bool result;
+
+		setMouse(NORMAL_MOUSE_ID);
+		_logic->fnPlayMusic(pars);
+		result = _gui->startControl();
+
+		// If the game is started from the beginning, the cutscene
+		// player will kill the music for us. Otherwise, the restore
+		// will either have killed the music, or done a crossfade.
+
+		if (_quit)
+			return;
+
+		if (result)
+			startGame();
+	} else
+		startGame();
+
+	debug(5, "CALLING: initialiseRenderCycle");
+	_graphics->initialiseRenderCycle();
+
+	_renderSkip = false;		// Toggled on 'S' key, to render only
+					// 1 in 4 frames, to speed up game
+
+	_gameCycle = 0;
 }
 
-void Sword2Engine::closeGame(void) {
+void Sword2Engine::mainRun() {
+	while (1) {
+		if (_debugger->isAttached())
+			_debugger->onFrame();
+
+		// the screen is build. Mostly because of first scroll
+		// cycle stuff
+
+#ifdef _SWORD2_DEBUG
+		// if we've just stepped forward one cycle while the
+		// game was paused
+
+		if (_stepOneCycle) {
+			pauseGame();
+			_stepOneCycle = false;
+		}
+#endif
+
+		KeyboardEvent *ke = keyboardEvent();
+
+		if (ke) {
+			if ((ke->modifiers == OSystem::KBD_CTRL && ke->keycode == 'd') || ke->ascii == '#' || ke->ascii == '~') {
+				_debugger->attach();
+			} else if (ke->modifiers == 0 || ke->modifiers == OSystem::KBD_SHIFT) {
+				switch (ke->keycode) {
+				case 'p':
+					if (_gamePaused)
+						unpauseGame();
+					else
+						pauseGame();
+					break;
+				case 'c':
+					if (!Logic::_scriptVars[DEMO] && !_logic->_choosing)
+						_logic->fnPlayCredits(NULL);
+					break;
+#ifdef _SWORD2_DEBUG
+				case ' ':
+					if (_gamePaused) {
+						_stepOneCycle = true;
+						unpauseGame();
+					}
+					break;
+				case 's':
+					_renderSkip = !_renderSkip;
+					break;
+#endif
+				default:
+					break;
+				}
+			}
+		}
+
+		// skip GameCycle if we're paused
+		if (!_gamePaused) {
+			_gameCycle++;
+			gameCycle();
+		}
+
+		// We can't use this as termination condition for the looop,
+		// because we want the break to happen before updating the
+		// screen again.
+
+		if (_quit)
+			break;
+
+		// creates the debug text blocks
+		_debugger->buildDebugText();
+
+#ifdef _SWORD2_DEBUG
+		// if not in console & '_renderSkip' is set, only render
+		// display once every 4 game-cycles
+
+		if (console_status || !_renderSkip || (_gameCycle % 4) == 0)
+			buildDisplay();	// create and flip the screen
+#else
+		// create and flip the screen
+		buildDisplay();
+#endif
+	}
+}
+
+void Sword2Engine::go() {
+	mainInit();
+	mainRun();
+
+	// Stop music instantly!
+	killMusic();
+}
+
+void Sword2Engine::closeGame() {
 	_quit = true;
 }
 
-bool Sword2Engine::checkForMouseEvents(void) {
+bool Sword2Engine::checkForMouseEvents() {
 	return _mouseEvent.pending;
 }
 
-MouseEvent *Sword2Engine::mouseEvent(void) {
+MouseEvent *Sword2Engine::mouseEvent() {
 	if (!_mouseEvent.pending)
 		return NULL;
 
@@ -287,7 +419,7 @@
 	return &_mouseEvent;
 }
 
-KeyboardEvent *Sword2Engine::keyboardEvent(void) {
+KeyboardEvent *Sword2Engine::keyboardEvent() {
 	if (!_keyboardEvent.pending)
 		return NULL;
 
@@ -306,7 +438,7 @@
  * OSystem Event Handler. Full of cross platform goodness and 99% fat free!
  */
 
-void Sword2Engine::parseEvents(void) {
+void Sword2Engine::parseEvents() {
 	OSystem::Event event;
 	
 	while (_system->pollEvent(event)) {
@@ -370,7 +502,7 @@
 	}
 }
 
-void Sword2Engine::gameCycle(void) {
+void Sword2Engine::gameCycle() {
 	// do one game cycle
 
 	// got a screen to run?
@@ -401,136 +533,7 @@
 	processFxQueue();
 }
 
-void Sword2Engine::go() {
-	_quit = false;
-
-	debug(5, "CALLING: readOptionSettings");
-	_gui->readOptionSettings();
-
-	debug(5, "CALLING: initialiseGame");
-	if (initialiseGame())
-		return;
-
-	if (_saveSlot != -1) {
-		if (saveExists(_saveSlot))
-			restoreGame(_saveSlot);
-		else {
-			setMouse(NORMAL_MOUSE_ID);
-			if (!_gui->restoreControl())
-				startGame();
-		}
-	} else if (!_bootParam && saveExists()) {
-		int32 pars[2] = { 221, FX_LOOP };
-		bool result;
-
-		setMouse(NORMAL_MOUSE_ID);
-		_logic->fnPlayMusic(pars);
-		result = _gui->startControl();
-
-		// If the game is started from the beginning, the cutscene
-		// player will kill the music for us. Otherwise, the restore
-		// will either have killed the music, or done a crossfade.
-
-		if (_quit)
-			return;
-
-		if (result)
-			startGame();
-	} else
-		startGame();
-
-	debug(5, "CALLING: initialiseRenderCycle");
-	_graphics->initialiseRenderCycle();
-
-	_renderSkip = false;		// Toggled on 'S' key, to render only
-					// 1 in 4 frames, to speed up game
-
-	_gameCycle = 0;
-
-	while (1) {
-		if (_debugger->isAttached())
-			_debugger->onFrame();
-
-		// the screen is build. Mostly because of first scroll
-		// cycle stuff
-
-#ifdef _SWORD2_DEBUG
-		// if we've just stepped forward one cycle while the
-		// game was paused
-
-		if (_stepOneCycle) {
-			pauseGame();
-			_stepOneCycle = false;
-		}
-#endif
-
-		KeyboardEvent *ke = keyboardEvent();
-
-		if (ke) {
-			if ((ke->modifiers == OSystem::KBD_CTRL && ke->keycode == 'd') || ke->ascii == '#' || ke->ascii == '~') {
-				_debugger->attach();
-			} else if (ke->modifiers == 0 || ke->modifiers == OSystem::KBD_SHIFT) {
-				switch (ke->keycode) {
-				case 'p':
-					if (_gamePaused)
-						unpauseGame();
-					else
-						pauseGame();
-					break;
-				case 'c':
-					if (!Logic::_scriptVars[DEMO] && !_logic->_choosing)
-						_logic->fnPlayCredits(NULL);
-					break;
-#ifdef _SWORD2_DEBUG
-				case ' ':
-					if (_gamePaused) {
-						_stepOneCycle = true;
-						unpauseGame();
-					}
-					break;
-				case 's':
-					_renderSkip = !_renderSkip;
-					break;
-#endif
-				default:
-					break;
-				}
-			}
-		}
-
-		// skip GameCycle if we're paused
-		if (!_gamePaused) {
-			_gameCycle++;
-			gameCycle();
-		}
-
-		// We can't use this as termination condition for the looop,
-		// because we want the break to happen before updating the
-		// screen again.
-
-		if (_quit)
-			break;
-
-		// creates the debug text blocks
-		_debugger->buildDebugText();
-
-#ifdef _SWORD2_DEBUG
-		// if not in console & '_renderSkip' is set, only render
-		// display once every 4 game-cycles
-
-		if (console_status || !_renderSkip || (_gameCycle % 4) == 0)
-			buildDisplay();	// create and flip the screen
-#else
-		// create and flip the screen
-		buildDisplay();
-#endif
-	}
-
-	// Stop music instantly!
-	killMusic();
-}
-
-void Sword2Engine::startGame(void) {
+void Sword2Engine::startGame() {
 	// boot the game straight into a start script
 
 	int screen_manager_id;
@@ -587,7 +590,7 @@
 	}
 }
 
-void Sword2Engine::pauseGame(void) {
+void Sword2Engine::pauseGame() {
 	// don't allow Pause while screen fading or while black
 	if (_graphics->getFadeStatus() != RDFADE_NONE)
 		return;
@@ -623,7 +626,7 @@
 	_gamePaused = true;
 }
 
-void Sword2Engine::unpauseGame(void) {
+void Sword2Engine::unpauseGame() {
 	if (Logic::_scriptVars[OBJECT_HELD] && _realLuggageItem)
 		setLuggage(_realLuggageItem);
 

Index: sword2.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sword2.h,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- sword2.h	14 Nov 2004 15:00:01 -0000	1.66
+++ sword2.h	15 Nov 2004 08:22:16 -0000	1.67
@@ -138,28 +138,28 @@
 
 	uint32 _lastPaletteRes;
 
-	void drawBackPar0Frames(void);
-	void drawBackPar1Frames(void);
-	void drawBackFrames(void);
+	void drawBackPar0Frames();
+	void drawBackPar1Frames();
+	void drawBackFrames();
 	void drawSortFrames(byte *file);
-	void drawForeFrames(void);
-	void drawForePar0Frames(void);
-	void drawForePar1Frames(void);
+	void drawForeFrames();
+	void drawForePar0Frames();
+	void drawForePar1Frames();
 
-	void startNewPalette(void);
+	void startNewPalette();
 	void processLayer(byte *file, uint32 layer_number);
 	void processImage(BuildUnit *build_unit);
 
-	void getPlayerStructures(void);
-	void putPlayerStructures(void);
+	void getPlayerStructures();
+	void putPlayerStructures();
 
 	uint32 saveData(uint16 slotNo, byte *buffer, uint32 bufferSize);
 	uint32 restoreData(uint16 slotNo, byte *buffer, uint32 bufferSize);
 
 	uint32 calcChecksum(byte *buffer, uint32 size);
 
-	void pauseGame(void);
-	void unpauseGame(void);
+	void pauseGame();
+	void unpauseGame();
 
 	MenuObject _tempList[TOTAL_engine_pockets];
 	uint32 _totalTemp;
@@ -170,14 +170,16 @@
 public:
 	Sword2Engine(GameDetector *detector, OSystem *syst);
 	~Sword2Engine();
-	void go(void);
-	void setupPersistentResources(void);
-	int32 initialiseGame(void);
+	void go();
+	void mainInit();
+	void mainRun();
+
+	void setupPersistentResources();
 
 	bool _quit;
 
 	uint32 _features;
-	char *_targetName; // target name for saves
+	Common::String _targetName; // target name for saves
 
 	MemoryManager *_memory;
 	ResourceManager	*_resman;
@@ -200,14 +202,14 @@
 
 	uint32 setEventFilter(uint32 filter);
 
-	void parseEvents(void);
+	void parseEvents();
 
-	bool checkForMouseEvents(void);
-	MouseEvent *mouseEvent(void);
-	KeyboardEvent *keyboardEvent(void);
+	bool checkForMouseEvents();
+	MouseEvent *mouseEvent();
+	KeyboardEvent *keyboardEvent();
 
-	void resetRenderLists(void);
-	void buildDisplay(void);
+	void resetRenderLists();
+	void buildDisplay();
 	void displayMsg(byte *text, int time);
 	void setFullPalette(int32 palRes);
 
@@ -244,14 +246,14 @@
 	int32 initBackground(int32 res, int32 new_palette);
 
 #if RIGHT_CLICK_CLEARS_LUGGAGE
-	bool heldIsInInventory(void);
+	bool heldIsInInventory();
 #endif
 
 	int menuClick(int menu_items);
 
 	void addMenuObject(MenuObject *obj);
-	void buildMenu(void);
-	void buildSystemMenu(void);
+	void buildMenu();
+	void buildSystemMenu();
 
 	// _thisScreen describes the current back buffer and its in-game scroll
 	// positions, etc.
@@ -287,25 +289,25 @@
 	uint32 _pointerTextBlocNo;
 	uint32 _playerActivityDelay;	// Player activity delay counter
 
-	void resetMouseList(void);
+	void resetMouseList();
 
-	void normalMouse(void);
-	void menuMouse(void);
-	void dragMouse(void);
-	void systemMenuMouse(void);
+	void normalMouse();
+	void menuMouse();
+	void dragMouse();
+	void systemMenuMouse();
 
-	void mouseOnOff(void);
-	uint32 checkMouseList(void);
-	void mouseEngine(void);
+	void mouseOnOff();
+	uint32 checkMouseList();
+	void mouseEngine();
 
 	void setMouse(uint32 res);
 	void setLuggage(uint32 res);
 
-	void clearPointerText(void);
+	void clearPointerText();
 
 	void createPointerText(uint32 text_id, uint32 pointer_res);
-	void monitorPlayerActivity(void);
-	void noHuman(void);
+	void monitorPlayerActivity();
+	void noHuman();
 
 	void registerMouse(ObjectMouse *ob_mouse);
 
@@ -359,32 +361,32 @@
 	uint32 saveGame(uint16 slotNo, byte *description);
 	uint32 restoreGame(uint16 slotNo);
 	uint32 getSaveDescription(uint16 slotNo, byte *description);
-	bool saveExists(void);
+	bool saveExists();
 	bool saveExists(uint16 slotNo);
 	void fillSaveBuffer(byte *buffer, uint32 size, byte *desc);
 	uint32 restoreFromBuffer(byte *buffer, uint32 size);
-	uint32 findBufferSize(void);
+	uint32 findBufferSize();
 
 	uint8 _scrollFraction;
 
-	void setScrolling(void);
+	void setScrolling();
 
 	// used to store id of tunes that loop, for save & restore
 	uint32 _loopingMusicId;
 
 	// to be called during system initialisation
-	void initFxQueue(void);
+	void initFxQueue();
 
 	// to be called from the main loop, once per cycle
-	void processFxQueue(void);
+	void processFxQueue();
 
 	// stops all fx & clears the queue - eg. when leaving a location
-	void clearFxQueue(void);
+	void clearFxQueue();
 
-	void pauseAllSound(void);
-	void unpauseAllSound(void);
+	void pauseAllSound();
+	void unpauseAllSound();
 
-	void killMusic(void);
+	void killMusic();
 
 	void triggerFx(uint8 j);
 
@@ -392,14 +394,14 @@
 	bool _graphicsLevelFudged;
 	bool _stepOneCycle;		// for use while game paused
 
-	void startGame(void);
-	void gameCycle(void);
-	void closeGame(void);
+	void startGame();
+	void gameCycle();
+	void closeGame();
 
 	void sleepUntil(uint32 time);
 
 	void errorString(const char *buf_input, char *buf_output);
-	void initialiseFontResourceFlags(void);
+	void initialiseFontResourceFlags();
 	void initialiseFontResourceFlags(uint8 language);
 };
 





More information about the Scummvm-git-logs mailing list