Skip to content

Commit 7f38d09

Browse files
authored
Merge pull request #545 from sdslabs/fix-autosave
autosave toggle in editor and off in game
2 parents 4bd2180 + edb91a0 commit 7f38d09

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

editor/editor_application.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,13 @@ void EditorApplication::setGameMode(bool enabled)
6868
InputSystem::GetSingleton()->loadSchemes(m_ApplicationSettings->getJSON()["systems"]["InputSystem"]["inputSchemes"]);
6969
InputSystem::GetSingleton()->pushScheme(m_ApplicationSettings->getJSON()["systems"]["InputSystem"]["startScheme"]);
7070
InputInterface::GetSingleton()->m_IsEnabled = enabled;
71-
m_IsAutoSave = !enabled;
7271

7372
EventManager::GetSingleton()->call(EditorEvents::EditorReset);
7473
}
7574

7675
void EditorApplication::process(float deltaMilliseconds)
7776
{
78-
if (m_IsAutoSave && ((m_ApplicationTimer.Now() - m_PointAtLast10Second).count()) * NS_TO_MS * MS_TO_S > m_AutoSaveDurationS)
77+
if (((m_ApplicationTimer.Now() - m_PointAtLast10Second).count()) * NS_TO_MS * MS_TO_S > m_AutoSaveDurationS)
7978
{
8079
EventManager::GetSingleton()->call(EditorEvents::EditorAutoSave);
8180
m_PointAtLast10Second = m_ApplicationTimer.Now();

editor/editor_application.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class EditorApplication : public Application
88
static void SetSingleton(EditorApplication* app);
99

1010
unsigned int m_AutoSaveDurationS = 300.0f;
11-
bool m_IsAutoSave = true;
1211
TimePoint m_PointAtLast10Second;
1312
FrameTimer m_FrameTimer;
1413

editor/editor_system.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ void EditorSystem::drawDefaultUI(float deltaMilliseconds)
458458
}
459459
if (ImGui::BeginMenu("Scene"))
460460
{
461+
ImGui::Checkbox("Autosave", &m_Autosave);
462+
461463
if (SceneLoader::GetSingleton()->getCurrentScene())
462464
{
463465
SceneLoader::GetSingleton()->getCurrentScene()->getSettings().draw();
@@ -859,9 +861,14 @@ Variant EditorSystem::saveAll(const Event* event)
859861

860862
Variant EditorSystem::autoSave(const Event* event)
861863
{
862-
PRINT("Auto-saving current scene...");
863-
saveAll(nullptr);
864-
return true;
864+
if (m_Autosave && !(m_Toolbar->getSettings().m_InEditorPlaying))
865+
{
866+
PRINT("Auto-saving current scene...");
867+
saveAll(nullptr);
868+
return true;
869+
}
870+
871+
return false;
865872
}
866873

867874
Variant EditorSystem::saveBeforeQuit(const Event* event)

editor/editor_system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class EditorSystem : public System
3232
unsigned int m_EditorStyleVarPushCount;
3333
bool m_WireframeMode = false;
3434
bool m_WorldMode = true;
35+
bool m_Autosave = false;
3536

3637
ImFont* m_EditorFont;
3738
ImFont* m_EditorFontItalic;

editor/gui/toolbar_dock.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
Variant ToolbarDock::disablePlayInEditor(const Event* e)
1515
{
16-
m_InEditorPlaying = false;
16+
m_ToolbarDockSettings.m_InEditorPlaying = false;
1717
EditorApplication::GetSingleton()->setGameMode(false);
1818
if (!m_StartPlayingScene.empty())
1919
{
@@ -48,7 +48,7 @@ void ToolbarDock::draw(float deltaMilliseconds)
4848
"Play Game"
4949
};
5050

51-
if (m_InEditorPlaying)
51+
if (m_ToolbarDockSettings.m_InEditorPlaying)
5252
{
5353
ImColor lightErrorColor = EditorSystem::GetSingleton()->getFatalColor();
5454
lightErrorColor.Value.x *= 0.8f;
@@ -67,21 +67,21 @@ void ToolbarDock::draw(float deltaMilliseconds)
6767
switch (playModeSelected)
6868
{
6969
case 0:
70-
m_InEditorPlaying = true;
70+
m_ToolbarDockSettings.m_InEditorPlaying = true;
7171
m_StartPlayingScene = SceneLoader::GetSingleton()->getCurrentScene()->getScenePath();
7272
EventManager::GetSingleton()->call(EditorEvents::EditorSaveAll);
7373
EditorApplication::GetSingleton()->setGameMode(true);
7474
SceneLoader::GetSingleton()->loadScene(m_StartPlayingScene, {});
7575
PRINT("Loaded Scene in Editor");
7676
break;
7777
case 1:
78-
m_InEditorPlaying = false;
78+
m_ToolbarDockSettings.m_InEditorPlaying = false;
7979
EventManager::GetSingleton()->call(EditorEvents::EditorSaveAll);
8080
OS::RunApplication("\"" + OS::GetGameExecutablePath() + "\" " + SceneLoader::GetSingleton()->getCurrentScene()->getScenePath());
8181
PRINT("Launched Game process with Scene");
8282
break;
8383
case 2:
84-
m_InEditorPlaying = false;
84+
m_ToolbarDockSettings.m_InEditorPlaying = false;
8585
EventManager::GetSingleton()->call(EditorEvents::EditorSaveAll);
8686
OS::RunApplication("\"" + OS::GetGameExecutablePath() + "\"");
8787
PRINT("Launched Game process");

editor/gui/toolbar_dock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class ToolbarDock
1313
struct ToolbarDockSettings
1414
{
1515
bool m_IsActive = true;
16+
bool m_InEditorPlaying = false;
1617
};
1718

1819
private:
1920
ToolbarDockSettings m_ToolbarDockSettings;
2021
Vector<float> m_FPSRecords;
2122
unsigned int m_FPSRecordsPoolSize = 100;
22-
bool m_InEditorPlaying = false;
2323
String m_StartPlayingScene;
2424

2525
Variant disablePlayInEditor(const Event* e);

0 commit comments

Comments
 (0)