From f3c2d8e2b62c2fe40a3ecb8a11019ad4f1d94c4c Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 20 Sep 2020 15:30:48 +0100 Subject: [PATCH] Updated to KomputeSummator for static compiled --- .../src/{summator.cpp => KomputeSummator.cpp} | 58 +++++++++++-------- .../src/{summator.h => KomputeSummator.hpp} | 17 +++--- .../custom_module/src/register_types.cpp | 4 +- .../gdnative_shared/src/KomputeSummator.hpp | 3 - 4 files changed, 45 insertions(+), 37 deletions(-) rename examples/godot_examples/custom_module/src/{summator.cpp => KomputeSummator.cpp} (70%) rename examples/godot_examples/custom_module/src/{summator.h => KomputeSummator.hpp} (65%) diff --git a/examples/godot_examples/custom_module/src/summator.cpp b/examples/godot_examples/custom_module/src/KomputeSummator.cpp similarity index 70% rename from examples/godot_examples/custom_module/src/summator.cpp rename to examples/godot_examples/custom_module/src/KomputeSummator.cpp index ab87d1376..a206f275f 100644 --- a/examples/godot_examples/custom_module/src/summator.cpp +++ b/examples/godot_examples/custom_module/src/KomputeSummator.cpp @@ -2,9 +2,33 @@ #include -#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 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 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); } diff --git a/examples/godot_examples/custom_module/src/summator.h b/examples/godot_examples/custom_module/src/KomputeSummator.hpp similarity index 65% rename from examples/godot_examples/custom_module/src/summator.h rename to examples/godot_examples/custom_module/src/KomputeSummator.hpp index 9c13c5565..cfa1c9cc9 100644 --- a/examples/godot_examples/custom_module/src/summator.h +++ b/examples/godot_examples/custom_module/src/KomputeSummator.hpp @@ -1,24 +1,24 @@ -/* summator.h */ - -#ifndef SUMMATOR_H -#define SUMMATOR_H +#pragma once #include #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 mSecondaryTensor; }; -#endif // SUMMATOR_H diff --git a/examples/godot_examples/custom_module/src/register_types.cpp b/examples/godot_examples/custom_module/src/register_types.cpp index 3cb5b536f..76dfc95d5 100644 --- a/examples/godot_examples/custom_module/src/register_types.cpp +++ b/examples/godot_examples/custom_module/src/register_types.cpp @@ -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(); + ClassDB::register_class(); } void unregister_summator_types() { diff --git a/examples/godot_examples/gdnative_shared/src/KomputeSummator.hpp b/examples/godot_examples/gdnative_shared/src/KomputeSummator.hpp index 7a5029ffe..9131e7f57 100644 --- a/examples/godot_examples/gdnative_shared/src/KomputeSummator.hpp +++ b/examples/godot_examples/gdnative_shared/src/KomputeSummator.hpp @@ -24,9 +24,6 @@ public: static void _register_methods(); -protected: - //static void _bind_methods(); - private: kp::Manager mManager; std::weak_ptr mSequence;