File indexing completed on 2024-05-05 03:51:48
0001 /*. 0002 SPDX-FileCopyrightText: 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "simulationthread.h" 0008 0009 #include <stepcore/world.h> 0010 #include <stepcore/solver.h> 0011 0012 void SimulationThread::run() 0013 { 0014 _mutex.lock(); 0015 forever { 0016 _waitCondition.wait(&_mutex); 0017 0018 if(_stopThread) break; 0019 0020 int result; 0021 if(! (*_world)->evolveAbort()) { 0022 //qDebug("begin doWorldEvolve() t=%#x", int(QThread::currentThread())); 0023 result = (*_world)->doEvolve(_delta); 0024 //qDebug("end doWorldEvolve()"); 0025 } else { 0026 result = StepCore::Solver::Aborted; 0027 } 0028 0029 emit worldEvolveDone(result); 0030 } 0031 _mutex.unlock(); 0032 } 0033 0034 void SimulationThread::doWorldEvolve(double delta) 0035 { 0036 // XXX: ensure that previous frame was finished 0037 _mutex.lock(); 0038 _delta = delta; 0039 _waitCondition.wakeOne(); 0040 _mutex.unlock(); 0041 //} 0042 /* 0043 _mutex->lock(); 0044 qDebug("begin doWorldEvolve() t=%#x", int(QThread::currentThread())); 0045 int result = (*_world)->doEvolve(delta); 0046 qDebug("end doWorldEvolve()"); 0047 _mutex->unlock(); 0048 emit worldEvolveDone(result); 0049 */ 0050 } 0051 0052 SimulationThread::~SimulationThread() 0053 { 0054 _stopThread = true; 0055 _waitCondition.wakeOne(); 0056 wait(); 0057 } 0058 0059 #include "moc_simulationthread.cpp"