Conway's game of life simulator made in SkeletonGL & C++ with a focus on performance
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

63 lines
1.6 KiB

// Author: XENOBYTE.XYZ
// License: MIT License
// Website: https://xenobyte.xyz/projects/?nav=skeletongl
#ifndef CELL_AUTO_SIMULATION_HPP
#define CELL_AUTO_SIMULATION_HPP
#include <iostream>
#include <vector>
#include <thread>
#include <cstdint>
#include "skeletonGL/skeletonGL.hpp"
enum class SIMULATIONS : std::uint8_t
{
SIM_1 = 0,
SIM_2 = 1,
SIM_3 = 2,
END_ENUM = 3
};
const std::uint16_t SIMULATION_WIDTH = 100;
const std::uint16_t SIMULATION_HEIGHT = 100;
class CellAutoSimulation
{
private:
std::vector<std::pair<std::uint16_t, std::uint16_t>> _cellsToRender;
std::array<std::uint16_t, SIMULATION_WIDTH*SIMULATION_HEIGHT> _simulation, _simulationDelta;
bool _simulationStarted;
std::uint64_t _iterations;
public:
CellAutoSimulation();
void update();
void setCell(std::uint16_t x, std::uint16_t y, std::string str);
//std::uint8_t getCellStatus(std::uint16_t x, std::uint16_t y);
// Get the active cells positions, this COPIES the internal vector
// and thus the process can be notoriously slow depending on the
// dimensions of the simulation
std::vector<std::pair<std::uint16_t, std::uint16_t>> cellsToRender();
// Returns a copy of the array populated by setCell(), call right after
// generating the array to get the simulation's inital values or "seed"
std::array<std::uint16_t, SIMULATION_WIDTH*SIMULATION_HEIGHT> getArrayValues();
std::pair<std::uint16_t, std::uint16_t> getActiveCell(std::uint16_t cellID);
std::uint16_t getTotalActiveCells();
std::uint64_t getIterations();
void clearActiveCells();
void resetSimulation();
};
#endif