Skip to content

Commit

Permalink
🔥 [Nodes] Remove the notion of template node
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFouchy committed Oct 10, 2023
1 parent e7eb113 commit 45a2100
Show file tree
Hide file tree
Showing 26 changed files with 20 additions and 230 deletions.
2 changes: 1 addition & 1 deletion Nodes/21 Greyscale Modifier/Absolute Value.clbnode
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// To learn how to write nodes, see https://coollab-art.com/Tutorials/Writing%20Nodes/Intro

Any main(Any x)
float main(float x)
{
return abs(x);
}
2 changes: 1 addition & 1 deletion Nodes/21 Greyscale Modifier/Clamp.clbnode
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
INPUT float 'Min Value';
INPUT float 'Max Value';

Any main(Any V)
float main(float V)
{
return clamp(V, 'Min Value', 'Max Value');
}
4 changes: 2 additions & 2 deletions Nodes/21 Greyscale Modifier/Cos.clbnode
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// To learn how to write nodes, see https://coollab-art.com/Tutorials/Writing%20Nodes/Intro

Any main(Any value)
float main(float value)
{
return cos(value);
return cos(value);
}
4 changes: 2 additions & 2 deletions Nodes/21 Greyscale Modifier/Exponential.clbnode
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// To learn how to write nodes, see https://coollab-art.com/Tutorials/Writing%20Nodes/Intro

Any main(Any value)
float main(float value)
{
return exp(value);
return exp(value);
}
4 changes: 2 additions & 2 deletions Nodes/21 Greyscale Modifier/Logarithm.clbnode
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// To learn how to write nodes, see https://coollab-art.com/Tutorials/Writing%20Nodes/Intro

Any main(Any value)
float main(float value)
{
return log(value);
return log(value);
}
4 changes: 2 additions & 2 deletions Nodes/21 Greyscale Modifier/Max.clbnode
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// To learn how to write nodes, see https://coollab-art.com/Tutorials/Writing%20Nodes/Intro

Any main(Any value1, Any value2)
float main(float value1, float value2)
{
return max(value1, value2);
return max(value1, value2);
}
4 changes: 2 additions & 2 deletions Nodes/21 Greyscale Modifier/Min.clbnode
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// To learn how to write nodes, see https://coollab-art.com/Tutorials/Writing%20Nodes/Intro

Any main(Any value1, Any value2)
float main(float value1, float value2)
{
return min(value1, value2);
return min(value1, value2);
}
2 changes: 1 addition & 1 deletion Nodes/21 Greyscale Modifier/Pow.clbnode
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// To learn how to write nodes, see https://coollab-art.com/Tutorials/Writing%20Nodes/Intro
INPUT float 'Power';

Any main(Any value)
float main(float value)
{
return pow(value, 'Power');
}
4 changes: 2 additions & 2 deletions Nodes/21 Greyscale Modifier/Tan.clbnode
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// To learn how to write nodes, see https://coollab-art.com/Tutorials/Writing%20Nodes/Intro

