commit ab88d0b254d4f87670d3308d2baa5ff67464daa1 Author: Patrick Date: Sun Aug 6 00:42:21 2023 +0200 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.github/ISSUE_TEMPLATE.yml b/.github/ISSUE_TEMPLATE.yml new file mode 100644 index 0000000..2ec5cd2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.yml @@ -0,0 +1,44 @@ +name: Bug report +description: Report a bug with the godot-cpp template +body: + +- type: markdown + attributes: + value: | + - Write a descriptive issue title above. + - Search [open]() and [closed]() issues to ensure it has not already been reported. +- type: input + attributes: + label: Godot version + description: > + Specify the Git commit hash of your Godot build. + placeholder: v4.0.stable.official [92bee43ad] + validations: + required: true + +- type: input + attributes: + label: godot-cpp version + description: > + Specify the Git commit hash of the godot-cpp submodule in your project. You can run `git status` inside the folder to check it. + placeholder: v4.0.stable.official [9d1c396c5] + validations: + required: true + +- type: input + attributes: + label: System information + description: | + Specify the OS version. + placeholder: Windows 10 + validations: + required: true + +- type: textarea + attributes: + label: Issue description + description: | + Describe your issue briefly. What doesn't work, and how do you expect it to work instead? + You can include images or videos with drag and drop, and format code blocks or logs with ``` tags. + validations: + required: true \ No newline at end of file diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml new file mode 100644 index 0000000..2095eb3 --- /dev/null +++ b/.github/workflows/builds.yml @@ -0,0 +1,121 @@ +name: Builds + +on: push + +env: + LIBNAME: example + +concurrency: + group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-macos + cancel-in-progress: true + +jobs: + build: + runs-on: ${{matrix.os}} + name: ${{matrix.name}} + strategy: + fail-fast: false + matrix: + include: + - identifier: windows-debug + os: windows-latest + name: 🏁 Windows Debug + target: template_debug + platform: windows + arch: x86_64 + - identifier: windows-release + os: windows-latest + name: 🏁 Windows Release + target: template_release + platform: windows + arch: x86_64 + - identifier: macos-debug + os: macos-latest + name: 🍎 macOS (universal) Debug + target: template_debug + platform: macos + arch: universal + - identifier: macos-release + os: macos-latest + name: 🍎 macOS (universal) Release + target: template_release + platform: macos + arch: universal + - identifier: linux-debug + os: ubuntu-latest + name: 🐧 Linux Debug + runner: ubuntu-20.04 + target: template_debug + platform: linux + arch: x86_64 + - identifier: linux-release + os: ubuntu-latest + name: 🐧 Linux Release + runner: ubuntu-20.04 + target: template_release + platform: linux + arch: x86_64 + + steps: + - name: Checkout project + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Set up SCons + shell: bash + run: | + python -c "import sys; print(sys.version)" + python -m pip install scons + scons --version + - name: Linux dependencies + if: ${{ matrix.platform == 'linux' }} + run: | + sudo apt-get update -qq + sudo apt-get install -qqq build-essential pkg-config + - name: Setup MinGW for Windows/MinGW build + if: ${{ matrix.platform == 'windows' }} + uses: egor-tensin/setup-mingw@v2 + + - name: Compile godot-cpp + shell: sh + run: | + scons target='${{ matrix.target }}' platform='${{ matrix.platform }}' arch='${{ matrix.arch }}' + working-directory: godot-cpp + + - name: Compile Extension + shell: sh + run: | + scons target='${{ matrix.target }}' platform='${{ matrix.platform }}' arch='${{ matrix.arch }}' + - name: Delete compilation files + if: ${{ matrix.platform == 'windows' }} + run: | + Remove-Item bin/* -Include *.exp,*.lib,*.pdb -Force + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ github.event.repository.name }} + path: | + ${{ github.workspace }}/bin/* + - name: Archive Release + uses: thedoctor0/zip-release@0.7.1 + with: + type: 'zip' + filename: '${{ env.LIBNAME }}.${{ matrix.platform }}.${{ matrix.arch }}.zip' + path: '${{ github.workspace }}/bin/' + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + + - name: Create and upload asset + if: success() && github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + artifacts: "${{ env.LIBNAME }}.${{ matrix.platform }}.${{ matrix.arch }}.zip" + omitNameDuringUpdate: true + omitBodyDuringUpdate: true + token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..76e5d9e --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# Godot 4+ specific ignores +.godot/ + +# Ignore library files but not the gdextension file +demo/bin/* +!demo/bin/*.gdextension +.sconsign*.dblite + +# Binaries +*.o +*.os +*.so +*.obj +*.bc +*.pyc +*.dblite +*.pdb +*.lib +*.config +*.creator +*.creator.user +*.files +*.includes +*.idb +*.exp + +# Other stuff +*.log \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..5f8a098 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "godot-cpp"] + path = godot-cpp + url = https://github.com/godotengine/godot-cpp.git + branch = 4.0 diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..fdddb29 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/README.md b/README.md new file mode 100644 index 0000000..987b9a5 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# godot-cpp template +This repository serves as a quickstart template for GDExtension development with Godot 4.0+. + +## Contents +* An empty Godot project (`demo/`) +* godot-cpp as a submodule (`godot-cpp/`) +* GitHub Issues template (`.github/ISSUE_TEMPLATE.yml`) +* GitHub CI/CD to publish your library packages when creating a release (`.github/workflows/builds.yml`) +* preconfigured source files for C++ development of the GDExtension (`src/`) + +## Usage +To use this template, click the green "Use this template" button at the top of the repository page. +This will let you create a copy of this repository with a clean git history. Make sure you clone the correct branch as these are configured for development of their respective Godot development branches and differ from each other. Refer to the docs to see what changed between the versions. + +For getting started after cloning your own copy to your local machine, you should +* change the name of the compiled library file inside the `SConstruct` file by modifying the `libname` string. +* change the name of the to be loaded library name inside the `.gdextension` file. This should be the same name as in your `SConstruct` file. +* change the `entry_symbol` string inside your `.gdextension` file to be configured for your GDExtension name. This should be the same as the `GDExtensionBool GDE_EXPORT` external C function. As the name suggests, this sets the entry function for your GDExtension to be loaded by the Godot editors C API. +* register the classes you want Godot to interact with inside the `register_types.cpp` file in the initialization method (here `initialize_gdextension_types`) in the syntax `ClassDB::register_class();`. \ No newline at end of file diff --git a/SConstruct b/SConstruct new file mode 100644 index 0000000..ee05e13 --- /dev/null +++ b/SConstruct @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +libname = "EXTENSION-NAME" + +env = SConscript("godot-cpp/SConstruct") + +env.Append(CPPPATH=["src/"]) +sources = Glob("src/*.cpp") + +if env["platform"] == "macos": + platlibname = "{}.{}.{}".format(libname, env["platform"], env["target"]) + library = env.SharedLibrary( + "bin/{}.framework/{}".format(platlibname, platlibname), + source=sources, + ) +else: + library = env.SharedLibrary( + "bin/{}{}{}".format(libname, env["suffix"], env["SHLIBSUFFIX"]), + source=sources, + ) + +Default(library) \ No newline at end of file diff --git a/demo/bin/example.gdextension b/demo/bin/example.gdextension new file mode 100644 index 0000000..6ec0d0b --- /dev/null +++ b/demo/bin/example.gdextension @@ -0,0 +1,22 @@ +[configuration] + +entry_symbol = "example_library_init" + +[libraries] + +macos.debug = "res://bin/libgdexample.macos.template_debug.framework" +macos.release = "res://bin/libgdexample.macos.template_release.framework" +windows.debug.x86_32 = "res://bin/libgdexample.windows.template_debug.x86_32.dll" +windows.release.x86_32 = "res://bin/libgdexample.windows.template_release.x86_32.dll" +windows.debug.x86_64 = "res://bin/libgdexample.windows.template_debug.x86_64.dll" +windows.release.x86_64 = "res://bin/libgdexample.windows.template_release.x86_64.dll" +linux.debug.x86_64 = "res://bin/libgdexample.linux.template_debug.x86_64.so" +linux.release.x86_64 = "res://bin/libgdexample.linux.template_release.x86_64.so" +linux.debug.arm64 = "res://bin/libgdexample.linux.template_debug.arm64.so" +linux.release.arm64 = "res://bin/libgdexample.linux.template_release.arm64.so" +linux.debug.rv64 = "res://bin/libgdexample.linux.template_debug.rv64.so" +linux.release.rv64 = "res://bin/libgdexample.linux.template_release.rv64.so" +android.debug.x86_64 = "res://bin/libgdexample.android.template_debug.x86_64.so" +android.release.x86_64 = "res://bin/libgdexample.android.template_release.x86_64.so" +android.debug.arm64 = "res://bin/libgdexample.android.template_debug.arm64.so" +android.release.arm64 = "res://bin/libgdexample.android.template_release.arm64.so" \ No newline at end of file diff --git a/demo/icon.svg b/demo/icon.svg new file mode 100644 index 0000000..adc26df --- /dev/null +++ b/demo/icon.svg @@ -0,0 +1 @@ + diff --git a/demo/icon.svg.import b/demo/icon.svg.import new file mode 100644 index 0000000..c8d2b12 --- /dev/null +++ b/demo/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dbx66sovxd1" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/demo/project.godot b/demo/project.godot new file mode 100644 index 0000000..2e1a393 --- /dev/null +++ b/demo/project.godot @@ -0,0 +1,15 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="godot cpp template" +config/features=PackedStringArray("4.0", "Forward Plus") +config/icon="res://icon.svg" diff --git a/godot-cpp b/godot-cpp new file mode 160000 index 0000000..3a9118c --- /dev/null +++ b/godot-cpp @@ -0,0 +1 @@ +Subproject commit 3a9118cb0dafef74773216c47a030c3a4a490747 diff --git a/src/register_types.cpp b/src/register_types.cpp new file mode 100644 index 0000000..1a80f94 --- /dev/null +++ b/src/register_types.cpp @@ -0,0 +1,34 @@ +#include "register_types.h" +#include +#include +#include +#include + +using namespace godot; + +void initialize_gdextension_types(ModuleInitializationLevel p_level) +{ + if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } +} + +void uninitialize_gdextension_types(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } +} + +extern "C" +{ + // Initialization + GDExtensionBool GDE_EXPORT example_library_init(const GDExtensionInterface *p_interface, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) + { + GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization); + init_obj.register_initializer(initialize_gdextension_types); + init_obj.register_terminator(uninitialize_gdextension_types); + init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE); + + return init_obj.init(); + } +} \ No newline at end of file diff --git a/src/register_types.h b/src/register_types.h new file mode 100644 index 0000000..e6fe2b0 --- /dev/null +++ b/src/register_types.h @@ -0,0 +1,7 @@ +#ifndef EXAMPLE_REGISTER_TYPES_H +#define EXAMPLE_REGISTER_TYPES_H + +void initialize_gdextension_types(); +void uninitialize_gdextension_types(); + +#endif // EXAMPLE_REGISTER_TYPES_H \ No newline at end of file