Added full module example

This commit is contained in:
Alejandro Saucedo 2020-09-20 17:19:12 +01:00
parent f3c2d8e2b6
commit b74d9b203c
35 changed files with 92 additions and 40 deletions

View file

@ -1 +1,2 @@
.import
godot_engine/godot

View file

@ -1,2 +1,3 @@
vulkan-kompute
lib
godot

View file

@ -42,4 +42,24 @@ Now to build godot you will need to set up a couple of things for the Scons file
* Copy the `kompute.lib` library from the Kompute build to `lib/kompute.lib`
* Make sure the versions above match as we provide the headers in the `include` folder - if you used different versions make sure these match as well
### Clone godot repository
Now we can clone the godot repository - it must be on a separate repository, so you can use the parent directory if you are on the Kompute repo.
```
cd ../../godot_engine
git clone --branch 3.2.3-stable https://github.com/godotengine/godot
cd godot/
```
And now we can build against our module
```
wscons -j16 custom_modules=../../custom_module/ platform=windows target=release_debug
```

View file

@ -2,13 +2,13 @@
#include <vector>
#include "KomputeSummator.hpp"
#include "KomputeSummatorNode.h"
KomputeSummator::KomputeSummator() {
KomputeSummatorNode::KomputeSummatorNode() {
this->_init();
}
void KomputeSummator::add(float value) {
void KomputeSummatorNode::add(float value) {
// Set the new data in the local device
this->mSecondaryTensor->setData({value});
// Execute recorded sequence
@ -20,14 +20,14 @@ void KomputeSummator::add(float value) {
}
}
void KomputeSummator::reset() {
void KomputeSummatorNode::reset() {
}
float KomputeSummator::get_total() const {
float KomputeSummatorNode::get_total() const {
return this->mPrimaryTensor->data()[0];
}
void KomputeSummator::_init() {
void KomputeSummatorNode::_init() {
std::cout << "CALLING INIT" << std::endl;
this->mPrimaryTensor = this->mManager.buildTensor({ 0.0 });
this->mSecondaryTensor = this->mManager.buildTensor({ 0.0 });
@ -74,16 +74,16 @@ void KomputeSummator::_init() {
}
}
void KomputeSummator::_process(float delta) {
void KomputeSummatorNode::_process(float delta) {
}
void KomputeSummator::_bind_methods() {
ClassDB::bind_method(D_METHOD("_process", "delta"), &KomputeSummator::_process);
ClassDB::bind_method(D_METHOD("_init"), &KomputeSummator::_init);
void KomputeSummatorNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("_process", "delta"), &KomputeSummatorNode::_process);
ClassDB::bind_method(D_METHOD("_init"), &KomputeSummatorNode::_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);
ClassDB::bind_method(D_METHOD("add", "value"), &KomputeSummatorNode::add);
ClassDB::bind_method(D_METHOD("reset"), &KomputeSummatorNode::reset);
ClassDB::bind_method(D_METHOD("get_total"), &KomputeSummatorNode::get_total);
}

View file

@ -4,13 +4,13 @@
#include "kompute/Kompute.hpp"
#include "scene/main/node_2d.h"
#include "scene/main/node.h"
class KomputeSummator : public Node2D {
GDCLASS(KomputeSummator, Node2D);
class KomputeSummatorNode : public Node {
GDCLASS(KomputeSummatorNode, Node);
public:
KomputeSummator();
KomputeSummatorNode();
void add(float value);
void reset();

View file

@ -6,9 +6,8 @@ dir_path = os.getcwd()
# Kompute & Vulkan header files
env.Append(CPPPATH = ['include/'])
env.Append(CPPPATH = ['src/'])
env.add_source_files(env.modules_sources, "src/*.cpp")
env.add_source_files(env.modules_sources, "*.cpp")
# Kompute & Vulkan libraries
env.Append(LIBS=[

View file

@ -0,0 +1,14 @@
/* register_types.cpp */
#include "register_types.h"
#include "core/class_db.h"
#include "KomputeSummatorNode.h"
void register_kompute_summator_types() {
ClassDB::register_class<KomputeSummatorNode>();
}
void unregister_kompute_summator_types() {
// Nothing to do here in this example.
}

View file

@ -1,6 +1,6 @@
/* register_types.h */
#pragma once
void register_summator_types();
void unregister_summator_types();
void register_kompute_summator_types();
void unregister_kompute_summator_types();
/* yes, the word in the middle must be the same as the module folder name */

View file

@ -1,14 +0,0 @@
/* register_types.cpp */
#include "register_types.h"
#include "core/class_db.h"
#include "KomputeSummator.hpp"
void register_summator_types() {
ClassDB::register_class<KomputeSummator>();
}
void unregister_summator_types() {
// Nothing to do here in this example.
}

View file

@ -1,5 +0,0 @@
def can_build(env, platform):
return True
def configure(env):
pass

View file

@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://godot_resources/scripts/CustomModuleExampleScene.gd" type="Script" id=1]
[node name="Parent" type="Node2D"]
script = ExtResource( 1 )
[node name="CustomKomputeNode" type="KomputeSummatorNode" parent="."]

View file

@ -0,0 +1,28 @@
extends Node2D
# Called when the node enters the scene tree for the first time.
func _ready():
print("hello")
# Use existing node
print($CustomKomputeNode.get_total())
$CustomKomputeNode.add(10)
print($CustomKomputeNode.get_total())
$CustomKomputeNode.add(10)
print($CustomKomputeNode.get_total())
# Create new instance
var s = KomputeSummatorNode.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())