mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-12 20:17:49 +00:00
ENGINES: Implement autosaving in the Engine base class
This commit is contained in:
parent
a00e44ba6c
commit
30d34fa63d
@ -89,6 +89,10 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
|
||||
handleKeyRepeat();
|
||||
}
|
||||
|
||||
if (g_engine)
|
||||
// Handle autosaves if enabled
|
||||
g_engine->handleAutoSave();
|
||||
|
||||
if (_eventQueue.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -148,7 +148,9 @@ Engine::Engine(OSystem *syst)
|
||||
_saveSlotToLoad(-1),
|
||||
_engineStartTime(_system->getMillis()),
|
||||
_mainMenuDialog(NULL),
|
||||
_debugger(NULL) {
|
||||
_debugger(NULL),
|
||||
_autosaveInterval(ConfMan.getInt("autosave_period")),
|
||||
_lastAutosaveTime(_system->getMillis()) {
|
||||
|
||||
g_engine = this;
|
||||
Common::setErrorOutputFormatter(defaultOutputFormatter);
|
||||
@ -482,10 +484,16 @@ void Engine::checkCD() {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Engine::shouldPerformAutoSave(int lastSaveTime) {
|
||||
const int diff = _system->getMillis() - lastSaveTime;
|
||||
const int autosavePeriod = ConfMan.getInt("autosave_period");
|
||||
return autosavePeriod != 0 && diff > autosavePeriod * 1000;
|
||||
void Engine::handleAutoSave() {
|
||||
const int diff = _system->getMillis() - _lastAutosaveTime;
|
||||
|
||||
if (_autosaveInterval != 0 && diff > (_autosaveInterval * 1000)) {
|
||||
// Save the autosave
|
||||
saveGameState(getAutosaveSlot(), _("Autosave"), true);
|
||||
|
||||
// Reset the last autosave time
|
||||
_lastAutosaveTime = _system->getMillis();
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::errorString(const char *buf1, char *buf2, int size) {
|
||||
|
@ -91,6 +91,16 @@ private:
|
||||
*/
|
||||
int32 _engineStartTime;
|
||||
|
||||
/**
|
||||
* Autosave interval
|
||||
*/
|
||||
const int _autosaveInterval;
|
||||
|
||||
/**
|
||||
* The last time an autosave was done
|
||||
*/
|
||||
int _lastAutosaveTime;
|
||||
|
||||
/**
|
||||
* Save slot selected via global main menu.
|
||||
* This slot will be loaded after main menu execution (not from inside
|
||||
@ -290,7 +300,6 @@ public:
|
||||
bool loadGameDialog();
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Actual implementation of pauseEngine by subclasses. See there
|
||||
* for details.
|
||||
@ -367,17 +376,27 @@ public:
|
||||
inline Common::SaveFileManager *getSaveFileManager() { return _saveFileMan; }
|
||||
|
||||
public:
|
||||
|
||||
/** On some systems, check if the game appears to be run from CD. */
|
||||
void checkCD();
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Indicate whether an autosave should be performed.
|
||||
* Checks for whether it's time to do an autosave, and if so, does it.
|
||||
*/
|
||||
bool shouldPerformAutoSave(int lastSaveTime);
|
||||
void handleAutoSave();
|
||||
|
||||
/**
|
||||
* Returns the slot that should be used for autosaves
|
||||
*/
|
||||
virtual int getAutosaveSlot() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool shouldPerformAutoSave(int lastSaveTime) {
|
||||
// TODO: Remove deprecated method once all engines are refactored
|
||||
// to no longer do autosaves directly themselves
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Chained games
|
||||
|
Loading…
Reference in New Issue
Block a user