sexy nodes

main
Brett 2024-01-15 15:34:54 -05:00
parent 3f61f74fa6
commit c4b2de9503
2 changed files with 80 additions and 10 deletions

View File

@ -1,3 +1,3 @@
Start testing: Jan 14 13:37 EST Start testing: Jan 15 14:34 EST
---------------------------------------------------------- ----------------------------------------------------------
End testing: Jan 14 13:37 EST End testing: Jan 15 14:34 EST

View File

@ -1,22 +1,92 @@
#include <iostream> #include <iostream>
#include <blt/std/memory.h> #include <blt/std/allocator.h>
#include <blt/gfx/window.h> #include <blt/gfx/window.h>
#include <blt/gfx/state.h> #include <blt/gfx/state.h>
#include <blt/gfx/stb/stb_image.h> #include <blt/gfx/stb/stb_image.h>
#include <blt/std/hashmap.h>
#include "blt/gfx/renderer/resource_manager.h" #include "blt/gfx/renderer/resource_manager.h"
#include "blt/gfx/renderer/batch_2d_renderer.h" #include "blt/gfx/renderer/batch_2d_renderer.h"
#include <variant>
class node #include <random>
{
node* left;
node* right;
};
blt::gfx::matrix_state_manager global_matrices; blt::gfx::matrix_state_manager global_matrices;
blt::gfx::resource_manager resources; blt::gfx::resource_manager resources;
blt::gfx::batch_renderer_2d renderer_2d(resources); blt::gfx::batch_renderer_2d renderer_2d(resources);
struct node;
blt::area_allocator<node, 32000> allocator;
std::variant<float, blt::vec3f> input_t;
enum class function_t
{
// 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
};
static constexpr int OPERATOR_COUNT = 13;
class tree;
struct node
{
friend tree;
private:
node* left;
node* right;
function_t type;
std::array<float, 7> data;
public:
static node* construct_random()
{
node* n = allocator.allocate(1);
allocator.construct(n);
std::random_device dev;
std::mt19937_64 engine{dev()};
std::uniform_real_distribution<float> dist(0.0f, 1.0f);
for (float& f : n->data)
f = dist(engine);
std::uniform_int_distribution op(0, OPERATOR_COUNT - 1);
n->type = static_cast<function_t>(op(engine));
return n;
}
~node()
{
allocator.destroy(left);
allocator.deallocate(left, 1);
allocator.destroy(right);
allocator.deallocate(right, 1);
}
};
class tree
{
public:
node* root;
};
void init() void init()
{ {
global_matrices.create_internals(); global_matrices.create_internals();