From b13fb52e40c297acbdb68be144c13ae040d867be Mon Sep 17 00:00:00 2001 From: Andrew Luchuk Date: Fri, 13 Mar 2026 23:58:40 -0400 Subject: [PATCH] Scaffold GDExtension template --- .gitignore | 3 +++ .gitmodules | 4 ++++ SConstruct | 43 ++++++++++++++++++++++++++++++++++++++++++ demo/.editorconfig | 4 ++++ demo/.gitattributes | 2 ++ demo/.gitignore | 3 +++ demo/icon.svg | 1 + demo/icon.svg.import | 43 ++++++++++++++++++++++++++++++++++++++++++ demo/project.godot | 19 +++++++++++++++++++ redot-cpp | 1 + src/register_types.cpp | 40 +++++++++++++++++++++++++++++++++++++++ src/register_types.h | 13 +++++++++++++ 12 files changed, 176 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 SConstruct create mode 100644 demo/.editorconfig create mode 100644 demo/.gitattributes create mode 100644 demo/.gitignore create mode 100644 demo/icon.svg create mode 100644 demo/icon.svg.import create mode 100644 demo/project.godot create mode 160000 redot-cpp create mode 100644 src/register_types.cpp create mode 100644 src/register_types.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2dd9f84 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +demo/bin + +.idea \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e63d92b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "redot-cpp"] + path = redot-cpp + url = https://github.com/speratus/redot-cpp + branch = 26.1 diff --git a/SConstruct b/SConstruct new file mode 100644 index 0000000..a1ce249 --- /dev/null +++ b/SConstruct @@ -0,0 +1,43 @@ +#!/usr/bin/env python +import os +import sys + +env = SConscript("godot-cpp/SConstruct") + +# For reference: +# - CCFLAGS are compilation flags shared between C and C++ +# - CFLAGS are for C-specific compilation flags +# - CXXFLAGS are for C++-specific compilation flags +# - CPPFLAGS are for pre-processor flags +# - CPPDEFINES are for pre-processor defines +# - LINKFLAGS are for linking flags + +# tweak this if you want to use different folders, or more folders, to store your source code in. +env.Append(CPPPATH=["src/"]) +sources = Glob("src/*.cpp") + +if env["platform"] == "macos": + library = env.SharedLibrary( + "demo/bin/libgdexample.{}.{}.framework/libgdexample.{}.{}".format( + env["platform"], env["target"], env["platform"], env["target"] + ), + source=sources, + ) +elif env["platform"] == "ios": + if env["ios_simulator"]: + library = env.StaticLibrary( + "demo/bin/libgdexample.{}.{}.simulator.a".format(env["platform"], env["target"]), + source=sources, + ) + else: + library = env.StaticLibrary( + "demo/bin/libgdexample.{}.{}.a".format(env["platform"], env["target"]), + source=sources, + ) +else: + library = env.SharedLibrary( + "demo/bin/libgdexample{}{}".format(env["suffix"], env["SHLIBSUFFIX"]), + source=sources, + ) + +Default(library) diff --git a/demo/.editorconfig b/demo/.editorconfig new file mode 100644 index 0000000..f28239b --- /dev/null +++ b/demo/.editorconfig @@ -0,0 +1,4 @@ +root = true + +[*] +charset = utf-8 diff --git a/demo/.gitattributes b/demo/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/demo/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/demo/.gitignore b/demo/.gitignore new file mode 100644 index 0000000..e2dce33 --- /dev/null +++ b/demo/.gitignore @@ -0,0 +1,3 @@ +# Redot 4+ specific ignores +.godot/ +/android/ diff --git a/demo/icon.svg b/demo/icon.svg new file mode 100644 index 0000000..b1eb350 --- /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..79fbcbb --- /dev/null +++ b/demo/icon.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d11l530q5178u" +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/uastc_level=0 +compress/rdo_quality_loss=0.0 +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/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +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..1c71a83 --- /dev/null +++ b/demo/project.godot @@ -0,0 +1,19 @@ +; 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="demo" +config/features=PackedStringArray("26.1", "Forward Plus", "Redot") +config/icon="res://icon.svg" + +[dotnet] + +project/assembly_name="demo" diff --git a/redot-cpp b/redot-cpp new file mode 160000 index 0000000..f81d6ca --- /dev/null +++ b/redot-cpp @@ -0,0 +1 @@ +Subproject commit f81d6cadd886ffbdabd1403cc62a55705cd57d0a diff --git a/src/register_types.cpp b/src/register_types.cpp new file mode 100644 index 0000000..3d99daa --- /dev/null +++ b/src/register_types.cpp @@ -0,0 +1,40 @@ +// +// Created by andrew on 3/13/26. +// + +#include "register_types.h" + +#include + +using namespace godot; + +void register_gdextension_types(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } + + //TODO: Implement type registration +} + +void unregister_gdextension_types(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } + + //TODO: Implement plugin unregistration +} + +extern "C" { +GDExtensionBool GDE_EXPORT init_gdextension( + GDExtensionInterfaceGetProcAddress p_get_proc_address, + const GDExtensionClassLibraryPtr p_library, + GDExtensionInitialization *r_initialization + ) { + godot::GDExtensionBinding::InitObject init_object(p_get_proc_address, p_library, r_initialization); + + init_object.register_initializer(register_gdextension_types); + init_object.register_terminator(unregister_gdextension_types); + init_object.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_LATE); +} +} + diff --git a/src/register_types.h b/src/register_types.h new file mode 100644 index 0000000..4e0a85c --- /dev/null +++ b/src/register_types.h @@ -0,0 +1,13 @@ +// +// Created by andrew on 3/13/26. +// + +#ifndef GDEXTENSION_TEMPLATE_REGISTER_TYPES_H +#define GDEXTENSION_TEMPLATE_REGISTER_TYPES_H + +using namespace godot; + +void register_gdextension_types(); +void unregister_gdextension_types(); + +#endif //GDEXTENSION_TEMPLATE_REGISTER_TYPES_H \ No newline at end of file