52 lines
905 B
C++
52 lines
905 B
C++
#pragma once
|
|
#ifndef _NB_GRID
|
|
#define _NB_GRID
|
|
|
|
#include <exception>
|
|
|
|
#include "Draw.h"
|
|
|
|
namespace NB{
|
|
|
|
class ConwayGridError : std::runtime_error {
|
|
public:
|
|
ConwayGridError(const std::string&);
|
|
};
|
|
|
|
struct Vec2 {
|
|
float x;
|
|
float y;
|
|
};
|
|
|
|
enum Cell : unsigned char {
|
|
Dead = 0,
|
|
Alive = 1
|
|
};
|
|
|
|
class ConwayGrid {
|
|
public:
|
|
typedef std::vector<std::vector<Cell>> CellGrid;
|
|
|
|
ConwayGrid(const Shader&, unsigned int m=2, unsigned int n=2, Vec2 bl={-1, -1}, Vec2 tr={1, 1});
|
|
|
|
CellGrid getCells() const;
|
|
|
|
void setCells(const CellGrid&);
|
|
Cell& at(unsigned int, unsigned int);
|
|
void calcNext();
|
|
void sendCells();
|
|
void draw();
|
|
void click(double, double);
|
|
|
|
private:
|
|
unsigned int _m, _n;
|
|
Vec2 _bl, _tr, _cell_size;
|
|
std::vector<float> _cell_verts;
|
|
std::vector<float> _cell_offsets;
|
|
DrawInstanceBuffer _buffer;
|
|
CellGrid _cells;
|
|
};
|
|
|
|
}
|
|
|
|
#endif |