Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

Commit

Permalink
Auto quick saves - allow automatic save states to be taken and saved …
Browse files Browse the repository at this point in the history
…to slot #6 (read-only) every X minutes
  • Loading branch information
SourMesen committed Sep 1, 2016
1 parent c4a3b65 commit 1ddb980
Show file tree
Hide file tree
Showing 18 changed files with 320 additions and 41 deletions.
32 changes: 32 additions & 0 deletions Core/AutoSaveManager.cpp
@@ -0,0 +1,32 @@
#include "stdafx.h"
#include "AutoSaveManager.h"
#include "Console.h"
#include "EmulationSettings.h"
#include "SaveStateManager.h"

AutoSaveManager::AutoSaveManager()
{
_stopThread = false;
_timer.Reset();
_autoSaveThread = std::thread([=]() {
while(!_stopThread) {
bool showMessage = false;
uint32_t autoSaveDelay = EmulationSettings::GetAutoSaveDelay(showMessage) * 60 * 1000;
if(autoSaveDelay > 0) {
if(_timer.GetElapsedMS() > autoSaveDelay) {
SaveStateManager::SaveState(_autoSaveSlot, showMessage);
_timer.Reset();
}
} else {
_timer.Reset();
}
std::this_thread::sleep_for(std::chrono::duration<int, std::milli>(1000));
}
});
}

AutoSaveManager::~AutoSaveManager()
{
_stopThread = true;
_autoSaveThread.join();
}
17 changes: 17 additions & 0 deletions Core/AutoSaveManager.h
@@ -0,0 +1,17 @@
#pragma once
#include "stdafx.h"
#include <thread>
#include "../Utilities/Timer.h"

