Skip to content

Commit

Permalink
#5660: Queue the redraw in the idle event after the current activity …
Browse files Browse the repository at this point in the history
…is finished. This avoids dispatching thousands of wxWidget::Refresh() calls during map load.
  • Loading branch information
codereader committed Jul 2, 2021
1 parent 9df337b commit 4f9fd03
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
13 changes: 9 additions & 4 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -73,6 +73,7 @@ CamWnd::CamWnd(wxWindow* parent) :
_view(true),
_camera(GlobalCameraManager().createCamera(_view, std::bind(&CamWnd::requestRedraw, this, std::placeholders::_1))),
_drawing(false),
_updateRequested(false),
_wxGLWidget(new wxutil::GLWidget(_mainWxWidget, std::bind(&CamWnd::onRender, this), "CamWnd")),
_timer(this),
_timerLock(false),
Expand All @@ -85,6 +86,7 @@ CamWnd::CamWnd(wxWindow* parent) :
{
Bind(wxEVT_TIMER, &CamWnd::onFrame, this, _timer.GetId());
Bind(wxEVT_TIMER, &CamWnd::onFreeMoveTimer, this, _freeMoveTimer.GetId());
_wxGLWidget->Bind(wxEVT_IDLE, &CamWnd::onIdle, this);

setFarClipPlaneDistance(calculateFarPlaneDistance(getCameraSettings()->cubicScale()));
setFarClipPlaneEnabled(getCameraSettings()->farClipEnabled());
Expand Down Expand Up @@ -976,11 +978,14 @@ void CamWnd::releaseStates()

void CamWnd::queueDraw()
{
if (_drawing)
{
return;
}
_updateRequested = true;
}

void CamWnd::onIdle(wxIdleEvent& ev)
{
if (!_updateRequested) return;

_updateRequested = false;
_wxGLWidget->Refresh(false);
}

Expand Down
4 changes: 4 additions & 0 deletions radiant/camera/CamWnd.h
Expand Up @@ -69,6 +69,9 @@ class CamWnd :
// Is true during an active drawing process
bool _drawing;

// Update of this window in the next idle event loop
bool _updateRequested;

// The GL widget
wxutil::GLWidget* _wxGLWidget;

Expand Down Expand Up @@ -242,6 +245,7 @@ class CamWnd :

void onFrame(wxTimerEvent& ev);
void onFreeMoveTimer(wxTimerEvent& ev);
void onIdle(wxIdleEvent& ev);

void handleFreeMovement(float timePassed);
void setFreeMoveFlags(unsigned int mask);
Expand Down
17 changes: 10 additions & 7 deletions radiant/xyview/XYWnd.cpp
Expand Up @@ -70,6 +70,7 @@ XYWnd::XYWnd(int id, wxWindow* parent) :
_id(id),
_wxGLWidget(new wxutil::GLWidget(parent, std::bind(&XYWnd::onRender, this), "XYWnd")),
_drawing(false),
_updateRequested(false),
_minWorldCoord(game::current::getValue<float>("/defaults/minWorldCoord")),
_maxWorldCoord(game::current::getValue<float>("/defaults/maxWorldCoord")),
_defaultCursor(wxCURSOR_DEFAULT),
Expand Down Expand Up @@ -291,15 +292,11 @@ void XYWnd::forceRedraw()

void XYWnd::queueDraw()
{
if (_drawing)
{
return; // deny redraw requests if we're currently drawing
}

_wxGLWidget->Refresh(false);
_updateRequested = true;
}

void XYWnd::onSceneGraphChange() {
void XYWnd::onSceneGraphChange()
{
// Pass the call to queueDraw.
queueDraw();
}
Expand Down Expand Up @@ -1587,6 +1584,12 @@ void XYWnd::onIdle(wxIdleEvent& ev)
{
performChaseMouse();
}

if (_updateRequested)
{
_updateRequested = false;
_wxGLWidget->Refresh(false);
}
}

void XYWnd::onGLResize(wxSizeEvent& ev)
Expand Down
1 change: 1 addition & 0 deletions radiant/xyview/XYWnd.h
Expand Up @@ -36,6 +36,7 @@ class XYWnd :

wxutil::GLWidget* _wxGLWidget;
bool _drawing;
bool _updateRequested;

// The maximum/minimum values of a coordinate
double _minWorldCoord;
Expand Down

0 comments on commit 4f9fd03

Please sign in to comment.