I'm writing a Conway's game of Life simulator for the Arduino. The Arduino environment is kind-of C++, but with static memory allocation only (no new
, no malloc()
and no STL.)
class Life {
private:
uint8_t hue;
uint8_t currState[WIDTH][HEIGHT];
uint8_t nextState[WIDTH][HEIGHT];
public:
void draw() {
// Update the nextState array with the next generation
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
nextState[x][y] = alive(x, y) ? hue++ : 0;
}
}
// Copy nextState into leds array
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
pixel(x, y) = CHSV(nextState[x][y], 255, 255);
}
}
// make nextState our new currentState, ready for the next generation
uint8_t tempState[][] = currState;
currState = nextState;
nextState = tempState;
};
//...
};
I'm getting a compilation error on both the declaration of tempState and the last line:
Array has incomplete element type 'uint8_t []'
Array type 'uint8_t [36][20]' is not assignable
Now, I know that in C/C++, "an array is just a pointer to the first element of the array", but the compiler does not seem to agree. What is the magic declaration that will allow me to alias currState
to nextState
for the next iteration of my draw()
method?