class AutoSaveManager
{
private:
const uint32_t _autoSaveSlot = 6;
std::thread _autoSaveThread;
atomic<bool> _stopThread;
Timer _timer;

public:
AutoSaveManager();
~AutoSaveManager();
};
7 changes: 6 additions & 1 deletion Core/Console.cpp
Expand Up @@ -54,6 +54,7 @@ void Console::Initialize(string romFilename, stringstream *filestream, string ip
if(mapper) {
_romFilepath = romFilename;

_autoSaveManager.reset(new AutoSaveManager());
VideoDecoder::GetInstance()->StopThread();

_mapper = mapper;
Expand Down Expand Up @@ -210,7 +211,7 @@ void Console::ResetComponents(bool softReset)
_controlManager->Reset(softReset);

_lagCounter = 0;

SoundMixer::StopAudio(true);

if(softReset) {
Expand Down Expand Up @@ -262,6 +263,8 @@ void Console::Run()
Timer clockTimer;
double targetTime;
uint32_t lastFrameNumber = -1;

_autoSaveManager.reset(new AutoSaveManager());

_runLock.Acquire();
_stopLock.Acquire();
Expand Down Expand Up @@ -348,6 +351,8 @@ void Console::Run()
SoundMixer::StopRecording();
PlatformUtilities::EnableScreensaver();

_autoSaveManager.reset();

VideoDecoder::GetInstance()->StopThread();

_initialized = false;
Expand Down
3 changes: 3 additions & 0 deletions Core/Console.h
Expand Up @@ -7,6 +7,7 @@
#include "MemoryManager.h"
#include "ControlManager.h"
#include "../Utilities/SimpleLock.h"
#include "AutoSaveManager.h"

class Debugger;
class BaseMapper;
Expand All @@ -28,6 +29,8 @@ class Console
unique_ptr<ControlManager> _controlManager;
shared_ptr<MemoryManager> _memoryManager;

unique_ptr<AutoSaveManager> _autoSaveManager;

NesModel _model;

string _romFilepath;
Expand Down
2 changes: 2 additions & 0 deletions Core/Core.vcxproj
Expand Up @@ -404,6 +404,7 @@
<ClInclude Include="APU.h" />
<ClInclude Include="ArkanoidController.h" />
<ClInclude Include="AutoRomTest.h" />
<ClInclude Include="AutoSaveManager.h" />
<ClInclude Include="Bandai74161_7432.h" />
<ClInclude Include="BandaiFcg.h" />
<ClInclude Include="BandaiKaraoke.h" />
Expand Down Expand Up @@ -683,6 +684,7 @@
<ClCompile Include="ApuLengthCounter.cpp" />
<ClCompile Include="ArkanoidController.cpp" />
<ClCompile Include="AutoRomTest.cpp" />
<ClCompile Include="AutoSaveManager.cpp" />
<ClCompile Include="BaseControlDevice.cpp" />
<ClCompile Include="BaseMapper.cpp" />
<ClCompile Include="BaseSoundFilter.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions Core/Core.vcxproj.filters
Expand Up @@ -925,6 +925,9 @@
<ClInclude Include="MMC3_219.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="AutoSaveManager.h">
<Filter>Misc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand Down Expand Up @@ -1095,5 +1098,8 @@
<ClCompile Include="OekaKidsTablet.cpp">
<Filter>Nes\Controllers</Filter>
</ClCompile>
<ClCompile Include="AutoSaveManager.cpp">
<Filter>Misc</Filter>
</ClCompile>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions Core/EmulationSettings.cpp
Expand Up @@ -38,6 +38,9 @@ int32_t EmulationSettings::_nsfAutoDetectSilenceDelay = 3000;
int32_t EmulationSettings::_nsfMoveToNextTrackTime = 120;
bool EmulationSettings::_nsfDisableApuIrqs = true;

uint32_t EmulationSettings::_autoSaveDelay = 5;
bool EmulationSettings::_autoSaveNotify = false;

RamPowerOnState EmulationSettings::_ramPowerOnState = RamPowerOnState::AllZeros;

InputDisplaySettings EmulationSettings::_inputDisplaySettings = { 0, InputDisplayPosition::TopLeft, false };
Expand Down
15 changes: 15 additions & 0 deletions Core/EmulationSettings.h
Expand Up @@ -305,6 +305,9 @@ class EmulationSettings

static InputDisplaySettings _inputDisplaySettings;

static uint32_t _autoSaveDelay;
static bool _autoSaveNotify;

static RamPowerOnState _ramPowerOnState;

public:
Expand Down Expand Up @@ -777,4 +780,16 @@ class EmulationSettings
{
return _ramPowerOnState;
}

static void SetAutoSaveOptions(uint32_t delayInMinutes, bool showMessage)
{
_autoSaveDelay = delayInMinutes;
_autoSaveNotify = showMessage;
}

static uint32_t GetAutoSaveDelay(bool &showMessage)
{
showMessage = _autoSaveNotify;
return _autoSaveDelay;
}
};
7 changes: 5 additions & 2 deletions Core/SaveStateManager.cpp
Expand Up @@ -27,7 +27,7 @@ uint64_t SaveStateManager::GetStateInfo(int stateIndex)
return 0;
}

void SaveStateManager::SaveState(int stateIndex)
void SaveStateManager::SaveState(int stateIndex, bool displayMessage)
{
string filepath = SaveStateManager::GetStateFilepath(stateIndex);
ofstream file(filepath, ios::out | ios::binary);
Expand All @@ -43,7 +43,10 @@ void SaveStateManager::SaveState(int stateIndex)
Console::SaveState(file);
Console::Resume();
file.close();
MessageManager::DisplayMessage("SaveStates", "SaveStateSaved" , std::to_string(stateIndex));

if(displayMessage) {
MessageManager::DisplayMessage("SaveStates", "SaveStateSaved", std::to_string(stateIndex));
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions Core/SaveStateManager.h
Expand Up @@ -11,7 +11,6 @@ class SaveStateManager
static const uint32_t FileFormatVersion = 5;

static uint64_t GetStateInfo(int stateIndex);
static void SaveState(int stateIndex);
static void SaveState(int stateIndex, bool displayMessage = true);
static bool LoadState(int stateIndex);

};
5 changes: 5 additions & 0 deletions GUI.NET/Config/PreferenceInfo.cs
Expand Up @@ -23,6 +23,10 @@ public class PreferenceInfo
public bool AllowInvalidInput = false;
public bool RemoveSpriteLimit = false;

public bool AutoSave = true;
public Int32 AutoSaveDelay = 5;
public bool AutoSaveNotify = false;

public bool FdsAutoLoadDisk = true;
public bool FdsFastForwardOnLoad = false;

Expand Down Expand Up @@ -92,6 +96,7 @@ static public void ApplyConfig()
InteropEmu.SetFlag(EmulationFlags.DisableGameDatabase, preferenceInfo.DisableGameDatabase);

InteropEmu.NsfSetNsfConfig(preferenceInfo.NsfAutoDetectSilence ? preferenceInfo.NsfAutoDetectSilenceDelay : 0, preferenceInfo.NsfMoveToNextTrackAfterTime ? preferenceInfo.NsfMoveToNextTrackTime : -1, preferenceInfo.NsfDisableApuIrqs);
InteropEmu.SetAutoSaveOptions(preferenceInfo.AutoSave ? (uint)preferenceInfo.AutoSaveDelay : 0, preferenceInfo.AutoSaveNotify);
}
}
}
9 changes: 8 additions & 1 deletion GUI.NET/Dependencies/resources.fr.xml
Expand Up @@ -279,7 +279,13 @@
<Control ID="chkFdsAutoLoadDisk">Insérer le côté A du disque 1 lors du chargement d'un jeu de FDS</Control>
<Control ID="chkFdsFastForwardOnLoad">Augmenter la vitesse d'émulation pendant le chargement des jeux FDS</Control>

