Export variables with gdextension

Signed-off-by: somebody_master <somebody_master@somebodyserver.mooo.com>
This commit is contained in:
Somebody Master 2023-04-14 12:01:06 +02:00
parent 78c4323b8f
commit f1a0aaccd7
Signed by: somebody_master
GPG Key ID: 78315CFDF0B25505
3 changed files with 71 additions and 21 deletions

View File

@ -2,7 +2,7 @@ extends Test
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
start_test();
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:

View File

@ -1,17 +1,37 @@
#ifndef TEST_HPP
#define TEST_HPP
#include <godot_cpp/classes/mesh_instance3d.hpp>
#include <godot_cpp/classes/node3d.hpp>
#include <godot_cpp/classes/texture2d.hpp>
using namespace godot;
class Test : public Node3D {
GDCLASS(Test, Node3D);
public:
void start_test();
protected:
static void _bind_methods();
private:
int i_value = 0;
float f_value = 0.0;
String s_value = "Hello";
Ref<Texture2D> tex_value;
public:
int get_i_value();
void set_i_value(int input);
float get_f_value();
void set_f_value(float input);
String get_s_value();
void set_s_value(String s);
Ref<Texture2D> get_tex_value();
void set_tex_value(Ref<Texture2D> tex);
};
#endif

View File

@ -5,22 +5,52 @@
#include <godot_cpp/classes/image_texture.hpp>
void Test::start_test() {
Ref<ImageTexture> tex(memnew(ImageTexture));
auto format = tex->get_format();
UtilityFunctions::print(tex->get_reference_count());
Ref<ImageTexture> tex2 = tex;
UtilityFunctions::print(tex->get_reference_count());
tex2.unref();
UtilityFunctions::print(tex->get_reference_count());
tex.unref();
}
void Test::_bind_methods() {
ClassDB:
ClassDB::bind_method(D_METHOD("start_test"), &Test::start_test);
ClassDB::bind_method(D_METHOD("get_i_value"), &Test::get_i_value);
ClassDB::bind_method(D_METHOD("set_i_value", "i_val"), &Test::set_i_value);
ADD_PROPERTY(PropertyInfo(Variant::INT, "i_value"), "set_i_value", "get_i_value");
ClassDB::bind_method(D_METHOD("get_f_value"), &Test::get_f_value);
ClassDB::bind_method(D_METHOD("set_f_value", "f_val"), &Test::set_f_value);
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "f_value"), "set_f_value", "get_f_value");
ClassDB::bind_method(D_METHOD("get_s_value"), &Test::get_s_value);
ClassDB::bind_method(D_METHOD("set_s_value", "s_val"), &Test::set_s_value);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "s_value"), "set_s_value", "get_s_value");
ClassDB::bind_method(D_METHOD("get_tex_value"), &Test::get_tex_value);
ClassDB::bind_method(D_METHOD("set_tex_value", "tex"), &Test::set_tex_value);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tex_value", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_tex_value", "get_tex_value");
}
int Test::get_i_value() {
return i_value;
}
void Test::set_i_value(int input) {
i_value = input;
}
float Test::get_f_value() {
return f_value;
}
void Test::set_f_value(float input) {
f_value = input;
}
String Test::get_s_value() {
return s_value;
}
void Test::set_s_value(String s) {
s_value = s;
}
Ref<Texture2D> Test::get_tex_value() {
return tex_value;
}
void Test::set_tex_value(Ref<Texture2D> tex) {
tex_value = tex;
}