21 static constexpr
size_t ScreenWidth = 800;
22 static constexpr
size_t ScreenHeight = 480;
23 static constexpr
size_t PixelSize = 5;
24 static constexpr
size_t BoardWidth = ScreenWidth / PixelSize;
25 static constexpr
size_t BoardHeight = ScreenHeight / PixelSize;
49 "1: 7; 2: 5 7 8; 3: 5 7; 4: 5; 5: 3; 6: 1 3;" 55 "1: 1 2 3 5; 2: 1; 3: 4 5; 4: 2 3 5; 5: 1 3 5;" 61 "1:2; 2:4; 3:1 2 5 6 7;" 67 "1:25; 2:23 25; 3:13 14 21 22 35 36; 4:12 16 21 22 35 36; 5:1 2 11 17 21 22;" 68 "6:1 2 11 15 17 18 23 25; 7:11 17 25; 8:12 16; 9:13 14;" 74 "1:3 4 5; 2:3 5; 3:3 5; 4:4; 5:1 3 4 5; 6: 2 4 6; 7:5; 8:3 5; 9:3 5;" 91 void setState(
State newState) { state = newState; age = 0; }
96 std::mutex boardLock{};
97 rose::SignalSerialNumber mSignalSerialNumber{};
99 std::unique_ptr<Cell[]> board{};
100 size_t mBoardWidth{}, mBoardHeight{}, mCellPixels{}, mArrayLen{}, mGeneration{};
102 Cell& at(
size_t x,
size_t y) {
103 size_t l = y * mBoardWidth + x;
105 return board.get()[l];
107 throw std::range_error(
"Board co-ordinates out of range.");
110 Cell& check(
size_t x,
size_t y) {
111 if (x < mBoardWidth && y < mBoardHeight)
114 throw std::range_error(
"Board co-ordinates out of range.");
120 Board(
size_t screenWidth,
size_t screenHeight,
size_t cellSize,
size_t boardWidth,
size_t boardHeight);
122 ~
Board()
override =
default;
128 void initializeComposite()
override;
131 return rose::Rectangle{0, 0, (int)(mBoardWidth * mCellPixels), (int)(mBoardHeight * mCellPixels)};
138 size_t countCell(
int x,
int y);
140 std::shared_ptr<rose::Slot<uint32_t>> mTimerRx;
166 std::shared_ptr<rose::Button> mExit{},
173 std::shared_ptr<rose::Label> mGeneration{};
174 std::shared_ptr<rose::Slider> mSlider{};
177 std::shared_ptr<rose::Slot<rose::Button::SignalType>> mButtonRx;
178 std::shared_ptr<rose::Slot<rose::Slider::SignalType>> mRateRx;
180 std::shared_ptr<Board> mBoard{};
186 ConwayLife(
int argc,
char **argv,
const std::string_view title) : rose::Rose(
rose::Size{800, 480},
187 argc, argv, title), mTimer(1000) {
188 if (mCmdLineParser.cmdOptionExists(
"-rate")) {
189 mTimer.setInterval(std::strtoul(mCmdLineParser.getCmdOption(
"-rate").c_str(),
nullptr, 10));
192 if (mCmdLineParser.cmdOptionExists(
"-pattern")) {
193 auto pattern = mCmdLineParser.getCmdOption(
"-pattern");
194 if (pattern ==
"gun")
195 mStartPattern = GosperGliderGun;
196 else if (pattern ==
"acorn")
197 mStartPattern = Acorn;
198 else if (pattern ==
"switch1")
199 mStartPattern = Switch1;
200 else if (pattern ==
"switch2")
201 mStartPattern = Switch2;
202 else if (pattern ==
"tribute")
203 mStartPattern = Tribute;
205 std::cout <<
"Available patterns are: gun, acorn, switch1, switch2\n";
std::string_view data
A string encoding the initial pattern.
Definition: ConwayLife.h:43
Exit the application.
Definition: ConwayLife.h:151
PatternOrigin origin
The general origin of the pattern.
Definition: ConwayLife.h:37
State
The state of a cell.
Definition: ConwayLife.h:80
Cell is empty.
Definition: ConwayLife.h:81
uint32_t SignalToken
A type definition for SignalToken used to identify the source of a Signal.
Definition: Types.h:53
Cell is dead on the next generation.
Definition: ConwayLife.h:83
Definition: ConwayLife.h:36
The value that can be used for the first SignalToken of a user application.
Definition: Constants.h:61
Centered on the board.
Definition: ConwayLife.h:33
Definition: ConwayLife.h:159
Definition: ConwayLife.h:94
rose::Size boardSize
The size of the board in cells.
Definition: ConwayLife.h:39
A position in integer (x, y) co-ordinates.
Definition: Types.h:95
Constants and Enumerations.
Bottom left corner of the board.
Definition: ConwayLife.h:32
Cell is alive on the next generation.
Definition: ConwayLife.h:84
Cell is living.
Definition: ConwayLife.h:82
Restart with the Switch1 pattern.
Definition: ConwayLife.h:154
size_t pixelSize
The size of the square pixels that represent cells.
Definition: ConwayLife.h:38
rose::Position delay
The delay in generations before automatic scrolling.
Definition: ConwayLife.h:41
PatternOrigin
Set the general location of the pattern initialization.
Definition: ConwayLife.h:30
Top left corner of the board.
Definition: ConwayLife.h:31
UserSignalTokenValues
Signal tokens used to identify which button was pressed.
Definition: ConwayLife.h:150
Definition: ConwayLife.h:87
A composite of a Position and a Size.
Definition: Types.h:307
rose::Position offset
The off set from origin to place the initial pattern in. Corrects for pattern size.
Definition: ConwayLife.h:40
Conway's Tribute pattern.
Definition: ConwayLife.h:156
Written as a workaround for an issue in the SDL2 Library.
Definition: Renderer.h:64
A size in integer dimensions.
Definition: Types.h:230
Restart with the Gosner Glider Gun pattern.
Definition: ConwayLife.h:152
rose::Position velocity
The velocity and direction of automatic scrolling in generations per cell.
Definition: ConwayLife.h:42
Restart with the Switch2 pattern.
Definition: ConwayLife.h:155
Establish an intra-application signaling protocol.
Restart with the Acorn pattern.
Definition: ConwayLife.h:153