|
|
|
@ -15,10 +15,14 @@ Simulation::Simulation() { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
void Simulation::draw(QPainter *p, int screenSize) { |
|
|
|
|
pendulaMutex.lock(); |
|
|
|
|
|
|
|
|
|
double scale = screenSize * 0.95 / size; |
|
|
|
|
|
|
|
|
|
for (const auto pendulum : pendula) |
|
|
|
|
pendulum->draw(p, scale); |
|
|
|
|
|
|
|
|
|
pendulaMutex.unlock(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Simulation::update() { |
|
|
|
@ -40,12 +44,14 @@ void Simulation::update() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Simulation::clearPendula() { |
|
|
|
|
auto deleteLater = pendula; |
|
|
|
|
pendulaMutex.lock(); |
|
|
|
|
|
|
|
|
|
for (auto p : pendula) |
|
|
|
|
delete p; |
|
|
|
|
pendula.clear(); |
|
|
|
|
pendula.shrink_to_fit(); |
|
|
|
|
QThread::usleep(500000); |
|
|
|
|
for (auto p : deleteLater) |
|
|
|
|
delete p; |
|
|
|
|
|
|
|
|
|
pendulaMutex.unlock(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Simulation::addPendula(const std::vector<Pendulum *> &add) { |
|
|
|
|