Added a framerate limiter.

Now it does not use all the CPU power while panning even on simple boards.
This commit is contained in:
Maciej Suminski 2013-06-20 09:58:18 +02:00
parent bb9ee216e8
commit 929a849b99
2 changed files with 13 additions and 2 deletions

View File

@ -88,6 +88,8 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this );
Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this );
m_timeStamp = 0;
}
@ -107,7 +109,7 @@ EDA_DRAW_PANEL_GAL::~EDA_DRAW_PANEL_GAL()
}
void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& aEvent )
void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
{
Refresh();
}
@ -121,6 +123,14 @@ void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent )
void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect )
{
const unsigned int FPS_LIMIT = 50;
// Framerate limiter
wxLongLong currentTimeStamp = wxGetLocalTimeMillis();
if( currentTimeStamp - m_timeStamp < ( 1 / FPS_LIMIT ) )
return;
m_timeStamp = currentTimeStamp;
#ifdef __WXDEBUG__
prof_counter time;

View File

@ -79,7 +79,7 @@ public:
virtual void Refresh( bool eraseBackground = true, const wxRect* rect = NULL );
protected:
void onPaint( wxPaintEvent& aEvent );
void onPaint( wxPaintEvent& WXUNUSED( aEvent ) );
void onSize( wxSizeEvent& aEvent );
KiGfx::GAL* m_gal; ///< Interface for drawing objects on a 2D-surface
@ -90,6 +90,7 @@ protected:
KiGfx::WX_VIEW_CONTROLS* m_viewControls; ///< Control for VIEW (moving, zooming, etc.)
GalType m_currentGal; ///< Currently used GAL
bool m_useShaders; ///< Are shaders used? (only for OpenGL GAL)
wxLongLong m_timeStamp;
std::string m_galShaderPath; ///< Path to shader files, used in OpenGL mode
};