Any main(Any value)
float main(float value)
{
return tan(value);
return tan(value);
}
20 changes: 3 additions & 17 deletions src/Module_Nodes/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static auto gen_value_inputs(
) -> tl::expected<Properties, std::string>
{
using fmt::literals::operator""_a;
Properties res{};
Properties res{};

size_t property_index{0};
for (auto const& prop : node.value_inputs())
Expand Down Expand Up @@ -368,20 +368,6 @@ static auto gen_helper_functions(std::vector<FunctionPieces> const& helper_funct
return res;
}

/// Returns the signature where all template types have been resolved to a concrete type.
static auto concrete_signature(NodeDefinition const& def, Node const& node)
-> FunctionSignature
{
if (!def.signature().is_template())
return def.signature();

return FunctionSignature{
.from = node.chosen_any_type(),
.to = node.chosen_any_type(),
.arity = def.signature().arity,
};
}

static auto gen_includes(NodeDefinition const& node_definition)
-> std::string
{
Expand Down Expand Up @@ -416,7 +402,7 @@ static auto gen_base_function(

auto func_implementation = gen_function_definition({
.signature = make_complete_function_signature(MainFunctionSignature{
.signature = concrete_signature(node_definition, node),
.signature = node_definition.signature(),
.parameter_names = node_definition.parameter_names(),
}),
.name = func_name,
Expand Down Expand Up @@ -564,7 +550,7 @@ auto gen_desired_function(
));

auto const func_body = gen_desired_function_implementation(
concrete_signature(*node_definition, node),
node_definition->signature(),
desired_signature,
*base_function_name,
node,
Expand Down
2 changes: 0 additions & 2 deletions src/Module_Nodes/FunctionSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ struct FunctionSignature {
size_t arity{1};

friend auto operator==(const FunctionSignature&, const FunctionSignature&) -> bool = default;

auto is_template() const -> bool { return from == PrimitiveType::Any || to == PrimitiveType::Any; }
};

struct ParamDesc {
Expand Down
37 changes: 0 additions & 37 deletions src/Module_Nodes/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,6 @@

namespace Lab {

static auto type_to_template_combo_index(PrimitiveType type) -> int
{
switch (type)
{
#include "generated/type_to_template_combo_index.inl"
default:
throw std::logic_error{fmt::format("Unexpected primitive type as a template instance: {}.", static_cast<int>(type))};
};
}

static auto template_combo_index_to_type(int index) -> PrimitiveType
{
switch (index)
{
#include "generated/template_combo_index_to_type.inl"
default:
throw std::logic_error{fmt::format("Unexpected index of primitive type as a template instance: {}.", index)};
};
}

auto Node::imgui_chosen_any_type() -> bool
{
if (!_chosen_any_type)
return false;

int index = type_to_template_combo_index(*_chosen_any_type); // We don't use *_chosen_any_type directly as an int because in the future we might want to change the order of the types in the dropdown, and we absolutely do not want to change the underlying int representation of PrimitiveType because it would break serialization.
if (ImGui::Combo("Type", &index,
#include "generated/template_node_type_dropdown_string.inl"
))
{
*_chosen_any_type = template_combo_index_to_type(index);
return true;
}

return false;
}

auto to_string(Node const& node) -> std::string
{
return !node.name().empty() ? node.name() : node.definition_name();
Expand Down
12 changes: 2 additions & 10 deletions src/Module_Nodes/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ namespace Lab {
class Node {
public:
Node() = default;
Node(Cool::NodeDefinitionIdentifier const& id_names, size_t number_of_main_input_pins, size_t number_of_function_inputs, bool is_template_node)
Node(Cool::NodeDefinitionIdentifier const& id_names, size_t number_of_main_input_pins, size_t number_of_function_inputs)
: _id_names{id_names}
, _number_of_main_input_pins{number_of_main_input_pins}
, _number_of_function_inputs{number_of_function_inputs}
, _chosen_any_type{is_template_node ? std::make_optional(PrimitiveType::Float) : std::nullopt}
{}

auto name() const -> std::string { return _name; }
Expand Down Expand Up @@ -53,10 +52,6 @@ class Node {
auto value_input_pin_idx_begin() const -> size_t { return function_input_pin_idx_end(); }
auto value_input_pin_idx_end() const -> size_t { return _input_pins.size(); }

/// Only call this if this node is a template node
auto chosen_any_type() const -> PrimitiveType { return _chosen_any_type.value(); }
auto imgui_chosen_any_type() -> bool;

private:
Cool::NodeDefinitionIdentifier _id_names;
std::string _name{};
Expand All @@ -67,8 +62,6 @@ class Node {
size_t _number_of_main_input_pins{};
size_t _number_of_function_inputs{};

std::optional<PrimitiveType> _chosen_any_type{}; // Only present if the node has `Any` in its signature.

private:
friend class cereal::access;
template<class Archive>
Expand All @@ -81,8 +74,7 @@ class Node {
cereal::make_nvp("Output Pins", _output_pins),
cereal::make_nvp("Value inputs", _value_inputs),
cereal::make_nvp("Number of main input pins", _number_of_main_input_pins),
cereal::make_nvp("Number of function inputs", _number_of_function_inputs),
cereal::make_nvp("Chosen Any type", _chosen_any_type)
cereal::make_nvp("Number of function inputs", _number_of_function_inputs)
);
}
};
Expand Down
4 changes: 0 additions & 4 deletions src/Module_Nodes/NodesConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ void NodesConfig::imgui_in_inspector_below_node_info(Cool::Node& abstract_node,

ImGui::NewLine();

if (node.imgui_chosen_any_type())
_ui.set_dirty(_regenerate_code_flag);

for (size_t i = 0; i < node.value_inputs().size(); ++i)
{
Cool::ImGuiExtras::disabled_if(
Expand Down Expand Up @@ -301,7 +298,6 @@ auto NodesConfig::make_node(Cool::NodeDefinitionAndCategoryName const& cat_id) -
{def.name(), cat_id.category_name},
needs_main_pin ? def.signature().arity : 0,
def.function_inputs().size(),
def.signature().is_template(),
};
auto const node_category_config = _get_node_category_config(cat_id.category_name);

Expand Down
Loading

0 comments on commit 45a2100

Please sign in to comment.