From cc9dc90655cf7949af611b721802d74edca5cf4b Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 12 Oct 2022 12:09:51 +0200 Subject: [PATCH] nodes: Added Float <-> Buffer casting nodes --- .../source/content/data_processor_nodes.cpp | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/plugins/builtin/source/content/data_processor_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes.cpp index 073cb59b2..abf3544b2 100644 --- a/plugins/builtin/source/content/data_processor_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes.cpp @@ -402,8 +402,8 @@ namespace hex::plugin::builtin { void process() override { auto input = this->getIntegerOnInput(0); - std::vector output(sizeof(u64), 0x00); - std::memcpy(output.data(), &input, sizeof(u64)); + std::vector output(sizeof(input), 0x00); + std::memcpy(output.data(), &input, sizeof(input)); this->setBufferOnOutput(1, output); } @@ -416,16 +416,47 @@ namespace hex::plugin::builtin { void process() override { auto input = this->getBufferOnInput(0); - if (input.empty() || input.size() > sizeof(u64)) + i64 output = 0; + if (input.empty() || input.size() > sizeof(output)) throwNodeError("Buffer is empty or bigger than 64 bits"); - u64 output = 0; std::memcpy(&output, input.data(), input.size()); this->setIntegerOnOutput(1, output); } }; + class NodeCastFloatToBuffer : public dp::Node { + public: + NodeCastFloatToBuffer() : Node("hex.builtin.nodes.casting.float_to_buffer.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Float, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { } + + void process() override { + auto input = this->getFloatOnInput(0); + + std::vector output(sizeof(input), 0x00); + std::memcpy(output.data(), &input, sizeof(input)); + + this->setBufferOnOutput(1, output); + } + }; + + class NodeCastBufferToFloat : public dp::Node { + public: + NodeCastBufferToFloat() : Node("hex.builtin.nodes.casting.buffer_to_float.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Float, "hex.builtin.nodes.common.output") }) { } + + void process() override { + auto input = this->getBufferOnInput(0); + + float output = 0; + if (input.empty() || input.size() != sizeof(output)) + throwNodeError("Buffer is empty or not the right size to fit a float"); + + std::memcpy(&output, input.data(), input.size()); + + this->setFloatOnOutput(1, output); + } + }; + 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.common.input.a"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { } @@ -1038,6 +1069,8 @@ namespace hex::plugin::builtin { ContentRegistry::DataProcessorNode::add("hex.builtin.nodes.casting", "hex.builtin.nodes.casting.int_to_buffer"); ContentRegistry::DataProcessorNode::add("hex.builtin.nodes.casting", "hex.builtin.nodes.casting.buffer_to_int"); + ContentRegistry::DataProcessorNode::add("hex.builtin.nodes.casting", "hex.builtin.nodes.casting.float_to_buffer"); + ContentRegistry::DataProcessorNode::add("hex.builtin.nodes.casting", "hex.builtin.nodes.casting.buffer_to_float"); ContentRegistry::DataProcessorNode::add("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.add"); ContentRegistry::DataProcessorNode::add("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.sub");