Updated to use komputesummator class

This commit is contained in:
Alejandro Saucedo 2020-09-20 15:20:03 +01:00
parent b5bdb2e7d1
commit 6ff55d4f3f
16 changed files with 95 additions and 121 deletions

View file

@ -1,4 +1,4 @@
#include "summator.h"
#include "KomputeSummator.hpp"
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
godot::Godot::gdnative_init(o);
@ -11,5 +11,5 @@ extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_opt
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) {
godot::Godot::nativescript_init(handle);
godot::register_class<godot::Summator>();
godot::register_class<godot::KomputeSummator>();
}

View file

@ -3,16 +3,16 @@
#include <vector>
#include <iostream>
#include "summator.h"
#include "KomputeSummator.hpp"
namespace godot {
Summator::Summator() {
KomputeSummator::KomputeSummator() {
std::cout << "CALLING CONSTRUCTOR" << std::endl;
this->_init();
}
void Summator::add(float value) {
void KomputeSummator::add(float value) {
// Set the new data in the local device
this->mSecondaryTensor->setData({value});
// Execute recorded sequence
@ -24,14 +24,14 @@ void Summator::add(float value) {
}
}
void Summator::reset() {
void KomputeSummator::reset() {
}
float Summator::get_total() const {
float KomputeSummator::get_total() const {
return this->mPrimaryTensor->data()[0];
}
void Summator::_init() {
void KomputeSummator::_init() {
std::cout << "CALLING INIT" << std::endl;
this->mPrimaryTensor = this->mManager.buildTensor({ 0.0 });
this->mSecondaryTensor = this->mManager.buildTensor({ 0.0 });
@ -78,24 +78,18 @@ void Summator::_init() {
}
}
void Summator::_process(float delta) {
std::cout << "CALLING PROCESS" << std::endl;
void KomputeSummator::_process(float delta) {
}
void Summator::_register_methods() {
register_method((char *)"_process", &Summator::_process);
register_method((char *)"_init", &Summator::_init);
register_method((char *)"add", &Summator::add);
register_method((char *)"reset", &Summator::reset);
register_method((char *)"get_total", &Summator::get_total);
}
void KomputeSummator::_register_methods() {
register_method((char *)"_process", &KomputeSummator::_process);
register_method((char *)"_init", &KomputeSummator::_init);
//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);
//}
register_method((char *)"add", &KomputeSummator::add);
register_method((char *)"reset", &KomputeSummator::reset);
register_method((char *)"get_total", &KomputeSummator::get_total);
}
}

View file

@ -8,12 +8,12 @@
#include "kompute/Kompute.hpp"
namespace godot {
class Summator : public Node2D {
class KomputeSummator : public Node2D {
private:
GODOT_CLASS(Summator, Node2D);
GODOT_CLASS(KomputeSummator, Node2D);
public:
Summator();
KomputeSummator();
void add(float value);
void reset();

View file

@ -1,39 +0,0 @@
#include "Player.h"
using namespace godot;
void Player::_register_methods() {
register_method((char*)"_process", &Player::_process);
}
void Player::_init() {}
Player::Player() {
motion = Vector2(0, 0);
}
Player::~Player() {}
void Player::_process(float delta)
{
UpdateMotionFromInput();
move_and_slide(motion);
}
void Player::UpdateMotionFromInput()
{
motion = Vector2(0, 0);
Input* i = Input::get_singleton();
if (i->is_action_pressed("ui_up"))
motion.y -= speed;
if (i->is_action_pressed("ui_down"))
motion.y += speed;
if (i->is_action_pressed("ui_left"))
motion.x -= speed;
if (i->is_action_pressed("ui_right"))
motion.x += speed;
}

View file

@ -1,42 +0,0 @@
#pragma once
#include <Godot.hpp>
#include <KinematicBody2D.hpp>
#include <Input.hpp>
namespace godot {
class Player : public KinematicBody2D
{
// Godot structure
private:
GODOT_CLASS(Player, KinematicBody2D)
public:
static void _register_methods();
void _init();
void _process(float delta);
Player();
~Player();
// Gameplay variables
public:
const int speed = 300;
private:
Vector2 motion;
// Gameplay methods
public:
void UpdateMotionFromInput();
private:
};
}

View file

@ -1 +0,0 @@
#include "Root.h"

View file

@ -1,5 +0,0 @@
#pragma once
class Root
{
};