This commit is contained in:
Lendemor 2016-06-02 23:23:53 +02:00
commit e35cdd3b15
9 changed files with 270 additions and 199 deletions

View File

@ -14,11 +14,11 @@
DrawWidget::DrawWidget(QWidget *parent) :
QOpenGLWidget(parent),
m_Qt_fbo(NULL),
m_pipeline(NULL),
m_map(NULL)
m_pipeline(NULL)
{
new_simulation = false;
update_needed = false;
m_map = NULL;
}
DrawWidget::~DrawWidget()
@ -32,7 +32,7 @@ DrawWidget::~DrawWidget()
void DrawWidget::initializeGL()
{
renderer.initGL(width(), height());
renderer.setScene(m_map);
stopSimulation();
}
void DrawWidget::paintGL()
@ -43,6 +43,8 @@ void DrawWidget::paintGL()
delete m_pipeline;
m_map->initDraw();
m_pipeline = new PixelPipeline(m_map);
if(m_map == m_dummyMap)
m_pipeline->setShowToreiller(false);
m_pipeline->setTargetFBO(m_Qt_fbo);
m_pipeline->resizeGL(m_width, m_height);
renderer.setScene(m_map);
@ -69,7 +71,7 @@ void DrawWidget::resizeGL(int w, int h)
if(m_Qt_fbo != NULL && m_Qt_fbo != FrameBuffer::screen)
delete(m_Qt_fbo);
m_Qt_fbo = new FrameBuffer(defaultFramebufferObject());
if(m_map != NULL)
if(m_pipeline != NULL)
m_pipeline->setTargetFBO(m_Qt_fbo);
}
@ -77,6 +79,14 @@ void DrawWidget::startSimulation(MapScene *map)
{
m_map = map;
new_simulation = true;
m_dummyMap = NULL;
repaint();
}
void DrawWidget::stopSimulation()
{
m_map = m_dummyMap = new MapScene();
new_simulation = true;
repaint();
}

View File

@ -23,6 +23,7 @@ class DrawWidget : public QOpenGLWidget
QPoint lastMousePos;
bool grabbedMouse;
MapScene *m_map;
MapScene *m_dummyMap;
FrameBuffer *m_Qt_fbo;
PixelPipeline *m_pipeline;
int m_width;
@ -48,6 +49,7 @@ class DrawWidget : public QOpenGLWidget
DrawWidget(QWidget *parent = 0);
~DrawWidget();
void startSimulation(MapScene *map);
void stopSimulation();
public slots:
void updateDudesBehavior();

View File

@ -6,6 +6,7 @@
#include <iostream>
#include <chrono>
#include <QTimer>
#include <QErrorMessage>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
@ -20,14 +21,17 @@ MainWindow::MainWindow(QWidget *parent) :
m_simuTimer = new QTimer(this);
connect(m_simuTimer,SIGNAL(timeout()),this, SLOT(updateSimu()));
m_simuTimer->start(m_simSpeed);
connect(ui->startButton, SIGNAL(pressed()), this, SLOT(openSimuDialog()));
connect(ui->actionCreate_new_simulation, SIGNAL(triggered(bool)), this, SLOT(openSimuDialog()));
connect(ui->simSpeedSlider, SIGNAL(valueChanged(int)), this, SLOT(changeSimSpeed(int)));
connect(ui->flatSphereSlider, SIGNAL(valueChanged(int)), ui->drawWidget, SLOT(setFlatSphere(int)));
connect(ui->surfaceRatioSlider, SIGNAL(valueChanged(int)), ui->drawWidget, SLOT(setSurfaceRatio(int)));
connect(ui->flatSphereSlider, SIGNAL(valueChanged(int)), ui->drawWidget, SLOT(repaint()));
connect(ui->surfaceRatioSlider, SIGNAL(valueChanged(int)), ui->drawWidget, SLOT(repaint()));
connect(ui->pauseButton, SIGNAL(toggled(bool)), this, SLOT(pauseSimu(bool)));
connect(ui->actionPlayPause, SIGNAL(toggled(bool)), this, SLOT(pauseSimu(bool)));
connect(ui->actionAction_step, SIGNAL(triggered(bool)), this, SLOT(stepSimu()));
connect(ui->actionStop, SIGNAL(triggered(bool)), this, SLOT(stopSimu()));
changeSimSpeed(ui->simSpeedSlider->value());
ui->advancedGroupBox->hide();
}
MainWindow::~MainWindow()
@ -40,7 +44,8 @@ void MainWindow::openSimuDialog()
pauseSimu(true);
SimulationDialog *dialog = new SimulationDialog(this);
dialog->setWindowTitle("Starting a new Simulation");
connect(dialog, SIGNAL(sendError(QString, int)), ui->statusBar, SLOT(showMessage(QString, int)));
QErrorMessage *err = new QErrorMessage(dialog);
connect(dialog, SIGNAL(sendError(QString)), err, SLOT(showMessage(QString)));
int ret = dialog->exec();
if(ret == QDialog::Accepted)
{
@ -51,6 +56,7 @@ void MainWindow::openSimuDialog()
m_date = 0;
}
pauseSimu(false);
delete dialog;
}
void MainWindow::changeSimSpeed(int newSpeed)
@ -80,19 +86,27 @@ void MainWindow::updateSimu()
}
}
void MainWindow::stepSimu()
{
m_paused = false;
updateSimu();
pauseSimu(true);
}
void MainWindow::stopSimu()
{
pauseSimu(true);
ui->drawWidget->stopSimulation();
delete p_simu;
}
void MainWindow::pauseSimu(bool pause)
{
m_paused = pause;
ui->pauseButton->setChecked(m_paused);
ui->actionPlayPause->setChecked(m_paused);
if(m_paused)
{
m_simuTimer->stop();
ui->pauseButton->setText("RESUME");
}
else
{
m_simuTimer->start(m_simSpeed);
ui->pauseButton->setText("PAUSE");
}
m_simSpeedChanged = false;
}

