diff --git a/.gitignore b/.gitignore index 88295ff8..574bea2f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ src/*.cpp src/*.hpp include/*.hpp +*.o *.os *.so *.obj diff --git a/SConstruct b/SConstruct index 941f1d7b..daf66d35 100644 --- a/SConstruct +++ b/SConstruct @@ -32,73 +32,43 @@ if platform == "osx": env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-arch', 'x86_64']) env.Append(LINKFLAGS = ['-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup']) -if target == "core": - if platform == "linux": - env.Append(CCFLAGS = ['-g','-O3', '-std=c++14']) +if platform == "linux": + env.Append(CCFLAGS = ['-g','-O3', '-std=c++14']) + +env.Append(CPPPATH=['.', godot_headers_path, 'include', 'include/core']) + +if platform == "windows": + env.Append(LIBS=[godot_name]) + env.Append(LIBPATH=[godot_lib_path]) + +sources = [] +add_sources(sources, "src/core") + + +if ARGUMENTS.get("generate_bindings", "no") == "yes": + godot_executable = godot_bin_path + godot_name + + if env["CXX"] == "clang++": + godot_executable += ".llvm" + + if platform == "windows": + godot_executable += ".exe" + # TODO Generating the API should be done only if the Godot build is more recent than the JSON file + json_api_file = 'godot_api.json' - env.Append(CPPPATH=['include/core', godot_headers_path]) + subprocess.call([godot_executable, '--gdnative-generate-json-api', json_api_file]) - if platform == "windows": - env.Append(LIBS=[godot_name + '.lib']) - env.Append(LIBPATH=[godot_lib_path]) + # actually create the bindings here + + import binding_generator - env.Append(CPPFLAGS=['-D_GD_CPP_CORE_API_IMPL']) - - sources = [] - add_sources(sources, "src/core") - - library = env.SharedLibrary(target='bin/godot_cpp_core', source=sources) - Default(library) + + binding_generator.generate_bindings(json_api_file) -elif target == "bindings": +add_sources(sources, "src") - if ARGUMENTS.get("generate_bindings", "no") == "yes": - godot_executable = godot_bin_path + godot_name - - if env["CXX"] == "clang++": - godot_executable += ".llvm" - - if platform == "windows": - godot_executable += ".exe" - - # TODO Generating the API should be done only if the Godot build is more recent than the JSON file - json_api_file = 'godot_api.json' - - subprocess.call([godot_executable, '--gdnative-generate-json-api', json_api_file]) - - # actually create the bindings here - - import binding_generator - - - binding_generator.generate_bindings(json_api_file) - - - if platform == "linux": - if env["CXX"] == "clang++": - env.Append(CCFLAGS = ['-Wno-writable-strings']) - else: - env.Append(CCFLAGS = ['-Wno-write-strings', '-Wno-return-local-addr']) - - env.Append(CCFLAGS = ['-g','-O3', '-std=c++14']) - env.Append(LINKFLAGS = ['-Wl,-R,\'$$ORIGIN\'']) - - env.Append(CPPPATH=['.', godot_headers_path, 'include', 'include/core']) - - if platform == "windows": - env.Append(LIBS=[godot_name]) - env.Append(LIBPATH=[godot_lib_path]) - - env.Append(LIBS=['godot_cpp_core']) - env.Append(LIBPATH=['bin']) - - env.Append(CPPFLAGS=['-D_GD_CPP_BINDING_IMPL']) - - sources = [] - add_sources(sources, "src") - - library = env.SharedLibrary(target='bin/godot_cpp_bindings', source=sources) - Default(library) +library = env.StaticLibrary(target='bin/godot_cpp_bindings', source=sources) +Default(library) diff --git a/binding_generator.py b/binding_generator.py index 310efb03..c376b425 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -62,18 +62,6 @@ def generate_class_header(used_classes, c): source.append("#ifndef GODOT_CPP_" + strip_name(c["name"]).upper() + "_HPP") source.append("#define GODOT_CPP_" + strip_name(c["name"]).upper() + "_HPP") source.append("") - - - source.append("#if defined(_WIN32) && defined(_GD_CPP_BINDING_IMPL)") - source.append("# define GD_CPP_BINDING_API __declspec(dllexport)") - source.append("#elif defined(_WIN32)") - source.append("# define GD_CPP_BINDING_API __declspec(dllimport)") - source.append("#else") - source.append("# define GD_CPP_BINDING_API") - source.append("#endif"); - source.append("") - source.append("") - source.append("") source.append("") source.append("#include ") @@ -101,7 +89,7 @@ def generate_class_header(used_classes, c): # generate the class definition here - source.append("class GD_CPP_BINDING_API " + strip_name(c["name"]) + ("" if c["base_class"] == "" else (" : public " + strip_name(c["base_class"])) ) + " {") + source.append("class " + strip_name(c["name"]) + ("" if c["base_class"] == "" else (" : public " + strip_name(c["base_class"])) ) + " {") source.append("public:") source.append("") @@ -253,7 +241,7 @@ def generate_class_implementation(icalls, used_classes, c): source.append("static inline void ___singleton_init()") source.append("{") source.append("\tif (" + core_object_name + " == nullptr) {") - source.append("\t\t" + core_object_name + " = godot_global_get_singleton(\"" + strip_name(c["name"]) + "\");") + source.append("\t\t" + core_object_name + " = godot_global_get_singleton((char *) \"" + strip_name(c["name"]) + "\");") source.append("\t}") source.append("}") @@ -265,7 +253,7 @@ def generate_class_implementation(icalls, used_classes, c): if c["instanciable"]: source.append("void *" + strip_name(c["name"]) + "::operator new(size_t)") source.append("{") - source.append("\treturn godot_get_class_constructor(\"" + c["name"] + "\")();") + source.append("\treturn godot_get_class_constructor((char *)\"" + c["name"] + "\")();") source.append("}") source.append("void " + strip_name(c["name"]) + "::operator delete(void *ptr)") diff --git a/include/core/Array.hpp b/include/core/Array.hpp index 9a39b35a..1b607888 100644 --- a/include/core/Array.hpp +++ b/include/core/Array.hpp @@ -1,16 +1,6 @@ #ifndef ARRAY_H #define ARRAY_H -#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 #include "String.hpp" @@ -28,7 +18,7 @@ class PoolColorArray; class Object; -class GD_CPP_CORE_API Array { +class Array { godot_array _godot_array; public: Array(); diff --git a/include/core/Basis.hpp b/include/core/Basis.hpp index eda3d09a..dad20b6a 100644 --- a/include/core/Basis.hpp +++ b/include/core/Basis.hpp @@ -1,16 +1,6 @@ #ifndef BASIS_H #define BASIS_H -#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 "Defs.hpp" #include "Vector3.hpp" @@ -19,10 +9,12 @@ namespace godot { class Quat; -class GD_CPP_CORE_API Basis { +class Basis { public: - - Vector3 elements[3]; + union { + Vector3 elements[3]; + Vector3 x, y, z; + }; Basis(const Quat& p_quat); // euler Basis(const Vector3& p_euler); // euler diff --git a/include/core/Color.hpp b/include/core/Color.hpp index dbaf7aa1..528e6744 100644 --- a/include/core/Color.hpp +++ b/include/core/Color.hpp @@ -1,16 +1,6 @@ #ifndef COLOR_H #define COLOR_H -#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 #include @@ -20,7 +10,7 @@ namespace godot { -struct GD_CPP_CORE_API Color { +struct Color { private: diff --git a/include/core/Dictionary.hpp b/include/core/Dictionary.hpp index 34582c8d..4c719f5f 100644 --- a/include/core/Dictionary.hpp +++ b/include/core/Dictionary.hpp @@ -1,16 +1,6 @@ #ifndef DICTIONARY_H #define DICTIONARY_H -#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 "Variant.hpp" #include "Array.hpp" @@ -19,7 +9,7 @@ namespace godot { -class GD_CPP_CORE_API Dictionary { +class Dictionary { godot_dictionary _godot_dictionary; public: Dictionary(); diff --git a/include/core/GodotGlobal.hpp b/include/core/GodotGlobal.hpp index df93c0a5..18e23062 100644 --- a/include/core/GodotGlobal.hpp +++ b/include/core/GodotGlobal.hpp @@ -1,22 +1,12 @@ #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 { +class Godot { public: static void print(const String& message); diff --git a/include/core/NodePath.hpp b/include/core/NodePath.hpp index 3f75ca17..91cb1e19 100644 --- a/include/core/NodePath.hpp +++ b/include/core/NodePath.hpp @@ -1,16 +1,6 @@ #ifndef NODEPATH_H #define NODEPATH_H -#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" #include @@ -18,7 +8,7 @@ namespace godot { -class GD_CPP_CORE_API NodePath +class NodePath { godot_node_path _node_path; public: diff --git a/include/core/Plane.hpp b/include/core/Plane.hpp index dbcf4486..5ad5fcd4 100644 --- a/include/core/Plane.hpp +++ b/include/core/Plane.hpp @@ -1,16 +1,6 @@ #ifndef PLANE_H #define PLANE_H -#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 "Vector3.hpp" #include @@ -25,7 +15,7 @@ enum ClockDirection { COUNTERCLOCKWISE }; -class GD_CPP_CORE_API Plane { +class Plane { public: Vector3 normal; real_t d; diff --git a/include/core/PoolArrays.hpp b/include/core/PoolArrays.hpp index ebbd61d5..e2a51f12 100644 --- a/include/core/PoolArrays.hpp +++ b/include/core/PoolArrays.hpp @@ -1,16 +1,6 @@ #ifndef POOLARRAYS_H #define POOLARRAYS_H -#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 "Defs.hpp" #include "String.hpp" @@ -24,7 +14,7 @@ namespace godot { class Array; -class GD_CPP_CORE_API PoolByteArray { +class PoolByteArray { godot_pool_byte_array _godot_array; public: PoolByteArray(); @@ -55,7 +45,7 @@ public: }; -class GD_CPP_CORE_API PoolIntArray { +class PoolIntArray { godot_pool_int_array _godot_array; public: PoolIntArray(); @@ -86,7 +76,7 @@ public: }; -class GD_CPP_CORE_API PoolRealArray { +class PoolRealArray { godot_pool_real_array _godot_array; public: PoolRealArray(); @@ -117,7 +107,7 @@ public: }; -class GD_CPP_CORE_API PoolStringArray { +class PoolStringArray { godot_pool_string_array _godot_array; public: PoolStringArray(); @@ -149,7 +139,7 @@ public: -class GD_CPP_CORE_API PoolVector2Array { +class PoolVector2Array { godot_pool_vector2_array _godot_array; public: PoolVector2Array(); @@ -180,7 +170,7 @@ public: }; -class GD_CPP_CORE_API PoolVector3Array { +class PoolVector3Array { godot_pool_vector3_array _godot_array; public: PoolVector3Array(); @@ -211,7 +201,7 @@ public: }; -class GD_CPP_CORE_API PoolColorArray { +class PoolColorArray { godot_pool_color_array _godot_array; public: PoolColorArray(); diff --git a/include/core/Quat.hpp b/include/core/Quat.hpp index 03bb015f..927d4a37 100644 --- a/include/core/Quat.hpp +++ b/include/core/Quat.hpp @@ -1,16 +1,6 @@ #ifndef QUAT_H #define QUAT_H -#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 #include "Vector3.hpp" @@ -19,7 +9,7 @@ namespace godot { -class GD_CPP_CORE_API Quat{ +class Quat{ public: real_t x,y,z,w; diff --git a/include/core/RID.hpp b/include/core/RID.hpp index 7d3bc418..58550496 100644 --- a/include/core/RID.hpp +++ b/include/core/RID.hpp @@ -1,23 +1,13 @@ #ifndef RID_H #define RID_H -#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 namespace godot { class Object; -class GD_CPP_CORE_API RID { +class RID { godot_rid _godot_rid; public: diff --git a/include/core/Rect2.hpp b/include/core/Rect2.hpp index 849fa681..792972d0 100644 --- a/include/core/Rect2.hpp +++ b/include/core/Rect2.hpp @@ -1,16 +1,6 @@ #ifndef RECT2_H #define RECT2_H -#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 "Vector2.hpp" #include @@ -26,7 +16,7 @@ typedef Vector2 Point2; class Transform2D; -struct GD_CPP_CORE_API Rect2 { +struct Rect2 { Point2 pos; Size2 size; diff --git a/include/core/Rect3.hpp b/include/core/Rect3.hpp index b04195c7..acd674f5 100644 --- a/include/core/Rect3.hpp +++ b/include/core/Rect3.hpp @@ -1,16 +1,6 @@ #ifndef RECT3_H #define RECT3_H -#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 "Vector3.hpp" #include "Plane.hpp" @@ -19,7 +9,7 @@ namespace godot { -class GD_CPP_CORE_API Rect3 { +class Rect3 { public: Vector3 pos; Vector3 size; diff --git a/include/core/Ref.hpp b/include/core/Ref.hpp index 78b1926c..30d0816a 100644 --- a/include/core/Ref.hpp +++ b/include/core/Ref.hpp @@ -1,16 +1,6 @@ #ifndef REF_H #define REF_H -#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 "Variant.hpp" namespace godot { diff --git a/include/core/String.hpp b/include/core/String.hpp index ee6532ea..0b4e4fb0 100644 --- a/include/core/String.hpp +++ b/include/core/String.hpp @@ -1,23 +1,13 @@ #ifndef STRING_H #define STRING_H -#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 namespace godot { class NodePath; -class GD_CPP_CORE_API String +class String { godot_string _godot_string; public: diff --git a/include/core/Transform.hpp b/include/core/Transform.hpp index f6f5143d..c6b9b141 100644 --- a/include/core/Transform.hpp +++ b/include/core/Transform.hpp @@ -1,16 +1,6 @@ #ifndef TRANSFORM_H #define TRANSFORM_H -#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 "Basis.hpp" #include "Plane.hpp" @@ -18,7 +8,7 @@ namespace godot { -class GD_CPP_CORE_API Transform { +class Transform { public: Basis basis; diff --git a/include/core/Transform2D.hpp b/include/core/Transform2D.hpp index 553c324f..f3bc5fbd 100644 --- a/include/core/Transform2D.hpp +++ b/include/core/Transform2D.hpp @@ -1,16 +1,6 @@ #ifndef TRANSFORM2D_H #define TRANSFORM2D_H -#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 "Vector2.hpp" @@ -20,7 +10,7 @@ typedef Vector2 Size2; class Rect2; -struct GD_CPP_CORE_API Transform2D { +struct Transform2D { // Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper": // M = (elements[0][0] elements[1][0]) // (elements[0][1] elements[1][1]) diff --git a/include/core/Variant.hpp b/include/core/Variant.hpp index 05ca4e45..670c5c26 100644 --- a/include/core/Variant.hpp +++ b/include/core/Variant.hpp @@ -1,16 +1,6 @@ #ifndef VARIANT_H #define VARIANT_H -#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 #include "Defs.hpp" @@ -38,7 +28,7 @@ class Dictionary; class Array; -class GD_CPP_CORE_API Variant { +class Variant { godot_variant _godot_variant; public: enum Type { diff --git a/include/core/Vector2.hpp b/include/core/Vector2.hpp index 73dd562c..9cdde2a5 100644 --- a/include/core/Vector2.hpp +++ b/include/core/Vector2.hpp @@ -1,17 +1,6 @@ #ifndef VECTOR2_H #define VECTOR2_H - -#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 #include "Defs.hpp" @@ -20,7 +9,7 @@ namespace godot { class String; -struct GD_CPP_CORE_API Vector2 { +struct Vector2 { union { real_t x; diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp index 52a5d73a..fa7dcf41 100644 --- a/include/core/Vector3.hpp +++ b/include/core/Vector3.hpp @@ -1,16 +1,6 @@ #ifndef VECTOR3_H #define VECTOR3_H -#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 "Defs.hpp" #include "String.hpp" @@ -18,7 +8,7 @@ namespace godot { -struct GD_CPP_CORE_API Vector3 { +struct Vector3 { enum Axis { AXIS_X, @@ -40,8 +30,6 @@ struct GD_CPP_CORE_API Vector3 { Vector3(); - Vector3(const Vector3& b); - const real_t& operator[](int p_axis) const; real_t& operator[](int p_axis); diff --git a/src/core/Vector3.cpp b/src/core/Vector3.cpp index b73362d6..377778a5 100644 --- a/src/core/Vector3.cpp +++ b/src/core/Vector3.cpp @@ -26,13 +26,6 @@ Vector3::Vector3() this->z = 0; } -Vector3::Vector3(const Vector3& b) -{ - this->x = b.x; - this->y = b.y; - this->z = b.z; -} - const real_t& Vector3::operator[](int p_axis) const { return coord[p_axis];