1
0
mirror of synced 2024-11-12 10:10:53 +01:00

node: Added arithmetic nodes (add, sub, mul, div, mod)

This commit is contained in:
WerWolv 2021-03-06 14:46:47 +01:00
parent cadd4e5c2b
commit d4265f16eb
5 changed files with 184 additions and 6 deletions

View File

@ -360,6 +360,97 @@ namespace hex::plugin::builtin {
}
};
class NodeArithmeticAdd : public dp::Node {
public:
NodeArithmeticAdd() : Node("hex.builtin.nodes.arithmetic.add.header", {
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.add.input.a"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.add.input.b"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.add.output") }) {}
void process() override {
auto inputA = this->getIntegerOnInput(0);
auto inputB = this->getIntegerOnInput(1);
auto output = inputA + inputB;
this->setIntegerOnOutput(2, output);
}
};
class NodeArithmeticSubtract : public dp::Node {
public:
NodeArithmeticSubtract() : Node("hex.builtin.nodes.arithmetic.sub.header", {
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.sub.input.a"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.sub.input.b"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.sub.output") }) {}
void process() override {
auto inputA = this->getIntegerOnInput(0);
auto inputB = this->getIntegerOnInput(1);
auto output = inputA - inputB;
this->setIntegerOnOutput(2, output);
}
};
class NodeArithmeticMultiply : public dp::Node {
public:
NodeArithmeticMultiply() : Node("hex.builtin.nodes.arithmetic.mul.header", {
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.mul.input.a"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.mul.input.b"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.mul.output") }) {}
void process() override {
auto inputA = this->getIntegerOnInput(0);
auto inputB = this->getIntegerOnInput(1);
auto output = inputA * inputB;
this->setIntegerOnOutput(2, output);
}
};
class NodeArithmeticDivide : public dp::Node {
public:
NodeArithmeticDivide() : Node("hex.builtin.nodes.arithmetic.div.header", {
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.div.input.a"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.div.input.b"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.div.output") }) {}
void process() override {
auto inputA = this->getIntegerOnInput(0);
auto inputB = this->getIntegerOnInput(1);
if (inputB == 0)
throwNodeError("Division by zero");
auto output = inputA / inputB;
this->setIntegerOnOutput(2, output);
}
};
class NodeArithmeticModulus : public dp::Node {
public:
NodeArithmeticModulus() : Node("hex.builtin.nodes.arithmetic.mod.header", {
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.mod.input.a"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.mod.input.b"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.arithmetic.mod.output") }) {}
void process() override {
auto inputA = this->getIntegerOnInput(0);
auto inputB = this->getIntegerOnInput(1);
if (inputB == 0)
throwNodeError("Division by zero");
auto output = inputA % inputB;
this->setIntegerOnOutput(2, output);
}
};
class NodeIf : public dp::Node {
public:
NodeIf() : Node("ex.builtin.nodes.control_flow.if.header",
@ -583,6 +674,12 @@ namespace hex::plugin::builtin {
ContentRegistry::DataProcessorNode::add<NodeCastIntegerToBuffer>("hex.builtin.nodes.casting", "hex.builtin.nodes.casting.int_to_buffer");
ContentRegistry::DataProcessorNode::add<NodeCastBufferToInteger>("hex.builtin.nodes.casting", "hex.builtin.nodes.casting.buffer_to_int");
ContentRegistry::DataProcessorNode::add<NodeArithmeticAdd>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.add");
ContentRegistry::DataProcessorNode::add<NodeArithmeticSubtract>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.sub");
ContentRegistry::DataProcessorNode::add<NodeArithmeticMultiply>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.mul");
ContentRegistry::DataProcessorNode::add<NodeArithmeticDivide>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.div");
ContentRegistry::DataProcessorNode::add<NodeArithmeticModulus>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.mod");
ContentRegistry::DataProcessorNode::add<NodeIf>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.if");
ContentRegistry::DataProcessorNode::add<NodeEquals>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.equals");
ContentRegistry::DataProcessorNode::add<NodeNot>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.not");

View File

@ -347,6 +347,33 @@ namespace hex::plugin::builtin {
{ "hex.builtin.nodes.casting.buffer_to_int.input", "In" },
{ "hex.builtin.nodes.casting.buffer_to_int.output", "Out" },
{ "hex.builtin.nodes.arithmetic", "Arithmetisch" },
{ "hex.builtin.nodes.arithmetic.add", "Addition" },
{ "hex.builtin.nodes.arithmetic.add.header", "Plus" },
{ "hex.builtin.nodes.arithmetic.add.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.add.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.add.output", "Output" },
{ "hex.builtin.nodes.arithmetic.sub", "Subtraktion" },
{ "hex.builtin.nodes.arithmetic.sub.header", "Minus" },
{ "hex.builtin.nodes.arithmetic.sub.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.sub.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.sub.output", "Output" },
{ "hex.builtin.nodes.arithmetic.mul", "Multiplikation" },
{ "hex.builtin.nodes.arithmetic.mul.header", "Mal" },
{ "hex.builtin.nodes.arithmetic.mul.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.mul.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.mul.output", "Output" },
{ "hex.builtin.nodes.arithmetic.div", "Division" },
{ "hex.builtin.nodes.arithmetic.div.header", "Durch" },
{ "hex.builtin.nodes.arithmetic.div.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.div.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.div.output", "Output" },
{ "hex.builtin.nodes.arithmetic.mod", "Modulus" },
{ "hex.builtin.nodes.arithmetic.mod.header", "Modulo" },
{ "hex.builtin.nodes.arithmetic.mod.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.mod.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.mod.output", "Output" },
{ "hex.builtin.nodes.control_flow", "Kontrollfluss" },
{ "hex.builtin.nodes.control_flow.if", "If" },
{ "hex.builtin.nodes.control_flow.if.header", "If" },

View File

@ -347,6 +347,33 @@ namespace hex::plugin::builtin {
{ "hex.builtin.nodes.casting.buffer_to_int.input", "In" },
{ "hex.builtin.nodes.casting.buffer_to_int.output", "Out" },
{ "hex.builtin.nodes.arithmetic", "Arithmetic" },
{ "hex.builtin.nodes.arithmetic.add", "Addition" },
{ "hex.builtin.nodes.arithmetic.add.header", "Add" },
{ "hex.builtin.nodes.arithmetic.add.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.add.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.add.output", "Output" },
{ "hex.builtin.nodes.arithmetic.sub", "Subtraction" },
{ "hex.builtin.nodes.arithmetic.sub.header", "Subtract" },
{ "hex.builtin.nodes.arithmetic.sub.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.sub.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.sub.output", "Output" },
{ "hex.builtin.nodes.arithmetic.mul", "Multiplication" },
{ "hex.builtin.nodes.arithmetic.mul.header", "Multiply" },
{ "hex.builtin.nodes.arithmetic.mul.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.mul.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.mul.output", "Output" },
{ "hex.builtin.nodes.arithmetic.div", "Division" },
{ "hex.builtin.nodes.arithmetic.div.header", "Divide" },
{ "hex.builtin.nodes.arithmetic.div.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.div.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.div.output", "Output" },
{ "hex.builtin.nodes.arithmetic.mod", "Modulus" },
{ "hex.builtin.nodes.arithmetic.mod.header", "Modulo" },
{ "hex.builtin.nodes.arithmetic.mod.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.mod.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.mod.output", "Output" },
{ "hex.builtin.nodes.control_flow", "Control flow" },
{ "hex.builtin.nodes.control_flow.if", "If" },
{ "hex.builtin.nodes.control_flow.if.header", "If" },

View File

@ -347,6 +347,33 @@ namespace hex::plugin::builtin {
{ "hex.builtin.nodes.casting.buffer_to_int.input", "Entrata" },
{ "hex.builtin.nodes.casting.buffer_to_int.output", "Uscita" },
{ "hex.builtin.nodes.arithmetic", "Aritmetica" },
{ "hex.builtin.nodes.arithmetic.add", "Aggiunta" },
{ "hex.builtin.nodes.arithmetic.add.header", "Aggiungere" },
{ "hex.builtin.nodes.arithmetic.add.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.add.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.add.output", "Output" },
{ "hex.builtin.nodes.arithmetic.sub", "Sottrazione" },
{ "hex.builtin.nodes.arithmetic.sub.header", "Sottrarre" },
{ "hex.builtin.nodes.arithmetic.sub.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.sub.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.sub.output", "Output" },
{ "hex.builtin.nodes.arithmetic.mul", "Moltiplicazione" },
{ "hex.builtin.nodes.arithmetic.mul.header", "Moltiplicare" },
{ "hex.builtin.nodes.arithmetic.mul.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.mul.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.mul.output", "Output" },
{ "hex.builtin.nodes.arithmetic.div", "Divisione" },
{ "hex.builtin.nodes.arithmetic.div.header", "Dividere" },
{ "hex.builtin.nodes.arithmetic.div.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.div.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.div.output", "Output" },
{ "hex.builtin.nodes.arithmetic.mod", "Modulo" },
{ "hex.builtin.nodes.arithmetic.mod.header", "Modulo" },
{ "hex.builtin.nodes.arithmetic.mod.input.a", "Input A" },
{ "hex.builtin.nodes.arithmetic.mod.input.b", "Input B" },
{ "hex.builtin.nodes.arithmetic.mod.output", "Output" },
{ "hex.builtin.nodes.control_flow", "Controlla Flusso" },
{ "hex.builtin.nodes.control_flow.if", "Se" },
{ "hex.builtin.nodes.control_flow.if.header", "Se" },

View File

@ -165,16 +165,16 @@ namespace hex {
}
}
for (const auto &[category, name, function] : ContentRegistry::DataProcessorNode::getEntries()) {
if (category.empty() && name.empty()) {
for (const auto &[unlocalizedCategory, unlocalizedName, function] : ContentRegistry::DataProcessorNode::getEntries()) {
if (unlocalizedCategory.empty() && unlocalizedName.empty()) {
ImGui::Separator();
} else if (category.empty()) {
if (ImGui::MenuItem(name.c_str())) {
} else if (unlocalizedCategory.empty()) {
if (ImGui::MenuItem(LangEntry(unlocalizedName))) {
node = function();
}
} else {
if (ImGui::BeginMenu(category.c_str())) {
if (ImGui::MenuItem(name.c_str())) {
if (ImGui::BeginMenu(LangEntry(unlocalizedCategory))) {
if (ImGui::MenuItem(LangEntry(unlocalizedName))) {
node = function();
}
ImGui::EndMenu();