From 75c50f10520dc8a059b94cb82a12beb2f3915c5b Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 1 Jul 2010 16:31:06 +0000 Subject: [PATCH] - fixed CPU usage on windows for map editor --- source/glest_map_editor/main.cpp | 17 +++++++++++++---- source/glest_map_editor/main.h | 3 +++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/source/glest_map_editor/main.cpp b/source/glest_map_editor/main.cpp index fef51a98..e67a085d 100755 --- a/source/glest_map_editor/main.cpp +++ b/source/glest_map_editor/main.cpp @@ -54,7 +54,8 @@ MainWindow::MainWindow() , enabledGroup(ctHeight) , fileModified(false) , menuBar(NULL) - , panel(NULL) { + , panel(NULL) + , timer(NULL) { this->panel = new wxPanel(this, wxID_ANY); @@ -302,9 +303,11 @@ MainWindow::MainWindow() //std::cout << "C" << std::endl; SetIcon(icon); + lastPaintEvent.start(); + //#ifndef WIN32 - timer = new wxTimer(this); - timer->Start(250); + //timer = new wxTimer(this); + //timer->Start(250); //#endif glCanvas->SetFocus(); } @@ -342,8 +345,8 @@ MainWindow::~MainWindow() { if(timer != NULL) delete timer; timer = NULL; - delete program; delete glCanvas; + delete program; } void MainWindow::setDirty(bool val) { @@ -430,6 +433,12 @@ void MainWindow::onMouseMove(wxMouseEvent &event, int x, int y) { } void MainWindow::onPaint(wxPaintEvent &event) { + if(lastPaintEvent.getMillis() < 100) { + sleep(5); + return; + } + lastPaintEvent.start(); + if(panel) panel->Update(); if(menuBar) menuBar->Update(); diff --git a/source/glest_map_editor/main.h b/source/glest_map_editor/main.h index 2da6e229..90ef9b24 100644 --- a/source/glest_map_editor/main.h +++ b/source/glest_map_editor/main.h @@ -20,10 +20,12 @@ #include "program.h" #include "util.h" +#include "platform_common.h" using std::string; using std::vector; using std::pair; +using namespace Shared::PlatformCommon; namespace MapEditor { @@ -165,6 +167,7 @@ private: string fileName; bool fileModified; + Chrono lastPaintEvent; public: MainWindow();