first iteration of interface refactoring

This commit is contained in:
Anselme 2016-06-02 17:41:46 +02:00
parent 807162bb0f
commit 38cde0d571
10 changed files with 225 additions and 216 deletions

BIN
rc/pause.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
rc/play.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
rc/step.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
rc/stop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -39,6 +39,10 @@
<file>rc/radio_unchecked_disabled.png</file> <file>rc/radio_unchecked_disabled.png</file>
<file>rc/radio_unchecked_focus.png</file> <file>rc/radio_unchecked_focus.png</file>
<file>rc/radio_unchecked.png</file> <file>rc/radio_unchecked.png</file>
<file>rc/play.png</file>
<file>rc/step.png</file>
<file>rc/stop.png</file>
<file>rc/pause.png</file>
<file>rc/PixelWars.png</file> <file>rc/PixelWars.png</file>
</qresource> </qresource>
<qresource prefix="qdarkstyle"> <qresource prefix="qdarkstyle">

View File

@ -38,16 +38,16 @@ struct Action
COMMUNICATE COMMUNICATE
}; };
Com com_data;
Type type; Type type;
Dir dir; Dir dir;
Com com_data;
}; };
struct Info struct Info
{ {
virtual bool getSuccess() const = 0; virtual bool getSuccess() const = 0;
virtual PixelType getInventory() 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 PixelType getNear(Dir d) const = 0;
virtual int getInfo(Dir d) const = 0; virtual int getInfo(Dir d) const = 0;
}; };

View File

