Generate shared object
Modify build-script to generate a shared library for Godot.
This commit is contained in:
parent
d8431a7485
commit
2c4cdb41a1
9 changed files with 150 additions and 48 deletions
13
.gitignore
vendored
13
.gitignore
vendored
|
|
@ -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/*
|
||||
|
|
|
|||
8
bin/main.gdextension
Normal file
8
bin/main.gdextension
Normal file
|
|
@ -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"
|
||||
|
|
@ -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([\
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 950 B After Width: | Height: | Size: 950 B |
|
|
@ -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"
|
||||
|
|
@ -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
|
||||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
113
src/main.c
113
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue