updated to use the new NativeScript and GDNative interface

pull/23/head
Karroffel 2017-07-24 14:23:09 +02:00
parent 2195f2e9a8
commit c27af379b8
23 changed files with 67 additions and 47 deletions

View File

@ -15,7 +15,7 @@ env = Environment()
if ARGUMENTS.get("use_llvm", "no") == "yes":
env["CXX"] = "clang++"
target = ARGUMENTS.get("target", "core")
target = ARGUMENTS.get("target", "debug")
platform = ARGUMENTS.get("p", "linux")
@ -33,7 +33,7 @@ if platform == "osx":
env.Append(LINKFLAGS = ['-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup'])
if platform == "linux":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14'])
env.Append(CCFLAGS = ['-fPIC', '-g','-O3', '-std=c++14'])
env.Append(CPPPATH=['.', godot_headers_path, 'include', 'include/core'])

View File

@ -64,7 +64,7 @@ def generate_class_header(used_classes, c):
source.append("")
source.append("")
source.append("#include <godot.h>")
source.append("#include <godot/gdnative.h>")
source.append("#include <stdint.h>")
source.append("")
@ -419,7 +419,7 @@ def generate_icall_header(icalls):
source.append("")
source.append("#include <godot.h>")
source.append("#include <godot/gdnative.h>")
source.append("#include <stdint.h>")
source.append("")
@ -469,7 +469,7 @@ def generate_icall_implementation(icalls):
source.append("")
source.append("#include <godot.h>")
source.append("#include <godot/gdnative.h>")
source.append("#include <stdint.h>")
source.append("")

View File

@ -1,7 +1,7 @@
#ifndef ARRAY_H
#define ARRAY_H
#include <godot/godot_array.h>
#include <godot/array.h>
#include "String.hpp"

View File

@ -1,7 +1,7 @@
#ifndef COLOR_H
#define COLOR_H
#include <godot/godot_color.h>
#include <godot/color.h>
#include <cmath>

View File

@ -5,7 +5,7 @@
#include "Array.hpp"
#include <godot/godot_dictionary.h>
#include <godot/dictionary.h>
namespace godot {

View File

@ -4,7 +4,8 @@
#include <cstdlib>
#include <cstring>
#include <godot.h>
#include <godot/gdnative.h>
#include <godot_nativescript.h>
#include <CoreTypes.hpp>
@ -39,16 +40,10 @@ public:
#if !defined(_WIN32)
#define GD_EXPORT
#else
#define GD_EXPORT __declspec(dllexport)
#endif
#define GODOT_NATIVE_INIT(arg) extern "C" void GD_EXPORT godot_native_init(arg)
#define GODOT_NATIVE_TERMINATE(arg) extern "C" void GD_EXPORT godot_native_terminate(arg)
#define GDNATIVE_INIT(arg) void gdnative_init(arg)
#define GDNATIVE_TERMINATE(arg) void gdnative_terminate(arg)
#define NATIVESCRIPT_INIT() void nativescript_init()
#define GODOT_CLASS(Name) \
public: inline static char *___get_type_name() { return (char *) #Name; } \
@ -92,7 +87,7 @@ struct _ArgCast<Variant> {
template<class T>
T *as(Object *obj)
{
return (T *) godot_native_get_userdata(obj);
return (T *) godot_nativescript_get_userdata(obj);
}
// instance and destroy funcs
@ -114,7 +109,6 @@ void _godot_class_destroy_func(godot_object *p, void *method_data, void *data)
}
template<class T>
void register_class()
{
@ -125,7 +119,7 @@ void register_class()
destroy.destroy_func = _godot_class_destroy_func<T>;
godot_script_register_class(T::___get_type_name(), T::___get_base_type_name(), create, destroy);
godot_nativescript_register_class(godot::_RegisterState::nativescript_handle, T::___get_type_name(), T::___get_base_type_name(), create, destroy);
T::_register_methods();
}
@ -139,7 +133,7 @@ void register_tool_class()
destroy.destroy_func = _godot_class_destroy_func<T>;
godot_script_register_tool_class(T::___get_type_name(), T::___get_base_type_name(), create, destroy);
godot_nativescript_register_tool_class(godot::_RegisterState::nativescript_handle, T::___get_type_name(), T::___get_base_type_name(), create, destroy);
T::_register_methods();
}
@ -292,7 +286,7 @@ void register_method(char *name, M method_ptr, godot_method_rpc_mode rpc_type =
godot_method_attributes attr = {};
attr.rpc_type = rpc_type;
godot_script_register_method(___get_method_class_name(method_ptr), name, attr, method);
godot_nativescript_register_method(godot::_RegisterState::nativescript_handle, ___get_method_class_name(method_ptr), name, attr, method);
}
@ -300,12 +294,12 @@ void register_method(char *name, M method_ptr, godot_method_rpc_mode rpc_type =
template<class T, class P>
struct _PropertySetFunc {
void (T::*f)(P);
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant value)
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value)
{
_PropertySetFunc<T, P> *set_func = (_PropertySetFunc<T, P> *) method_data;
T *obj = (T *) user_data;
Variant *v = (Variant *) &value;
Variant *v = (Variant *) value;
(obj->*(set_func->f))(_ArgCast<P>::_arg_cast(*v));
}
@ -338,12 +332,12 @@ struct _PropertyGetFunc {
template<class T, class P>
struct _PropertyDefaultSetFunc {
P (T::*f);
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant value)
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value)
{
_PropertyDefaultSetFunc<T, P> *set_func = (_PropertyDefaultSetFunc<T, P> *) method_data;
T *obj = (T *) user_data;
Variant *v = (Variant *) &value;
Variant *v = (Variant *) value;
(obj->*(set_func->f)) = _ArgCast<P>::_arg_cast(*v);
}
@ -410,7 +404,7 @@ void register_property(char *name, P (T::*var), P default_value, godot_method_rp
get_func.free_func = godot_free;
get_func.get_func = &_PropertyDefaultGetFunc<T, P>::_wrapped_getter;
godot_script_register_property(T::___get_type_name(), name, &attr, set_func, get_func);
godot_nativescript_register_property(godot::_RegisterState::nativescript_handle, T::___get_type_name(), name, &attr, set_func, get_func);
}
@ -444,7 +438,7 @@ void register_property(char *name, void (T::*setter)(P), P (T::*getter)(), P def
get_func.free_func = godot_free;
get_func.get_func = &_PropertyGetFunc<T, P>::_wrapped_getter;
godot_script_register_property(T::___get_type_name(), name, &attr, set_func, get_func);
godot_nativescript_register_property(godot::_RegisterState::nativescript_handle, T::___get_type_name(), name, &attr, set_func, get_func);
}
@ -473,11 +467,13 @@ void register_signal(String name, Dictionary args = Dictionary())
signal.args[i].type = args.values()[i];
}
godot_script_register_signal(T::___get_type_name(), &signal);
godot_nativescript_register_signal(godot::_RegisterState::nativescript_handle, T::___get_type_name(), &signal);
for (int i = 0; i < signal.num_args; i++) {
godot_string_destroy(&signal.args[i].name);
}
godot_free(signal.args);
}

