lju/refactorize #2

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

View File

@@ -2,7 +2,7 @@
* File name: context.hpp
* Author: lejulien
* Date created: 01-01-1970 00:59:59
// Date modified: 10-01-2026 22:24:41
// Date modified: 12-01-2026 20:31:50
* ------
*/
@@ -13,11 +13,13 @@
#include <memory>
class World;
class Rules;
namespace gol {
typedef struct ctx {
std::shared_ptr<World> world = nullptr;
std::shared_ptr<Rules> rules = nullptr;
nlohmann::json config_json;
} ctx;

View File

@@ -2,7 +2,7 @@
* File name: control_menu.cpp
* Author: lejulien
* Date created: 10-01-2026 22:12:44
// Date modified: 10-01-2026 22:43:36
// Date modified: 12-01-2026 20:36:39
* ------
*/
@@ -12,6 +12,7 @@
#include <control_menu.hpp>
#include <world.hpp>
#include <rules.hpp>
namespace gol {
@@ -59,6 +60,15 @@ void ControlMenu::update() {
} else if (edit_ctrl_) {
menu_state_ = MenuState::EDIT;
}
if (step_ctrl_) {
context_.world->saveCompressed();
context_.rules->update();
step_ctrl_ = false;
}
if (step_back_ctrl_) {
context_.world->stepBack();
step_back_ctrl_ = false;
}
}
void ControlMenu::display() {

View File

@@ -2,7 +2,7 @@
* File name: main.cpp
* Author: lejulien
* Date created: 10-01-2026 21:59:32
// Date modified: 10-01-2026 22:55:11
// Date modified: 12-01-2026 20:34:37
* ------
*/
@@ -101,7 +101,7 @@ int main(int ac, char **av) {
// Initialize objects
context.world = std::make_shared<World>(context);
Rules rules = Rules();
context.rules = std::make_shared<Rules>();
Render render(context.config_json["cell_size"]);
// Imgui control menu
@@ -122,7 +122,7 @@ int main(int ac, char **av) {
std::string sel_txt_input_hint("patern name");
// Setups
rules.setup(&(*context.world));
context.rules->setup(&(*context.world));
// Diplay generations
while (!WindowShouldClose()) {
// Frames shinenigans
@@ -171,15 +171,6 @@ int main(int ac, char **av) {
if (!sel_ctrl) {
patern_name[0] = '\0';
}
if (control_menu.step_ctrl_) {
context.world->saveCompressed();
rules.update();
control_menu.step_ctrl_ = false;
}
if (control_menu.step_back_ctrl_) {
context.world->stepBack();
control_menu.step_back_ctrl_ = false;
}
if (control_menu.apply_ctrl_) {
bool resize_needed = false;
@@ -198,7 +189,7 @@ int main(int ac, char **av) {
context.world->resize(context.config_json["screen_width"].get<int>() / control_menu.cell_size_ctrl_,
context.config_json["screen_height"].get<int>() / control_menu.cell_size_ctrl_);
render.updateCellSize(control_menu.cell_size_ctrl_);
rules.newWorld(&(*context.world));
context.rules->newWorld(&(*context.world));
context.config_json["cell_size"] = control_menu.cell_size_ctrl_;
}
if (control_menu.dark_theme_ctrl_ != context.config_json["dark_theme"]) {
@@ -218,7 +209,7 @@ int main(int ac, char **av) {
deltaTimeAccumulator -= timePerUpdate;
if (control_menu.menu_state_ == MenuState::PLAY) {
context.world->saveCompressed();
rules.update();
context.rules->update();
}
}
BeginDrawing();