View File

@ -30,6 +30,8 @@ private slots:
void openSimuDialog();
void changeSimSpeed(int newSpeed);
void updateSimu();
void stepSimu();
void stopSimu();
void pauseSimu(bool);
};

View File

@ -35,25 +35,6 @@
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>744</width>
<height>18</height>
</rect>
</property>
<widget class="QMenu" name="menuMenu">
<property name="title">
<string>Menu</string>
</property>
<addaction name="actionControl_Panel"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
<addaction name="menuMenu"/>
</widget>
<widget class="QDockWidget" name="dockWidget">
<attribute name="dockWidgetArea">
<number>1</number>
@ -74,7 +55,7 @@
</property>
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0,0">
<property name="leftMargin">
<number>5</number>
</property>
@ -88,16 +69,77 @@
<number>5</number>
</property>
<property name="spacing">
<number>8</number>
<number>10</number>
</property>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<item row="6" column="1" colspan="2">
<widget class="QLabel" name="dateLabel">
<property name="text">
<string>Simulation Speed</string>
<string>0</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="3">
<item row="8" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Population</string>
</property>
</widget>
</item>
<item row="8" column="1" colspan="2">
<widget class="QLabel" name="populationLabel">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
<widget class="QSlider" name="simSpeedSlider">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>980</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="pageStep">
<number>10</number>
</property>
<property name="value">
<number>980</number>
</property>
<property name="sliderPosition">
<number>980</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="invertedControls">
<bool>false</bool>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<number>100</number>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Date</string>
</property>
</widget>
</item>
<item row="12" column="0" colspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -110,16 +152,30 @@
</property>
</spacer>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Simulation Speed</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="11" column="0" colspan="3">
<widget class="QGroupBox" name="advancedGroupBox">
<property name="title">
<string>Advanced</string>
<string>Advanced Settings</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>true</bool>
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="leftMargin">
@ -210,140 +266,47 @@
</layout>
</widget>
</item>
<item row="7" column="1" colspan="2">
<widget class="QLabel" name="populationLabel">
<item row="10" column="0">
<widget class="QCheckBox" name="advancedCheckBox">
<property name="text">
<string>0</string>
<string>Advanced</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QSlider" name="simSpeedSlider">
<property name="enabled">
<bool>true</bool>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>980</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="pageStep">
<number>10</number>
</property>
<property name="value">
<number>980</number>
</property>
<property name="sliderPosition">
<number>980</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<property name="movable">
<bool>false</bool>
</property>
<property name="invertedControls">
<property name="allowedAreas">
<set>Qt::TopToolBarArea</set>
</property>
<property name="floatable">
<bool>false</bool>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<number>100</number>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QLabel" name="dateLabel">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Population</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Date</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="3">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QPushButton" name="startButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>START</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pauseButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>PAUSE</string>
</property>
<property name="shortcut">
<string>Space</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionCreate_new_simulation"/>
<addaction name="actionStop"/>
<addaction name="separator"/>
<addaction name="actionPlayPause"/>
<addaction name="actionAction_step"/>
<addaction name="separator"/>
<addaction name="actionControl_Panel"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionQuit">
<property name="text">
<string>Quit</string>
</property>
</action>
<action name="actionControl_Panel">
<property name="checkable">
<bool>true</bool>
@ -352,7 +315,65 @@
<bool>true</bool>
</property>
<property name="text">
<string>Control Panel</string>
<string>Toggle Control Panel</string>
</property>
</action>
<action name="actionPlayPause">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qss_icons/rc/pause.png</normaloff>
<normalon>:/qss_icons/rc/play.png</normalon>:/qss_icons/rc/pause.png</iconset>
</property>
<property name="text">
<string>PlayPause</string>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Play / Pause&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="shortcut">
<string>Space</string>
</property>
</action>
<action name="actionStop">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qss_icons/rc/stop.png</normaloff>:/qss_icons/rc/stop.png</iconset>
</property>
<property name="text">
<string>Stop</string>
</property>
<property name="toolTip">
<string>Stop this simulation</string>
</property>
</action>
<action name="actionCreate_new_simulation">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qss_icons/rc/PixelWars.png</normaloff>:/qss_icons/rc/PixelWars.png</iconset>
</property>
<property name="text">
<string>Create new simulation</string>
</property>
<property name="toolTip">
<string>Create new simulation</string>
</property>
</action>
<action name="actionAction_step">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qss_icons/rc/step.png</normaloff>:/qss_icons/rc/step.png</iconset>
</property>
<property name="text">
<string>Action step</string>
</property>
<property name="toolTip">
<string>performs only one turn of simulation</string>
</property>
<property name="shortcut">
<string>Right</string>
</property>
</action>
</widget>
@ -362,26 +383,23 @@
<class>DrawWidget</class>
<extends>QOpenGLWidget</extends>
<header>drawwidget.h</header>
<slots>
<signal>pauseEvent()</signal>
<signal>updateFPS(double,double)</signal>
<slot>addParticles()</slot>
<slot>addMesh()</slot>
<slot>resetScene()</slot>
<slot>setPaused(bool)</slot>
<slot>resetCamera()</slot>
<slot>setTimeRate(int)</slot>
<slot>setNbIterations(int)</slot>
</slots>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>actionQuit</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>371</x>
<y>244</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionControl_Panel</sender>
<signal>toggled(bool)</signal>
@ -414,5 +432,21 @@
</hint>
</hints>
</connection>
<connection>
<sender>advancedCheckBox</sender>
<signal>toggled(bool)</signal>
<receiver>advancedGroupBox</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>54</x>
<y>183</y>
</hint>
<hint type="destinationlabel">
<x>102</x>
<y>240</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -32,7 +32,8 @@ PixelPipeline::PixelPipeline(MapScene *map) :
m_map(map),
m_mapWidth(map->getWidth()),
m_mapHeight(map->getHeight()),
m_camera(0, 0, 1)
m_camera(0, 0, 1),
m_showToreiller(true)
{
m_width = 256;
m_height = 256;
@ -76,6 +77,9 @@ PixelPipeline::~PixelPipeline()
delete m_texMapShader;
delete m_renderShader;
delete m_map;
delete m_skyboxShader;
delete m_skyTexBack;
delete m_skyTexFront;
}
void PixelPipeline::updateChanges()
@ -116,6 +120,8 @@ void PixelPipeline::renderGL(Scene *scene)
m_toreiller->draw(m_skyboxShader);
glDepthMask(GL_TRUE);
if(m_showToreiller)
{
m_renderShader->bind();
m_renderShader->bindVec3(m_renderShader->getLocation("camera"), m_camera);
m_renderShader->bindVec2(m_renderShader->getLocation("worldSize"), glm::vec2(m_mapWidth, m_mapHeight));
@ -128,6 +134,7 @@ void PixelPipeline::renderGL(Scene *scene)
glm::mat4 mvp = m_proj * m_view;
m_renderShader->bindMat4(m_renderShader->getLocation("mvp"), mvp);
m_toreiller->draw(m_renderShader);
}
}
void PixelPipeline::resizeGL(int w, int h)