View File

@ -15,6 +15,12 @@ public:
};
struct _RegisterState {
static void *nativescript_handle;
};
}
#endif

View File

@ -3,7 +3,7 @@
#include "String.hpp"
#include <godot/godot_node_path.h>
#include <godot/node_path.h>
namespace godot {

View File

@ -8,7 +8,7 @@
#include "Vector2.hpp"
#include "Vector3.hpp"
#include <godot/godot_pool_arrays.h>
#include <godot/pool_arrays.h>
namespace godot {

View File

@ -1,7 +1,7 @@
#ifndef RID_H
#define RID_H
#include <godot/godot_rid.h>
#include <godot/rid.h>
namespace godot {

View File

@ -1,7 +1,7 @@
#ifndef STRING_H
#define STRING_H
#include <godot/godot_string.h>
#include <godot/string.h>
namespace godot {

View File

@ -1,7 +1,7 @@
#ifndef VARIANT_H
#define VARIANT_H
#include <godot/godot_variant.h>
#include <godot/variant.h>
#include "Defs.hpp"

View File

@ -1,7 +1,7 @@
#ifndef VECTOR2_H
#define VECTOR2_H
#include <godot/godot_vector2.h>
#include <godot/vector2.h>
#include "Defs.hpp"

View File

@ -2,8 +2,6 @@
#include <cstdlib>
#include <godot/godot_array.h>
#include "Variant.hpp"
namespace godot {

View File

@ -1,6 +1,6 @@
#include "Color.hpp"
#include <godot/godot_color.h>
#include <godot/color.h>
#include <cmath>

View File

@ -4,7 +4,6 @@
#include "Array.hpp"
#include <godot/godot_dictionary.h>
namespace godot {

View File

@ -2,10 +2,12 @@
#include "String.hpp"
#include <godot.h>
#include <godot/gdnative.h>
namespace godot {
void *_RegisterState::nativescript_handle;
void Godot::print(const String& message)
{
godot_print((godot_string *) &message);
@ -22,3 +24,22 @@ void Godot::print_error(const String& description, const String& function, const
}
};
void gdnative_init(godot_gdnative_init_options *options);
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *options)
{
gdnative_init(options);
}
void gdnative_terminate(godot_gdnative_terminate_options *options);
extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *options)
{
gdnative_terminate(options);
}
void nativescript_init();
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
{
godot::_RegisterState::nativescript_handle = handle;
nativescript_init();
}

View File

@ -2,7 +2,7 @@
#include "String.hpp"
#include <godot/godot_node_path.h>
#include <godot/node_path.h>
namespace godot {

View File

@ -7,7 +7,7 @@
#include "Vector2.hpp"
#include "Vector3.hpp"
#include <godot/godot_pool_arrays.h>
#include <godot/pool_arrays.h>
namespace godot {

View File

@ -1,6 +1,6 @@
#include "RID.hpp"
#include <godot/godot_rid.h>
#include <godot/rid.h>
namespace godot {

View File

@ -2,7 +2,7 @@
#include "NodePath.hpp"
#include <godot/godot_string.h>
#include <godot/string.h>
#include <string.h>

View File

@ -1,6 +1,6 @@
#include "Variant.hpp"
#include <godot/godot_variant.h>
#include <godot/variant.h>
#include "Defs.hpp"

View File

@ -2,7 +2,7 @@
#include <cmath>
#include <godot/godot_vector2.h>
#include <godot/vector2.h>
#include "String.hpp"