<Control ID="tpgCloudSave">Sauvegarde en ligne</Control>
<Control ID="tpgSaveData">Sauvegardes</Control>
<Control ID="grpAutomaticSaves">Sauvegarde d'état automatique</Control>
<Control ID="chkAutoSave">Créer une sauvegarde d'état à chaque</Control>
<Control ID="lblAutoSave">minutes (Appuyer sur F6 pour charger)</Control>
<Control ID="chkAutoSaveNotify">Afficher une notification à l'écran au moment de la sauvegarde automatique</Control>

<Control ID="grpCloudSaves">Sauvegarde en ligne</Control>
<Control ID="lblGoogleDriveIntegration">Mesen peut utiliser Google Drive pour mettre vos sauvegardes dans votre compte Google Drive. Lorsque l'intégration est activée, toutes les données de sauvegarde de vos jeux (fichiers .sav et sauvegardes rapides) sont facilement accessibles à partir de n'importe quel ordinateur.</Control>
<Control ID="lblIntegrationOK">L'intégration avec Google Drive est active.</Control>
<Control ID="btnDisableIntegration">Désactiver l'intégration Google Drive</Control>
Expand All @@ -295,6 +301,7 @@
<Control ID="chkNsfMoveToNextTrackAfterTime">Limiter la durée des pistes à</Control>
<Control ID="lblNsfSeconds">secondes</Control>
<Control ID="chkNsfDisableApuIrqs">Désactiver les IRQs du APU (Recommandé)</Control>


<Control ID="btnOK">OK</Control>
<Control ID="btnCancel">Annuler</Control>
Expand Down
8 changes: 7 additions & 1 deletion GUI.NET/Dependencies/resources.ja.xml
Expand Up @@ -278,7 +278,13 @@
<Control ID="chkFdsAutoLoadDisk">ファミコンディスクシステムのゲームをロードする時に自動的にディスク1のA面を入れる</Control>
<Control ID="chkFdsFastForwardOnLoad">ファミコンディスクシステムのゲームをディスクからロードする時に自動的に最高速度にする</Control>

<Control ID="tpgCloudSave">クラウドバックアップ</Control>
<Control ID="tpgSaveData">セーブデータ</Control>
<Control ID="grpAutomaticSaves">オートクイックセーブ</Control>
<Control ID="chkAutoSave">オートクイックセーブを</Control>
<Control ID="lblAutoSave">分おきにする(F6でクイックロード)</Control>
<Control ID="chkAutoSaveNotify">オートクイックセーブする際、通信を表示する</Control>

<Control ID="grpCloudSaves">クラウドバックアップ</Control>
<Control ID="lblGoogleDriveIntegration">MesenはGoogle Driveを利用することでクラウドバックアップが出来ます。 Google Drive同期を有効にすれば、ゲームのセーブデータはGoogle Driveにバックアップされ、どんなパソコンからでもアクセスが可能になります。</Control>
<Control ID="lblIntegrationOK">Google Drive同期は有効です。</Control>
<Control ID="btnDisableIntegration">Google Drive同期を無効にする</Control>
Expand Down

0 comments on commit 1ddb980

Please sign in to comment.