@ -37,6 +37,7 @@ void Dude::move(Dir d)
void Dude::receiveComData(Dir dir, const char *data) void Dude::receiveComData(Dir dir, const char *data)
{ {
m_receivedComData = true;
m_com_data.flag = dir; m_com_data.flag = dir;
memcpy(m_com_data.data, data, COM_SIZE); 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) void Dude::update(BehaviorFunction func)
{ {
func(&m_action, m_memory, (Info*)this); func(&m_action, m_memory, (Info*)this);
m_receivedComData = false;
} }
PixelType Dude::getNear(Dir d) const PixelType Dude::getNear(Dir d) const

View File

@ -6,17 +6,18 @@
class Dude : public Info class Dude : public Info
{ {
private: private:
Action m_action; // action containing output com data
Com m_com_data; // input com data
Coord m_pos; Coord m_pos;
char m_memory[DUDE_MEMORY_SIZE];
Map *p_map; Map *p_map;
int m_team; int m_team;
bool m_dead; bool m_dead;
bool m_success; bool m_success;
bool m_receivedComData;
PixelType m_inventory; PixelType m_inventory;
PixelType m_under; PixelType m_under;
int m_underResCount; 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: public:
Dude(const Coord &_pos, Map *_map, int &_team); Dude(const Coord &_pos, Map *_map, int &_team);
@ -32,7 +33,7 @@ public:
virtual bool getSuccess() const { return m_success; } virtual bool getSuccess() const { return m_success; }
virtual PixelType getInventory() const { return m_inventory; } 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 PixelType getNear(Dir d) const;
virtual int getInfo(Dir d) const; virtual int getInfo(Dir d) const;
}; };

View File

@ -11,7 +11,6 @@ MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow), ui(new Ui::MainWindow),
p_simu(NULL), p_simu(NULL),
m_simSpeed(500),
m_simSpeedChanged(false), m_simSpeedChanged(false),
m_paused(false) m_paused(false)
{ {
@ -27,6 +26,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->flatSphereSlider, SIGNAL(valueChanged(int)), ui->drawWidget, SLOT(repaint())); connect(ui->flatSphereSlider, SIGNAL(valueChanged(int)), ui->drawWidget, SLOT(repaint()));
connect(ui->surfaceRatioSlider, 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->pauseButton, SIGNAL(toggled(bool)), this, SLOT(pauseSimu(bool)));
changeSimSpeed(ui->simSpeedSlider->value());
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -55,7 +55,7 @@ void MainWindow::openSimuDialog()
void MainWindow::changeSimSpeed(int newSpeed) void MainWindow::changeSimSpeed(int newSpeed)
{ {
m_simSpeedChanged = true; m_simSpeedChanged = true;
m_simSpeed = ui->simSpeedSlider->maximum()-newSpeed; m_simSpeed = ui->simSpeedSlider->maximum()+20-newSpeed;
} }
void MainWindow::updateSimu() void MainWindow::updateSimu()

View File

@ -60,47 +60,88 @@
</attribute> </attribute>
<widget class="QWidget" name="dockWidgetContents"> <widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>9</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>9</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>9</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>9</number>
</property> </property>
<item> <item>
<widget class="QToolBox" name="toolBox"> <widget class="QWidget" name="widget_2" native="true">
<property name="currentIndex"> <layout class="QGridLayout" name="gridLayout_2">
<number>0</number> <property name="leftMargin">
<number>5</number>
</property> </property>
<widget class="QWidget" name="page_5"> <property name="topMargin">
<property name="geometry"> <number>5</number>
<rect>
<x>0</x>
<y>0</y>
<width>260</width>
<height>346</height>
</rect>
</property> </property>
<attribute name="label"> <property name="rightMargin">
<string>Settings</string> <number>5</number>
</attribute> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <property name="bottomMargin">
<item> <number>5</number>
</property>
<property name="spacing">
<number>8</number>
</property>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Simulation Speed</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="3">
<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>
<item row="9" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Advanced</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<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 row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Spherical / Flat</string> <string>Spherical / Flat</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="1">
<widget class="QSlider" name="flatSphereSlider"> <widget class="QSlider" name="flatSphereSlider">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
@ -128,14 +169,14 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="1" column="0">
<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> <item row="1" column="1">
<widget class="QSlider" name="surfaceRatioSlider"> <widget class="QSlider" name="surfaceRatioSlider">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
@ -166,35 +207,38 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> </layout>
<widget class="QLabel" name="label_3"> </widget>
</item>
<item row="7" column="1" colspan="2">
<widget class="QLabel" name="populationLabel">
<property name="text"> <property name="text">
<string>Simulation Speed</string> <string>0</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="4" column="1" colspan="2">
<widget class="QSlider" name="simSpeedSlider"> <widget class="QSlider" name="simSpeedSlider">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="minimum"> <property name="minimum">
<number>100</number> <number>0</number>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>2000</number> <number>980</number>
</property> </property>
<property name="singleStep"> <property name="singleStep">
<number>100</number> <number>10</number>
</property> </property>
<property name="pageStep"> <property name="pageStep">
<number>100</number> <number>10</number>
</property> </property>
<property name="value"> <property name="value">
<number>2000</number> <number>980</number>
</property> </property>
<property name="sliderPosition"> <property name="sliderPosition">
<number>2000</number> <number>980</number>
</property> </property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -213,65 +257,36 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="5" column="1" colspan="2">
<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">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>260</width>
<height>346</height>
</rect>
</property>
<attribute name="label">
<string>Stats</string>
</attribute>
<layout class="QFormLayout" name="formLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Date</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="dateLabel"> <widget class="QLabel" name="dateLabel">
<property name="text"> <property name="text">
<string>0</string> <string>0</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="7" column="0">
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="label_6">
<property name="text"> <property name="text">
<string>Population</string> <string>Population</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="5" column="0">
<widget class="QLabel" name="populationLabel"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">
<string>0</string> <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> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget>
</item> </item>
<item> <item>
<widget class="QWidget" name="widget" native="true"> <widget class="QWidget" name="widget" native="true">
@ -301,19 +316,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="stopButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>STOP</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="pauseButton"> <widget class="QPushButton" name="pauseButton">
<property name="focusPolicy"> <property name="focusPolicy">