diff --git a/CMakeLists.txt b/CMakeLists.txt index e6ba3e8..4f2ff7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(lilfbtf5 VERSION 0.1.37) +project(lilfbtf5 VERSION 0.1.38) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) diff --git a/include/lilfbtf/tree.h b/include/lilfbtf/tree.h index 3fcc798..484896e 100644 --- a/include/lilfbtf/tree.h +++ b/include/lilfbtf/tree.h @@ -66,8 +66,8 @@ namespace fb [[nodiscard]] inline function_id getFunction() const { return function; } - inline void call(blt::span args) - { func(*this, args); }; + inline void call(blt::span args, blt::unsafe::buffer_any_t extra_args) + { func({*this, args, extra_args}); }; ~func_t() = default; }; @@ -99,9 +99,9 @@ namespace fb children[i] = nullptr; } - inline void evaluate() + inline void evaluate(blt::unsafe::buffer_any_t extra_args) { - type.call(blt::span{children, type.argc()}); + type.call(blt::span{children, type.argc()}, extra_args); } inline blt::unsafe::any_t value() @@ -173,7 +173,7 @@ namespace fb static tree_t make_tree(detail::tree_construction_info_t tree_info, blt::size_t min_depth, blt::size_t max_depth, std::optional starting_type = {}); - detail::tree_eval_t evaluate(const fitness_eval_func_t& fitnessEvalFunc); + detail::tree_eval_t evaluate(blt::unsafe::buffer_any_t extra_args, const fitness_eval_func_t& fitnessEvalFunc); blt::size_t depth(); diff --git a/libs/BLT b/libs/BLT index 16641a2..1256ec2 160000 --- a/libs/BLT +++ b/libs/BLT @@ -1 +1 @@ -Subproject commit 16641a27cbe6fccb8f6a6518d903432311cbeb81 +Subproject commit 1256ec201cdb3a8d3d9bb4ebe9c25637a718465e diff --git a/src/tree.cpp b/src/tree.cpp index b683811..acc96b0 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -63,7 +63,7 @@ namespace fb return tree; } - detail::tree_eval_t tree_t::evaluate(const fitness_eval_func_t& fitnessEvalFunc) + detail::tree_eval_t tree_t::evaluate(blt::unsafe::buffer_any_t extra_args, const fitness_eval_func_t& fitnessEvalFunc) { using detail::node_t; std::stack nodes; @@ -83,7 +83,7 @@ namespace fb while (!node_stack.empty()) { - node_stack.top()->evaluate(); + node_stack.top()->evaluate(extra_args); node_stack.pop(); } diff --git a/tests/src/main.cpp b/tests/src/main.cpp index 563dd0e..dd2b14d 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -25,36 +25,6 @@ struct pixel const blt::size_t image_width = 128, image_height = 128; -struct pixelator_t -{ - private: - blt::size_t width, height; - blt::size_t x = 0, y = 0; - public: - pixelator_t(blt::size_t width, blt::size_t height): width(width), height(height) - {} - - pixel next() - { - if (x > width) - { - x = 0; - y++; - } - return {x++, y}; - } - - [[nodiscard]] inline blt::size_t curX() const - { - return x; - } - - [[nodiscard]] inline blt::size_t curY() const - { - return y; - } -} pixelator{image_width, image_height}; - const fb::func_t_call_t add_f = [](const fb::detail::func_t_arguments& args) { args.self.setValue(args.arguments[0]->value().any_cast() + args.arguments[1]->value().any_cast()); }; @@ -73,6 +43,12 @@ const fb::func_t_call_t div_f = [](const fb::detail::func_t_arguments& args) { }; const fb::func_t_call_t empty_f = [](const fb::detail::func_t_arguments&) {}; +const fb::func_t_call_t coord_x_f = [](const fb::detail::func_t_arguments& args) { + args.self.setValue(args.extra_args.any_cast().x); +}; +const fb::func_t_call_t coord_y_f = [](const fb::detail::func_t_arguments& args) { + args.self.setValue(args.extra_args.any_cast().y); +}; const fb::func_t_init_t value_init_f = [](fb::func_t& self) { self.setValue(fb::random_value()); };