Copying from gitlab
This commit is contained in:
29
includes/render.hpp
Normal file
29
includes/render.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* / ) */
|
||||
/* render.hpp (\__/) ( ( */
|
||||
/* ) ( ) ) */
|
||||
/* By: lejulien <leo.julien.42@gmail.com> ={ }= / / */
|
||||
/* ) `-------/ / */
|
||||
/* Created: 2023/01/09 12:44:54 by lejulien ( / */
|
||||
/* Updated: 2023/01/14 16:51:15 by lejulien \ | */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "world.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
class Render {
|
||||
public:
|
||||
// Constructor
|
||||
Render(int cell_size);
|
||||
|
||||
// Member function
|
||||
void display(World *world);
|
||||
void updateCellSize(int new_size);
|
||||
|
||||
private:
|
||||
void display_world(std::vector<bool> *data, int width, int height);
|
||||
int cell_size_;
|
||||
};
|
||||
35
includes/rules.hpp
Normal file
35
includes/rules.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* / ) */
|
||||
/* rules.hpp (\__/) ( ( */
|
||||
/* ) ( ) ) */
|
||||
/* By: lejulien <leo.julien.42@gmail.com> ={ }= / / */
|
||||
/* ) `-------/ / */
|
||||
/* Created: 2023/01/09 12:16:47 by lejulien ( / */
|
||||
/* Updated: 2023/01/14 16:47:04 by lejulien \ | */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "world.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
class Rules {
|
||||
private:
|
||||
void ortho_neighbors(int &neighbors, int i, int j);
|
||||
void diag_neighbors(int &neighbors, int i, int j);
|
||||
bool is_alive(int i, int j);
|
||||
void offset_coord(int &i, int &j);
|
||||
|
||||
public:
|
||||
Rules();
|
||||
void setup(World *world);
|
||||
void newWorld(World *world);
|
||||
void update();
|
||||
|
||||
private:
|
||||
World *_world;
|
||||
std::vector<bool> _buffer;
|
||||
int _width;
|
||||
int _height;
|
||||
};
|
||||
12
includes/types.hpp
Normal file
12
includes/types.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
enum class MenuState {
|
||||
NONE,
|
||||
PLAY,
|
||||
EDIT,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
} Vector2i;
|
||||
45
includes/world.hpp
Normal file
45
includes/world.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
|
||||
#include "../includes/types.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MAX_HISTORY_SIZE 100
|
||||
|
||||
class World {
|
||||
|
||||
public:
|
||||
World(int width, int height);
|
||||
~World();
|
||||
|
||||
std::vector<bool> *getWorldData();
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
void randomize();
|
||||
void saveCompressed();
|
||||
size_t getCycle() const { return _cycle_index; }
|
||||
void stepBack();
|
||||
void clear();
|
||||
void setCell(int x, int y);
|
||||
void resize(int width, int height); // destructive
|
||||
std::vector<uint32_t> getSelection(Vector2i &origin, Vector2i &size);
|
||||
|
||||
// Private members
|
||||
private:
|
||||
std::vector<uint32_t> getCompressed();
|
||||
void loadCompressed(const std::vector<uint32_t> &compressed);
|
||||
|
||||
std::vector<bool> *_data;
|
||||
size_t _cycle_index = 0;
|
||||
std::vector<std::vector<uint32_t>> _history = {};
|
||||
|
||||
// Private data
|
||||
private:
|
||||
int _width;
|
||||
int _height;
|
||||
};
|
||||
Reference in New Issue
Block a user