-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrid.h
69 lines (55 loc) · 1.62 KB
/
Grid.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
#pragma once
#include <SDL.h>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
/* one pixel on the grid
current represents what the value of the pixel is currently
sync represents what the pixel will be after a grid evaluation
in this rework we want the pixel to be as light as possible
the grid will handle these changes and drawing to reduce weight */
struct Pixel {
bool current = 0;
bool sync = 0;
Pixel() {
current = sync = 0;
}
};
class Grid {
protected:
int gridSize; // grid will be square
int pixelSize; //size of a displayed pixel of the grid
Pixel ***pixel; // 2d array of pointers
void freeGrid(); //deallocate pixel array
SDL_Thread *riser;
SDL_Thread *faller;
int safeN(int n); //modulo math to ensure n is in the array
//single threaded solution, smaller grids
void planMove();//sets the sync bit
void updateGrid();//cp sync bit to current bit
int updateThreaded();
//double threaded solution faster for exceptionally large grids
static int startRiserPlan(void *self);
static int startRiserUpdate(void *self);
static int startFallerPlan(void *self);
static int startFallerUpdate(void *self);
int neighbors(int x, int y);
bool pixelCheck(int x, int y); //check nullptrs
public:
Grid(int gridSize = 4, int pixelSize = 2);
Grid(const Grid &g);
~Grid();
void draw(SDL_Renderer *ren);
void update(bool threaded = false);
size_t me();
bool isEmpty();
int count();
void setState(int x, int y, bool val);
void setState(vector<pair<int, int> > sc);
void clear();
vector<pair<int, int> > getCoords();
void printCoords();
bool isAlive(int x, int y);
bool operator==(Grid g);
};