diff --git a/rc/pause.png b/rc/pause.png new file mode 100644 index 0000000..f01977a Binary files /dev/null and b/rc/pause.png differ diff --git a/rc/play.png b/rc/play.png new file mode 100644 index 0000000..fe080dd Binary files /dev/null and b/rc/play.png differ diff --git a/rc/step.png b/rc/step.png new file mode 100644 index 0000000..c0b90af Binary files /dev/null and b/rc/step.png differ diff --git a/rc/stop.png b/rc/stop.png new file mode 100644 index 0000000..0600ab5 Binary files /dev/null and b/rc/stop.png differ diff --git a/resources.qrc b/resources.qrc index 9ba8ca0..b68b2c3 100644 --- a/resources.qrc +++ b/resources.qrc @@ -39,6 +39,10 @@ rc/radio_unchecked_disabled.png rc/radio_unchecked_focus.png rc/radio_unchecked.png + rc/play.png + rc/step.png + rc/stop.png + rc/pause.png rc/PixelWars.png diff --git a/src/behavior.h b/src/behavior.h index 67bdb7f..298e943 100644 --- a/src/behavior.h +++ b/src/behavior.h @@ -38,16 +38,16 @@ struct Action COMMUNICATE }; + Com com_data; Type type; Dir dir; - Com com_data; }; struct Info { virtual bool getSuccess() const = 0; virtual PixelType getInventory() const = 0; - virtual const Com& getCom() const = 0; + virtual const Com* getCom() const = 0; virtual PixelType getNear(Dir d) const = 0; virtual int getInfo(Dir d) const = 0; }; diff --git a/src/dude.cpp b/src/dude.cpp index c25e4b9..7bc0b4c 100644 --- a/src/dude.cpp +++ b/src/dude.cpp @@ -37,6 +37,7 @@ void Dude::move(Dir d) void Dude::receiveComData(Dir dir, const char *data) { + m_receivedComData = true; m_com_data.flag = dir; memcpy(m_com_data.data, data, COM_SIZE); } @@ -44,6 +45,7 @@ void Dude::receiveComData(Dir dir, const char *data) void Dude::update(BehaviorFunction func) { func(&m_action, m_memory, (Info*)this); + m_receivedComData = false; } PixelType Dude::getNear(Dir d) const diff --git a/src/dude.h b/src/dude.h index 03124c2..48e8dc4 100644 --- a/src/dude.h +++ b/src/dude.h @@ -6,17 +6,18 @@ class Dude : public Info { private: + Action m_action; // action containing output com data + Com m_com_data; // input com data Coord m_pos; + char m_memory[DUDE_MEMORY_SIZE]; Map *p_map; int m_team; bool m_dead; bool m_success; + bool m_receivedComData; PixelType m_inventory; PixelType m_under; int m_underResCount; - char m_memory[DUDE_MEMORY_SIZE]; - Action m_action; // action containing output com data - Com m_com_data; // input com data public: Dude(const Coord &_pos, Map *_map, int &_team); @@ -32,7 +33,7 @@ public: virtual bool getSuccess() const { return m_success; } virtual PixelType getInventory() const { return m_inventory; } - virtual const Com& getCom() const { return m_com_data; } + virtual const Com* getCom() const { return m_receivedComData ? &m_com_data : nullptr; } virtual PixelType getNear(Dir d) const; virtual int getInfo(Dir d) const; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 870f2bc..5d97d15 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -11,7 +11,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), p_simu(NULL), - m_simSpeed(500), m_simSpeedChanged(false), m_paused(false) { @@ -27,6 +26,7 @@ MainWindow::MainWindow(QWidget *parent) : 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))); + changeSimSpeed(ui->simSpeedSlider->value()); } MainWindow::~MainWindow() @@ -55,7 +55,7 @@ void MainWindow::openSimuDialog() void MainWindow::changeSimSpeed(int newSpeed) { m_simSpeedChanged = true; - m_simSpeed = ui->simSpeedSlider->maximum()-newSpeed; + m_simSpeed = ui->simSpeedSlider->maximum()+20-newSpeed; } void MainWindow::updateSimu() diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 44dbc5e..f6de0ff 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -60,217 +60,232 @@ - - 0 - - 0 + 9 - 0 + 9 - 0 + 9 - 0 + 9 - - - 0 - - - - - 0 - 0 - 260 - 346 - + + + + 5 - - Settings - - - - - - Spherical / Flat - - - - - - - true - - - Qt::LeftToRight - - - 100 - - + + 5 + + + 5 + + + 5 + + + 8 + + + + + Simulation Speed + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Advanced + + + false + + + true + + + 5 - + 5 - - Qt::Horizontal + + 5 - - QSlider::TicksBelow + + 5 - - 10 - - - - - - - surface ratio - - - - - - - true - - - 0 - - - 100 - - - 10 - - - 10 - - - 50 - - - Qt::Horizontal - - - QSlider::TicksBelow - - - 10 - - - - - - - Simulation Speed - - - - - - - true - - - 100 - - - 2000 - - - 100 - - - 100 - - - 2000 - - - 2000 - - - Qt::Horizontal - - - false - - - false - - - QSlider::TicksBelow - - - 100 - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - 0 - 0 - 260 - 346 - - - - Stats - - - - - - Date - - - - - - - 0 - - - - - - - Population - - - - - - - 0 - - - - - + + + + Spherical / Flat + + + + + + + true + + + Qt::LeftToRight + + + 100 + + + 5 + + + 5 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 10 + + + + + + + surface ratio + + + + + + + true + + + 0 + + + 100 + + + 10 + + + 10 + + + 50 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 10 + + + + + + + + + + 0 + + + + + + + true + + + 0 + + + 980 + + + 10 + + + 10 + + + 980 + + + 980 + + + Qt::Horizontal + + + false + + + false + + + QSlider::TicksBelow + + + 100 + + + + + + + 0 + + + + + + + Population + + + + + + + Date + + + + + + + Qt::Horizontal + + + + @@ -301,19 +316,6 @@ - - - - false - - - Qt::NoFocus - - - STOP - - -