fixed rendering issue, enhanced duplicate removing in mapscene, and added updating of graphics and date label
This commit is contained in:
parent
69890b57cb
commit
ea3bd65bc7
@ -49,7 +49,10 @@ void DrawWidget::paintGL()
|
|||||||
new_simulation = false;
|
new_simulation = false;
|
||||||
}
|
}
|
||||||
else if(update_needed)
|
else if(update_needed)
|
||||||
|
{
|
||||||
m_pipeline->updateChanges();
|
m_pipeline->updateChanges();
|
||||||
|
update_needed = false;
|
||||||
|
}
|
||||||
renderer.renderGL();
|
renderer.renderGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow)
|
ui(new Ui::MainWindow),
|
||||||
|
m_simSpeed(500)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
connect(ui->startButton, SIGNAL(pressed()), this, SLOT(openSimuDialog()));
|
connect(ui->startButton, SIGNAL(pressed()), this, SLOT(openSimuDialog()));
|
||||||
@ -32,11 +33,15 @@ void MainWindow::openSimuDialog()
|
|||||||
ui->drawWidget->startSimulation(p_simu->getMap());
|
ui->drawWidget->startSimulation(p_simu->getMap());
|
||||||
QTimer *timer = new QTimer(this);
|
QTimer *timer = new QTimer(this);
|
||||||
connect(timer,SIGNAL(timeout()),this, SLOT(updateSimu()));
|
connect(timer,SIGNAL(timeout()),this, SLOT(updateSimu()));
|
||||||
timer->start(2000);
|
timer->start(m_simSpeed);
|
||||||
|
m_date = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateSimu()
|
void MainWindow::updateSimu()
|
||||||
{
|
{
|
||||||
p_simu->update();
|
p_simu->update();
|
||||||
|
ui->dateLabel->setText(QString::number(++m_date));
|
||||||
|
ui->drawWidget->updateDudesBehavior();
|
||||||
|
ui->drawWidget->repaint();
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
Simulation* p_simu;
|
Simulation* p_simu;
|
||||||
|
int m_date;
|
||||||
|
int m_simSpeed;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void openSimuDialog();
|
void openSimuDialog();
|
||||||
|
@ -83,56 +83,78 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>120</width>
|
<width>260</width>
|
||||||
<height>75</height>
|
<height>344</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="label">
|
<attribute name="label">
|
||||||
<string>Settings</string>
|
<string>Settings</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item row="0" column="1">
|
<item>
|
||||||
<widget class="QSlider" name="horizontalSlider">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Flat / Sphere</string>
|
<string>Flat / Sphere</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>surface ratio</string>
|
<string>surface ratio</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item>
|
||||||
<widget class="QSlider" name="horizontalSlider_3">
|
<widget class="QSlider" name="horizontalSlider_2">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item>
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Simulation Speed</string>
|
<string>Simulation Speed</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item>
|
||||||
<widget class="QSlider" name="horizontalSlider_2">
|
<widget class="QSlider" name="horizontalSlider_3">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="page_6">
|
<widget class="QWidget" name="page_6">
|
||||||
@ -156,7 +178,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="dateLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>0</string>
|
<string>0</string>
|
||||||
</property>
|
</property>
|
||||||
@ -170,7 +192,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QLabel" name="label_7">
|
<widget class="QLabel" name="populationLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>0</string>
|
<string>0</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -43,7 +43,15 @@ MapScene::~MapScene()
|
|||||||
|
|
||||||
void MapScene::updatePixel(const Coord &c)
|
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)
|
void MapScene::setColors(int teamId, const glm::vec3 &spawnColor, const glm::vec3 &dudeColor)
|
||||||
@ -87,19 +95,15 @@ void MapScene::draw()
|
|||||||
|
|
||||||
// updating VBO data
|
// updating VBO data
|
||||||
m_mutex.lock();
|
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);
|
glBufferData(GL_ARRAY_BUFFER, m_pixels.size() * sizeof(Pix), m_pixels.data(), GL_DYNAMIC_DRAW);
|
||||||
m_mutex.unlock();
|
m_mutex.unlock();
|
||||||
|
|
||||||
// clearing temporary data structures
|
|
||||||
m_updatedCoordSet.clear();
|
|
||||||
m_pixels.clear();
|
|
||||||
|
|
||||||
// drawing changes
|
// drawing changes
|
||||||
glDrawArrays(GL_POINTS, 0, m_pixels.size());
|
glDrawArrays(GL_POINTS, 0, m_pixels.size());
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
// clearing temporary data structures
|
||||||
|
m_updatedCoordMap.clear();
|
||||||
|
m_pixels.clear();
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <glm/vec2.hpp>
|
#include <glm/vec2.hpp>
|
||||||
#include <glm/vec3.hpp>
|
#include <glm/vec3.hpp>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <set>
|
#include <map>
|
||||||
|
|
||||||
struct MapScene : public Map, public BasicScene
|
struct MapScene : public Map, public BasicScene
|
||||||
{
|
{
|
||||||
@ -48,7 +48,7 @@ private:
|
|||||||
Pix(glm::vec2 p, glm::vec3 c) : pos(p), color(c) {}
|
Pix(glm::vec2 p, glm::vec3 c) : pos(p), color(c) {}
|
||||||
};
|
};
|
||||||
std::vector<Pix> m_pixels;
|
std::vector<Pix> m_pixels;
|
||||||
std::set<Coord> m_updatedCoordSet;
|
std::map<Coord, int> m_updatedCoordMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAPSCENE_H
|
#endif // MAPSCENE_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user