diff --git a/.gitignore b/.gitignore index 65b551bc..e511a432 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ src/*.cpp +src/*.hpp include/*.hpp *.os *.so diff --git a/binding_generator.py b/binding_generator.py index c84625db..887175c8 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -441,7 +441,7 @@ def generate_icall_implementation(icalls): source.append("") source.append("") - source.append("using namespace godot;") + source.append("namespace godot {") source.append("") for icall in icalls: @@ -497,6 +497,7 @@ def generate_icall_implementation(icalls): source.append("}") + source.append("}") source.append("") return "\n".join(source) diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp index 0069b639..f28ceb34 100644 --- a/include/core/Godot.hpp +++ b/include/core/Godot.hpp @@ -1,5 +1,5 @@ -#ifndef GODOT_H -#define GODOT_H +#ifndef GODOT_HPP +#define GODOT_HPP #include @@ -11,9 +11,30 @@ #include +#include + + namespace godot { +template +class GodotScript { +public: + T *owner; + + // GodotScript() {} + + void _init() {} + static char *___get_base_type_name() + { + return T::___get_class_name(); + } + + static void _register_methods() {} +}; + + + #if !defined(_WIN32) @@ -28,11 +49,8 @@ namespace godot { -#define GODOT_CLASS(Name, Base) \ +#define GODOT_CLASS(Name) \ public: inline static char *___get_type_name() { return (char *) #Name; } \ - inline static char *___get_base_type_name() { return (char *) #Base; } \ - Base *self; \ - inline Name(godot_object *o) { self = (Base *) o; } \ private: #define GODOT_SUBCLASS(Name, Base) \ @@ -73,7 +91,8 @@ T *as(Object *obj) template void *_godot_class_instance_func(godot_object *p, void *method_data) { - T *d = new T(p); + T *d = new T(); + *(godot_object **) &d->owner = p; d->_init(); return d; } diff --git a/include/core/GodotGlobal.hpp b/include/core/GodotGlobal.hpp new file mode 100644 index 00000000..df93c0a5 --- /dev/null +++ b/include/core/GodotGlobal.hpp @@ -0,0 +1,30 @@ +#ifndef GODOT_GLOBAL_HPP +#define GODOT_GLOBAL_HPP + +#if defined(_WIN32) +# ifdef _GD_CPP_CORE_API_IMPL +# define GD_CPP_CORE_API __declspec(dllexport) +# else +# define GD_CPP_CORE_API __declspec(dllimport) +# endif +#else +# define GD_CPP_CORE_API +#endif + +#include "String.hpp" + + +namespace godot { + +class GD_CPP_CORE_API Godot { + +public: + static void print(const String& message); + static void print_warning(const String& description, const String& function, const String& file, int line); + static void print_error(const String& description, const String& function, const String& file, int line); + +}; + +} + +#endif diff --git a/src/core/GodotGlobal.cpp b/src/core/GodotGlobal.cpp new file mode 100644 index 00000000..cd910fff --- /dev/null +++ b/src/core/GodotGlobal.cpp @@ -0,0 +1,24 @@ +#include "GodotGlobal.hpp" + +#include "String.hpp" + +#include + +namespace godot { + +void Godot::print(const String& message) +{ + godot_print((godot_string *) &message); +} + +void Godot::print_warning(const String& description, const String& function, const String& file, int line) +{ + godot_print_warning(description.c_string(), function.c_string(), file.c_string(), line); +} + +void Godot::print_error(const String& description, const String& function, const String& file, int line) +{ + godot_print_error(description.c_string(), function.c_string(), file.c_string(), line); +} + +}; diff --git a/src/core/Variant.cpp b/src/core/Variant.cpp index 6442bc28..7b665479 100644 --- a/src/core/Variant.cpp +++ b/src/core/Variant.cpp @@ -399,7 +399,7 @@ Variant::Type Variant::get_type() const Variant Variant::call(const String& method, const Variant **args, const int arg_count) { Variant v; - *(godot_variant *) &v = godot_variant_call(&_godot_variant, (godot_string *) &method, (const godot_variant **)args, arg_count); + *(godot_variant *) &v = godot_variant_call(&_godot_variant, (godot_string *) &method, (const godot_variant **)args, arg_count, nullptr); return v; }