-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_window.h
165 lines (135 loc) · 3.21 KB
/
main_window.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ant_sim.h"
#include "cave_gen.h"
#include "custom_graphics_scene.h"
#include <QGraphicsScene>
#include <QMainWindow>
#include <QThread>
#include <QTimer>
#include <mutex>
/*
* Main GUI class.
*/
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
/*
* Ask the cave generator for a new cave.
*/
void onNewCaveRequested();
/*
* Ask the simulator to perform initialization.
*/
void onSimInitRequested();
/*
* Ask the simulator to start the simulation.
*/
void onSimStartRequested();
/*
* Ask the simulator to stop the simulation.
*/
void onSimStopRequested();
/*
* Allow the user to initialize the simulation.
*/
void allowSimInit();
/*
* Allow the user to start and stop the simulation.
*/
void allowSimControl();
/*
* Prevent the user from starting or stopping the simulation.
*/
void revokeSimControl();
/*
* Set the simulation speed based on `speed`.
*/
void setSimSpeed(int speed);
/*
* Draw the cave.
*/
void onCaveReady(Grid<SimCellData> grid);
/*
* Draw the simulation grid.
*/
void onSimReady(Grid<SimCellData> grid);
/*
* Pass the clicked cell coordinates to the simulator.
*/
void onCanvasClick(QPointF coords);
/*
* Update food counters.
*/
void onFoodUpdated(int delivered, int total);
/*
* Update zoom level.
*/
void updateZoom();
/*
* Reset the generator's parameters to their defaults.
*/
void resetGenParams();
/*
* Reset the simulator's parameters to their defaults.
*/
void resetSimParams();
signals:
/*
* Emitted when a new cave is requested.
*/
void startCaveGeneration(int rows, int cols);
/*
* Emitted when the initialization of the simulator is requested.
*/
void initializeSim();
/*
* Emitted on each simulation update.
*/
void performSimStep();
/*
* Emitted on canvas click.
*/
void cellClicked(int x, int y);
private:
Ui::MainWindow *m_gui; // Class responsible for the GUI
CustomGraphicsScene *m_scene; // Scene depicted in the canvas
CaveGenerator m_gen; // Cave generator object
AntSimulator m_sim; // Ant simulator object
int m_simSpeed = 5; // Simulation speed
QTimer *m_timer; // Simulation timer
int m_cols = 128; // Number of grid columns
int m_rows = 64; // Number of grid rows
int m_cellSide = 1; // Width of grid cells, in pixels
QThread m_genWorker; // Cave generation thread
QThread m_simWorker; // Population simulation thread
/*
* Connect the GUI items' signals to the relative slots.
*/
void connectSlots();
/*
* Set up the GUI elements.
*/
void prepareGUI();
/*
* Set the GUI parameters for cave generation to their defaults.
*/
void setGenGUIParams();
/*
* Set the GUI parameters for ant simulation to their defaults.
*/
void setSimGUIParams();
/*
* Draw the grid on the canvas.
*/
void drawGrid(Grid<SimCellData> grid);
};
#endif // MAINWINDOW_H