diff --git a/src/drawwidget.cpp b/src/drawwidget.cpp
index 8a2ce1d..44c02bd 100644
--- a/src/drawwidget.cpp
+++ b/src/drawwidget.cpp
@@ -49,7 +49,10 @@ void DrawWidget::paintGL()
new_simulation = false;
}
else if(update_needed)
+ {
m_pipeline->updateChanges();
+ update_needed = false;
+ }
renderer.renderGL();
}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index d711673..017f017 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -9,7 +9,8 @@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
- ui(new Ui::MainWindow)
+ ui(new Ui::MainWindow),
+ m_simSpeed(500)
{
ui->setupUi(this);
connect(ui->startButton, SIGNAL(pressed()), this, SLOT(openSimuDialog()));
@@ -32,11 +33,15 @@ void MainWindow::openSimuDialog()
ui->drawWidget->startSimulation(p_simu->getMap());
QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this, SLOT(updateSimu()));
- timer->start(2000);
+ timer->start(m_simSpeed);
+ m_date = 0;
}
}
void MainWindow::updateSimu()
{
p_simu->update();
+ ui->dateLabel->setText(QString::number(++m_date));
+ ui->drawWidget->updateDudesBehavior();
+ ui->drawWidget->repaint();
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 8275422..e8a416a 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -20,6 +20,8 @@ public:
private:
Ui::MainWindow *ui;
Simulation* p_simu;
+ int m_date;
+ int m_simSpeed;
private slots:
void openSimuDialog();
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index 9d73140..1730be6 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -83,56 +83,78 @@
0
0
- 120
- 75
+ 260
+ 344
Settings
-
- -
-
-
- Qt::Horizontal
-
-
-
- -
+
+
-
Flat / Sphere
- -
+
-
+
+
+ false
+
+
+ Qt::Horizontal
+
+
+
+ -
surface ratio
- -
-
+
-
+
+
+ false
+
Qt::Horizontal
- -
+
-
Simulation Speed
- -
-
+
-
+
+
+ false
+
Qt::Horizontal
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
@@ -156,7 +178,7 @@
-
-
+
0
@@ -170,7 +192,7 @@
-
-
+
0
diff --git a/src/mapscene.cpp b/src/mapscene.cpp
index 28c10de..ea4850f 100644
--- a/src/mapscene.cpp
+++ b/src/mapscene.cpp
@@ -43,7 +43,15 @@ MapScene::~MapScene()
void MapScene::updatePixel(const Coord &c)
{
- m_updatedCoordSet.emplace(c);
+ QMutexLocker lock(&m_mutex);
+ auto it = m_updatedCoordMap.find(c);
+ if(it != m_updatedCoordMap.end())
+ m_pixels[it->second].color = getColor(getPixel(c));
+ else
+ {
+ it->second = m_pixels.size();
+ m_pixels.push_back(Pix(glm::vec2(c.x+0.5f, c.y+0.5f), getColor(getPixel(c))));
+ }
}
void MapScene::setColors(int teamId, const glm::vec3 &spawnColor, const glm::vec3 &dudeColor)
@@ -87,19 +95,15 @@ void MapScene::draw()
// updating VBO data
m_mutex.lock();
- for(const Coord &c : m_updatedCoordSet) // WARNING : potential bottleneck
- m_pixels.push_back(Pix(glm::vec2(c.x+0.5f, c.y+0.5f), getColor(getPixel(c))));
glBufferData(GL_ARRAY_BUFFER, m_pixels.size() * sizeof(Pix), m_pixels.data(), GL_DYNAMIC_DRAW);
m_mutex.unlock();
- // clearing temporary data structures
- m_updatedCoordSet.clear();
- m_pixels.clear();
-
// drawing changes
glDrawArrays(GL_POINTS, 0, m_pixels.size());
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
-
+ // clearing temporary data structures
+ m_updatedCoordMap.clear();
+ m_pixels.clear();
}
diff --git a/src/mapscene.h b/src/mapscene.h
index 5ddb991..c58b421 100644
--- a/src/mapscene.h
+++ b/src/mapscene.h
@@ -6,7 +6,7 @@
#include
#include
#include
-#include
+#include