diff --git a/gui_qt/basepreview.cpp b/gui_qt/basepreview.cpp index c3009b4..2e7f18d 100644 --- a/gui_qt/basepreview.cpp +++ b/gui_qt/basepreview.cpp @@ -20,6 +20,7 @@ public: _ysize = ysize; _need_render = true; + _alive = true; } bool isFrom(BasePreview* preview) @@ -27,6 +28,11 @@ public: return _preview == preview; } + void interrupt() + { + _alive = false; + } + void update() { _need_render = true; @@ -48,6 +54,10 @@ public: for (int y = 0; y < _ysize; y++) { QRgb col = pixbuf.pixel(x, y); + if (!_alive) + { + return false; + } if (qAlpha(col) < 255) { QColor newcol = _preview->getPixelColor(_xstart + x, _ystart + y); @@ -70,6 +80,7 @@ public: } private: BasePreview* _preview; + bool _alive; bool _need_render; int _xstart; int _ystart; @@ -121,6 +132,22 @@ void PreviewDrawingManager::startThreads() } } +void PreviewDrawingManager::stopThreads() +{ + for (int i = 0; i < _threads.size(); i++) + { + _threads.at(i)->askStop(); + } + for (int i = 0; i < _chunks.size(); i++) + { + _chunks.at(i)->interrupt(); + } + for (int i = 0; i < _threads.size(); i++) + { + _threads.at(i)->wait(); + } +} + void PreviewDrawingManager::addChunk(PreviewChunk* chunk) { _lock.lock(); @@ -169,27 +196,19 @@ void PreviewDrawingManager::updateChunks(BasePreview* preview) void PreviewDrawingManager::performOneThreadJob() { PreviewChunk* chunk; - do + + chunk = NULL; + _lock.lock(); + if (!_updateQueue.isEmpty()) { - chunk = NULL; - _lock.lock(); - if (!_updateQueue.isEmpty()) - { - chunk = _updateQueue.takeFirst(); - } - _lock.unlock(); - - if (chunk) - { - chunk->render(); - PreviewDrawingThread::usleep(50000); - } - else - { - PreviewDrawingThread::usleep(50000); - } - - } while (true); + chunk = _updateQueue.takeFirst(); + } + _lock.unlock(); + + if (chunk) + { + chunk->render(); + } } /*************** BasePreview ***************/ @@ -247,7 +266,7 @@ void BasePreview::initDrawers() void BasePreview::stopDrawers() { - //delete _drawing_manager; + _drawing_manager->stopThreads(); } void BasePreview::updateData() diff --git a/gui_qt/basepreview.h b/gui_qt/basepreview.h index 844a1bd..bddcc16 100644 --- a/gui_qt/basepreview.h +++ b/gui_qt/basepreview.h @@ -108,6 +108,7 @@ class PreviewDrawingManager { public: PreviewDrawingManager(); void startThreads(); + void stopThreads(); void addChunk(PreviewChunk* chunk); void removeChunks(BasePreview* preview); void updateChunks(BasePreview* preview); diff --git a/gui_qt/mainwindow.cpp b/gui_qt/mainwindow.cpp index ef82e23..833dd9a 100644 --- a/gui_qt/mainwindow.cpp +++ b/gui_qt/mainwindow.cpp @@ -60,6 +60,8 @@ int main(int argc, char** argv) result = app.exec(); + BasePreview::stopDrawers(); + delete window; paysagesQuit(); diff --git a/i18n/paysages_fr.ts b/i18n/paysages_fr.ts index 24915c6..235e797 100644 --- a/i18n/paysages_fr.ts +++ b/i18n/paysages_fr.ts @@ -709,139 +709,139 @@ Maintenir Ctrl : Plus rapide MainWindow - + Terrain Terrain - + Textures Textures - + Water Eau - + Atmosphere Atmosphère - + &Load &Ouvrir - + Crtl+L Ctrl+O - + &Explore (F2) &Explorer (F2) - + F2 F2 - + &Quick render (F5) &Rendu rapide (F5) - + F5 F5 - + Do you want to start a new scenery ? Any unsaved changes will be lost. Voulez-vous commencer un nouveau paysage ? Les modifications non sauvegardées seront perdues. - + Paysages 3D - New scenery Paysages 3D - Nouvelle scène - + Paysages 3D - Choose a file to save the scenery Paysages 3D - Choisissez un fichier pour enregistrer la scène - - + + Paysages 3D Scenery (*.p3d) Scène Paysages 3D (*.p3d) - - + + Paysages 3D - File saving error - + Can't write specified file : %1 - + Unexpected error while saving file : %1 - + Do you want to load a scenery from file ? Any unsaved changes will be lost. Voulez-vous charger une scène ? Les modifications nons sauvegardées seront perdues. - + Paysages 3D - Load scenery Paysages 3D - Charger une scène - + Paysages 3D - Choose a scenery file to load Paysages 3D - Choisissez un fichier de scène à charger - - - - + + + + Paysages 3D - File loading error - + Can't read specified file : %1 - + This file doesn't look like a Paysages 3D file : %1 - + This file was created with an incompatible Paysages 3D version : %1 - + Unexpected error while loading file : %1 - + A 3D landscape editing and rendering software. Authors : @@ -854,12 +854,12 @@ GLib - http://www.gtk.org/ - + Sky Ciel - + Clouds Nuages @@ -868,7 +868,7 @@ GLib - http://www.gtk.org/ Eclairage - + Render Rendu @@ -877,22 +877,22 @@ GLib - http://www.gtk.org/ &Scène - + &New &Nouveau - + Crtl+N Ctrl+N - + &Save &Sauvegarder - + Crtl+S Ctrl+S @@ -929,7 +929,7 @@ GLib - http://www.gtk.org/ Ai&de - + &About &A propos @@ -950,7 +950,7 @@ GLib - http://www.gtk.org/ Voulez-vous charger un paysage ? Les modifications nons sauvegardées seront perdues. - + Paysages 3D Paysages 3D