Limit redrawing frequency (#693)
Co-authored-by: Tamás Bálint Misius <lbphacker@gmail.com>
This commit is contained in:
parent
bdcf486a8d
commit
f137bad7f8
@ -176,6 +176,17 @@ void SDLOpen()
|
||||
}
|
||||
}
|
||||
|
||||
if (Client::Ref().GetPrefBool("AutoDrawLimit", false))
|
||||
{
|
||||
SDL_DisplayMode displayMode;
|
||||
SDL_GetCurrentDisplayMode(displayIndex, &displayMode);
|
||||
|
||||
if(displayMode.refresh_rate >= 60)
|
||||
{
|
||||
ui::Engine::Ref().SetDrawingFrequencyLimit(displayMode.refresh_rate);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN
|
||||
SDL_SysWMinfo SysInfo;
|
||||
SDL_VERSION(&SysInfo.version);
|
||||
@ -497,9 +508,16 @@ void EngineProcess()
|
||||
{
|
||||
double frameTimeAvg = 0.0f, correctedFrameTimeAvg = 0.0f;
|
||||
SDL_Event event;
|
||||
|
||||
int drawingTimer = 0;
|
||||
int frameStart = 0;
|
||||
|
||||
while(engine->Running())
|
||||
{
|
||||
int frameStart = SDL_GetTicks();
|
||||
int oldFrameStart = frameStart;
|
||||
frameStart = SDL_GetTicks();
|
||||
drawingTimer += frameStart - oldFrameStart;
|
||||
|
||||
if(engine->Broken()) { engine->UnBreak(); break; }
|
||||
event.type = 0;
|
||||
while (SDL_PollEvent(&event))
|
||||
@ -510,21 +528,27 @@ void EngineProcess()
|
||||
if(engine->Broken()) { engine->UnBreak(); break; }
|
||||
|
||||
engine->Tick();
|
||||
engine->Draw();
|
||||
|
||||
if (scale != engine->Scale || fullscreen != engine->Fullscreen ||
|
||||
altFullscreen != engine->GetAltFullscreen() ||
|
||||
forceIntegerScaling != engine->GetForceIntegerScaling() || resizable != engine->GetResizable())
|
||||
int drawcap = ui::Engine::Ref().GetDrawingFrequencyLimit();
|
||||
if (!drawcap || drawingTimer > 1000.f/drawcap)
|
||||
{
|
||||
SDLSetScreen(engine->Scale, engine->GetResizable(), engine->Fullscreen, engine->GetAltFullscreen(),
|
||||
engine->GetForceIntegerScaling());
|
||||
}
|
||||
engine->Draw();
|
||||
drawingTimer = 0;
|
||||
|
||||
if (scale != engine->Scale || fullscreen != engine->Fullscreen ||
|
||||
altFullscreen != engine->GetAltFullscreen() ||
|
||||
forceIntegerScaling != engine->GetForceIntegerScaling() || resizable != engine->GetResizable())
|
||||
{
|
||||
SDLSetScreen(engine->Scale, engine->GetResizable(), engine->Fullscreen, engine->GetAltFullscreen(),
|
||||
engine->GetForceIntegerScaling());
|
||||
}
|
||||
|
||||
#ifdef OGLI
|
||||
blit();
|
||||
blit();
|
||||
#else
|
||||
blit(engine->g->vid);
|
||||
blit(engine->g->vid);
|
||||
#endif
|
||||
}
|
||||
|
||||
int frameTime = SDL_GetTicks() - frameStart;
|
||||
frameTimeAvg = frameTimeAvg * 0.8 + frameTime * 0.2;
|
||||
|
@ -17,6 +17,7 @@ using namespace ui;
|
||||
|
||||
Engine::Engine():
|
||||
FpsLimit(60.0f),
|
||||
drawingFrequencyLimit(0),
|
||||
Scale(1),
|
||||
Fullscreen(false),
|
||||
FrameIndex(0),
|
||||
|
@ -47,6 +47,8 @@ namespace ui
|
||||
void Break();
|
||||
void UnBreak();
|
||||
|
||||
void SetDrawingFrequencyLimit(int limit) {drawingFrequencyLimit = limit;}
|
||||
inline int GetDrawingFrequencyLimit() {return drawingFrequencyLimit;}
|
||||
void SetFullscreen(bool fullscreen) { Fullscreen = fullscreen; }
|
||||
inline bool GetFullscreen() { return Fullscreen; }
|
||||
void SetAltFullscreen(bool altFullscreen) { this->altFullscreen = altFullscreen; }
|
||||
@ -82,6 +84,7 @@ namespace ui
|
||||
//inline State* GetState() { return state_; }
|
||||
inline Window* GetWindow() { return state_; }
|
||||
float FpsLimit;
|
||||
int drawingFrequencyLimit;
|
||||
Graphics * g;
|
||||
int Scale;
|
||||
bool Fullscreen;
|
||||
|
@ -117,6 +117,11 @@ void OptionsController::SetMomentumScroll(bool momentumScroll)
|
||||
model->SetMomentumScroll(momentumScroll);
|
||||
}
|
||||
|
||||
void OptionsController::SetAutoDrawLimit(bool autoDrawLimit)
|
||||
{
|
||||
model->SetAutoDrawLimit(autoDrawLimit);
|
||||
}
|
||||
|
||||
void OptionsController::Exit()
|
||||
{
|
||||
view->CloseActiveWindow();
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
void SetIncludePressure(bool includePressure);
|
||||
void SetPerfectCircle(bool perfectCircle);
|
||||
void SetMomentumScroll(bool momentumScroll);
|
||||
void SetAutoDrawLimit(bool autoDrawLimit);
|
||||
|
||||
void Exit();
|
||||
OptionsView * GetView();
|
||||
|
@ -238,6 +238,17 @@ void OptionsModel::SetMomentumScroll(bool state)
|
||||
notifySettingsChanged();
|
||||
}
|
||||
|
||||
bool OptionsModel::GetAutoDrawLimit()
|
||||
{
|
||||
return Client::Ref().GetPrefBool("AutoDrawLimit", false);
|
||||
}
|
||||
|
||||
void OptionsModel::SetAutoDrawLimit(bool state)
|
||||
{
|
||||
Client::Ref().SetPref("AutoDrawLimit", state);
|
||||
notifySettingsChanged();
|
||||
}
|
||||
|
||||
void OptionsModel::notifySettingsChanged()
|
||||
{
|
||||
for (size_t i = 0; i < observers.size(); i++)
|
||||
|
@ -53,6 +53,8 @@ public:
|
||||
void SetPerfectCircle(bool perfectCircle);
|
||||
bool GetMomentumScroll();
|
||||
void SetMomentumScroll(bool momentumScroll);
|
||||
bool GetAutoDrawLimit();
|
||||
void SetAutoDrawLimit(bool autoDrawLimit);
|
||||
virtual ~OptionsModel();
|
||||
};
|
||||
|
||||
|
@ -250,6 +250,17 @@ OptionsView::OptionsView():
|
||||
scrollPanel->AddChild(tempLabel);
|
||||
scrollPanel->AddChild(momentumScroll);
|
||||
|
||||
currentY += 20;
|
||||
autoDrawLimit = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Auto Draw Rate", "");
|
||||
autowidth(autoDrawLimit);
|
||||
autoDrawLimit->SetActionCallback({ [this] { c->SetAutoDrawLimit(autoDrawLimit->GetChecked()); } });
|
||||
tempLabel = new ui::Label(ui::Point(autoDrawLimit->Position.X + Graphics::textwidth(autoDrawLimit->GetText()) + 20, currentY), ui::Point(1, 16), "\bg- Based on monitor refresh rate at startup");
|
||||
autowidth(tempLabel);
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
scrollPanel->AddChild(tempLabel);
|
||||
scrollPanel->AddChild(autoDrawLimit);
|
||||
|
||||
currentY+=20;
|
||||
mouseClickRequired = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Sticky Categories", "");
|
||||
autowidth(mouseClickRequired);
|
||||
@ -350,6 +361,7 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender)
|
||||
includePressure->SetChecked(sender->GetIncludePressure());
|
||||
perfectCirclePressure->SetChecked(sender->GetPerfectCircle());
|
||||
momentumScroll->SetChecked(sender->GetMomentumScroll());
|
||||
autoDrawLimit->SetChecked(sender->GetAutoDrawLimit());
|
||||
}
|
||||
|
||||
void OptionsView::AttachController(OptionsController * c_)
|
||||
|
@ -32,6 +32,7 @@ class OptionsView: public ui::Window
|
||||
ui::DropDown * decoSpace;
|
||||
ui::Checkbox * showAvatars;
|
||||
ui::Checkbox * momentumScroll;
|
||||
ui::Checkbox * autoDrawLimit;
|
||||
ui::Checkbox * mouseClickRequired;
|
||||
ui::Checkbox * includePressure;
|
||||
ui::Checkbox * perfectCirclePressure;
|
||||
|
@ -1378,6 +1378,21 @@ int luatpt_setfpscap(lua_State* l)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luatpt_setdrawcap(lua_State* l)
|
||||
{
|
||||
int acount = lua_gettop(l);
|
||||
if (acount == 0)
|
||||
{
|
||||
lua_pushinteger(l, ui::Engine::Ref().GetDrawingFrequencyLimit());
|
||||
return 1;
|
||||
}
|
||||
int drawcap = luaL_checkint(l, 1);
|
||||
if(drawcap < 0)
|
||||
return luaL_error(l, "draw cap too small");
|
||||
ui::Engine::Ref().SetDrawingFrequencyLimit(drawcap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luatpt_getscript(lua_State* l)
|
||||
{
|
||||
int scriptID = luaL_checkinteger(l, 1);
|
||||
|
@ -127,6 +127,7 @@ int luatpt_setfire(lua_State* l);
|
||||
int luatpt_setdebug(lua_State* l);
|
||||
|
||||
int luatpt_setfpscap(lua_State* l);
|
||||
int luatpt_setdrawcap(lua_State* l);
|
||||
|
||||
int luatpt_getscript(lua_State* l);
|
||||
|
||||
|
@ -213,6 +213,7 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
|
||||
{"graphics_func",&luatpt_graphics_func},
|
||||
{"get_clipboard", &platform_clipboardCopy},
|
||||
{"set_clipboard", &platform_clipboardPaste},
|
||||
{"setdrawcap", &luatpt_setdrawcap},
|
||||
{NULL,NULL}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user