Updated to KomputeSummator for static compiled
This commit is contained in:
parent
6ff55d4f3f
commit
f3c2d8e2b6
4 changed files with 45 additions and 37 deletions
|
|
@ -2,9 +2,33 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "summator.h"
|
#include "KomputeSummator.hpp"
|
||||||
|
|
||||||
Summator::Summator() {
|
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::reset() {
|
||||||
|
}
|
||||||
|
|
||||||
|
float KomputeSummator::get_total() const {
|
||||||
|
return this->mPrimaryTensor->data()[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
void KomputeSummator::_init() {
|
||||||
|
std::cout << "CALLING INIT" << std::endl;
|
||||||
this->mPrimaryTensor = this->mManager.buildTensor({ 0.0 });
|
this->mPrimaryTensor = this->mManager.buildTensor({ 0.0 });
|
||||||
this->mSecondaryTensor = this->mManager.buildTensor({ 0.0 });
|
this->mSecondaryTensor = this->mManager.buildTensor({ 0.0 });
|
||||||
this->mSequence = this->mManager.getOrCreateManagedSequence("AdditionSeq");
|
this->mSequence = this->mManager.getOrCreateManagedSequence("AdditionSeq");
|
||||||
|
|
@ -50,28 +74,16 @@ Summator::Summator() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Summator::add(float value) {
|
void KomputeSummator::_process(float delta) {
|
||||||
// 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 Summator::reset() {
|
void KomputeSummator::_bind_methods() {
|
||||||
}
|
ClassDB::bind_method(D_METHOD("_process", "delta"), &KomputeSummator::_process);
|
||||||
|
ClassDB::bind_method(D_METHOD("_init"), &KomputeSummator::_init);
|
||||||
float Summator::get_total() const {
|
|
||||||
return this->mPrimaryTensor->data()[0];
|
ClassDB::bind_method(D_METHOD("add", "value"), &KomputeSummator::add);
|
||||||
}
|
ClassDB::bind_method(D_METHOD("reset"), &KomputeSummator::reset);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_total"), &KomputeSummator::get_total);
|
||||||
void Summator::_bind_methods() {
|
|
||||||
ClassDB::bind_method(D_METHOD("add", "value"), &Summator::add);
|
|
||||||
ClassDB::bind_method(D_METHOD("reset"), &Summator::reset);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_total"), &Summator::get_total);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,24 +1,24 @@
|
||||||
/* summator.h */
|
#pragma once
|
||||||
|
|
||||||
#ifndef SUMMATOR_H
|
|
||||||
#define SUMMATOR_H
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "kompute/Kompute.hpp"
|
#include "kompute/Kompute.hpp"
|
||||||
|
|
||||||
#include "scene/main/node.h"
|
#include "scene/main/node_2d.h"
|
||||||
|
|
||||||
class Summator : public Node {
|
class KomputeSummator : public Node2D {
|
||||||
GDCLASS(Summator, Node);
|
GDCLASS(KomputeSummator, Node2D);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Summator();
|
KomputeSummator();
|
||||||
|
|
||||||
void add(float value);
|
void add(float value);
|
||||||
void reset();
|
void reset();
|
||||||
float get_total() const;
|
float get_total() const;
|
||||||
|
|
||||||
|
void _process(float delta);
|
||||||
|
void _init();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
|
|
@ -29,4 +29,3 @@ private:
|
||||||
std::shared_ptr<kp::Tensor> mSecondaryTensor;
|
std::shared_ptr<kp::Tensor> mSecondaryTensor;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SUMMATOR_H
|
|
||||||
|
|
@ -3,10 +3,10 @@
|
||||||
#include "register_types.h"
|
#include "register_types.h"
|
||||||
|
|
||||||
#include "core/class_db.h"
|
#include "core/class_db.h"
|
||||||
#include "summator.h"
|
#include "KomputeSummator.hpp"
|
||||||
|
|
||||||
void register_summator_types() {
|
void register_summator_types() {
|
||||||
ClassDB::register_class<Summator>();
|
ClassDB::register_class<KomputeSummator>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unregister_summator_types() {
|
void unregister_summator_types() {
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,6 @@ public:
|
||||||
|
|
||||||
static void _register_methods();
|
static void _register_methods();
|
||||||
|
|
||||||
protected:
|
|
||||||
//static void _bind_methods();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
kp::Manager mManager;
|
kp::Manager mManager;
|
||||||
std::weak_ptr<kp::Sequence> mSequence;
|
std::weak_ptr<kp::Sequence> mSequence;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue