aboutsummaryrefslogtreecommitdiff
path: root/sky
diff options
context:
space:
mode:
authorRobert Göffringmann2003-07-11 22:19:16 +0000
committerRobert Göffringmann2003-07-11 22:19:16 +0000
commitf89c68c6f19d859a755741ddb0d66255b5f6b69c (patch)
tree6f0ce84c8fa573d01674c3ec15ab76adc5e6fbee /sky
parent021aa93c6c0cfa37198de3a7a4158498a165e41c (diff)
downloadscummvm-rg350-f89c68c6f19d859a755741ddb0d66255b5f6b69c.tar.gz
scummvm-rg350-f89c68c6f19d859a755741ddb0d66255b5f6b69c.tar.bz2
scummvm-rg350-f89c68c6f19d859a755741ddb0d66255b5f6b69c.zip
added autosaving every 5 minutes
svn-id: r8915
Diffstat (limited to 'sky')
-rw-r--r--sky/control.cpp80
-rw-r--r--sky/control.h8
-rw-r--r--sky/sky.cpp8
-rw-r--r--sky/sky.h1
4 files changed, 86 insertions, 11 deletions
diff --git a/sky/control.cpp b/sky/control.cpp
index a34b3a187c..3cf1e9f743 100644
--- a/sky/control.cpp
+++ b/sky/control.cpp
@@ -290,6 +290,7 @@ void SkyControl::initPanel(void) {
_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 @@ void SkyControl::initPanel(void) {
_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 @@ void SkyControl::buttonControl(SkyConResource *pButton) {
_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 @@ uint16 SkyControl::handleClick(SkyConResource *pButton) {
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 @@ uint16 SkyControl::shiftUp(uint8 speed) {
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 @@ uint16 SkyControl::saveRestorePanel(bool allowSave) {
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 @@ uint16 SkyControl::saveRestorePanel(bool allowSave) {
_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 @@ uint16 SkyControl::saveRestorePanel(bool allowSave) {
}
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 @@ void SkyControl::saveDescriptions(uint8 *srcBuf) {
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 @@ uint16 SkyControl::saveGameToFile(void) {
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 @@ uint16 SkyControl::parseSaveData(uint8 *srcBuf) {
#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;
diff --git a/sky/control.h b/sky/control.h
index 856fa37a12..de1cdad8ef 100644
--- a/sky/control.h
+++ b/sky/control.h
@@ -83,6 +83,7 @@ class SkyMouse;
#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 @@ public:
void doLoadSavePanel(void);
void restartGame(void);
void showGameQuitMsg(bool useScreen = true);
+ void doAutoSave(void);
private:
void initPanel(void);
@@ -209,7 +211,8 @@ private:
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 @@ private:
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;
diff --git a/sky/sky.cpp b/sky/sky.cpp
index 55c6cb618f..e36076a41e 100644
--- a/sky/sky.cpp
+++ b/sky/sky.cpp
@@ -155,8 +155,16 @@ void SkyState::go() {
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();
diff --git a/sky/sky.h b/sky/sky.h
index 5d62159765..46ef0b28e9 100644
--- a/sky/sky.h
+++ b/sky/sky.h
@@ -127,6 +127,7 @@ protected:
void checkCommands(uint32 *&cmdPtr);
void introFrame(uint8 **diffPtr, uint8 **vgaPtr, uint8 *screenData);
void escDelay(uint32 pDelay);
+ uint32 _lastSaveTime;
SkyText *getSkyText();
void initialise();