Adds ability to enable smooth framerate in Atlas

This commit is contained in:
Vladislav Belov
2026-06-21 11:30:27 +02:00
parent f9af0e571a
commit 45cb592f22
7 changed files with 44 additions and 10 deletions
@@ -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();
@@ -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<AtlasMessage::ObjectID>& selectedObjects);
@@ -268,7 +268,7 @@ QUERYHANDLER(RenderLoop)
if (CProfileManager::IsInitialised())
g_Profiler.Frame();
msg->wantHighFPS = g_AtlasGameLoop->view->WantsHighFramerate();
msg->smoothFramerate = g_AtlasGameLoop->view->GetSmoothFramerate();
}
//////////////////////////////////////////////////////////////////////////
@@ -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);
+5 -1
View File
@@ -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))
);
+14 -4
View File
@@ -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)
+8 -3
View File
@@ -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<std::wstring, SimState*> 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;
};