Updated to move to array
This commit is contained in:
parent
e78e2e4e72
commit
2a43d8bb51
3 changed files with 22 additions and 14 deletions
|
|
@ -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<kp::Sequence> 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<kp::Sequence> sq = this->mSequence.lock()) {
|
||||
sq->eval();
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("Sequence pointer no longer available");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <Godot.hpp>
|
||||
#include <Node2D.hpp>
|
||||
#include <Array.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
|
@ -15,7 +16,7 @@ private:
|
|||
public:
|
||||
KomputeSummator();
|
||||
|
||||
void add(float value);
|
||||
void add(Array data);
|
||||
void reset();
|
||||
float get_total() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue