Expose threaded rendering as a setting

This commit is contained in:
Tamás Bálint Misius 2024-08-21 15:31:06 +02:00
parent a9b84e5f26
commit bf5f9fdcb0
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
12 changed files with 56 additions and 6 deletions

View File

@ -1728,7 +1728,7 @@ void GameController::AfterSimDraw()
commandInterface->HandleEvent(AfterSimDrawEvent{});
}
bool GameController::HaveSimGraphicsEventHandlers()
bool GameController::ThreadedRenderingAllowed()
{
return commandInterface->HaveSimGraphicsEventHandlers();
return gameModel->GetThreadedRendering() && !commandInterface->HaveSimGraphicsEventHandlers();
}

View File

@ -205,5 +205,5 @@ public:
void BeforeSimDraw();
void AfterSimDraw();
bool HaveSimGraphicsEventHandlers();
bool ThreadedRenderingAllowed();
};

View File

@ -100,6 +100,7 @@ GameModel::GameModel():
rendererSettings.gravityFieldEnabled = prefs.Get("Renderer.GravityField", false);
rendererSettings.decorations_enable = prefs.Get("Renderer.Decorations", true);
threadedRendering = prefs.Get("Renderer.SeparateThread", false);
//Load config into simulation
edgeMode = prefs.Get("Simulation.EdgeMode", NUM_EDGEMODES, EDGE_VOID);
@ -537,6 +538,11 @@ void GameModel::SetTemperatureScale(int temperatureScale)
this->temperatureScale = temperatureScale;
}
void GameModel::SetThreadedRendering(bool newThreadedRendering)
{
threadedRendering = newThreadedRendering;
}
void GameModel::SetAmbientAirTemperature(float ambientAirTemp)
{
this->ambientAirTemp = ambientAirTemp;

View File

@ -130,6 +130,7 @@ private:
void SaveToSimParameters(const GameSave &saveData);
std::optional<int> queuedVote;
bool threadedRendering = false;
public:
GameModel();
@ -144,6 +145,11 @@ public:
{
return temperatureScale;
}
void SetThreadedRendering(bool newThreadedRendering);
bool GetThreadedRendering() const
{
return threadedRendering;
}
void SetAmbientAirTemperature(float ambientAirTemp);
float GetAmbientAirTemperature();
void SetDecoSpace(int decoSpace);

View File

@ -2153,8 +2153,8 @@ void GameView::OnDraw()
{
Graphics * g = GetGraphics();
auto wantRendererThread = !c->HaveSimGraphicsEventHandlers();
if (wantRendererThread)
auto threadedRenderingAllowed = c->ThreadedRenderingAllowed();
if (threadedRenderingAllowed)
{
StartRendererThread();
WaitForRendererThread();
@ -2526,7 +2526,7 @@ void GameView::OnDraw()
fpsInfo << " [FIND]";
if (showDebug)
{
if (wantRendererThread)
if (threadedRenderingAllowed)
{
fpsInfo << " [SRT]";
}

View File

@ -72,6 +72,11 @@ void OptionsController::SetTemperatureScale(int temperatureScale)
model->SetTemperatureScale(temperatureScale);
}
void OptionsController::SetThreadedRendering(bool newThreadedRendering)
{
model->SetThreadedRendering(newThreadedRendering);
}
void OptionsController::SetFullscreen(bool fullscreen)
{
model->SetFullscreen(fullscreen);

View File

@ -24,6 +24,7 @@ public:
void SetAmbientAirTemperature(float ambientAirTemp);
void SetEdgeMode(int edgeMode);
void SetTemperatureScale(int temperatureScale);
void SetThreadedRendering(bool newThreadedRendering);
void SetFullscreen(bool fullscreen);
void SetChangeResolution(bool newChangeResolution);
void SetForceIntegerScaling(bool forceIntegerScaling);

View File

@ -95,6 +95,18 @@ void OptionsModel::SetTemperatureScale(int temperatureScale)
notifySettingsChanged();
}
int OptionsModel::GetThreadedRendering()
{
return gModel->GetThreadedRendering();
}
void OptionsModel::SetThreadedRendering(bool newThreadedRendering)
{
GlobalPrefs::Ref().Set("Renderer.SeparateThread", newThreadedRendering);
gModel->SetThreadedRendering(newThreadedRendering);
notifySettingsChanged();
}
float OptionsModel::GetAmbientAirTemperature()
{
return gModel->GetSimulation()->air->ambientAirTemp;

View File

@ -31,6 +31,8 @@ public:
void SetEdgeMode(int edgeMode);
int GetTemperatureScale();
void SetTemperatureScale(int temperatureScale);
int GetThreadedRendering();
void SetThreadedRendering(bool newThreadedRendering);
int GetGravityMode();
void SetGravityMode(int gravityMode);
float GetCustomGravityX();

View File

@ -318,6 +318,9 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340))
}
currentY += 4; // and then undo the undo
}
threadedRendering = addCheckbox(0, "Separate rendering thread", "May increase framerate when fancy effects are in use", [this] {
c->SetThreadedRendering(threadedRendering->GetChecked());
});
decoSpace = addDropDown("Colour space used by decoration tools", {
{ "sRGB", DECOSPACE_SRGB },
{ "Linear", DECOSPACE_LINEAR },
@ -490,6 +493,7 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender)
includePressure->SetChecked(sender->GetIncludePressure());
perfectCircle->SetChecked(sender->GetPerfectCircle());
graveExitsConsole->SetChecked(sender->GetGraveExitsConsole());
threadedRendering->SetChecked(sender->GetThreadedRendering());
momentumScroll->SetChecked(sender->GetMomentumScroll());
}

View File

@ -41,6 +41,7 @@ class OptionsView: public ui::Window
ui::Checkbox *perfectCircle{};
ui::Checkbox *graveExitsConsole{};
ui::Checkbox *nativeClipoard{};
ui::Checkbox *threadedRendering{};
ui::ScrollPanel *scrollPanel{};
float customGravityX, customGravityY;
void UpdateAmbientAirTempPreview(float airTemp, bool isValid);

View File

@ -216,6 +216,18 @@ static int zoomScope(lua_State *L)
return 0;
}
static int separateThread(lua_State *L)
{
auto *lsi = GetLSI();
if (lua_gettop(L))
{
lsi->gameModel->SetThreadedRendering(lua_toboolean(L, 1));
return 0;
}
lua_pushboolean(L, lsi->gameModel->GetThreadedRendering());
return 1;
}
void LuaRenderer::Open(lua_State *L)
{
static const luaL_Reg reg[] = {
@ -234,6 +246,7 @@ void LuaRenderer::Open(lua_State *L)
LFUNC(zoomScope),
LFUNC(fireSize),
LFUNC(useDisplayPreset),
LFUNC(separateThread),
#undef LFUNC
{ NULL, NULL }
};