From 474e4284d428fa16c20dd3e997a4793c2b363476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 27 Jun 2012 13:05:57 +0000 Subject: [PATCH] paysages : Preview rendering is balanced when two previews are visible. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@366 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 1 - gui_qt/basepreview.cpp | 24 +++++++++++++++++++++--- gui_qt/basepreview.h | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index 520e9c0..eff4e67 100644 --- a/TODO +++ b/TODO @@ -28,7 +28,6 @@ Technology Preview 2 : - Fix "RGB parameters out of range" (and segfault) on preview while moving render params fast in render tab. => May need to change the updateData system. => Previews need to be paused while updating data. -- When there are two previews in the same view, balance rendering between the two. - Lock some previews together (eg: terrain height and colored preview). - Find a new licence. diff --git a/gui_qt/basepreview.cpp b/gui_qt/basepreview.cpp index da70358..9a357cb 100644 --- a/gui_qt/basepreview.cpp +++ b/gui_qt/basepreview.cpp @@ -25,6 +25,11 @@ public: _alive = true; } + inline BasePreview* preview() + { + return _preview; + } + inline bool isOnFront() { return _preview->isVisible() && _preview->window()->isActiveWindow(); @@ -132,6 +137,7 @@ PreviewDrawingManager::PreviewDrawingManager() { _thread_count = 1; } + _lastRendered = NULL; } void PreviewDrawingManager::startThreads() @@ -201,7 +207,7 @@ void PreviewDrawingManager::updateChunks(BasePreview* preview) chunk->update(); _lock.lock(); if (!_updateQueue.contains(chunk)) - { + { _updateQueue.prepend(chunk); } _lock.unlock(); @@ -220,7 +226,7 @@ void PreviewDrawingManager::updateAllChunks() chunk->update(); _lock.lock(); if (!_updateQueue.contains(chunk)) - { + { _updateQueue.prepend(chunk); } _lock.unlock(); @@ -236,12 +242,24 @@ void PreviewDrawingManager::performOneThreadJob() _lock.lock(); if (!_updateQueue.isEmpty()) { - chunk = _updateQueue.takeFirst(); + for (int i = _updateQueue.size(); i > 0; i--) + { + chunk = _updateQueue.takeFirst(); + if (chunk && i > 1 && chunk->preview() == _lastRendered) + { + _updateQueue.append(chunk); + } + else + { + break; + } + } } _lock.unlock(); if (chunk) { + _lastRendered = chunk->preview(); chunk->render(); } } diff --git a/gui_qt/basepreview.h b/gui_qt/basepreview.h index 52eba54..e5f9d58 100644 --- a/gui_qt/basepreview.h +++ b/gui_qt/basepreview.h @@ -136,6 +136,7 @@ private: QVector _threads; QVector _chunks; QList _updateQueue; + BasePreview* _lastRendered; QMutex _lock; };