diff --git a/README.md b/README.md index 5ca2635..ad17cb5 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ For non-GDNative demos (GDScript, VisualScript, and C#), please see the ## Godot versions The [`master`](https://github.com/godotengine/gdnative-demos) branch -is compatible with the latest stable Godot version (currently 3.2). +is compatible with the latest stable Godot version (currently 3.3). Older Godot versions are not supported by this repo. ## Useful links diff --git a/c/README.md b/c/README.md new file mode 100644 index 0000000..010485a --- /dev/null +++ b/c/README.md @@ -0,0 +1,21 @@ +# C demos + +These demos show how to use the GDNative C bindings. + +Dependencies: + * You need [Godot headers](https://github.com/godotengine/godot-headers), + this is now a Git submodule of this repo. + * `clang`, `gcc`, or any decent C compiler that's C11 compatible. + +## Compiling + +For each of the C demos, you can use SCons to compile the library: + +``` +scons platform=PLATFORM +``` + +Where PLATFORM is: `windows`, `linuxbsd`, or `macos`. + +This creates the file `libsimple` in the respective +subfolders in the `project/gdnative` directory. diff --git a/c/glfw/README.md b/c/glfw/README.md index ad55c8d..14be455 100644 --- a/c/glfw/README.md +++ b/c/glfw/README.md @@ -4,9 +4,9 @@ This is a small example using C to create a GDNative script that exposes a very small part of the GLFW API. Dependencies: - * You need [Godot headers](https://github.com/godotengine/godot_headers), - this is now a submodule of this repo. - * `clang`, `gcc`, or any decent C compiler that's C11 or C99 compatible. + * You need [Godot headers](https://github.com/godotengine/godot-headers), + this is now a Git submodule of this repo. + * `clang`, `gcc`, or any decent C compiler that's C11 compatible. * You need to have GLFW and its headers installed. ## Compile with SCons (cross platform) @@ -16,7 +16,7 @@ You can use SCons to compile the library if you have it installed: scons platform=PLATFORM ``` -Where platform is: windows, linuxbsd, or macos +Where PLATFORM is: `windows`, `linuxbsd`, or `macos`. ## Manually compiling diff --git a/c/instance_binding/README.md b/c/instance_binding/README.md index c5f3be5..d43581a 100644 --- a/c/instance_binding/README.md +++ b/c/instance_binding/README.md @@ -1,9 +1,9 @@ # Instance binding demo using C Dependencies: - * You need [Godot headers](https://github.com/godotengine/godot_headers), - this is now a submodule of this repo. - * `clang`, `gcc`, or any decent C compiler that's C11 or C99 compatible. + * You need [Godot headers](https://github.com/godotengine/godot-headers), + this is now a Git submodule of this repo. + * `clang`, `gcc`, or any decent C compiler that's C11 compatible. ## Compile with SCons (cross platform) You can use SCons to compile the library if you have it installed: @@ -12,7 +12,7 @@ You can use SCons to compile the library if you have it installed: scons platform=PLATFORM ``` -Where platform is: windows, linuxbsd, or macos +Where PLATFORM is: `windows`, `linuxbsd`, or `macos`. ## Manually compiling diff --git a/c/simple/README.md b/c/simple/README.md index 24f0e80..5d2120b 100644 --- a/c/simple/README.md +++ b/c/simple/README.md @@ -4,9 +4,9 @@ This is a small example using C to create a GDNative script that just showcases some very simple bare bones calls. Dependencies: - * You need [Godot headers](https://github.com/godotengine/godot_headers), - this is now a submodule of this repo. - * `clang`, `gcc`, or any decent C compiler that's C11 or C99 compatible. + * You need [Godot headers](https://github.com/godotengine/godot-headers), + this is now a Git submodule of this repo. + * `clang`, `gcc`, or any decent C compiler that's C11 compatible. ## Compile with SCons (cross platform) You can use SCons to compile the library if you have it installed: @@ -15,7 +15,7 @@ You can use SCons to compile the library if you have it installed: scons platform=PLATFORM ``` -Where platform is: windows, linuxbsd, or macos +Where PLATFORM is: `windows`, `linuxbsd`, or `macos`. ## Manually compiling diff --git a/cpp/README.md b/cpp/README.md index a7fab7d..ed23228 100644 --- a/cpp/README.md +++ b/cpp/README.md @@ -1,44 +1,21 @@ -## C++ +# C++ demos -### Initial setup +These demos show how to use the GDNative C++ bindings. -You need to clone the GDNative C++ bindings in the root of this project: +Dependencies: + * You need [godot-cpp](https://github.com/godotengine/godot-cpp), + this is now a Git submodule of this repo. + * `clang`, `gcc`, or any decent C++ compiler that's C++14 compatible. + +## Compiling + +For each of the C++ demos, you can use SCons to compile the library: ``` -git clone --recursive https://github.com/GodotNativeTools/godot-cpp +scons platform=PLATFORM ``` +Where PLATFORM is: `windows`, `linux`, or `osx`. -### Updating the api.json -Our api.json file contains meta data of all the classes that are part of the Godot core and are needed to generate the C++ binding classes for use in GDNative modules. - -This file is supplied with our godot_headers repository for your convinience but if you are running a custom build of Godot and need access to classes that have recent changes a new api.json file must be generated. You do this by starting your Godot executable with the following parameters: - -``` -$ godot --gdnative-generate-json-api api.json -``` - -Now copy the api.json file into your folder structure so its easy to access. **Note** the remark below for the extra ```custom_api_file``` command line parameter needed to tell scons where to find your file. - -### Compiling the cpp bindings library -The final step is to compile our cpp bindings library: -``` -$ cd godot-cpp -$ scons platform= generate_bindings=yes -$ cd .. -``` - -> Replace `` with either `windows`, `linux` or `osx`. - -> Include `use_llvm=yes` for using clang++ - -> Include `target=runtime` to build a runtime build (windows only at the moment) - -> The resulting library will be created in `godot-cpp/bin/`, take note of its name as it will be different depending on platform. - -> If you want to use an alternative api.json file add `use_custom_api_file=yes custom_api_file=../api.json`, be sure to specify the correct location of where you placed your file. - - -### Compile the demos - -A `Makefile` is provided in each demo to make the process more convenient. +This creates the file `libsimple` in the respective +subfolders in the `project/gdnative` directory. diff --git a/cpp/simple/README.md b/cpp/simple/README.md new file mode 100644 index 0000000..b73c85c --- /dev/null +++ b/cpp/simple/README.md @@ -0,0 +1,30 @@ +# Simple GDNative C++ demo + +This is a small example using C++ to create a GDNative script +that just showcases some very simple bare bones calls. + +Language: C++ + +Renderer: GLES 2 + +Dependencies: + * You need [godot-cpp](https://github.com/godotengine/godot-cpp), + this is now a Git submodule of this repo. + * `clang`, `gcc`, or any decent C++ compiler that's C++14 compatible. + +## Compiling + +You can use SCons to compile the library: + +``` +scons platform=PLATFORM +``` + +Where PLATFORM is: `windows`, `linux`, or `osx`. + +This creates the file `libsimple` in the respective +subfolders in the `project/gdnative` directory. + +## Screenshots + +![Screenshot](screenshots/screenshot.png) diff --git a/cpp/simple/project/default_env.tres b/cpp/simple/project/default_env.tres deleted file mode 100644 index 0f8c712..0000000 --- a/cpp/simple/project/default_env.tres +++ /dev/null @@ -1,18 +0,0 @@ -[gd_resource type="Environment" load_steps=2 format=2] - -[sub_resource type="ProceduralSky" id=1] -radiance_size = 4 -sky_top_color = Color( 0.0470588, 0.454902, 0.976471, 1 ) -sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 ) -sky_curve = 0.25 -ground_bottom_color = Color( 0.101961, 0.145098, 0.188235, 1 ) -ground_horizon_color = Color( 0.482353, 0.788235, 0.952941, 1 ) -ground_curve = 0.01 -sun_energy = 16.0 - -[resource] -background_mode = 2 -background_sky = SubResource( 1 ) -fog_height_min = 0.0 -fog_height_max = 100.0 -ssao_quality = 0 diff --git a/cpp/simple/project/main.tscn b/cpp/simple/project/main.tscn index 82de7fe..81d370d 100644 --- a/cpp/simple/project/main.tscn +++ b/cpp/simple/project/main.tscn @@ -24,7 +24,7 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="Sprite" type="Sprite" parent="."] +[node name="SimpleSprite" type="Sprite" parent="."] position = Vector2( 100, 100 ) texture = ExtResource( 2 ) script = ExtResource( 3 ) diff --git a/cpp/simple/project/project.godot b/cpp/simple/project/project.godot index 579d639..e602154 100644 --- a/cpp/simple/project/project.godot +++ b/cpp/simple/project/project.godot @@ -14,11 +14,14 @@ _global_script_class_icons={ [application] -config/name="New Game Project" +config/name="Simple GDNative C++ demo" run/main_scene="res://main.tscn" config/icon="res://icon.png" [rendering] -quality/driver/fallback_to_gles2=true -environment/default_environment="res://default_env.tres" +quality/driver/driver_name="GLES2" +quality/intended_usage/framebuffer_allocation=0 +quality/intended_usage/framebuffer_allocation.mobile=0 +vram_compression/import_etc=true +vram_compression/import_etc2=false diff --git a/cpp/simple/screenshots/screenshot.png b/cpp/simple/screenshots/screenshot.png new file mode 100644 index 0000000..f53101a Binary files /dev/null and b/cpp/simple/screenshots/screenshot.png differ diff --git a/cpp/simple/src/Simple.cpp b/cpp/simple/src/Simple.cpp index a10108c..b99adbf 100644 --- a/cpp/simple/src/Simple.cpp +++ b/cpp/simple/src/Simple.cpp @@ -19,16 +19,17 @@ void SimpleSprite::_register_methods() { } // `_init` doesn't need to be registered in `_register_methods`. +// `_init` is always required, if you exclude it then Godot will crash. void SimpleSprite::_init() { godot::Godot::print("A SimpleSprite was initialized in GDNative!"); } -void SimpleSprite::_process(double delta) { +void SimpleSprite::_process(double p_delta) { godot::Input *input = godot::Input::get_singleton(); godot::Vector2 input_dir(0, 0); input_dir.x = input->get_action_strength("ui_right") - input->get_action_strength("ui_left"); input_dir.y = input->get_action_strength("ui_down") - input->get_action_strength("ui_up"); - set_position(get_position() + input_dir.normalized() * delta * 300); + set_position(get_position() + input_dir.normalized() * p_delta * 300); } diff --git a/cpp/simple/src/Simple.hpp b/cpp/simple/src/Simple.hpp index 5b07c54..baf86b9 100644 --- a/cpp/simple/src/Simple.hpp +++ b/cpp/simple/src/Simple.hpp @@ -1,3 +1,6 @@ +#ifndef SIMPLE_H +#define SIMPLE_H + #include #include @@ -24,5 +27,7 @@ public: void _init(); - void _process(double delta); + void _process(double p_delta); }; + +#endif // SIMPLE_H