From 2a43d8bb51b8e62b5b6a7f722644c981c053514c Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sat, 26 Sep 2020 15:18:35 +0100 Subject: [PATCH] Updated to move to array --- .../gdnative_shared/src/KomputeSummator.cpp | 25 ++++++++++++------- .../gdnative_shared/src/KomputeSummator.hpp | 3 ++- .../scripts/DynamicExampleScript.gd | 8 +++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp b/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp index f64e0d088..ca6fb7667 100644 --- a/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp +++ b/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp @@ -12,15 +12,22 @@ KomputeSummator::KomputeSummator() { this->_init(); } -void KomputeSummator::add(float value) { - // Set the new data in the local device - this->mSecondaryTensor->setData({value}); - // Execute recorded sequence - if (std::shared_ptr sq = this->mSequence.lock()) { - sq->eval(); - } - else { - throw std::runtime_error("Sequence pointer no longer available"); +void KomputeSummator::add(Array data) { + + for (size_t i = 0; i < data.size(); i++) { + + assert(var.get_type() == Variant::Type::REAL); + float value = data[i]; + + // Set the new data in the local device + this->mSecondaryTensor->setData({value}); + // Execute recorded sequence + if (std::shared_ptr sq = this->mSequence.lock()) { + sq->eval(); + } + else { + throw std::runtime_error("Sequence pointer no longer available"); + } } } diff --git a/examples/godot_examples/gdnative_shared/src/KomputeSummator.hpp b/examples/godot_examples/gdnative_shared/src/KomputeSummator.hpp index 9131e7f57..11345e9e8 100644 --- a/examples/godot_examples/gdnative_shared/src/KomputeSummator.hpp +++ b/examples/godot_examples/gdnative_shared/src/KomputeSummator.hpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -15,7 +16,7 @@ private: public: KomputeSummator(); - void add(float value); + void add(Array data); void reset(); float get_total() const; diff --git a/examples/godot_examples/godot_resources/scripts/DynamicExampleScript.gd b/examples/godot_examples/godot_resources/scripts/DynamicExampleScript.gd index 454314a57..4f96b586b 100755 --- a/examples/godot_examples/godot_resources/scripts/DynamicExampleScript.gd +++ b/examples/godot_examples/godot_resources/scripts/DynamicExampleScript.gd @@ -8,10 +8,10 @@ func _ready(): # Use existing node print($KomputeNode.get_total()) - $KomputeNode.add(10) + $KomputeNode.add([10.0, 20.0]) print($KomputeNode.get_total()) - $KomputeNode.add(10) + $KomputeNode.add([10.0, 20.0]) print($KomputeNode.get_total()) # Create new instance @@ -21,9 +21,9 @@ func _ready(): print(s.get_total()) # Now we can again send further commands - s.add(10) + s.add([10.0, 20.0]) print(s.get_total()) - s.add(10) + s.add([10.0, 20.0]) print(s.get_total())