diff --git a/cpp/kinematic_character/Character.tscn b/cpp/kinematic_character/Character.tscn index 980770b..76823d9 100644 --- a/cpp/kinematic_character/Character.tscn +++ b/cpp/kinematic_character/Character.tscn @@ -9,23 +9,13 @@ [ext_resource path="res://Player Red/playerRed_up2.png" type="Texture" id=7] [ext_resource path="res://Player Red/playerRed_up3.png" type="Texture" id=8] -[sub_resource type="GDNativeLibrary" id=3] - -platform/X11_32bit = "" -platform/X11_64bit = "res://Script/bin/libkinematic_char.so" -platform/Windows_32bit = "" -platform/Windows_64bit = "" -platform/OSX = "" -platform/Android = "" -platform/iOS = "" -platform/WebAssembly = "" -_sections_unfolded = [ "platform" ] +[ext_resource path="res://Script/bin/libkinematic_char.gdnlib" type="GDNativeLibrary" id=9] [sub_resource type="NativeScript" id=4] resource_name = "GDPlayer" class_name = "GDPlayer" -library = SubResource( 3 ) +library = ExtResource( 9 ) [sub_resource type="SpriteFrames" id=1] diff --git a/cpp/kinematic_character/README.md b/cpp/kinematic_character/README.md new file mode 100644 index 0000000..98ae68c --- /dev/null +++ b/cpp/kinematic_character/README.md @@ -0,0 +1,20 @@ +# GDNative example of a kinematic character + +This is a demo showing how to use GDNative together with the cpp_bindings layer to implement a couple of new nodes. +This demo was originally created by Ramesh Ravone. + +Before compiling this module you must clone https://github.com/GodotNativeTools/godot_headers and https://github.com/GodotNativeTools/godot-cpp +Note that both are git submodule in Scripts/src so you can initialise these with git submodule but at you'll likely use these for other projects as well I advise giving them their own location. + +After both repositories have been downloaded you need to compile the cpp bindings, for this follow the instructions in the godot-cpp repository. + +Note that if you are on the latest master of Godot it is possible godot_headers is outdated. Instead of using this repository you can also use /modules/gdnative/include +Make sure that you compile both godot-cpp and this repository using the same headers. + +Once you are then ready to compile this module simply cd into the Scripts subfolder and execute: +scons platform=xyz +where xyz is your platform (linux, window and osx are currently supported). + +If you have installed godot_headers and/or godot-cpp in a different location you can use the swiches headers and cpp_bindings respectively. You can also set these paths using the environmental variables GODOT_HEADERS and CPP_BINDINGS, that is particularly useful if you have multiple projects. + +Finally you can switch between release and debug builds by adding the switch target. This must line up with the setting you use for compiling godot-cpp. diff --git a/cpp/kinematic_character/Script/.sconsign.dblite b/cpp/kinematic_character/Script/.sconsign.dblite index ff40740..a5f5ad6 100644 Binary files a/cpp/kinematic_character/Script/.sconsign.dblite and b/cpp/kinematic_character/Script/.sconsign.dblite differ diff --git a/cpp/kinematic_character/Script/SConstruct b/cpp/kinematic_character/Script/SConstruct index 7505bc9..2aa7749 100644 --- a/cpp/kinematic_character/Script/SConstruct +++ b/cpp/kinematic_character/Script/SConstruct @@ -1,14 +1,22 @@ #!python import os -env = Environment() - +# platform= makes it in line with Godots scons file, keeping p for backwards compatibility platform = ARGUMENTS.get("p", "linux") -godot_headers_path = ARGUMENTS.get("headers", "godot_headers/") -godot_bindings_path = ARGUMENTS.get("cpp_bindings", "cpp_bindings/") -godot_src_path = ARGUMENTS.get("godotpath", "../../../../godot3-git/") +platform = ARGUMENTS.get("platform", platform) + +# This makes sure to keep the session environment variables on windows, +# that way you can run scons in a vs 2017 prompt and it will find all the required tools +env = Environment() +if platform == "windows": + env = Environment(ENV = os.environ) + +godot_headers_path = ARGUMENTS.get("headers", os.getenv("GODOT_HEADERS", "godot_headers")) +godot_bindings_path = ARGUMENTS.get("cpp_bindings", os.getenv("CPP_BINDINGS", "cpp_bindings")) + +# default to debug build, must be same setting as used for cpp_bindings +target = ARGUMENTS.get("target", "debug") -godot_name = "godot." + ("x11" if platform == "linux" else platform) + ".tools.64" if ARGUMENTS.get("use_llvm", "no") == "yes": env["CXX"] = "clang++" @@ -22,22 +30,21 @@ elif platform == "linux": env.Append(LINKFLAGS = ['-Wl,-R,\'$$ORIGIN\'']) elif platform == "windows": # need to add detection of msvc vs mingw, this is for msvc... - env.Append(CCFLAGS = ['/MD', '/WX', '/O2', '/EHsc', '/nologo']) env.Append(LINKFLAGS = ['/WX']) + if target == "debug": + env.Append(CCFLAGS = ['-EHsc', '-D_DEBUG', '/MDd']) + else: + env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '/MD']) def add_sources(sources, dir): for f in os.listdir(dir): if f.endswith(".cpp"): sources.append(dir + "/" + f) -env.Append(CPPPATH=[godot_headers_path, godot_bindings_path + 'include/', godot_bindings_path + 'include/core/', 'src' ]) +env.Append(CPPPATH=[godot_headers_path, godot_bindings_path + '/include/', godot_bindings_path + '/include/core/', 'src' ]) env.Append(LIBS=['godot_cpp_bindings']) -env.Append(LIBPATH=[ godot_bindings_path + 'bin/' ]) - -if platform == "windows": - env.Append(LIBS=[ godot_name ]) - env.Append(LIBPATH=[ godot_src_path + 'bin/' ]) +env.Append(LIBPATH=[ godot_bindings_path + '/bin/' ]) sources = [] add_sources(sources, "src") diff --git a/cpp/kinematic_character/Script/bin/libkinematic_char.gdnlib b/cpp/kinematic_character/Script/bin/libkinematic_char.gdnlib new file mode 100644 index 0000000..b1a4778 --- /dev/null +++ b/cpp/kinematic_character/Script/bin/libkinematic_char.gdnlib @@ -0,0 +1,17 @@ +[general] + +singleton=false +load_once=false +symbol_prefix="godot_" + +[entry] + +X11.64="res://Script/bin/libkinematic_char.so" +Windows.64="res://Script/bin/libkinematic_char.dll" +OSX.64="res://Script/bin/libkinematic_char.dylib" + +[dependencies] + +X11.64=[] +Windows.64=[] +OSX.64=[] \ No newline at end of file diff --git a/cpp/kinematic_character/Script/char_con.gdn b/cpp/kinematic_character/Script/char_con.gdn deleted file mode 100644 index cd8ca2e..0000000 --- a/cpp/kinematic_character/Script/char_con.gdn +++ /dev/null @@ -1,23 +0,0 @@ -[gd_resource type="GDNativeScript" load_steps=2 format=2] - -[sub_resource type="GDNativeLibrary" id=1] - -platform/unix = "" -platform/x11 = "res://Script/lib/libgodot_char_control.so" -platform/server = "" -platform/android = "" -platform/haiku = "" -platform/mac = "" -platform/ios = "" -platform/osx = "" -platform/html5 = "" -platform/windows = "" -platform/uwp = "" -_sections_unfolded = [ "platform" ] - -[resource] - -resource_name = "GDPlayer" -library = SubResource( 1 ) -script_name = "GDPlayer" - diff --git a/cpp/kinematic_character/Script/char_con.gdns b/cpp/kinematic_character/Script/char_con.gdns new file mode 100644 index 0000000..22f6399 --- /dev/null +++ b/cpp/kinematic_character/Script/char_con.gdns @@ -0,0 +1,11 @@ +[gd_resource type="GDNativeScript" load_steps=2 format=2] + +[ext_resource path="res://Script/bin/libkinematic_char.gdnlib" type="GDNativeLibrary" id=1] + +[resource] + +resource_name = "GDPlayer" +class_name = "GDPlayer" +library = ExtResource( 1 ) + + diff --git a/cpp/kinematic_character/Script/colworld.gdn b/cpp/kinematic_character/Script/colworld.gdn deleted file mode 100644 index 68af1c2..0000000 --- a/cpp/kinematic_character/Script/colworld.gdn +++ /dev/null @@ -1,23 +0,0 @@ -[gd_resource type="GDNativeScript" load_steps=2 format=2] - -[sub_resource type="GDNativeLibrary" id=1] - -platform/unix = "" -platform/x11 = "res://Script/lib/libgodot_char_control.so" -platform/server = "" -platform/android = "" -platform/haiku = "" -platform/mac = "" -platform/ios = "" -platform/osx = "" -platform/html5 = "" -platform/windows = "" -platform/uwp = "" -_sections_unfolded = [ "platform" ] - -[resource] - -resource_name = "GDPlayer" -library = SubResource( 1 ) -script_name = "ColWorld" - diff --git a/cpp/kinematic_character/Script/colworld.gdns b/cpp/kinematic_character/Script/colworld.gdns new file mode 100644 index 0000000..5778034 --- /dev/null +++ b/cpp/kinematic_character/Script/colworld.gdns @@ -0,0 +1,11 @@ +[gd_resource type="GDNativeScript" load_steps=2 format=2] + +[ext_resource path="res://Script/bin/libkinematic_char.gdnlib" type="GDNativeLibrary" id=1] + +[resource] + +resource_name = "GDPlayer" +class_name = "ColWorld" +library = ExtResource( 1 ) + + diff --git a/cpp/kinematic_character/Script/src/.gdignore b/cpp/kinematic_character/Script/src/.gdignore new file mode 100644 index 0000000..e69de29 diff --git a/cpp/kinematic_character/Script/src/player.h b/cpp/kinematic_character/Script/src/player.h index 00c0b83..89b5f10 100644 --- a/cpp/kinematic_character/Script/src/player.h +++ b/cpp/kinematic_character/Script/src/player.h @@ -18,7 +18,6 @@ #define PLAYER_H #include - #include #include diff --git a/cpp/kinematic_character/colworld.tscn b/cpp/kinematic_character/colworld.tscn index ec894cf..ada1dba 100644 --- a/cpp/kinematic_character/colworld.tscn +++ b/cpp/kinematic_character/colworld.tscn @@ -5,25 +5,13 @@ [ext_resource path="res://Character.tscn" type="PackedScene" id=3] [ext_resource path="res://circle.png" type="Texture" id=4] [ext_resource path="res://long_obstacle.png" type="Texture" id=5] - -[sub_resource type="GDNativeLibrary" id=1] - -platform/X11_32bit = "" -platform/X11_64bit = "res://Script/bin/libkinematic_char.so" -platform/Windows_32bit = "" -platform/Windows_64bit = "" -platform/OSX = "" -platform/Android = "" -platform/iOS_32bit = "" -platform/iOS_64bit = "" -platform/WebAssembly = "" -_sections_unfolded = [ "platform" ] +[ext_resource path="res://Script/bin/libkinematic_char.gdnlib" type="GDNativeLibrary" id=6] [sub_resource type="NativeScript" id=2] resource_name = "ColWorld" class_name = "ColWorld" -library = SubResource( 1 ) +library = ExtResource( 6 ) [sub_resource type="RectangleShape2D" id=3] diff --git a/cpp/kinematic_character/project.godot b/cpp/kinematic_character/project.godot index 2f270a4..ae47600 100644 --- a/cpp/kinematic_character/project.godot +++ b/cpp/kinematic_character/project.godot @@ -10,7 +10,9 @@ config_version=3 [application] +config/name="Kinematic Character" run/main_scene="res://colworld.tscn" +config/icon="res://icon.png" name="Kinematic Character" main_scene="res://colworld.tscn" icon="res://icon.png"