diff --git a/.gitignore b/.gitignore index 2c465ee..017f933 100644 --- a/.gitignore +++ b/.gitignore @@ -16,12 +16,25 @@ !README !TODO +# /bin +!/bin/ +/bin/* + +!/bin/main.gdextension + # /docs !/docs/ /docs/* !/docs/1.1_PRIVACY +# /engine +!/engine/ +/engine/* + +!/engine/project.godot +!/engine/icon.svg + # /src !/src/ /src/* diff --git a/bin/main.gdextension b/bin/main.gdextension new file mode 100644 index 0000000..05881c7 --- /dev/null +++ b/bin/main.gdextension @@ -0,0 +1,8 @@ +[configuration] +entry_symbol = "rtr_extension_init" +compatibility_minimum = "4.2" + +[libraries] +windows.x86_64 = "../src/.libs/librtr.dll" +macos = "../src/.libs/librtr.dylib" +linux.debug.x86_64 = "res://../src/.libs/librtr.so" diff --git a/configure.ac b/configure.ac index fca562e..e8a28de 100644 --- a/configure.ac +++ b/configure.ac @@ -7,6 +7,8 @@ AC_INIT(\ [https://www.delay.cloud/] \ ) +AC_COPYRIGHT(ISC License) + # AC_CHECK_LIB is not utilized, since it checks the presence of libraries by # linking them to test program; this process introduces more overhead and longer # build times. @@ -19,6 +21,12 @@ AM_CONFIG_HEADER([src/config.h]) AC_CONFIG_MACRO_DIR([m4 ]) +AC_PROG_LIBTOOL +AC_PROG_INSTALL + +AC_ENABLE_SHARED +AC_DISABLE_STATIC + # Do not generate GNU project files and disable some checks. # Includes flags to strictly compile Standard C89. AM_INIT_AUTOMAKE([\ diff --git a/icon.svg b/engine/icon.svg similarity index 100% rename from icon.svg rename to engine/icon.svg diff --git a/project.godot b/engine/project.godot similarity index 90% rename from project.godot rename to engine/project.godot index 347146b..e3c7b88 100644 --- a/project.godot +++ b/engine/project.godot @@ -11,5 +11,6 @@ config_version=5 [application] config/name="RTR" +run/main_scene="res://environment.tscn" config/features=PackedStringArray("4.2", "Forward Plus") config/icon="res://icon.svg" diff --git a/icon.svg.import b/icon.svg.import deleted file mode 100644 index c5813e0..0000000 --- a/icon.svg.import +++ /dev/null @@ -1,37 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://dlvt0jcfajhh0" -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/src/Makefile.am b/src/Makefile.am index e579782..dba315a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,9 +3,13 @@ #bin_PROGRAMS = $(top_builddir)/bin/rtr # Program name. #__top_builddir__bin_rtr_CFLAGS = -DBUILD # Define BUILD variable. #__top_builddir__bin_rtr_SOURCES = main.c # Sources -bin_PROGRAMS = rtr -rtr_CFLAGS = -DBUILD -c -fPIC # Define BUILD variable. -rtr_SOURCES = main.c # Sources +lib_LTLIBRARIES = librtr.la +librtr_la_SOURCES = main.c +librtr_la_LDFLAGS = -module -avoid-version -export-dynamic + +#bin_PROGRAMS = rtr +#rtr_CFLAGS = -DBUILD -c -fPIC -shared # Define BUILD and output shared. +#rtr_SOURCES = main.c # Sources #if extra #__top_builddir__bin_rtr_LDADD = ./extra/libextra.la # Include extra. diff --git a/src/main.c b/src/main.c index c890817..5156004 100644 --- a/src/main.c +++ b/src/main.c @@ -18,3 +18,116 @@ int main() return(0); } */ + +typedef struct { + uint8_t godot_data_dont_touch_this[sizeof(void *)]; +} String; + +typedef struct { + uint8_t godot_data_dont_touch_this[sizeof(void *)]; +} StringName; + +typedef struct { + uint8_t godot_data_dont_touch_this[24]; +} Variant; + +// GDExtension interface function pointers +static GDExtensionInterfaceStringNewWithUtf8Chars string_new_with_utf8_chars; +static GDExtensionInterfaceVariantGetPtrConstructor variant_get_ptr_constructor; +static GDExtensionInterfaceVariantGetPtrDestructor variant_get_ptr_destructor; +static GDExtensionInterfaceGetVariantFromTypeConstructor get_variant_from_type_constructor; +static GDExtensionInterfaceVariantGetPtrUtilityFunction variant_get_ptr_utility_function; +static GDExtensionInterfaceVariantDestroy variant_destroy; +// Godot API function pointers +static GDExtensionPtrConstructor construct_StringName_from_String; +static GDExtensionVariantFromTypeConstructorFunc construct_Variant_from_String; +static GDExtensionPtrDestructor destroy_String; +static GDExtensionPtrDestructor destroy_StringName; + +// here is our global "print" StringName +static StringName print_StringName; +// and here is our global "print" function +static GDExtensionPtrUtilityFunction print_function; + +StringName construct_StringName_from_cstring(const char *text) { + // 1. Construct a String from the C string + String string; + string_new_with_utf8_chars(&string, text); + + // 2. Construct a StringName from the String + StringName string_name; + GDExtensionConstTypePtr constructor_arguments[1] = { &string }; + construct_StringName_from_String(&string_name, constructor_arguments); + + // 3. Destroy the String, since it's not needed anymore + destroy_String(&string); + + return string_name; +} + +void print(const char *text) { + // 1. Construct a String from the C string + String string; + string_new_with_utf8_chars(&string, text); + + // 2. Construct a Variant from the String + Variant arg1; + construct_Variant_from_String(&arg1, &string); + + // 3. Call the utility function + // Since it's a void function, use "NULL" for the return pointer + GDExtensionConstVariantPtr args[1] = { &arg1 }; + print_function(NULL, args, 1); + + // 4. Clean up resources that are no longer needed + variant_destroy(&arg1); + destroy_String(&string); +} + +void initialize(void *userdata, GDExtensionInitializationLevel p_level) { + if (p_level != GDEXTENSION_INITIALIZATION_SCENE) { + return; + } + + // StringName constructor at index 2 is the one that receives String + // You can find this information in `extension_api.json` file + construct_StringName_from_String = variant_get_ptr_constructor(GDEXTENSION_VARIANT_TYPE_STRING_NAME, 2); + construct_Variant_from_String = get_variant_from_type_constructor(GDEXTENSION_VARIANT_TYPE_STRING); + destroy_String = variant_get_ptr_destructor(GDEXTENSION_VARIANT_TYPE_STRING); + destroy_StringName = variant_get_ptr_destructor(GDEXTENSION_VARIANT_TYPE_STRING_NAME); + + // Initialize "print" StringName + print_StringName = construct_StringName_from_cstring("print"); + // then fetch the "print" function pointer + print_function = variant_get_ptr_utility_function(&print_StringName, 2648703342); + + print("Hello GDExtension from C!"); +} + +void deinitialize(void *userdata, GDExtensionInitializationLevel p_level) { + if (p_level != GDEXTENSION_INITIALIZATION_SCENE) { + return; + } + + print("Goodbye GDExtension from C!"); + + // Destroy "print" StringName + destroy_StringName(&print_StringName); +} + +GDExtensionBool hello_extension_entry( + GDExtensionInterfaceGetProcAddress p_get_proc_address, + GDExtensionClassLibraryPtr p_library, + GDExtensionInitialization *r_initialization +) { + r_initialization->initialize = &initialize; + r_initialization->deinitialize = &deinitialize; + // save the GDExtension API function pointers globally + string_new_with_utf8_chars = (GDExtensionInterfaceStringNewWithUtf8Chars) p_get_proc_address("string_new_with_utf8_chars"); + variant_get_ptr_constructor = (GDExtensionInterfaceVariantGetPtrConstructor) p_get_proc_address("variant_get_ptr_constructor"); + variant_get_ptr_destructor = (GDExtensionInterfaceVariantGetPtrDestructor) p_get_proc_address("variant_get_ptr_destructor"); + get_variant_from_type_constructor = (GDExtensionInterfaceGetVariantFromTypeConstructor) p_get_proc_address("get_variant_from_type_constructor"); + variant_get_ptr_utility_function = (GDExtensionInterfaceVariantGetPtrUtilityFunction) p_get_proc_address("variant_get_ptr_utility_function"); + variant_destroy = (GDExtensionInterfaceVariantDestroy) p_get_proc_address("variant_destroy"); + return 1; +} diff --git a/src/main.gdextension b/src/main.gdextension deleted file mode 100644 index 6c44bf2..0000000 --- a/src/main.gdextension +++ /dev/null @@ -1,8 +0,0 @@ -[configuration] -entry_symbol = "main_extension_entry" -compatibility_minimum = "4.2" - -[libraries] -windows.x86_64 = "main-gdextension.dll" -macos = "libmain-gdextension.dylib" -linux.x86_64 = "libhello-gdextension.so"