diff --git a/src/drawwidget.cpp b/src/drawwidget.cpp index 3bc8376..9d53182 100644 --- a/src/drawwidget.cpp +++ b/src/drawwidget.cpp @@ -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(); } diff --git a/src/drawwidget.h b/src/drawwidget.h index c43ef2b..7da88d1 100644 --- a/src/drawwidget.h +++ b/src/drawwidget.h @@ -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(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6ee6090..4f2782f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -6,6 +6,7 @@ #include #include #include +#include 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; } diff --git a/src/mainwindow.h b/src/mainwindow.h index 7f85e8a..faeccd8 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -30,6 +30,8 @@ private slots: void openSimuDialog(); void changeSimSpeed(int newSpeed); void updateSimu(); + void stepSimu(); + void stopSimu(); void pauseSimu(bool); }; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index f6de0ff..08b94e0 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -35,25 +35,6 @@ - - - - 0 - 0 - 744 - 18 - - - - - Menu - - - - - - - 1 @@ -74,7 +55,7 @@ - + 5 @@ -88,16 +69,77 @@ 5 - 8 + 10 - - + + - Simulation Speed + 0 - + + + + Population + + + + + + + 0 + + + + + + + true + + + 0 + + + 980 + + + 10 + + + 10 + + + 980 + + + 980 + + + Qt::Horizontal + + + false + + + false + + + QSlider::TicksBelow + + + 100 + + + + + + + Date + + + + Qt::Vertical @@ -110,16 +152,30 @@ + + + + Simulation Speed + + + - + + + Qt::Horizontal + + + + + - Advanced + Advanced Settings false - true + false @@ -210,125 +266,10 @@ - - + + - 0 - - - - - - - true - - - 0 - - - 980 - - - 10 - - - 10 - - - 980 - - - 980 - - - Qt::Horizontal - - - false - - - false - - - QSlider::TicksBelow - - - 100 - - - - - - - 0 - - - - - - - Population - - - - - - - Date - - - - - - - Qt::Horizontal - - - - - - - - - - - 5 - - - 5 - - - 5 - - - 5 - - - 5 - - - - - Qt::NoFocus - - - START - - - - - - - Qt::NoFocus - - - PAUSE - - - Space - - - true + Advanced @@ -338,12 +279,34 @@ - - - - Quit + + + toolBar - + + false + + + Qt::TopToolBarArea + + + false + + + TopToolBarArea + + + false + + + + + + + + + + true @@ -352,7 +315,65 @@ true - Control Panel + Toggle Control Panel + + + + + true + + + + :/qss_icons/rc/pause.png + :/qss_icons/rc/play.png:/qss_icons/rc/pause.png + + + PlayPause + + + <html><head/><body><p>Play / Pause</p></body></html> + + + Space + + + + + + :/qss_icons/rc/stop.png:/qss_icons/rc/stop.png + + + Stop + + + Stop this simulation + + + + + + :/qss_icons/rc/PixelWars.png:/qss_icons/rc/PixelWars.png + + + Create new simulation + + + Create new simulation + + + + + + :/qss_icons/rc/step.png:/qss_icons/rc/step.png + + + Action step + + + performs only one turn of simulation + + + Right @@ -362,26 +383,23 @@ DrawWidget QOpenGLWidget
drawwidget.h
+ + pauseEvent() + updateFPS(double,double) + addParticles() + addMesh() + resetScene() + setPaused(bool) + resetCamera() + setTimeRate(int) + setNbIterations(int) + - + + + - - actionQuit - triggered() - MainWindow - close() - - - -1 - -1 - - - 371 - 244 - - - actionControl_Panel toggled(bool) @@ -414,5 +432,21 @@ + + advancedCheckBox + toggled(bool) + advancedGroupBox + setVisible(bool) + + + 54 + 183 + + + 102 + 240 + + + diff --git a/src/pixelpipeline.cpp b/src/pixelpipeline.cpp index bf6d723..a7d2194 100644 --- a/src/pixelpipeline.cpp +++ b/src/pixelpipeline.cpp @@ -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,18 +120,21 @@ void PixelPipeline::renderGL(Scene *scene) m_toreiller->draw(m_skyboxShader); glDepthMask(GL_TRUE); - 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)); - m_renderShader->bindVec2(m_renderShader->getLocation("screenSize"), glm::vec2(m_width, m_height)); - m_renderShader->bindFloat(m_renderShader->getLocation("surfaceRatio"), m_surfaceRatio); - m_renderShader->bindFloat(m_renderShader->getLocation("flatSphere"), m_flatSphere); - m_mapTex->bind(0); - m_renderShader->bindInteger(m_renderShader->getLocation("colorMap"), 0); - - glm::mat4 mvp = m_proj * m_view; - m_renderShader->bindMat4(m_renderShader->getLocation("mvp"), mvp); - m_toreiller->draw(m_renderShader); + 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)); + m_renderShader->bindVec2(m_renderShader->getLocation("screenSize"), glm::vec2(m_width, m_height)); + m_renderShader->bindFloat(m_renderShader->getLocation("surfaceRatio"), m_surfaceRatio); + m_renderShader->bindFloat(m_renderShader->getLocation("flatSphere"), m_flatSphere); + m_mapTex->bind(0); + m_renderShader->bindInteger(m_renderShader->getLocation("colorMap"), 0); + + 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) diff --git a/src/pixelpipeline.h b/src/pixelpipeline.h index 27fd8a9..36bff88 100644 --- a/src/pixelpipeline.h +++ b/src/pixelpipeline.h @@ -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 diff --git a/src/simulationdialog.cpp b/src/simulationdialog.cpp index 0d21942..1747c2d 100644 --- a/src/simulationdialog.cpp +++ b/src/simulationdialog.cpp @@ -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) { diff --git a/src/simulationdialog.h b/src/simulationdialog.h index 6e29104..a694b5f 100644 --- a/src/simulationdialog.h +++ b/src/simulationdialog.h @@ -47,7 +47,7 @@ private: void updatePreviewPixmap(); signals: - void sendError(QString, int); + void sendError(QString); }; #endif // SIMULATIONDIALOG_H