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