lju/refactorize #2

Merged
lejulien merged 11 commits from lju/refactorize into main 2026-01-13 13:50:59 +00:00
4 changed files with 11 additions and 10 deletions
Showing only changes of commit c00c430382 - Show all commits

View File

@@ -12,7 +12,7 @@
#include <memory>
#include <world.hpp>
class World;
namespace gol {

View File

@@ -13,7 +13,8 @@
#include <time.h>
#include <vector>
#include "../includes/types.hpp"
#include <types.hpp>
#include <context.hpp>
#pragma once
@@ -22,7 +23,7 @@
class World {
public:
World(int width, int height);
World(gol::ctx &ctx);
~World();
std::vector<bool> *getWorldData();

View File

@@ -101,11 +101,7 @@ int main(int ac, char **av) {
RenderTexture2D selectionTexture = LoadRenderTexture(200, 200);
// Initialize objects
context.world = std::make_shared<World>(
context.config_json["screen_width"].get<int>() /
context.config_json["cell_size"].get<int>(),
context.config_json["screen_height"].get<int>() /
context.config_json["cell_size"].get<int>());
context.world = std::make_shared<World>(context);
Rules rules = Rules();
Render render(context.config_json["cell_size"]);

View File

@@ -12,9 +12,13 @@
// Constructor and destructor
World::World(int width, int height) : _width(width), _height(height) {
World::World(gol::ctx &context) {
_width = context.config_json["screen_width"].get<int>() /
context.config_json["cell_size"].get<int>();
_height = context.config_json["screen_height"].get<int>() /
context.config_json["cell_size"].get<int>();
// create world data
this->_data = new std::vector<bool>(width * height, false);
this->_data = new std::vector<bool>(_width * _height, false);
}
World::~World() { delete this->_data; }