From 7adae4673c7c351501e20d60b7158bec37c97783 Mon Sep 17 00:00:00 2001 From: Nickolai Korshunov Date: Fri, 23 Feb 2018 14:39:35 +0300 Subject: [PATCH 1/7] fixed forward declarations --- include/core/Rect2.hpp | 2 +- include/core/Transform2D.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/core/Rect2.hpp b/include/core/Rect2.hpp index 792972d0..7668548c 100644 --- a/include/core/Rect2.hpp +++ b/include/core/Rect2.hpp @@ -14,7 +14,7 @@ class String; typedef Vector2 Size2; typedef Vector2 Point2; -class Transform2D; +struct Transform2D; struct Rect2 { diff --git a/include/core/Transform2D.hpp b/include/core/Transform2D.hpp index f3bc5fbd..4273752c 100644 --- a/include/core/Transform2D.hpp +++ b/include/core/Transform2D.hpp @@ -8,7 +8,7 @@ namespace godot { typedef Vector2 Size2; -class Rect2; +struct Rect2; struct Transform2D { // Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper": From 73a67b16b1904b3cfaa8c1f1f9891cd9d416cb43 Mon Sep 17 00:00:00 2001 From: Nickolai Korshunov Date: Fri, 23 Feb 2018 14:56:36 +0300 Subject: [PATCH 2/7] fixed some includes. replace cycle include with forward declaration --- include/core/Godot.hpp | 10 +++++----- include/core/Ref.hpp | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp index 6d0289f6..e84f88a9 100644 --- a/include/core/Godot.hpp +++ b/include/core/Godot.hpp @@ -8,13 +8,13 @@ #include -#include -#include -#include +#include "CoreTypes.hpp" +#include "Variant.hpp" +#include "Ref.hpp" -#include +#include "Object.hpp" -#include +#include "GodotGlobal.hpp" namespace godot { diff --git a/include/core/Ref.hpp b/include/core/Ref.hpp index f81dbbeb..d96c9de3 100644 --- a/include/core/Ref.hpp +++ b/include/core/Ref.hpp @@ -3,9 +3,10 @@ #include "Variant.hpp" #include "GodotGlobal.hpp" -#include "../Reference.hpp" namespace godot { +class Reference; +class Object; // Replicates Godot's Ref behavior // Rewritten from f5234e70be7dec4930c2d5a0e829ff480d044b1d. From e123650d76d4554a3b3db373594714c62f83fa2c Mon Sep 17 00:00:00 2001 From: Nickolai Korshunov Date: Fri, 23 Feb 2018 15:50:41 +0300 Subject: [PATCH 3/7] Strict enums --- binding_generator.py | 2 +- include/core/Defs.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/binding_generator.py b/binding_generator.py index 54c56f2d..60dfb7a2 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -131,7 +131,7 @@ def generate_class_header(used_classes, c): source.append("\n\t// enums") for enum in c["enums"]: - source.append("\tenum " + strip_name(enum["name"]) + " {") + source.append("\tenum class " + strip_name(enum["name"]) + " {") for value in enum["values"]: source.append("\t\t" + remove_nested_type_prefix(value) + " = " + str(enum["values"][value]) + ",") enum_values.append(value) diff --git a/include/core/Defs.hpp b/include/core/Defs.hpp index f8c76d3e..4b73cfa5 100644 --- a/include/core/Defs.hpp +++ b/include/core/Defs.hpp @@ -4,7 +4,7 @@ namespace godot { -enum Error { +enum class Error { OK, FAILED, ///< Generic fail error ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable From 3f8456135f4ea073837c1166983fa2d93242289d Mon Sep 17 00:00:00 2001 From: Nickolai Korshunov Date: Fri, 23 Feb 2018 15:57:37 +0300 Subject: [PATCH 4/7] local deps included with quotes --- binding_generator.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/binding_generator.py b/binding_generator.py index 60dfb7a2..5a67f133 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -88,17 +88,17 @@ def generate_class_header(used_classes, c): used_class_name = remove_enum_prefix(extract_nested_type(used_class)) if used_class_name not in included: included.append(used_class_name) - source.append("#include <" + used_class_name + ".hpp>") + source.append("#include \"" + used_class_name + ".hpp\"") elif is_enum(used_class) and is_nested_type(used_class) and not is_nested_type(used_class, class_name): used_class_name = remove_enum_prefix(used_class) if used_class_name not in included: included.append(used_class_name) - source.append("#include <" + used_class_name + ".hpp>") + source.append("#include \"" + used_class_name + ".hpp\"") source.append("") if c["base_class"] != "": - source.append("#include <" + strip_name(c["base_class"]) + ".hpp>") + source.append("#include \"" + strip_name(c["base_class"]) + ".hpp\"") @@ -243,7 +243,7 @@ def generate_class_header(used_classes, c): def generate_class_implementation(icalls, used_classes, c): class_name = strip_name(c["name"]) source = [] - source.append("#include <" + class_name + ".hpp>") + source.append("#include \"" + class_name + ".hpp\"") source.append("") source.append("") @@ -263,7 +263,7 @@ def generate_class_implementation(icalls, used_classes, c): if is_enum(used_class): continue else: - source.append("#include <" + strip_name(used_class) + ".hpp>") + source.append("#include \"" + strip_name(used_class) + ".hpp\"") source.append("") source.append("") @@ -473,7 +473,7 @@ def generate_icall_header(icalls): source.append("") source.append("#include ") - source.append("#include ") + source.append("#include \"Object.hpp\"") source.append("") source.append("") @@ -524,7 +524,7 @@ def generate_icall_implementation(icalls): source.append("#include ") source.append("#include ") - source.append("#include ") + source.append("#include \"Object.hpp\"") source.append("") source.append("") From f1c35f24f6d6cb482c7b3e7c8bbe707ab15a72d3 Mon Sep 17 00:00:00 2001 From: Nickolai Korshunov Date: Fri, 23 Feb 2018 16:08:36 +0300 Subject: [PATCH 5/7] NULL -> nullptr --- binding_generator.py | 4 ++-- include/core/AABB.hpp | 4 ++-- include/core/Godot.hpp | 2 +- include/core/PoolArrays.hpp | 28 ++++++++++++++-------------- include/core/Rect2.hpp | 2 +- include/core/Ref.hpp | 26 +++++++++++++------------- src/core/GodotGlobal.cpp | 20 ++++++++++---------- 7 files changed, 43 insertions(+), 43 deletions(-) diff --git a/binding_generator.py b/binding_generator.py index 5a67f133..e1334289 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -334,8 +334,8 @@ def generate_class_implementation(icalls, used_classes, c): source.append("\t___singleton_init();") - source.append("\tstatic godot_method_bind *mb = NULL;") - source.append("\tif (mb == NULL) {") + source.append("\tstatic godot_method_bind *mb = nullptr;") + source.append("\tif (mb == nullptr) {") source.append("\t\tmb = godot::api->godot_method_bind_get_method(\"" + c["name"] +"\", \"" + method["name"] + "\");") source.append("\t}") diff --git a/include/core/AABB.hpp b/include/core/AABB.hpp index 656fd76b..21d73d15 100644 --- a/include/core/AABB.hpp +++ b/include/core/AABB.hpp @@ -41,8 +41,8 @@ public: AABB merge(const AABB& p_with) const; void merge_with(const AABB& p_aabb); ///merge with another AABB AABB intersection(const AABB& p_aabb) const; ///get box where two intersect, empty if no intersection occurs - bool intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const; - bool intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const; + bool intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip=nullptr,Vector3* r_normal=nullptr) const; + bool intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip=nullptr,Vector3* r_normal=nullptr) const; bool smits_intersect_ray(const Vector3 &from,const Vector3& p_dir, real_t t0, real_t t1) const; bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const; diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp index e84f88a9..f7106583 100644 --- a/include/core/Godot.hpp +++ b/include/core/Godot.hpp @@ -454,7 +454,7 @@ void register_signal(String name, Dictionary args = Dictionary()) signal.num_args = args.size(); signal.num_default_args = 0; - // Need to check because malloc(0) is platform-dependent. Zero arguments will leave args to NULL. + // Need to check because malloc(0) is platform-dependent. Zero arguments will leave args to nullptr. if(signal.num_args != 0) { signal.args = (godot_signal_argument*) godot::api->godot_alloc(sizeof(godot_signal_argument) * signal.num_args); memset((void *) signal.args, 0, sizeof(godot_signal_argument) * signal.num_args); diff --git a/include/core/PoolArrays.hpp b/include/core/PoolArrays.hpp index 78a370d1..4d22fd7a 100644 --- a/include/core/PoolArrays.hpp +++ b/include/core/PoolArrays.hpp @@ -25,7 +25,7 @@ public: godot_pool_byte_array_read_access *_read_access; public: inline Read() { - _read_access = NULL; + _read_access = nullptr; } inline Read(const Read & p_other) { @@ -54,7 +54,7 @@ public: godot_pool_byte_array_write_access *_write_access; public: inline Write() { - _write_access = NULL; + _write_access = nullptr; } inline Write(const Write & p_other) { @@ -121,7 +121,7 @@ public: godot_pool_int_array_read_access *_read_access; public: inline Read() { - _read_access = NULL; + _read_access = nullptr; } inline Read(const Read & p_other) { @@ -150,7 +150,7 @@ public: godot_pool_int_array_write_access *_write_access; public: inline Write() { - _write_access = NULL; + _write_access = nullptr; } inline Write(const Write & p_other) { @@ -217,7 +217,7 @@ public: godot_pool_real_array_read_access *_read_access; public: inline Read() { - _read_access = NULL; + _read_access = nullptr; } inline Read(const Read & p_other) { @@ -246,7 +246,7 @@ public: godot_pool_real_array_write_access *_write_access; public: inline Write() { - _write_access = NULL; + _write_access = nullptr; } inline Write(const Write & p_other) { @@ -313,7 +313,7 @@ public: godot_pool_string_array_read_access *_read_access; public: inline Read() { - _read_access = NULL; + _read_access = nullptr; } inline Read(const Read & p_other) { @@ -342,7 +342,7 @@ public: godot_pool_string_array_write_access *_write_access; public: inline Write() { - _write_access = NULL; + _write_access = nullptr; } inline Write(const Write & p_other) { @@ -410,7 +410,7 @@ public: godot_pool_vector2_array_read_access *_read_access; public: inline Read() { - _read_access = NULL; + _read_access = nullptr; } inline Read(const Read & p_other) { @@ -439,7 +439,7 @@ public: godot_pool_vector2_array_write_access *_write_access; public: inline Write() { - _write_access = NULL; + _write_access = nullptr; } inline Write(const Write & p_other) { @@ -506,7 +506,7 @@ public: godot_pool_vector3_array_read_access *_read_access; public: inline Read() { - _read_access = NULL; + _read_access = nullptr; } inline Read(const Read & p_other) { @@ -535,7 +535,7 @@ public: godot_pool_vector3_array_write_access *_write_access; public: inline Write() { - _write_access = NULL; + _write_access = nullptr; } inline Write(const Write & p_other) { @@ -602,7 +602,7 @@ public: godot_pool_color_array_read_access *_read_access; public: inline Read() { - _read_access = NULL; + _read_access = nullptr; } inline Read(const Read & p_other) { @@ -631,7 +631,7 @@ public: godot_pool_color_array_write_access *_write_access; public: inline Write() { - _write_access = NULL; + _write_access = nullptr; } inline Write(const Write & p_other) { diff --git a/include/core/Rect2.hpp b/include/core/Rect2.hpp index 7668548c..b25c4044 100644 --- a/include/core/Rect2.hpp +++ b/include/core/Rect2.hpp @@ -45,7 +45,7 @@ struct Rect2 { bool intersects_transformed(const Transform2D& p_xform, const Rect2& p_rect) const; - bool intersects_segment(const Point2& p_from, const Point2& p_to, Point2* r_pos=NULL, Point2* r_normal=NULL) const; + bool intersects_segment(const Point2& p_from, const Point2& p_to, Point2* r_pos=nullptr, Point2* r_normal=nullptr) const; inline bool encloses(const Rect2& p_rect) const { diff --git a/include/core/Ref.hpp b/include/core/Ref.hpp index d96c9de3..254da3e3 100644 --- a/include/core/Ref.hpp +++ b/include/core/Ref.hpp @@ -13,7 +13,7 @@ class Object; template class Ref { - T *reference = NULL; + T *reference = nullptr; void ref(const Ref &p_from) { @@ -102,7 +102,7 @@ public: //r.reference = Object::cast_to(refb); r.reference = (T*)refb; ref(r); - r.reference = NULL; + r.reference = nullptr; } void operator=(const Variant &p_variant) { @@ -118,19 +118,19 @@ public: //r.reference = Object::cast_to(refb); r.reference = (T *)refb; ref(r); - r.reference = NULL; + r.reference = nullptr; } Ref(const Ref &p_from) { - reference = NULL; + reference = nullptr; ref(p_from); } template Ref(const Ref &p_from) { - reference = NULL; + reference = nullptr; // TODO We need a safe cast Reference *refb = const_cast(static_cast(p_from.ptr())); if (!refb) { @@ -142,7 +142,7 @@ public: //r.reference = Object::cast_to(refb); r.reference = (T *)refb; ref(r); - r.reference = NULL; + r.reference = nullptr; } Ref(T *p_reference) { @@ -150,12 +150,12 @@ public: if (p_reference) ref_pointer(p_reference); else - reference = NULL; + reference = nullptr; } Ref(const Variant &p_variant) { - reference = NULL; + reference = nullptr; // TODO We need a safe cast Reference *refb = (Reference *) (Object *) p_variant; if (!refb) { @@ -167,11 +167,11 @@ public: //r.reference = Object::cast_to(refb); r.reference = (T *)refb; ref(r); - r.reference = NULL; + r.reference = nullptr; } - inline bool is_valid() const { return reference != NULL; } - inline bool is_null() const { return reference == NULL; } + inline bool is_valid() const { return reference != nullptr; } + inline bool is_null() const { return reference == nullptr; } void unref() { //TODO this should be moved to mutexes, since this engine does not really @@ -183,7 +183,7 @@ public: //memdelete(reference); delete reference; } - reference = NULL; + reference = nullptr; } void instance() { @@ -193,7 +193,7 @@ public: Ref() { - reference = NULL; + reference = nullptr; } ~Ref() { diff --git a/src/core/GodotGlobal.cpp b/src/core/GodotGlobal.cpp index a2b50507..c8f420fc 100644 --- a/src/core/GodotGlobal.cpp +++ b/src/core/GodotGlobal.cpp @@ -5,8 +5,8 @@ namespace godot { void *_RegisterState::nativescript_handle; -const godot_gdnative_core_api_struct *api = NULL; -const godot_gdnative_ext_nativescript_api_struct *nativescript_api = NULL; +const godot_gdnative_core_api_struct *api = nullptr; +const godot_gdnative_ext_nativescript_api_struct *nativescript_api = nullptr; void Godot::print(const String& message) { @@ -21,13 +21,13 @@ void Godot::print_warning(const String& description, const String& function, con char * c_func = function.alloc_c_string(); char * c_file = file.alloc_c_string(); - if (c_desc != NULL && c_func !=NULL && c_file != NULL) { + if (c_desc != nullptr && c_func !=nullptr && c_file != nullptr) { godot::api->godot_print_warning(c_desc, c_func, c_file, line); }; - if (c_desc != NULL) godot::api->godot_free(c_desc); - if (c_func != NULL) godot::api->godot_free(c_func); - if (c_file != NULL) godot::api->godot_free(c_file); + if (c_desc != nullptr) godot::api->godot_free(c_desc); + if (c_func != nullptr) godot::api->godot_free(c_func); + if (c_file != nullptr) godot::api->godot_free(c_file); } void Godot::print_error(const String& description, const String& function, const String& file, int line) @@ -38,13 +38,13 @@ void Godot::print_error(const String& description, const String& function, const char * c_func = function.alloc_c_string(); char * c_file = file.alloc_c_string(); - if (c_desc != NULL && c_func !=NULL && c_file != NULL) { + if (c_desc != nullptr && c_func !=nullptr && c_file != nullptr) { godot::api->godot_print_error(c_desc, c_func, c_file, line); }; - if (c_desc != NULL) godot::api->godot_free(c_desc); - if (c_func != NULL) godot::api->godot_free(c_func); - if (c_file != NULL) godot::api->godot_free(c_file); + if (c_desc != nullptr) godot::api->godot_free(c_desc); + if (c_func != nullptr) godot::api->godot_free(c_func); + if (c_file != nullptr) godot::api->godot_free(c_file); } void Godot::gdnative_init(godot_gdnative_init_options *options) From a049a34f2837ad1c672a91cfafce99d5db940753 Mon Sep 17 00:00:00 2001 From: Nickolai Korshunov Date: Sat, 24 Feb 2018 11:13:22 +0300 Subject: [PATCH 6/7] fixed forward decl --- include/core/Ref.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/core/Ref.hpp b/include/core/Ref.hpp index 254da3e3..365c3ec2 100644 --- a/include/core/Ref.hpp +++ b/include/core/Ref.hpp @@ -3,10 +3,9 @@ #include "Variant.hpp" #include "GodotGlobal.hpp" +#include "../Reference.hpp" namespace godot { -class Reference; -class Object; // Replicates Godot's Ref behavior // Rewritten from f5234e70be7dec4930c2d5a0e829ff480d044b1d. From 876715b610a52749e5cc7824122f892dd430ffab Mon Sep 17 00:00:00 2001 From: Nickolai Korshunov Date: Wed, 25 Apr 2018 11:39:18 +0300 Subject: [PATCH 7/7] disable strict enums --- binding_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binding_generator.py b/binding_generator.py index e1334289..93371567 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -131,7 +131,7 @@ def generate_class_header(used_classes, c): source.append("\n\t// enums") for enum in c["enums"]: - source.append("\tenum class " + strip_name(enum["name"]) + " {") + source.append("\tenum " + strip_name(enum["name"]) + " {") for value in enum["values"]: source.append("\t\t" + remove_nested_type_prefix(value) + " = " + str(enum["values"][value]) + ",") enum_values.append(value)