diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp index ee63902d98..ff7b0b590c 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp @@ -376,6 +376,7 @@ enum ID_BigScreenshot, ID_JavaScript, ID_CameraReset, + ID_SmoothFramerate, ID_DumpState, ID_DumpBinaryState, @@ -408,6 +409,7 @@ BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame) EVT_MENU(ID_BigScreenshot, ScenarioEditor::OnScreenshot) EVT_MENU(ID_JavaScript, ScenarioEditor::OnJavaScript) EVT_MENU(ID_CameraReset, ScenarioEditor::OnCameraReset) + EVT_MENU(ID_SmoothFramerate, ScenarioEditor::OnSmoothFramerate) EVT_MENU(ID_DumpState, ScenarioEditor::OnDumpState) EVT_MENU(ID_DumpBinaryState, ScenarioEditor::OnDumpState) @@ -523,6 +525,7 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent) menuMisc->Append(ID_BigScreenshot, _("Big screenshot")); menuMisc->Append(ID_JavaScript, _("&JS console")); menuMisc->Append(ID_CameraReset, _("&Reset camera")); + menuMisc->AppendCheckItem(ID_SmoothFramerate, _("Smooth framerate")); wxMenu *menuSS = new wxMenu; menuMisc->AppendSubMenu(menuSS, _("Si&mulation state")); @@ -727,7 +730,7 @@ void ScenarioEditor::OnTimer(wxTimerEvent& evt) { AtlasMessage::qRenderLoop qryRenderLoop; qryRenderLoop.Post(); - if (!qryRenderLoop.wantHighFPS && + if (!qryRenderLoop.smoothFramerate && qryRenderLoop.timeSinceActivity > 1.0 && g_Timer.GetTime() - last_wx_user_activity > 1.0) m_RenderTimer.Start(TIMER_RENDER_SLOW_INTERVAL); // save CPU/GPU when activity is lower. else @@ -986,6 +989,11 @@ void ScenarioEditor::OnCameraReset(wxCommandEvent& WXUNUSED(event)) POST_MESSAGE(CameraReset, ()); } +void ScenarioEditor::OnSmoothFramerate(wxCommandEvent& event) +{ + POST_MESSAGE(SetSmoothFramerate, (event.IsChecked())); +} + void ScenarioEditor::OnDumpState(wxCommandEvent& event) { wxDateTime time = wxDateTime::Now(); diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h index b7a66c9cf2..ae9670c65d 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h @@ -65,6 +65,7 @@ public: void OnMediaPlayer(wxCommandEvent& event); void OnJavaScript(wxCommandEvent& event); void OnCameraReset(wxCommandEvent& event); + void OnSmoothFramerate(wxCommandEvent& event); void OnDumpState(wxCommandEvent& event); void OnSelectedObjectsChange(const std::vector& selectedObjects); diff --git a/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp index 339aa8d9d6..f15be0b097 100644 --- a/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp @@ -268,7 +268,7 @@ QUERYHANDLER(RenderLoop) if (CProfileManager::IsInitialised()) g_Profiler.Frame(); - msg->wantHighFPS = g_AtlasGameLoop->view->WantsHighFramerate(); + msg->smoothFramerate = g_AtlasGameLoop->view->GetSmoothFramerate(); } ////////////////////////////////////////////////////////////////////////// diff --git a/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp index 6a2a9e9a80..1523344f21 100644 --- a/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp @@ -100,6 +100,12 @@ MESSAGEHANDLER(SimPlay) AtlasView::GetView_Game()->SetTesting(msg->simTest); } +MESSAGEHANDLER(SetSmoothFramerate) +{ + AtlasView::GetView_Game()->SetSmoothFramerate(msg->enabled); + AtlasView::GetView_Actor()->SetSmoothFramerate(msg->enabled); +} + MESSAGEHANDLER(JavaScript) { g_GUI->GetActiveGUI()->GetScriptInterface()->LoadGlobalScript(L"Atlas", *msg->command); diff --git a/source/tools/atlas/GameInterface/Messages.h b/source/tools/atlas/GameInterface/Messages.h index 32ea2d9ce3..73cf3fcd99 100644 --- a/source/tools/atlas/GameInterface/Messages.h +++ b/source/tools/atlas/GameInterface/Messages.h @@ -59,6 +59,10 @@ MESSAGE(RenderEnable, ((int, view)) // eRenderView ); +MESSAGE(SetSmoothFramerate, + ((bool, enabled)) + ); + // SetViewParam: used for hints to the renderer, e.g. to set wireframe mode; // unrecognised param names are ignored MESSAGE(SetViewParamB, @@ -155,7 +159,7 @@ MESSAGE(ResizeScreen, ); QUERY(RenderLoop, , - ((bool, wantHighFPS)) + ((bool, smoothFramerate)) ((double, timeSinceActivity)) ); diff --git a/source/tools/atlas/GameInterface/View.cpp b/source/tools/atlas/GameInterface/View.cpp index f48891d4f0..7001dae442 100644 --- a/source/tools/atlas/GameInterface/View.cpp +++ b/source/tools/atlas/GameInterface/View.cpp @@ -118,12 +118,17 @@ entity_id_t AtlasViewActor::GetEntityId(AtlasMessage::ObjectID) return m_ActorViewer->GetEntity(); } -bool AtlasViewActor::WantsHighFramerate() +bool AtlasViewActor::GetSmoothFramerate() const { if (m_SpeedMultiplier != 0.f) return true; - return false; + return m_SmoothFramerate; +} + +void AtlasViewActor::SetSmoothFramerate(const bool enabled) +{ + m_SmoothFramerate = enabled; } void AtlasViewActor::SetEnabled(bool enabled) @@ -335,7 +340,7 @@ CCamera& AtlasViewGame::GetCamera() return *g_Game->GetView()->GetCamera(); } -bool AtlasViewGame::WantsHighFramerate() +bool AtlasViewGame::GetSmoothFramerate() const { if (g_Game->GetView()->GetCinema()->IsPlaying()) return true; @@ -343,7 +348,12 @@ bool AtlasViewGame::WantsHighFramerate() if (m_SpeedMultiplier != 0.f) return true; - return false; + return m_SmoothFramerate; +} + +void AtlasViewGame::SetSmoothFramerate(const bool enabled) +{ + m_SmoothFramerate = enabled; } void AtlasViewGame::SetSpeedMultiplier(float speed) diff --git a/source/tools/atlas/GameInterface/View.h b/source/tools/atlas/GameInterface/View.h index 170250ed87..2279d29ee0 100644 --- a/source/tools/atlas/GameInterface/View.h +++ b/source/tools/atlas/GameInterface/View.h @@ -49,7 +49,8 @@ public: virtual CCamera& GetCamera() = 0; virtual CSimulation2* GetSimulation2() { return NULL; } virtual entity_id_t GetEntityId(AtlasMessage::ObjectID obj) { return (entity_id_t)obj; } - virtual bool WantsHighFramerate() { return false; } + virtual bool GetSmoothFramerate() const { return false; } + virtual void SetSmoothFramerate(const bool) {} virtual void SetEnabled(bool /*enabled*/) {} virtual void SetParam(const std::wstring& name, bool value); @@ -96,7 +97,8 @@ public: virtual void DrawOverlays(CCanvas2D& canvas); virtual CCamera& GetCamera(); virtual CSimulation2* GetSimulation2(); - virtual bool WantsHighFramerate(); + virtual bool GetSmoothFramerate() const; + virtual void SetSmoothFramerate(const bool enabled); virtual void SetParam(const std::wstring& name, bool value); virtual void SetParam(const std::wstring& name, float value); @@ -112,6 +114,7 @@ public: private: float m_SpeedMultiplier; bool m_IsTesting; + bool m_SmoothFramerate{false}; std::map m_SavedStates; std::string m_DisplayPassability; @@ -139,7 +142,8 @@ public: virtual CCamera& GetCamera(); virtual CSimulation2* GetSimulation2(); virtual entity_id_t GetEntityId(AtlasMessage::ObjectID obj); - virtual bool WantsHighFramerate(); + virtual bool GetSmoothFramerate() const; + virtual void SetSmoothFramerate(const bool enabled); virtual void SetEnabled(bool enabled); virtual void SetParam(const std::wstring& name, bool value); @@ -151,6 +155,7 @@ public: private: float m_SpeedMultiplier; + bool m_SmoothFramerate{false}; CCamera m_Camera; ActorViewer* m_ActorViewer; };