Made the autosave period a configuration option and updated the engines using that feature (SCUMM, Queen and Sky). The value is supposed to be in seconds ; if it's set to 0 then autosaving is disabled. See also tracker item #1350187.

svn-id: r19700
This commit is contained in:
Gregory Montoir 2005-11-23 19:11:33 +00:00
parent d7351092a9
commit fe9def0ac0
7 changed files with 22 additions and 5 deletions

View file

@ -46,6 +46,8 @@ Engine::Engine(OSystem *syst)
Common::File::addDefaultDirectory(_gameDataPath); Common::File::addDefaultDirectory(_gameDataPath);
_saveFileMan = _system->getSavefileManager(); _saveFileMan = _system->getSavefileManager();
_autosavePeriod = ConfMan.getInt("autosave_period");
} }
Engine::~Engine() { Engine::~Engine() {
@ -136,6 +138,11 @@ void Engine::checkCD() {
#endif #endif
} }
bool Engine::shouldPerformAutoSave(int lastSaveTime) {
const int diff = _system->getMillis() - lastSaveTime;
return _autosavePeriod != 0 && diff > _autosavePeriod * 1000;
}
const char *Engine::getGameDataPath() const { const char *Engine::getGameDataPath() const {
return _gameDataPath.c_str(); return _gameDataPath.c_str();
} }

View file

@ -44,6 +44,9 @@ protected:
const Common::String _gameDataPath; const Common::String _gameDataPath;
Common::SaveFileManager *_saveFileMan; Common::SaveFileManager *_saveFileMan;
private:
int _autosavePeriod;
public: public:
Engine(OSystem *syst); Engine(OSystem *syst);
virtual ~Engine(); virtual ~Engine();
@ -72,6 +75,9 @@ public:
/** On some systems, check if the game appears to be run from CD. */ /** On some systems, check if the game appears to be run from CD. */
void checkCD(); void checkCD();
/* Indicate if an autosave should be performed */
bool shouldPerformAutoSave(int lastSaveTime);
}; };
extern Engine *g_engine; extern Engine *g_engine;

View file

@ -402,6 +402,11 @@ extern "C" int main(int argc, char *argv[]) {
// Update the config file // Update the config file
ConfMan.set("versioninfo", gScummVMVersion, Common::ConfigManager::kApplicationDomain); ConfMan.set("versioninfo", gScummVMVersion, Common::ConfigManager::kApplicationDomain);
if (!ConfMan.hasKey("autosave_period")) {
// By default, trigger autosave every 5 minutes
ConfMan.set("autosave_period", 5 * 60, Common::ConfigManager::kApplicationDomain);
}
// Load the plugins // Load the plugins
PluginManager::instance().loadPlugins(); PluginManager::instance().loadPlugins();

View file

@ -231,7 +231,7 @@ void QueenEngine::update(bool checkPlayerInput) {
_input->quickLoadReset(); _input->quickLoadReset();
loadGameState(0); loadGameState(0);
} }
if (_system->getMillis() - _lastSaveTime >= AUTOSAVE_INTERVAL) { if (shouldPerformAutoSave(_lastSaveTime)) {
saveGameState(AUTOSAVE_SLOT, "Autosave"); saveGameState(AUTOSAVE_SLOT, "Autosave");
_lastSaveTime = _system->getMillis(); _lastSaveTime = _system->getMillis();
} }

View file

@ -123,7 +123,6 @@ public:
SAVESTATE_MAX_NUM = 100, SAVESTATE_MAX_NUM = 100,
SAVESTATE_MAX_SIZE = 30000, SAVESTATE_MAX_SIZE = 30000,
AUTOSAVE_INTERVAL = 5 * 60 * 1000,
AUTOSAVE_SLOT = 0xFF, AUTOSAVE_SLOT = 0xFF,
MIN_TEXT_SPEED = 4, MIN_TEXT_SPEED = 4,

View file

@ -2359,8 +2359,8 @@ int ScummEngine::scummLoop(int delta) {
} }
} }
// Trigger autosave all 5 minutes. // Trigger autosave if necessary.
if (!_saveLoadFlag && _system->getMillis() > _lastSaveTime + 5 * 60 * 1000) { if (!_saveLoadFlag && shouldPerformAutoSave(_lastSaveTime)) {
_saveLoadSlot = 0; _saveLoadSlot = 0;
sprintf(_saveLoadName, "Autosave %d", _saveLoadSlot); sprintf(_saveLoadName, "Autosave %d", _saveLoadSlot);
_saveLoadFlag = 1; _saveLoadFlag = 1;

View file

@ -240,7 +240,7 @@ int SkyEngine::go() {
int32 frameTime = (int32)_system->getMillis(); int32 frameTime = (int32)_system->getMillis();
if (_system->getMillis() - _lastSaveTime > 5 * 60 * 1000) { if (shouldPerformAutoSave(_lastSaveTime)) {
if (_skyControl->loadSaveAllowed()) { if (_skyControl->loadSaveAllowed()) {
_lastSaveTime = _system->getMillis(); _lastSaveTime = _system->getMillis();
_skyControl->doAutoSave(); _skyControl->doAutoSave();