paysages : Fixed preview threads termination

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@313 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-04-30 19:25:30 +00:00 committed by ThunderK
parent 943cc9418e
commit 390fb34f65
4 changed files with 83 additions and 61 deletions

View file

@ -20,6 +20,7 @@ public:
_ysize = ysize; _ysize = ysize;
_need_render = true; _need_render = true;
_alive = true;
} }
bool isFrom(BasePreview* preview) bool isFrom(BasePreview* preview)
@ -27,6 +28,11 @@ public:
return _preview == preview; return _preview == preview;
} }
void interrupt()
{
_alive = false;
}
void update() void update()
{ {
_need_render = true; _need_render = true;
@ -48,6 +54,10 @@ public:
for (int y = 0; y < _ysize; y++) for (int y = 0; y < _ysize; y++)
{ {
QRgb col = pixbuf.pixel(x, y); QRgb col = pixbuf.pixel(x, y);
if (!_alive)
{
return false;
}
if (qAlpha(col) < 255) if (qAlpha(col) < 255)
{ {
QColor newcol = _preview->getPixelColor(_xstart + x, _ystart + y); QColor newcol = _preview->getPixelColor(_xstart + x, _ystart + y);
@ -70,6 +80,7 @@ public:
} }
private: private:
BasePreview* _preview; BasePreview* _preview;
bool _alive;
bool _need_render; bool _need_render;
int _xstart; int _xstart;
int _ystart; 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) void PreviewDrawingManager::addChunk(PreviewChunk* chunk)
{ {
_lock.lock(); _lock.lock();
@ -169,27 +196,19 @@ void PreviewDrawingManager::updateChunks(BasePreview* preview)
void PreviewDrawingManager::performOneThreadJob() void PreviewDrawingManager::performOneThreadJob()
{ {
PreviewChunk* chunk; PreviewChunk* chunk;
do
chunk = NULL;
_lock.lock();
if (!_updateQueue.isEmpty())
{ {
chunk = NULL; chunk = _updateQueue.takeFirst();
_lock.lock(); }
if (!_updateQueue.isEmpty()) _lock.unlock();
{
chunk = _updateQueue.takeFirst();
}
_lock.unlock();
if (chunk) if (chunk)
{ {
chunk->render(); chunk->render();
PreviewDrawingThread::usleep(50000); }
}
else
{
PreviewDrawingThread::usleep(50000);
}
} while (true);
} }
/*************** BasePreview ***************/ /*************** BasePreview ***************/
@ -247,7 +266,7 @@ void BasePreview::initDrawers()
void BasePreview::stopDrawers() void BasePreview::stopDrawers()
{ {
//delete _drawing_manager; _drawing_manager->stopThreads();
} }
void BasePreview::updateData() void BasePreview::updateData()

View file

@ -108,6 +108,7 @@ class PreviewDrawingManager {
public: public:
PreviewDrawingManager(); PreviewDrawingManager();
void startThreads(); void startThreads();
void stopThreads();
void addChunk(PreviewChunk* chunk); void addChunk(PreviewChunk* chunk);
void removeChunks(BasePreview* preview); void removeChunks(BasePreview* preview);
void updateChunks(BasePreview* preview); void updateChunks(BasePreview* preview);

View file

@ -60,6 +60,8 @@ int main(int argc, char** argv)
result = app.exec(); result = app.exec();
BasePreview::stopDrawers();
delete window; delete window;
paysagesQuit(); paysagesQuit();

View file

@ -709,139 +709,139 @@ Maintenir Ctrl : Plus rapide</translation>
<context> <context>
<name>MainWindow</name> <name>MainWindow</name>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="79"/> <location filename="../gui_qt/mainwindow.cpp" line="81"/>
<source>Terrain</source> <source>Terrain</source>
<translation>Terrain</translation> <translation>Terrain</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="83"/> <location filename="../gui_qt/mainwindow.cpp" line="85"/>
<source>Textures</source> <source>Textures</source>
<translation>Textures</translation> <translation>Textures</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="87"/> <location filename="../gui_qt/mainwindow.cpp" line="89"/>
<source>Water</source> <source>Water</source>
<translation>Eau</translation> <translation>Eau</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="95"/> <location filename="../gui_qt/mainwindow.cpp" line="97"/>
<source>Atmosphere</source> <source>Atmosphere</source>
<translation>Atmosphère</translation> <translation>Atmosphère</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="121"/> <location filename="../gui_qt/mainwindow.cpp" line="123"/>
<source>&amp;Load</source> <source>&amp;Load</source>
<translation>&amp;Ouvrir</translation> <translation>&amp;Ouvrir</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="121"/> <location filename="../gui_qt/mainwindow.cpp" line="123"/>
<source>Crtl+L</source> <source>Crtl+L</source>
<translation>Ctrl+O</translation> <translation>Ctrl+O</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="122"/> <location filename="../gui_qt/mainwindow.cpp" line="124"/>
<source>&amp;Explore (F2)</source> <source>&amp;Explore (F2)</source>
<translation>&amp;Explorer (F2)</translation> <translation>&amp;Explorer (F2)</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="122"/> <location filename="../gui_qt/mainwindow.cpp" line="124"/>
<source>F2</source> <source>F2</source>
<translation>F2</translation> <translation>F2</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="123"/> <location filename="../gui_qt/mainwindow.cpp" line="125"/>
<source>&amp;Quick <source>&amp;Quick
render (F5)</source> render (F5)</source>
<translation>&amp;Rendu <translation>&amp;Rendu
rapide (F5)</translation> rapide (F5)</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="123"/> <location filename="../gui_qt/mainwindow.cpp" line="125"/>
<source>F5</source> <source>F5</source>
<translation>F5</translation> <translation>F5</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="143"/> <location filename="../gui_qt/mainwindow.cpp" line="145"/>
<source>Do you want to start a new scenery ? Any unsaved changes will be lost.</source> <source>Do you want to start a new scenery ? Any unsaved changes will be lost.</source>
<translation>Voulez-vous commencer un nouveau paysage ? Les modifications non sauvegardées seront perdues.</translation> <translation>Voulez-vous commencer un nouveau paysage ? Les modifications non sauvegardées seront perdues.</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="143"/> <location filename="../gui_qt/mainwindow.cpp" line="145"/>
<source>Paysages 3D - New scenery</source> <source>Paysages 3D - New scenery</source>
<translation>Paysages 3D - Nouvelle scène</translation> <translation>Paysages 3D - Nouvelle scène</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="153"/> <location filename="../gui_qt/mainwindow.cpp" line="155"/>
<source>Paysages 3D - Choose a file to save the scenery</source> <source>Paysages 3D - Choose a file to save the scenery</source>
<translation>Paysages 3D - Choisissez un fichier pour enregistrer la scène</translation> <translation>Paysages 3D - Choisissez un fichier pour enregistrer la scène</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="153"/> <location filename="../gui_qt/mainwindow.cpp" line="155"/>
<location filename="../gui_qt/mainwindow.cpp" line="179"/> <location filename="../gui_qt/mainwindow.cpp" line="181"/>
<source>Paysages 3D Scenery (*.p3d)</source> <source>Paysages 3D Scenery (*.p3d)</source>
<translation>Scène Paysages 3D (*.p3d)</translation> <translation>Scène Paysages 3D (*.p3d)</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="167"/> <location filename="../gui_qt/mainwindow.cpp" line="169"/>
<location filename="../gui_qt/mainwindow.cpp" line="170"/> <location filename="../gui_qt/mainwindow.cpp" line="172"/>
<source>Paysages 3D - File saving error</source> <source>Paysages 3D - File saving error</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="167"/> <location filename="../gui_qt/mainwindow.cpp" line="169"/>
<source>Can&apos;t write specified file : %1</source> <source>Can&apos;t write specified file : %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="170"/> <location filename="../gui_qt/mainwindow.cpp" line="172"/>
<source>Unexpected error while saving file : %1</source> <source>Unexpected error while saving file : %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="177"/> <location filename="../gui_qt/mainwindow.cpp" line="179"/>
<source>Do you want to load a scenery from file ? Any unsaved changes will be lost.</source> <source>Do you want to load a scenery from file ? Any unsaved changes will be lost.</source>
<translation>Voulez-vous charger une scène ? Les modifications nons sauvegardées seront perdues.</translation> <translation>Voulez-vous charger une scène ? Les modifications nons sauvegardées seront perdues.</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="177"/> <location filename="../gui_qt/mainwindow.cpp" line="179"/>
<source>Paysages 3D - Load scenery</source> <source>Paysages 3D - Load scenery</source>
<translation>Paysages 3D - Charger une scène</translation> <translation>Paysages 3D - Charger une scène</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="179"/> <location filename="../gui_qt/mainwindow.cpp" line="181"/>
<source>Paysages 3D - Choose a scenery file to load</source> <source>Paysages 3D - Choose a scenery file to load</source>
<translation>Paysages 3D - Choisissez un fichier de scène à charger</translation> <translation>Paysages 3D - Choisissez un fichier de scène à charger</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="189"/> <location filename="../gui_qt/mainwindow.cpp" line="191"/>
<location filename="../gui_qt/mainwindow.cpp" line="192"/> <location filename="../gui_qt/mainwindow.cpp" line="194"/>
<location filename="../gui_qt/mainwindow.cpp" line="195"/> <location filename="../gui_qt/mainwindow.cpp" line="197"/>
<location filename="../gui_qt/mainwindow.cpp" line="198"/> <location filename="../gui_qt/mainwindow.cpp" line="200"/>
<source>Paysages 3D - File loading error</source> <source>Paysages 3D - File loading error</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="189"/> <location filename="../gui_qt/mainwindow.cpp" line="191"/>
<source>Can&apos;t read specified file : %1</source> <source>Can&apos;t read specified file : %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="192"/> <location filename="../gui_qt/mainwindow.cpp" line="194"/>
<source>This file doesn&apos;t look like a Paysages 3D file : %1</source> <source>This file doesn&apos;t look like a Paysages 3D file : %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="195"/> <location filename="../gui_qt/mainwindow.cpp" line="197"/>
<source>This file was created with an incompatible Paysages 3D version : %1</source> <source>This file was created with an incompatible Paysages 3D version : %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="198"/> <location filename="../gui_qt/mainwindow.cpp" line="200"/>
<source>Unexpected error while loading file : %1</source> <source>Unexpected error while loading file : %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="206"/> <location filename="../gui_qt/mainwindow.cpp" line="208"/>
<source>A 3D landscape editing and rendering software. <source>A 3D landscape editing and rendering software.
Authors : Authors :
@ -854,12 +854,12 @@ GLib - http://www.gtk.org/
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="91"/> <location filename="../gui_qt/mainwindow.cpp" line="93"/>
<source>Sky</source> <source>Sky</source>
<translation>Ciel</translation> <translation>Ciel</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="99"/> <location filename="../gui_qt/mainwindow.cpp" line="101"/>
<source>Clouds</source> <source>Clouds</source>
<translation>Nuages</translation> <translation>Nuages</translation>
</message> </message>
@ -868,7 +868,7 @@ GLib - http://www.gtk.org/
<translation type="obsolete">Eclairage</translation> <translation type="obsolete">Eclairage</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="107"/> <location filename="../gui_qt/mainwindow.cpp" line="109"/>
<source>Render</source> <source>Render</source>
<translation>Rendu</translation> <translation>Rendu</translation>
</message> </message>
@ -877,22 +877,22 @@ GLib - http://www.gtk.org/
<translation type="obsolete">&amp;Scène</translation> <translation type="obsolete">&amp;Scène</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="119"/> <location filename="../gui_qt/mainwindow.cpp" line="121"/>
<source>&amp;New</source> <source>&amp;New</source>
<translation>&amp;Nouveau</translation> <translation>&amp;Nouveau</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="119"/> <location filename="../gui_qt/mainwindow.cpp" line="121"/>
<source>Crtl+N</source> <source>Crtl+N</source>
<translation>Ctrl+N</translation> <translation>Ctrl+N</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="120"/> <location filename="../gui_qt/mainwindow.cpp" line="122"/>
<source>&amp;Save</source> <source>&amp;Save</source>
<translation>&amp;Sauvegarder</translation> <translation>&amp;Sauvegarder</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="120"/> <location filename="../gui_qt/mainwindow.cpp" line="122"/>
<source>Crtl+S</source> <source>Crtl+S</source>
<translation>Ctrl+S</translation> <translation>Ctrl+S</translation>
</message> </message>
@ -929,7 +929,7 @@ GLib - http://www.gtk.org/
<translation type="obsolete">Ai&amp;de</translation> <translation type="obsolete">Ai&amp;de</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="124"/> <location filename="../gui_qt/mainwindow.cpp" line="126"/>
<source>&amp;About</source> <source>&amp;About</source>
<translation>&amp;A propos</translation> <translation>&amp;A propos</translation>
</message> </message>
@ -950,7 +950,7 @@ GLib - http://www.gtk.org/
<translation type="obsolete">Voulez-vous charger un paysage ? Les modifications nons sauvegardées seront perdues.</translation> <translation type="obsolete">Voulez-vous charger un paysage ? Les modifications nons sauvegardées seront perdues.</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="206"/> <location filename="../gui_qt/mainwindow.cpp" line="208"/>
<source>Paysages 3D</source> <source>Paysages 3D</source>
<translation>Paysages 3D</translation> <translation>Paysages 3D</translation>
</message> </message>