-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcave_gen.h
170 lines (141 loc) · 4.13 KB
/
cave_gen.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
166
167
168
169
170
#ifndef CAVEGEN_H
#define CAVEGEN_H
#include "grid.h"
#include "sim_cell_data.h"
#include <QObject>
#include <mutex>
/*
* Generates 2D caves trough the use of cellular automata.
*/
class CaveGenerator : public QObject {
Q_OBJECT
public:
/*
* Neighbourhood types.
*/
enum Mode { MOORE, NEUMANN };
/*
* Creates a cave generator with the following parameters:
* - seed: seed for the initial configuration;
* - rockRatio: ratio of rocks in the initial configuration;
* - threshold: number of rock neighbours for a cell to turn into a rock;
* - steps: number of iterations;
* - radius: radius of the neighbourhood to consider.
*/
CaveGenerator(int seed = 0, int rockRatio = 60, int threshold = 5,
int steps = 8, int radius = 1);
/*
* Returns the seed parameter.
*/
int getSeed() const { return m_seed; }
/*
* Returns a pair containing the minimum and maximum values for the seed
* parameter.
*/
std::pair<int, int> getSeedRange() const { return {INT_MIN, INT_MAX}; }
/*
* Returns the threshold parameter.
*/
int getThreshold() const { return m_threshold; }
/*
* Returns a pair containing the minimum and maximum values for the threshold
* parameter.
*/
std::pair<int, int> getThresholdRange() const { return {0, INT_MAX}; }
/*
* Returns the rockRatio parameter.
*/
int getRockRatio() const { return m_rockRatio; }
/*
* Returns a pair containing the minimum and maximum values for the rockRatio
* parameter.
*/
std::pair<int, int> getRockRatioRange() const { return {0, 100}; }
/*
* Returns the steps parameter.
*/
int getSteps() const { return m_steps; }
/*
* Returns a pair containing the minimum and maximum values for the steps
* parameter.
*/
std::pair<int, int> getStepsRange() const { return {0, INT_MAX}; }
/*
* Returns the radius parameter.
*/
int getRadius() const { return m_radius; }
/*
* Returns a pair containing the minimum and maximum values for the radius
* parameter.
*/
std::pair<int, int> getRadiusRange() const { return std::pair{0, INT_MAX}; }
/*
* Sets the seed to `seed`.
*/
void setSeed(int seed) { m_seed = seed; }
/*
* Sets the threshold parameter to `threshold`.
*/
void setThreshold(int threshold) { m_threshold = threshold; }
/*
* Sets the rock ratio parameter to `rockRatio`.
*/
void setRockRatio(int rockRatio) { m_rockRatio = rockRatio; }
/*
* Sets the steps parameter to `steps`.
*/
void setSteps(int steps) { m_steps = steps; }
/*
* Sets the radius parameter to `radius`.
*/
void setRadius(int radius) { m_radius = radius; }
/*
* Resets all parameters to their default values.
*/
void resetParams();
public slots:
/*
* Generates a new cave based on the generator's parameters.
* Once the cave is ready, it is broadcasted through a `caveReady` signal
*/
void generateCave(int rows, int cols);
/*
* Sets the neighbourhood type to MOORE.
*/
void setMooreMode(bool checked) {
if (checked)
m_mode = MOORE;
}
/*
* Sets the neighbourhood type to NEUMANN.
*/
void setNeumannMode(bool checked) {
if (checked)
m_mode = NEUMANN;
}
signals:
void gridReady(Grid<SimCellData> grid);
private:
int m_seed; // Seed for the initial configuration
int m_rockRatio; // Amount of rocks in the initial configuration
int m_threshold; // Rock threshold for the evolution rule
int m_steps; // Number of iteration steps
Mode m_mode = MOORE; // Neighbourhood mode
int m_radius; // Neighbourhood radius
/*
* Sets up the initial state of `grid`, randomly assigning a state to
* each cell based on the results of a random number generator seeded with
* `m_seed` and the ratio `m_rockRatio`, which decides the likeliness of a
* cell to be initialized as rock
*/
void initialize(Grid<SimCellData> &grid);
/*
* Performs one step of the CA simulation on `grid`
*/
void step(Grid<SimCellData> &grid);
/*
* Performs `m_steps` steps of the CA simulation on `m_grid`
*/
void simulate(Grid<SimCellData> &grid);
};
#endif