Comments and minor fix
This commit is contained in:
parent
8015d16dac
commit
75588b85cd
9
main.cpp
9
main.cpp
@ -6,6 +6,9 @@
|
|||||||
#define DEAD_CELL 0 // '.' in the input data
|
#define DEAD_CELL 0 // '.' in the input data
|
||||||
#define NUM_GENERATIONS 250
|
#define NUM_GENERATIONS 250
|
||||||
|
|
||||||
|
// Using this struct seems to be more performant than just passing
|
||||||
|
// a bool** around functions. However, also adding the neighbor_count
|
||||||
|
// made performance worse.
|
||||||
struct World {
|
struct World {
|
||||||
World(int size_x, int size_y) : size_x(size_x), size_y(size_y) {
|
World(int size_x, int size_y) : size_x(size_x), size_y(size_y) {
|
||||||
data = new bool*[size_y];
|
data = new bool*[size_y];
|
||||||
@ -154,15 +157,15 @@ int main() {
|
|||||||
|
|
||||||
world_file.close();
|
world_file.close();
|
||||||
|
|
||||||
timing->stopSetup();
|
|
||||||
timing->startComputation();
|
|
||||||
|
|
||||||
// In this separate array, we keep track of how many live neighbors
|
// In this separate array, we keep track of how many live neighbors
|
||||||
// a certain cell has. This is because immediately updating based
|
// a certain cell has. This is because immediately updating based
|
||||||
// on the number of neighbors would mess with later calculations
|
// on the number of neighbors would mess with later calculations
|
||||||
// of adjacent cells.
|
// of adjacent cells.
|
||||||
int *neighbor_counts = new int[world.size_y * world.size_x];
|
int *neighbor_counts = new int[world.size_y * world.size_x];
|
||||||
|
|
||||||
|
timing->stopSetup();
|
||||||
|
timing->startComputation();
|
||||||
|
|
||||||
// Do some generations
|
// Do some generations
|
||||||
for (int i = 0; i < NUM_GENERATIONS; i++) {
|
for (int i = 0; i < NUM_GENERATIONS; i++) {
|
||||||
generation(world, neighbor_counts);
|
generation(world, neighbor_counts);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user