Updated to use komputesummator class
This commit is contained in:
parent
b5bdb2e7d1
commit
6ff55d4f3f
16 changed files with 95 additions and 121 deletions
|
|
@ -16,8 +16,8 @@ find_package(Vulkan REQUIRED)
|
|||
|
||||
add_library(kompute_godot
|
||||
SHARED
|
||||
src/summator.cpp
|
||||
src/gdlibrary.cpp)
|
||||
src/KomputeSummator.cpp
|
||||
src/KomputeGdNative.cpp)
|
||||
|
||||
target_include_directories(
|
||||
kompute_godot PUBLIC
|
||||
|
|
|
|||
|
|
@ -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>();
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -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();
|
||||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
@ -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:
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
#include "Root.h"
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
#pragma once
|
||||
class Root
|
||||
{
|
||||
};
|
||||
|
||||
10
examples/godot_examples/godot_resources/assets/DynamicExampleScene.tscn
Executable file
10
examples/godot_examples/godot_resources/assets/DynamicExampleScene.tscn
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://godot_resources/scripts/DynamicExampleScript.gd" type="Script" id=1]
|
||||
[ext_resource path="res://godot_resources/scripts/KomputeNativeClass.gdns" type="Script" id=2]
|
||||
|
||||
[node name="Parent" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="KomputeNode" type="Node2D" parent="."]
|
||||
script = ExtResource( 2 )
|
||||
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/icon.png-410975027061d785c4229e33fe5ba462.stex"
|
||||
path="res://.import/icon.png-dceb2295401b72087458cab0725ade4f.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://godot_resources/icon.png"
|
||||
dest_files=[ "res://.import/icon.png-410975027061d785c4229e33fe5ba462.stex" ]
|
||||
source_file="res://godot_resources/assets/icon.png"
|
||||
dest_files=[ "res://.import/icon.png-dceb2295401b72087458cab0725ade4f.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
29
examples/godot_examples/godot_resources/scripts/DynamicExampleScript.gd
Executable file
29
examples/godot_examples/godot_resources/scripts/DynamicExampleScript.gd
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
extends Node2D
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
|
||||
print("hello")
|
||||
|
||||
# Use existing node
|
||||
print($KomputeNode.get_total())
|
||||
|
||||
$KomputeNode.add(10)
|
||||
print($KomputeNode.get_total())
|
||||
|
||||
$KomputeNode.add(10)
|
||||
print($KomputeNode.get_total())
|
||||
|
||||
# Create new instance
|
||||
var s = KomputeSummator.new()
|
||||
|
||||
# This will print 0 as it's a new instance
|
||||
print(s.get_total())
|
||||
|
||||
# Now we can again send further commands
|
||||
s.add(10)
|
||||
print(s.get_total())
|
||||
|
||||
s.add(10)
|
||||
print(s.get_total())
|
||||
|
||||
8
examples/godot_examples/godot_resources/scripts/KomputeNativeClass.gdns
Executable file
8
examples/godot_examples/godot_resources/scripts/KomputeNativeClass.gdns
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
[gd_resource type="NativeScript" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://godot_resources/scripts/KomputeNativeLibrary.gdnlib" type="GDNativeLibrary" id=1]
|
||||
|
||||
[resource]
|
||||
class_name = "KomputeSummator"
|
||||
library = ExtResource( 1 )
|
||||
script_class_name = "KomputeSummator"
|
||||
14
examples/godot_examples/godot_resources/scripts/KomputeNativeLibrary.gdnlib
Executable file
14
examples/godot_examples/godot_resources/scripts/KomputeNativeLibrary.gdnlib
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
[general]
|
||||
|
||||
singleton=false
|
||||
load_once=true
|
||||
symbol_prefix="godot_"
|
||||
reloadable=false
|
||||
|
||||
[entry]
|
||||
|
||||
Windows.64="res://gdnative_shared/build/Release/kompute_godot.dll"
|
||||
|
||||
[dependencies]
|
||||
|
||||
Windows.64=[ ]
|
||||
|
|
@ -8,16 +8,22 @@
|
|||
|
||||
config_version=4
|
||||
|
||||
_global_script_classes=[ ]
|
||||
_global_script_classes=[ {
|
||||
"base": "Node2D",
|
||||
"class": "KomputeSummator",
|
||||
"language": "NativeScript",
|
||||
"path": "res://godot_resources/scripts/KomputeNativeClass.gdns"
|
||||
} ]
|
||||
_global_script_class_icons={
|
||||
|
||||
"KomputeSummator": ""
|
||||
}
|
||||
|
||||
[application]
|
||||
|
||||
config/name="KomputeGame"
|
||||
config/icon="res://godot_resources/icon.png"
|
||||
run/main_scene="res://godot_resources/assets/DynamicExampleScene.tscn"
|
||||
config/icon="res://godot_resources/assets/icon.png"
|
||||
|
||||
[rendering]
|
||||
|
||||
environment/default_environment="res://godot_resources/default_env.tres"
|
||||
environment/default_environment="res://godot_resources/assets/default_env.tres"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue