[Scummvm-cvs-logs] CVS: scummvm/sky control.cpp,1.38,1.39 control.h,1.18,1.19 sky.cpp,1.86,1.87 sky.h,1.41,1.42

Robert G?ffringmann lavosspawn at users.sourceforge.net
Fri Jul 11 15:20:09 CEST 2003


Update of /cvsroot/scummvm/scummvm/sky
In directory sc8-pr-cvs1:/tmp/cvs-serv31423/sky

Modified Files:
	control.cpp control.h sky.cpp sky.h 
Log Message:
added autosaving every 5 minutes

Index: control.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/control.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- control.cpp	10 Jul 2003 20:09:19 -0000	1.38
+++ control.cpp	11 Jul 2003 22:19:16 -0000	1.39
@@ -290,6 +290,7 @@
 	_upSlowButton   = createResource(_sprites.buttonDown, 1, 0, 212,  10,  0,   SHIFT_UP_SLOW, SAVEPANEL);
 	_quitButton     = createResource(    _sprites.button, 3, 0,  72, 129, 49,       SP_CANCEL, SAVEPANEL);
 	_restoreButton  = createResource(    _sprites.button, 3, 0,  29, 129, 51,  RESTORE_A_GAME, SAVEPANEL);
+	_autoSaveButton = createResource(    _sprites.button, 3, 0, 115, 129, 0x8FFF,    RESTORE_AUTO, SAVEPANEL);
 	
 	_savePanLookList[0] = _saveButton;
 	_restorePanLookList[0] = _restoreButton;
@@ -298,12 +299,14 @@
 	_restorePanLookList[3] = _savePanLookList[3] = _upFastButton;
 	_restorePanLookList[4] = _savePanLookList[4] = _upSlowButton;
 	_restorePanLookList[5] = _savePanLookList[5] = _quitButton;
+	_restorePanLookList[6] = _autoSaveButton;
 
 	_statusBar = new SkyControlStatus(_skyText, _system, _screenBuf);
 }
 
 void SkyControl::buttonControl(SkyConResource *pButton) {
 
+	char autoSave[] = "Restore Autosave";
 	if (pButton == NULL) {
 		if (_textSprite) free(_textSprite);
 		_textSprite = NULL;
@@ -316,9 +319,13 @@
 		_textSprite = NULL;
 		_curButtonText = pButton->_text;
 		if (pButton->_text) {
-			_skyText->getText(pButton->_text);
 			displayText_t textRes;
-			textRes = _skyText->displayText(NULL, false, PAN_LINE_WIDTH, 255);
+			if (pButton->_text == 0xFFFF) { // text for autosave button
+				textRes = _skyText->displayText(autoSave, NULL, false, PAN_LINE_WIDTH, 255);
+			} else {
+				_skyText->getText(pButton->_text);
+				textRes = _skyText->displayText(NULL, false, PAN_LINE_WIDTH, 255);
+			}
 			_textSprite = (dataFileHeader *)textRes.textData;
 			_text->setSprite(_textSprite);
 		} else _text->setSprite(NULL);
@@ -513,7 +520,11 @@
 
 		case RESTORE_A_GAME:
 			animClick(pButton);
-			return restoreGameFromFile();
+			return restoreGameFromFile(false);
+
+		case RESTORE_AUTO:
+			animClick(pButton);
+			return restoreGameFromFile(true);
 
 		case SP_CANCEL:
 			animClick(pButton);
@@ -772,6 +783,18 @@
 	return SHIFTED;
 }
 
+bool SkyControl::autoSaveExists(void) {
+
+	File test;
+	char fName[20];
+	if (SkyState::isCDVersion())
+		strcpy(fName, "SKY-VM-CD.ASD");
+	else
+        sprintf(fName, "SKY-VM%03d.ASD", SkyState::_systemVars.gameVersion);
+	test.open(fName, _savePath);
+	return test.isOpen();
+}
+
 uint16 SkyControl::saveRestorePanel(bool allowSave) {
 
 	_keyPressed = 0;
@@ -780,8 +803,18 @@
 
 	SkyConResource **lookList;
 	uint16 cnt;
-	if (allowSave) lookList = _savePanLookList;
-	else lookList = _restorePanLookList;
+	uint8 lookListLen;
+	if (allowSave) {
+		lookList = _savePanLookList;
+		lookListLen = 6;
+	} else {
+		lookList = _restorePanLookList;
+		if (autoSaveExists())
+			lookListLen = 7;
+		else
+			lookListLen = 6;
+	}
+	bool withAutoSave = (lookListLen == 7);
 
 	uint8 *saveGameTexts = (uint8 *)malloc(MAX_SAVE_GAMES * MAX_TEXT_LEN);
 	dataFileHeader *textSprites[MAX_ON_SCREEN + 1];
@@ -801,6 +834,8 @@
 				_text->flushForRedraw();
 				_savePanel->drawToScreen(NO_MASK);
 				_quitButton->drawToScreen(NO_MASK);
+				if (withAutoSave)
+					_autoSaveButton->drawToScreen(NO_MASK);
 			}
 			setUpGameSprites(saveGameTexts, textSprites, _firstText, _selectedGame);
 			showSprites(textSprites, allowSave);
@@ -829,7 +864,7 @@
 		}
 
 		bool haveButton = false;
