Moved node DB to its own file
parent
c87dc49046
commit
f4a5b36fe9
|
@ -1,163 +1,13 @@
|
|||
#include "voxel_generator_graph.h"
|
||||
#include "../../util/profiling_clock.h"
|
||||
#include "../../voxel_string_names.h"
|
||||
#include "voxel_graph_node_db.h"
|
||||
#include <modules/opensimplex/open_simplex_noise.h>
|
||||
|
||||
//#ifdef DEBUG_ENABLED
|
||||
//#define VOXEL_DEBUG_GRAPH_PROG_SENTINEL uint16_t(12345) // 48, 57 (base 10)
|
||||
//#endif
|
||||
|
||||
namespace {
|
||||
VoxelGeneratorGraph::NodeTypeDB *g_node_type_db = nullptr;
|
||||
}
|
||||
|
||||
VoxelGeneratorGraph::NodeTypeDB *VoxelGeneratorGraph::NodeTypeDB::get_singleton() {
|
||||
CRASH_COND(g_node_type_db == nullptr);
|
||||
return g_node_type_db;
|
||||
}
|
||||
|
||||
void VoxelGeneratorGraph::NodeTypeDB::create_singleton() {
|
||||
CRASH_COND(g_node_type_db != nullptr);
|
||||
g_node_type_db = memnew(NodeTypeDB());
|
||||
}
|
||||
|
||||
void VoxelGeneratorGraph::NodeTypeDB::destroy_singleton() {
|
||||
CRASH_COND(g_node_type_db == nullptr);
|
||||
memdelete(g_node_type_db);
|
||||
g_node_type_db = nullptr;
|
||||
}
|
||||
|
||||
VoxelGeneratorGraph::NodeTypeDB::NodeTypeDB() {
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_CONSTANT];
|
||||
t.outputs.push_back(Port("Value"));
|
||||
t.params.push_back(Param("Value"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_INPUT_X];
|
||||
t.outputs.push_back(Port("Value"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_INPUT_Y];
|
||||
t.outputs.push_back(Port("Value"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_INPUT_Z];
|
||||
t.outputs.push_back(Port("Value"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_OUTPUT_SDF];
|
||||
t.inputs.push_back(Port("Value"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_ADD];
|
||||
t.inputs.push_back(Port("A"));
|
||||
t.inputs.push_back(Port("B"));
|
||||
t.outputs.push_back(Port("Sum"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_SUBTRACT];
|
||||
t.inputs.push_back(Port("A"));
|
||||
t.inputs.push_back(Port("B"));
|
||||
t.outputs.push_back(Port("Sum"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_MULTIPLY];
|
||||
t.inputs.push_back(Port("A"));
|
||||
t.inputs.push_back(Port("B"));
|
||||
t.outputs.push_back(Port("Product"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_SINE];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_FLOOR];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_ABS];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_SQRT];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_DISTANCE_2D];
|
||||
t.inputs.push_back(Port("X0"));
|
||||
t.inputs.push_back(Port("Y0"));
|
||||
t.inputs.push_back(Port("X1"));
|
||||
t.inputs.push_back(Port("Y1"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_DISTANCE_3D];
|
||||
t.inputs.push_back(Port("X0"));
|
||||
t.inputs.push_back(Port("Y0"));
|
||||
t.inputs.push_back(Port("Y0"));
|
||||
t.inputs.push_back(Port("X1"));
|
||||
t.inputs.push_back(Port("Y1"));
|
||||
t.inputs.push_back(Port("Z1"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_CLAMP];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
t.params.push_back(Param("Min", -1.f));
|
||||
t.params.push_back(Param("Max", 1.f));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_MIX];
|
||||
t.inputs.push_back(Port("A"));
|
||||
t.inputs.push_back(Port("B"));
|
||||
t.inputs.push_back(Port("Ratio"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_REMAP];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
t.params.push_back(Param("Min0", -1.f));
|
||||
t.params.push_back(Param("Max0", 1.f));
|
||||
t.params.push_back(Param("Min1", -1.f));
|
||||
t.params.push_back(Param("Max1", 1.f));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_CURVE];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
t.params.push_back(Param("Curve"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_NOISE_2D];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.inputs.push_back(Port("Y"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
t.params.push_back(Param("Noise"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_NOISE_3D];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.inputs.push_back(Port("Y"));
|
||||
t.inputs.push_back(Port("Z"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
t.params.push_back(Param("Noise"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_IMAGE_2D];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.inputs.push_back(Port("Y"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
t.params.push_back(Param("Image"));
|
||||
}
|
||||
}
|
||||
|
||||
VoxelGeneratorGraph::VoxelGeneratorGraph() {
|
||||
clear();
|
||||
clear_bounds();
|
||||
|
@ -188,7 +38,7 @@ void VoxelGeneratorGraph::clear() {
|
|||
}
|
||||
|
||||
uint32_t VoxelGeneratorGraph::create_node(NodeTypeID type_id) {
|
||||
const NodeTypeDB::NodeType &type = NodeTypeDB::get_singleton()->types[type_id];
|
||||
const VoxelGraphNodeDB::NodeType &type = VoxelGraphNodeDB::get_singleton()->types[type_id];
|
||||
|
||||
ProgramGraph::Node *pg_node = _graph.create_node();
|
||||
pg_node->inputs.resize(type.inputs.size());
|
||||
|
@ -467,7 +317,7 @@ void VoxelGeneratorGraph::compile() {
|
|||
_memory.resize(3);
|
||||
|
||||
std::vector<uint8_t> &program = _program;
|
||||
const NodeTypeDB &type_db = *NodeTypeDB::get_singleton();
|
||||
const VoxelGraphNodeDB &type_db = *VoxelGraphNodeDB::get_singleton();
|
||||
HashMap<ProgramGraph::PortLocation, uint16_t, ProgramGraph::PortLocationHasher> output_port_addresses;
|
||||
bool has_output = false;
|
||||
|
||||
|
@ -475,7 +325,7 @@ void VoxelGeneratorGraph::compile() {
|
|||
const uint32_t node_id = order[i];
|
||||
const ProgramGraph::Node *pg_node = _graph.get_node(node_id);
|
||||
const Node *node = _nodes[node_id];
|
||||
const NodeTypeDB::NodeType &type = type_db.types[node->type];
|
||||
const VoxelGraphNodeDB::NodeType &type = type_db.types[node->type];
|
||||
|
||||
CRASH_COND(node == nullptr);
|
||||
CRASH_COND(pg_node->inputs.size() != type.inputs.size());
|
||||
|
|
|
@ -34,39 +34,6 @@ public:
|
|||
NODE_TYPE_COUNT
|
||||
};
|
||||
|
||||
struct NodeTypeDB {
|
||||
|
||||
struct Port {
|
||||
String name;
|
||||
|
||||
Port(String p_name) :
|
||||
name(p_name) {}
|
||||
};
|
||||
|
||||
struct Param {
|
||||
String name;
|
||||
Variant default_value;
|
||||
|
||||
Param(String p_name, Variant p_default_value = Variant()) :
|
||||
name(p_name),
|
||||
default_value(p_default_value) {}
|
||||
};
|
||||
|
||||
struct NodeType {
|
||||
std::vector<Port> inputs;
|
||||
std::vector<Port> outputs;
|
||||
std::vector<Param> params;
|
||||
};
|
||||
|
||||
NodeTypeDB();
|
||||
|
||||
static NodeTypeDB *get_singleton();
|
||||
static void create_singleton();
|
||||
static void destroy_singleton();
|
||||
|
||||
FixedArray<NodeType, NODE_TYPE_COUNT> types;
|
||||
};
|
||||
|
||||
VoxelGeneratorGraph();
|
||||
~VoxelGeneratorGraph();
|
||||
|
||||
|
|
|
@ -0,0 +1,152 @@
|
|||
#include "voxel_graph_node_db.h"
|
||||
|
||||
namespace {
|
||||
VoxelGraphNodeDB *g_node_type_db = nullptr;
|
||||
}
|
||||
|
||||
VoxelGraphNodeDB *VoxelGraphNodeDB::get_singleton() {
|
||||
CRASH_COND(g_node_type_db == nullptr);
|
||||
return g_node_type_db;
|
||||
}
|
||||
|
||||
void VoxelGraphNodeDB::create_singleton() {
|
||||
CRASH_COND(g_node_type_db != nullptr);
|
||||
g_node_type_db = memnew(VoxelGraphNodeDB());
|
||||
}
|
||||
|
||||
void VoxelGraphNodeDB::destroy_singleton() {
|
||||
CRASH_COND(g_node_type_db == nullptr);
|
||||
memdelete(g_node_type_db);
|
||||
g_node_type_db = nullptr;
|
||||
}
|
||||
|
||||
VoxelGraphNodeDB::VoxelGraphNodeDB() {
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_CONSTANT];
|
||||
t.outputs.push_back(Port("Value"));
|
||||
t.params.push_back(Param("Value"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_INPUT_X];
|
||||
t.outputs.push_back(Port("Value"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_INPUT_Y];
|
||||
t.outputs.push_back(Port("Value"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_INPUT_Z];
|
||||
t.outputs.push_back(Port("Value"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_OUTPUT_SDF];
|
||||
t.inputs.push_back(Port("Value"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_ADD];
|
||||
t.inputs.push_back(Port("A"));
|
||||
t.inputs.push_back(Port("B"));
|
||||
t.outputs.push_back(Port("Sum"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_SUBTRACT];
|
||||
t.inputs.push_back(Port("A"));
|
||||
t.inputs.push_back(Port("B"));
|
||||
t.outputs.push_back(Port("Sum"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_MULTIPLY];
|
||||
t.inputs.push_back(Port("A"));
|
||||
t.inputs.push_back(Port("B"));
|
||||
t.outputs.push_back(Port("Product"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_SINE];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_FLOOR];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_ABS];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_SQRT];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_DISTANCE_2D];
|
||||
t.inputs.push_back(Port("X0"));
|
||||
t.inputs.push_back(Port("Y0"));
|
||||
t.inputs.push_back(Port("X1"));
|
||||
t.inputs.push_back(Port("Y1"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_DISTANCE_3D];
|
||||
t.inputs.push_back(Port("X0"));
|
||||
t.inputs.push_back(Port("Y0"));
|
||||
t.inputs.push_back(Port("Y0"));
|
||||
t.inputs.push_back(Port("X1"));
|
||||
t.inputs.push_back(Port("Y1"));
|
||||
t.inputs.push_back(Port("Z1"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_CLAMP];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
t.params.push_back(Param("Min", -1.f));
|
||||
t.params.push_back(Param("Max", 1.f));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_MIX];
|
||||
t.inputs.push_back(Port("A"));
|
||||
t.inputs.push_back(Port("B"));
|
||||
t.inputs.push_back(Port("Ratio"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_REMAP];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
t.params.push_back(Param("Min0", -1.f));
|
||||
t.params.push_back(Param("Max0", 1.f));
|
||||
t.params.push_back(Param("Min1", -1.f));
|
||||
t.params.push_back(Param("Max1", 1.f));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_CURVE];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
t.params.push_back(Param("Curve"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_NOISE_2D];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.inputs.push_back(Port("Y"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
t.params.push_back(Param("Noise"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_NOISE_3D];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.inputs.push_back(Port("Y"));
|
||||
t.inputs.push_back(Port("Z"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
t.params.push_back(Param("Noise"));
|
||||
}
|
||||
{
|
||||
NodeType &t = types[VoxelGeneratorGraph::NODE_IMAGE_2D];
|
||||
t.inputs.push_back(Port("X"));
|
||||
t.inputs.push_back(Port("Y"));
|
||||
t.outputs.push_back(Port("Result"));
|
||||
t.params.push_back(Param("Image"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef VOXEL_GRAPH_NODE_DB_H
|
||||
#define VOXEL_GRAPH_NODE_DB_H
|
||||
|
||||
#include "voxel_generator_graph.h"
|
||||
#include <core/object.h>
|
||||
|
||||
class VoxelGraphNodeDB : public Object {
|
||||
GDCLASS(VoxelGraphNodeDB, Object)
|
||||
public:
|
||||
struct Port {
|
||||
String name;
|
||||
|
||||
Port(String p_name) :
|
||||
name(p_name) {}
|
||||
};
|
||||
|
||||
struct Param {
|
||||
String name;
|
||||
Variant default_value;
|
||||
|
||||
Param(String p_name, Variant p_default_value = Variant()) :
|
||||
name(p_name),
|
||||
default_value(p_default_value) {}
|
||||
};
|
||||
|
||||
struct NodeType {
|
||||
std::vector<Port> inputs;
|
||||
std::vector<Port> outputs;
|
||||
std::vector<Param> params;
|
||||
};
|
||||
|
||||
VoxelGraphNodeDB();
|
||||
|
||||
static VoxelGraphNodeDB *get_singleton();
|
||||
static void create_singleton();
|
||||
static void destroy_singleton();
|
||||
|
||||
FixedArray<NodeType, VoxelGeneratorGraph::NODE_TYPE_COUNT> types;
|
||||
};
|
||||
|
||||
#endif // VOXEL_GRAPH_NODE_DB_H
|
|
@ -1,6 +1,7 @@
|
|||
#include "register_types.h"
|
||||
#include "edition/voxel_tool.h"
|
||||
#include "generators/graph/voxel_generator_graph.h"
|
||||
#include "generators/graph/voxel_graph_node_db.h"
|
||||
#include "generators/voxel_generator_flat.h"
|
||||
#include "generators/voxel_generator_heightmap.h"
|
||||
#include "generators/voxel_generator_image.h"
|
||||
|
@ -65,7 +66,7 @@ void register_voxel_types() {
|
|||
|
||||
VoxelMemoryPool::create_singleton();
|
||||
VoxelStringNames::create_singleton();
|
||||
VoxelGeneratorGraph::NodeTypeDB::create_singleton();
|
||||
VoxelGraphNodeDB::create_singleton();
|
||||
|
||||
// Reminder: how to create a singleton accessible from scripts:
|
||||
// Engine::get_singleton()->add_singleton(Engine::Singleton("SingletonName",singleton_instance));
|
||||
|
@ -84,7 +85,7 @@ void unregister_voxel_types() {
|
|||
|
||||
VoxelMemoryPool::destroy_singleton();
|
||||
VoxelStringNames::destroy_singleton();
|
||||
VoxelGeneratorGraph::NodeTypeDB::destroy_singleton();
|
||||
VoxelGraphNodeDB::destroy_singleton();
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
VoxelDebug::free_debug_box_mesh();
|
||||
|
|
Loading…
Reference in New Issue