fixed rendering issue, enhanced duplicate removing in mapscene, and added updating of graphics and date label

This commit is contained in:
Anselme FRANÇOIS 2016-05-26 22:09:40 +02:00
parent 69890b57cb
commit ea3bd65bc7
6 changed files with 67 additions and 31 deletions

View File

@ -49,7 +49,10 @@ void DrawWidget::paintGL()
new_simulation = false;
}
else if(update_needed)
{
m_pipeline->updateChanges();
update_needed = false;
}
renderer.renderGL();
}

View File

@ -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();
}

View File

@ -20,6 +20,8 @@ public:
private:
Ui::MainWindow *ui;
Simulation* p_simu;
int m_date;
int m_simSpeed;
private slots:
void openSimuDialog();

View File

@ -83,56 +83,78 @@
<rect>
<x>0</x>
<y>0</y>
<width>120</width>
<height>75</height>
<width>260</width>
<height>344</height>
</rect>
</property>
<attribute name="label">
<string>Settings</string>
</attribute>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="1">
<widget class="QSlider" name="horizontalSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Flat / Sphere</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item>
<widget class="QSlider" name="horizontalSlider">
<property name="enabled">
<bool>false</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>surface ratio</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="horizontalSlider_3">
<item>
<widget class="QSlider" name="horizontalSlider_2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Simulation Speed</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSlider" name="horizontalSlider_2">
<item>
<widget class="QSlider" name="horizontalSlider_3">
<property name="enabled">
<bool>false</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_6">
@ -156,7 +178,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="dateLabel">
<property name="text">
<string>0</string>
</property>
@ -170,7 +192,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_7">
<widget class="QLabel" name="populationLabel">
<property name="text">
<string>0</string>
</property>

View File

@ -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();
}

View File

@ -6,7 +6,7 @@
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <QMutex>
#include <set>
#include <map>
struct MapScene : public Map, public BasicScene
{
@ -48,7 +48,7 @@ private:
Pix(glm::vec2 p, glm::vec3 c) : pos(p), color(c) {}
};
std::vector<Pix> m_pixels;
std::set<Coord> m_updatedCoordSet;
std::map<Coord, int> m_updatedCoordMap;
};
#endif // MAPSCENE_H