View File

@ -30,6 +30,7 @@ private:
float m_surfaceRatio;
float m_flatSphere;
glm::vec3 m_camera;
bool m_showToreiller;
Mesh *m_toreiller;
glm::mat4 m_proj;
@ -50,6 +51,7 @@ public:
void setSurfaceRatio(float surfaceRatio) { m_surfaceRatio = surfaceRatio; }
void setFlatSphere(float flatSphere) { m_flatSphere = flatSphere; }
void setShowToreiller(bool showToreiller) { m_showToreiller = showToreiller; }
};
#endif // PIXELPIPELINE_H

View File

@ -70,7 +70,7 @@ void SimulationDialog::refreshBehaviors()
}
}
else
emit sendError(QString("ERROR : can't open the teams folder.\n"), 5000);
emit sendError(QString("ERROR : can't open the teams folder.\n"));
}
void SimulationDialog::refreshGenerators()
@ -100,7 +100,7 @@ void SimulationDialog::refreshGenerators()
}
}
else
emit sendError(QString("ERROR : can't open the generators folder.\n"), 5000);
emit sendError(QString("ERROR : can't open the generators folder.\n"));
bool canGenerate = !m_genList.empty();
if(canGenerate)
{

View File

@ -47,7 +47,7 @@ private:
void updatePreviewPixmap();
signals:
void sendError(QString, int);
void sendError(QString);
};
#endif // SIMULATIONDIALOG_H