diff --git a/cmake-build-release/.ninja_deps b/cmake-build-release/.ninja_deps index 7a95beb..6c02fe1 100644 Binary files a/cmake-build-release/.ninja_deps and b/cmake-build-release/.ninja_deps differ diff --git a/cmake-build-release/.ninja_log b/cmake-build-release/.ninja_log index b461b55..e08b7ac 100644 --- a/cmake-build-release/.ninja_log +++ b/cmake-build-release/.ninja_log @@ -202,3 +202,11 @@ 26737 26901 1705257472228626060 libraries/BLT-With-Graphics-Template/libraries/freetype-2.13.2/libfreetype.a 1ef1507fdc5a3960 26901 27054 1705257472380619772 libraries/BLT-With-Graphics-Template/libBLT_WITH_GRAPHICS.a 2582d8919b3ccd7b 27054 27191 1705257472520613980 gp_image_test 627b40e9bcf815e3 +9 49 1705257551849331804 libraries/BLT-With-Graphics-Template/libraries/openal-soft/version_witness.txt 6325405b7e3e96f7 +9 49 1705257551849331804 libraries/BLT-With-Graphics-Template/libraries/openal-soft/version.h 6325405b7e3e96f7 +9 49 1705257551849331804 /home/brett/Documents/code/c++/gp_image_test/cmake-build-release/libraries/BLT-With-Graphics-Template/libraries/openal-soft/version_witness.txt 6325405b7e3e96f7 +9 49 1705257551849331804 /home/brett/Documents/code/c++/gp_image_test/cmake-build-release/libraries/BLT-With-Graphics-Template/libraries/openal-soft/version.h 6325405b7e3e96f7 +9 2237 1705433087834197608 libraries/BLT-With-Graphics-Template/libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/system.cpp.o 19facd5153bbeb65 +2237 2427 1705433088022195202 libraries/BLT-With-Graphics-Template/libraries/BLT/libBLT.a 5e3491f3bb42050d +9 3115 1705433088714186351 CMakeFiles/gp_image_test.dir/src/main.cpp.o d2247c8eaef04c80 +3116 3265 1705433088862184459 gp_image_test 627b40e9bcf815e3 diff --git a/cmake-build-release/CMakeFiles/gp_image_test.dir/src/main.cpp.o b/cmake-build-release/CMakeFiles/gp_image_test.dir/src/main.cpp.o index 0c58085..60cdfbe 100644 Binary files a/cmake-build-release/CMakeFiles/gp_image_test.dir/src/main.cpp.o and b/cmake-build-release/CMakeFiles/gp_image_test.dir/src/main.cpp.o differ diff --git a/cmake-build-release/Testing/Temporary/LastTest.log b/cmake-build-release/Testing/Temporary/LastTest.log index af0e397..2b1c83a 100644 --- a/cmake-build-release/Testing/Temporary/LastTest.log +++ b/cmake-build-release/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Jan 15 14:34 EST +Start testing: Jan 16 14:24 EST ---------------------------------------------------------- -End testing: Jan 15 14:34 EST +End testing: Jan 16 14:24 EST diff --git a/cmake-build-release/gp_image_test b/cmake-build-release/gp_image_test index 79c4123..65570b7 100755 Binary files a/cmake-build-release/gp_image_test and b/cmake-build-release/gp_image_test differ diff --git a/include/image.h b/include/image.h new file mode 100644 index 0000000..9d36447 --- /dev/null +++ b/include/image.h @@ -0,0 +1,121 @@ +/* + * + * Copyright (C) 2024 Brett Terpstra + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GP_IMAGE_TEST_IMAGE_H +#define GP_IMAGE_TEST_IMAGE_H + +#define NO_BLT_NAMESPACE_ON_TYPES + +#include +#include +#include +#include "blt/std/assert.h" + +inline constexpr i32 width = 1024, height = 1024; + +class image +{ + private: + std::array data; + public: + image() = default; + + u8 get(i32 x, i32 y) + { + return data[y * height + x]; + } + + void set(u8 c, i32 x, i32 y) + { + data[y * height + x] = c; + } +}; + +enum class function_t +{ + // FUNC // inputs + ADD, // 2 + SUB, // 2 + MUL, // 2 + DIV, // 2 + EXP, // 2 + + LOG, // 1 + SQRT, // 1 + QUAD, // 1 + + RANDOM, // 0 + NOISE, // 0 + COLOR, // 0 + SCALAR // 0 +}; + +inline i32 inputs(function_t op) +{ + // don't like this but it'll get compiled out + // and we get warnings when new enum is added + switch (op) + { + case function_t::ADD: + case function_t::SUB: + case function_t::MUL: + case function_t::DIV: + case function_t::EXP: + return 2; + case function_t::LOG: + case function_t::SQRT: + case function_t::QUAD: + return 1; + case function_t::RANDOM: + case function_t::NOISE: + case function_t::COLOR: + case function_t::SCALAR: + return 0; + } + BLT_THROW(std::runtime_error("If you are seeing this the universe has broken. Enjoy whatever hellhole is left")); +} + +struct op_con +{ + function_t op; + std::optional i1, i2; + + op_con(function_t op, const std::optional& i1, const std::optional& i2): op(op), i1(i1), i2(i2) + {} + + [[nodiscard]] bool has_both() const + { + return i1.has_value() && i2.has_value(); + } + + [[nodiscard]] bool has_one() const + { + return i1.has_value() || i2.has_value(); + } + + [[nodiscard]] image* getOne() + { + if (i1) + return i1.value(); + if (i2) + return i2.value(); + BLT_THROW(std::runtime_error("Unable to get when one is missing! You have an error in your GA!")); + } +}; + +#endif //GP_IMAGE_TEST_IMAGE_H diff --git a/src/main.cpp b/src/main.cpp index f70efd7..97491e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,9 +3,12 @@ #include #include #include +#include #include +#include #include "blt/gfx/renderer/resource_manager.h" #include "blt/gfx/renderer/batch_2d_renderer.h" +#include "blt/std/assert.h" #include #include @@ -15,29 +18,118 @@ blt::gfx::batch_renderer_2d renderer_2d(resources); struct node; -blt::area_allocator allocator; +blt::area_allocator node_allocator; +blt::area_allocator img_allocator; -std::variant input_t; - -enum class function_t +node* createNode() { - // FUNC // inputs - ADD, // 2 - SUB, // 2 - MUL, // 2 - DIV, // 2 - - LOG, // 1 - EXP, // 1 - SQRT, // 1 - POW, // 1 - QUAD, // 1 - - RANDOM, // 0 - NOISE, // 0 - COLOR, // 0 - SCALAR // 0 -}; + auto* n = node_allocator.allocate(1); + node_allocator.construct(n); + return n; +} + +image* createImage() +{ + auto* i = img_allocator.allocate(1); + img_allocator.construct(i); + return i; +} + +void destroyNode(node* n) +{ + node_allocator.destroy(n); + node_allocator.deallocate(n, 1); +} + +void destroyImage(image* img) +{ + img_allocator.destroy(img); + img_allocator.deallocate(img, 1); +} + +image* apply_operator(op_con operation) +{ + auto* ret = createImage(); + for (i32 y = 0; y < height; y++) + { + for (i32 x = 0; x < width; x++) + { + switch (operation.op) + { + case function_t::ADD: + { + BLT_ASSERT(operation.has_both()); + ret->set((operation.i1.value()->get(x, y) + operation.i2.value()->get(x, y)) % std::numeric_limits::max(), x, y); + break; + } + case function_t::SUB: + { + BLT_ASSERT(operation.has_both()); + ret->set((operation.i1.value()->get(x, y) - operation.i2.value()->get(x, y)) % std::numeric_limits::max(), x, y); + break; + } + case function_t::MUL: + { + BLT_ASSERT(operation.has_both()); + ret->set((operation.i1.value()->get(x, y) * operation.i2.value()->get(x, y)) % std::numeric_limits::max(), x, y); + break; + } + case function_t::DIV: + { + BLT_ASSERT(operation.has_both()); + auto den = operation.i2.value()->get(x, y); + if (den == 0) + ret->set(0, x, y); + else + ret->set((operation.i1.value()->get(x, y) / den) % std::numeric_limits::max(), x, y); + break; + } + case function_t::EXP: + { + BLT_ASSERT(operation.has_both()); + ret->set(static_cast(std::pow(operation.i1.value()->get(x, y), operation.i2.value()->get(x, y))), x, y); + break; + } + case function_t::LOG: + { + BLT_ASSERT(operation.has_one()); + ret->set(static_cast(std::log(static_cast(operation.getOne()->get(x, y)))), x, y); + break; + } + case function_t::SQRT: + { + BLT_ASSERT(operation.has_one()); + ret->set(static_cast(std::sqrt(static_cast(operation.getOne()->get(x, y)))), x, y); + break; + } + case function_t::QUAD: + { + BLT_ASSERT(operation.has_one()); + auto v = operation.getOne()->get(x, y); + ret->set(static_cast(v * v), x, y); + break; + } + case function_t::RANDOM: + { + + break; + } + case function_t::NOISE: + { + break; + } + case function_t::COLOR: + { + break; + } + case function_t::SCALAR: + { + break; + } + } + } + } +} static constexpr int OPERATOR_COUNT = 13; @@ -45,7 +137,7 @@ class tree; struct node { - friend tree; + friend tree; private: node* left; node* right; @@ -55,8 +147,7 @@ struct node static node* construct_random() { - node* n = allocator.allocate(1); - allocator.construct(n); + node* n = createNode(); std::random_device dev; std::mt19937_64 engine{dev()}; @@ -72,10 +163,8 @@ struct node ~node() { - allocator.destroy(left); - allocator.deallocate(left, 1); - allocator.destroy(right); - allocator.deallocate(right, 1); + destroyNode(left); + destroyNode(right); } };