-		for (cnt = 0; cnt < 6; cnt++)
+		for (cnt = 0; cnt < lookListLen; cnt++)
 			if (lookList[cnt]->isMouseOver(_mouseX, _mouseY)) {
 				buttonControl(lookList[cnt]);
 				haveButton = true;
@@ -1010,6 +1045,26 @@
 	free(tmpBuf);	
 }
 
+void SkyControl::doAutoSave(void) {
+	char fName[20];
+	if (SkyState::isCDVersion())
+		strcpy(fName, "SKY-VM-CD.ASD");
+	else
+        sprintf(fName, "SKY-VM%03d.ASD", SkyState::_systemVars.gameVersion);
+	File outf;
+	if (!outf.open(fName, _savePath, File::kFileWriteMode)) {
+		warning("Can't create file %s for autosaving", fName);
+		return;
+	}
+	uint8 *saveData = (uint8 *)malloc(0x20000);
+	uint32 fSize = prepareSaveData(saveData);
+
+	if (outf.write(saveData, fSize) != fSize)
+		warning("Can't write file %s for autosaving. Disk full?", fName);
+	outf.close();
+	free(saveData);
+}
+
 uint16 SkyControl::saveGameToFile(void) {
 
 	char fName[20];
@@ -1019,7 +1074,7 @@
 		return NO_DISK_SPACE;
 	}
 
-	uint8 *saveData = (uint8 *)malloc(0x50000);
+	uint8 *saveData = (uint8 *)malloc(0x20000);
 	uint32 fSize = prepareSaveData(saveData);
 
 	if (outf.write(saveData, fSize) != fSize) {
@@ -1391,10 +1446,17 @@
 #undef LODSD
 #undef LODSW
 
-uint16 SkyControl::restoreGameFromFile(void) {
+uint16 SkyControl::restoreGameFromFile(bool autoSave) {
 	
 	char fName[20];
-	sprintf(fName,"SKY-VM.%03d", _selectedGame);
+	if (autoSave) {
+		if (SkyState::isCDVersion())
+			strcpy(fName, "SKY-VM-CD.ASD");
+		else
+			sprintf(fName, "SKY-VM%03d.ASD", SkyState::_systemVars.gameVersion);
+	} else
+    	sprintf(fName,"SKY-VM.%03d", _selectedGame);
+
 	File inf;
 	if (!inf.open(fName, _savePath)) {
 		return RESTORE_FAILED;

Index: control.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/control.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- control.h	10 Jul 2003 00:08:07 -0000	1.18
+++ control.h	11 Jul 2003 22:19:16 -0000	1.19
@@ -83,6 +83,7 @@
 #define EXIT			15
 #define RESTART			16
 #define QUIT_TO_DOS		17
+#define RESTORE_AUTO	18
 
 // onClick return codes
 #define CANCEL_PRESSED	100
@@ -171,6 +172,7 @@
 	void doLoadSavePanel(void);
 	void restartGame(void);
 	void showGameQuitMsg(bool useScreen = true);
+	void doAutoSave(void);
     
 private:
 	void initPanel(void);
@@ -209,7 +211,8 @@
 	void stosStr(uint8 **destPos, uint16 *src, bool isGraph);
 	uint32 prepareSaveData(uint8 *destBuf);
 
-	uint16 restoreGameFromFile(void);
+	bool autoSaveExists(void);
+	uint16 restoreGameFromFile(bool autoSave);
 	void lodsMegaSet(uint8 **srcPos, MegaSet *mega);
 	void lodsCompact(uint8 **srcPos, Compact *cpt);
 	void lodsStr(uint8 **srcPos, uint16 *src);
@@ -276,8 +279,9 @@
 	SkyConResource *_savePanel;
 	SkyConResource *_saveButton, *_downFastButton, *_downSlowButton;
 	SkyConResource *_upFastButton, *_upSlowButton, *_quitButton, *_restoreButton;
+	SkyConResource *_autoSaveButton;
 
-	SkyConResource *_savePanLookList[6], *_restorePanLookList[6];
+	SkyConResource *_savePanLookList[6], *_restorePanLookList[7];
 
 	SkyControlStatus *_statusBar;
 

Index: sky.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/sky.cpp,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -d -r1.86 -r1.87
--- sky.cpp	11 Jul 2003 19:41:37 -0000	1.86
+++ sky.cpp	11 Jul 2003 22:19:16 -0000	1.87
@@ -155,8 +155,16 @@
 	if (introSkipped)
 		_skyControl->restartGame();
 
+	_lastSaveTime = _system->get_msecs();
+
 	while (1) {
 		delay(_systemVars.gameSpeed);
+
+		if (_system->get_msecs() - _lastSaveTime > 5 * 60 * 1000) {
+			_lastSaveTime = _system->get_msecs();
+			_skyControl->doAutoSave();
+		}
+
 		if (_key_pressed == 63) {
 			_key_pressed = 0;
 			_skyControl->doControlPanel();

Index: sky.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/sky.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- sky.h	10 Jul 2003 08:24:16 -0000	1.41
+++ sky.h	11 Jul 2003 22:19:16 -0000	1.42
@@ -127,6 +127,7 @@
 	void checkCommands(uint32 *&cmdPtr);
 	void introFrame(uint8 **diffPtr, uint8 **vgaPtr, uint8 *screenData);
 	void escDelay(uint32 pDelay);
+	uint32 _lastSaveTime;
 
 	SkyText *getSkyText();
 	void initialise();





More information about the Scummvm-git-logs mailing list