From c772d7f656da1606f7d5d6983bd09b1b29fd8b28 Mon Sep 17 00:00:00 2001 From: Karroffel Date: Mon, 6 Mar 2017 18:39:56 +0100 Subject: [PATCH] added Godot.hpp --- include/godot_cpp/Godot.hpp | 267 ++++++++++++++++++++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 include/godot_cpp/Godot.hpp diff --git a/include/godot_cpp/Godot.hpp b/include/godot_cpp/Godot.hpp new file mode 100644 index 00000000..d07fa7b1 --- /dev/null +++ b/include/godot_cpp/Godot.hpp @@ -0,0 +1,267 @@ +#ifndef GODOT_H +#define GODOT_H + +#include + +#include + + +#include +#include + +namespace godot { + + +#define GODOT_CLASS(Name, Base) \ + public: static char *___get_type_name() { return (char *) #Name; } \ + static char *___get_base_type_name() { return (char *) #Base; } \ + Name(godot_object *o) { __core_object = o; } \ + private: + + + +template +A object_cast(B b) +{ + A *a = (A*) &b; + return *a; +} + + + + + +// instance and destroy funcs + +template +void *_godot_class_instance_func(godot_object *p) +{ + T *d = new T(p); + d->_init(); + return d; +} + +template +void _godot_class_destroy_func(godot_object *p, void *data) +{ + T *d = (T *) data; + delete d; +} + + + +template +void register_class() +{ + godot_script_register(T::___get_type_name(), T::___get_base_type_name(), _godot_class_instance_func, _godot_class_destroy_func); + T::_register_methods(); +} + + + + + + +// wrapped methods + +template +struct WrappedMethod5 { + static godot_variant wrapped_method(godot_object *_, void *data, int num_args, godot_variant **args) + { + godot_variant _variant; + godot_variant_new_nil(&_variant); + godot::Variant *v = (godot::Variant *) &_variant; + T *obj = (T *) data; + godot::Variant **arg = (godot::Variant **) args; + *v = (obj->*p)(*arg[0], *arg[1], *arg[2], *arg[3], *arg[4]); + return _variant; + } +}; + +template +struct WrappedMethod5 { + static godot_variant wrapped_method(godot_object *_, void *data, int num_args, godot_variant **args) + { + godot_variant _variant; + godot_variant_new_nil(&_variant); + T *obj = (T *) data; + godot::Variant **arg = (godot::Variant **) args; + (obj->*p)(*arg[0], *arg[1], *arg[2], *arg[3], *arg[4]); + return _variant; + } +}; + +template +struct WrappedMethod4 { + static godot_variant wrapped_method(godot_object *_, void *data, int num_args, godot_variant **args) + { + godot_variant _variant; + godot_variant_new_nil(&_variant); + godot::Variant *v = (godot::Variant *) &_variant; + T *obj = (T *) data; + godot::Variant **arg = (godot::Variant **) args; + *v = (obj->*p)(*arg[0], *arg[1], *arg[2], *arg[3]); + return _variant; + } +}; + +template +struct WrappedMethod4 { + static godot_variant wrapped_method(godot_object *_, void *data, int num_args, godot_variant **args) + { + godot_variant _variant; + godot_variant_new_nil(&_variant); + T *obj = (T *) data; + godot::Variant **arg = (godot::Variant **) args; + (obj->*p)(*arg[0], *arg[1], *arg[2], *arg[3]); + return _variant; + } +}; + + +template +struct WrappedMethod3 { + static godot_variant wrapped_method(godot_object *_, void *data, int num_args, godot_variant **args) + { + godot_variant _variant; + godot_variant_new_nil(&_variant); + godot::Variant *v = (godot::Variant *) &_variant; + T *obj = (T *) data; + godot::Variant **arg = (godot::Variant **) args; + *v = (obj->*p)(*arg[0], *arg[1], *arg[2]); + return _variant; + } +}; + +template +struct WrappedMethod3 { + static godot_variant wrapped_method(godot_object *_, void *data, int num_args, godot_variant **args) + { + godot_variant _variant; + godot_variant_new_nil(&_variant); + T *obj = (T *) data; + godot::Variant **arg = (godot::Variant **) args; + (obj->*p)(*arg[0], *arg[1], *arg[2]); + return _variant; + } +}; + +template +struct WrappedMethod2 { + static godot_variant wrapped_method(godot_object *_, void *data, int num_args, godot_variant **args) + { + godot_variant _variant; + godot_variant_new_nil(&_variant); + godot::Variant *v = (godot::Variant *) &_variant; + T *obj = (T *) data; + godot::Variant **arg = (godot::Variant **) args; + *v = (obj->*p)(*arg[0], *arg[1]); + return _variant; + } +}; + +template +struct WrappedMethod2 { + static godot_variant wrapped_method(godot_object *_, void *data, int num_args, godot_variant **args) + { + godot_variant _variant; + godot_variant_new_nil(&_variant); + T *obj = (T *) data; + godot::Variant **arg = (godot::Variant **) args; + (obj->*p)(*arg[0], *arg[1]); + return _variant; + } +}; + +template +struct WrappedMethod1 { + static godot_variant wrapped_method(godot_object *_, void *data, int num_args, godot_variant **args) + { + godot_variant _variant; + godot_variant_new_nil(&_variant); + godot::Variant *v = (godot::Variant *) &_variant; + T *obj = (T *) data; + godot::Variant **arg = (godot::Variant **) args; + *v = (obj->*p)(*arg[0]); + return _variant; + } +}; + +template +struct WrappedMethod1 { + static godot_variant wrapped_method(godot_object *_, void *data, int num_args, godot_variant **args) + { + godot_variant _variant; + godot_variant_new_nil(&_variant); + T *obj = (T *) data; + godot::Variant **arg = (godot::Variant **) args; + (obj->*p)(*arg[0]); + return _variant; + } +}; + + + +template +struct WrappedMethod0 { + static godot_variant wrapped_method(godot_object *_, void *data, int num_args, godot_variant **args) + { + godot_variant _variant; + godot_variant_new_nil(&_variant); + godot::Variant *v = (godot::Variant *) &_variant; + T *obj = (T *) data; + *v = (obj->*p)(); + return _variant; + } +}; + +template +struct WrappedMethod0 { + static godot_variant wrapped_method(godot_object *_, void *data, int num_args, godot_variant **args) + { + godot_variant _variant; + godot_variant_new_nil(&_variant); + T *obj = (T *) data; + (obj->*p)(); + return _variant; + } +}; + +// method registering + + +template +void register_method(char *name, godot_method_attributes attr = {}) { + godot_script_add_method(T::___get_type_name(), name, &attr, &WrappedMethod0::wrapped_method); +} + +template +void register_method(char *name, godot_method_attributes attr = {}) { + godot_script_add_method(T::___get_type_name(), name, &attr, &WrappedMethod1::wrapped_method); +} + +template +void register_method(char *name, godot_method_attributes attr = {}) { + godot_script_add_method(T::___get_type_name(), name, &attr, &WrappedMethod2::wrapped_method); +} + +template +void register_method(char *name, godot_method_attributes attr = {}) { + godot_script_add_method(T::___get_type_name(), name, &attr, &WrappedMethod3::wrapped_method); +} + +template +void register_method(char *name, godot_method_attributes attr = {}) { + godot_script_add_method(T::___get_type_name(), name, &attr, &WrappedMethod4::wrapped_method); +} + + +template +void register_method(char *name, godot_method_attributes attr = {}) { + godot_script_add_method(T::___get_type_name(), name, &attr, &WrappedMethod5::wrapped_method); +} + + +} + +#endif // GODOT_H