Skip to content

Commit 4943d52

Browse files
committed
Update sample and build for GDExtensionLoader based new API
1 parent 26fc59a commit 4943d52

File tree

11 files changed

+465
-53
lines changed

11 files changed

+465
-53
lines changed

SwiftGodot

Submodule SwiftGodot updated 42 files

build_libgodot.sh

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ lib_suffix="so"
2121
host_debug=1
2222
debug=1
2323
force_host_rebuild=0
24-
force_regenerate=0
24+
update_api=0
2525

2626
case "$host_system" in
2727
Linux)
@@ -51,18 +51,25 @@ do
5151
--host-debug)
5252
host_debug=1
5353
;;
54-
--regenerate)
55-
force_regenerate=1
54+
--host-release)
55+
host_debug=0
56+
;;
57+
--update-api)
58+
update_api=1
59+
force_host_rebuild=1
5660
;;
5761
--debug)
5862
debug=1
5963
;;
64+
--release)
65+
debug=0
66+
;;
6067
--target)
6168
shift
6269
target_platform="${1:-}"
6370
;;
6471
*)
65-
echo "Usage: $0 [--host-debug] [--host-rebuild] [--debug] [--regenerate] --target <target platform>"
72+
echo "Usage: $0 [--host-debug] [--host-rebuild] [--host-debug] [--host-release] [--debug] [--release] [--update-api] [--target <target platform>]"
6673
exit 1
6774
;;
6875
esac
@@ -72,7 +79,7 @@ done
7279
if [ "$target_platform" = "ios" ]
7380
then
7481
target_arch="arm64"
75-
target="template_debug"
82+
target="template_release"
7683
lib_suffix="a"
7784
fi
7885

@@ -97,6 +104,10 @@ if [ $debug -eq 1 ]
97104
then
98105
target_build_options="$target_build_options dev_build=yes"
99106
target_godot_suffix="$target_godot_suffix.dev"
107+
if [ "$target_platform" = "ios" ]
108+
then
109+
target="template_debug"
110+
fi
100111
fi
101112

102113
target_godot_suffix="$target_godot_suffix.$target_arch"
@@ -113,22 +124,26 @@ fi
113124

114125
mkdir -p $BUILD_DIR
115126

116-
if [ ! -f $BUILD_DIR/extension_api.json ] || [ $force_regenerate -eq 1 ]
127+
if [ $update_api -eq 1 ]
117128
then
118129
cd $BUILD_DIR
119130
$host_godot --dump-extension-api
131+
cp -v $BUILD_DIR/extension_api.json $GODOT_CPP_DIR/gdextension/
132+
cp -v $GODOT_DIR/core/extension/gdextension_interface.h $GODOT_CPP_DIR/gdextension/
133+
cp -v $GODOT_DIR/core/extension/libgodot.h $GODOT_CPP_DIR/gdextension/
134+
cp -v $BUILD_DIR/extension_api.json $SWIFT_GODOT_DIR/Sources/ExtensionApi/
135+
cp -v $GODOT_DIR/core/extension/gdextension_interface.h $SWIFT_GODOT_DIR/Sources/GDExtension/include/
136+
cp -v $GODOT_DIR/core/extension/libgodot.h $SWIFT_GODOT_DIR/Sources/GDExtension/include/
137+
138+
echo "Successfully updated the GDExtension API."
139+
exit 0
120140
fi
121141

122142
cd $GODOT_DIR
123143
scons p=$target_platform target=$target $target_build_options library_type=shared_library
124144
cp -v $target_godot $BUILD_DIR/libgodot.$lib_suffix
125145

126-
cp -v $BUILD_DIR/extension_api.json $GODOT_CPP_DIR/gdextension/
127-
cp -v $GODOT_DIR/core/extension/gdextension_interface.h $GODOT_CPP_DIR/gdextension/
128-
129146
if [ "$target_platform" = "ios" ]
130147
then
131-
$SWIFT_GODOT_DIR/scripts/make-libgodot.framework $GODOT_DIR $BUILD_DIR
132-
cp -v $BUILD_DIR/extension_api.json $SWIFT_GODOT_DIR/Sources/ExtensionApi/
133-
cp -v $GODOT_DIR/core/extension/gdextension_interface.h $SWIFT_GODOT_DIR/Sources/GDExtension/include/
134-
fi
148+
$SWIFT_GODOT_DIR/scripts/make-libgodot.framework $GODOT_DIR $BUILD_DIR $target
149+
fi

godot

Submodule godot updated 2764 files

godot-cpp

Submodule godot-cpp updated 59 files

samples/cpp_sample/src/main.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <string>
55
#include <vector>
66

7-
#include <gdextension_interface.h>
7+
#include <libgodot.h>
88

99
#include <godot_cpp/core/defs.hpp>
1010
#include <godot_cpp/godot.hpp>
@@ -52,8 +52,15 @@ class LibGodot {
5252
fprintf(stderr, "Error opening libgodot: %s\n", dlerror());
5353
return;
5454
}
55-
*(void**)(&func_gdextension_create_godot_instance) = dlsym(handle, "gdextension_create_godot_instance");
56-
if (func_gdextension_create_godot_instance == nullptr) {
55+
*(void**)(&func_libgodot_create_godot_instance) = dlsym(handle, "libgodot_create_godot_instance");
56+
if (func_libgodot_create_godot_instance == nullptr) {
57+
fprintf(stderr, "Error acquiring function: %s\n", dlerror());
58+
dlclose(handle);
59+
handle == nullptr;
60+
return;
61+
}
62+
*(void**)(&func_libgodot_destroy_godot_instance) = dlsym(handle, "libgodot_destroy_godot_instance");
63+
if (func_libgodot_destroy_godot_instance == nullptr) {
5764
fprintf(stderr, "Error acquiring function: %s\n", dlerror());
5865
dlclose(handle);
5966
handle == nullptr;
@@ -68,23 +75,29 @@ class LibGodot {
6875
}
6976

7077
bool is_open() {
71-
return handle != nullptr && func_gdextension_create_godot_instance != nullptr;
78+
return handle != nullptr && func_libgodot_create_godot_instance != nullptr;
7279
}
7380

7481
godot::GodotInstance *create_godot_instance(int p_argc, char *p_argv[], GDExtensionInitializationFunction p_init_func = gdextension_default_init) {
7582
if (!is_open()) {
7683
return nullptr;
7784
}
78-
GDExtensionObjectPtr instance = func_gdextension_create_godot_instance(p_argc, p_argv, p_init_func);
85+
GDExtensionObjectPtr instance = func_libgodot_create_godot_instance(p_argc, p_argv, p_init_func);
7986
if (instance == nullptr) {
8087
return nullptr;
8188
}
8289
return reinterpret_cast<godot::GodotInstance *>(godot::internal::get_object_instance_binding(instance));
8390
}
8491

92+
void destroy_godot_instance(godot::GodotInstance* instance) {
93+
GDExtensionObjectPtr obj = godot::internal::gdextension_interface_object_get_instance_from_id(instance->get_instance_id());
94+
func_libgodot_destroy_godot_instance(obj);
95+
}
96+
8597
private:
8698
void *handle = nullptr;
87-
GDExtensionObjectPtr (*func_gdextension_create_godot_instance)(int, char *[], GDExtensionInitializationFunction) = nullptr;
99+
GDExtensionObjectPtr (*func_libgodot_create_godot_instance)(int, char *[], GDExtensionInitializationFunction) = nullptr;
100+
void (*func_libgodot_destroy_godot_instance)(GDExtensionObjectPtr) = nullptr;
88101
};
89102

90103
int main(int argc, char **argv) {
@@ -95,7 +108,7 @@ int main(int argc, char **argv) {
95108
if (argc > 0) {
96109
program = std::string(argv[0]);
97110
}
98-
std::vector<std::string> args = { program, "--path", "../../project/" };
111+
std::vector<std::string> args = { program, "--path", "../../project/", "--rendering-method", "gl_compatibility", "--rendering-driver", "opengl3" };
99112

100113
std::vector<char*> argvs;
101114
for (const auto& arg : args) {
@@ -111,7 +124,7 @@ int main(int argc, char **argv) {
111124

112125
instance->start();
113126
while (!instance->iteration()) {}
114-
instance->shutdown();
127+
libgodot.destroy_godot_instance(instance);
115128

116129
return EXIT_SUCCESS;
117130
}

samples/ios_sample/iosTest.xcodeproj/project.pbxproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
4009A2932BC608480066C885 /* SwiftGodotKit in Frameworks */ = {isa = PBXBuildFile; productRef = 4009A2922BC608480066C885 /* SwiftGodotKit */; };
11+
4041CDDD2C16837600400A0A /* game.pck in Resources */ = {isa = PBXBuildFile; fileRef = 4041CDDC2C16837600400A0A /* game.pck */; };
1112
63091EA02BA0B27300576D34 /* main.pck in Resources */ = {isa = PBXBuildFile; fileRef = 63091E9F2BA0B27300576D34 /* main.pck */; };
1213
633CF6A02B9EFEE1000461C9 /* iosTestApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 633CF69F2B9EFEE1000461C9 /* iosTestApp.swift */; };
1314
633CF6A22B9EFEE1000461C9 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 633CF6A12B9EFEE1000461C9 /* ContentView.swift */; };
@@ -38,6 +39,7 @@
3839
/* End PBXContainerItemProxy section */
3940

4041
/* Begin PBXFileReference section */
42+
4041CDDC2C16837600400A0A /* game.pck */ = {isa = PBXFileReference; lastKnownFileType = file; path = game.pck; sourceTree = "<group>"; };
4143
63091E9F2BA0B27300576D34 /* main.pck */ = {isa = PBXFileReference; lastKnownFileType = file; path = main.pck; sourceTree = "<group>"; };
4244
633CF69C2B9EFEE1000461C9 /* iosTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iosTest.app; sourceTree = BUILT_PRODUCTS_DIR; };
4345
633CF69F2B9EFEE1000461C9 /* iosTestApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iosTestApp.swift; sourceTree = "<group>"; };
@@ -106,6 +108,7 @@
106108
633CF69E2B9EFEE1000461C9 /* iosTest */ = {
107109
isa = PBXGroup;
108110
children = (
111+
4041CDDC2C16837600400A0A /* game.pck */,
109112
63091E9F2BA0B27300576D34 /* main.pck */,
110113
633CF69F2B9EFEE1000461C9 /* iosTestApp.swift */,
111114
633CF6A12B9EFEE1000461C9 /* ContentView.swift */,
@@ -263,6 +266,7 @@
263266
files = (
264267
63091EA02BA0B27300576D34 /* main.pck in Resources */,
265268
633CF6A72B9EFEE3000461C9 /* Preview Assets.xcassets in Resources */,
269+
4041CDDD2C16837600400A0A /* game.pck in Resources */,
266270
633CF6A42B9EFEE3000461C9 /* Assets.xcassets in Resources */,
267271
);
268272
runOnlyForDeploymentPostprocessing = 0;
@@ -454,7 +458,7 @@
454458
CODE_SIGN_STYLE = Automatic;
455459
CURRENT_PROJECT_VERSION = 1;
456460
DEVELOPMENT_ASSET_PATHS = "\"iosTest/Preview Content\"";
457-
DEVELOPMENT_TEAM = "";
461+
DEVELOPMENT_TEAM = CVQ7CHHHZY;
458462
ENABLE_PREVIEWS = YES;
459463
GENERATE_INFOPLIST_FILE = YES;
460464
HEADER_SEARCH_PATHS = "";
@@ -489,7 +493,7 @@
489493
CODE_SIGN_STYLE = Automatic;
490494
CURRENT_PROJECT_VERSION = 1;
491495
DEVELOPMENT_ASSET_PATHS = "\"iosTest/Preview Content\"";
492-
DEVELOPMENT_TEAM = "";
496+
DEVELOPMENT_TEAM = CVQ7CHHHZY;
493497
ENABLE_PREVIEWS = YES;
494498
GENERATE_INFOPLIST_FILE = YES;
495499
HEADER_SEARCH_PATHS = "";
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1540"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
<BuildActionEntries>
10+
<BuildActionEntry
11+
buildForTesting = "YES"
12+
buildForRunning = "YES"
13+
buildForProfiling = "YES"
14+
buildForArchiving = "YES"
15+
buildForAnalyzing = "YES">
16+
<BuildableReference
17+
BuildableIdentifier = "primary"
18+
BlueprintIdentifier = "633CF69B2B9EFEE1000461C9"
19+
BuildableName = "iosTest.app"
20+
BlueprintName = "iosTest"
21+
ReferencedContainer = "container:iosTest.xcodeproj">
22+
</BuildableReference>
23+
</BuildActionEntry>
24+
</BuildActionEntries>
25+
</BuildAction>
26+
<TestAction
27+
buildConfiguration = "Debug"
28+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
29+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
30+
shouldUseLaunchSchemeArgsEnv = "YES"
31+
shouldAutocreateTestPlan = "YES">
32+
<Testables>
33+
<TestableReference
34+
skipped = "NO"
35+
parallelizable = "YES">
36+
<BuildableReference
37+
BuildableIdentifier = "primary"
38+
BlueprintIdentifier = "633CF6AB2B9EFEE4000461C9"
39+
BuildableName = "iosTestTests.xctest"
40+
BlueprintName = "iosTestTests"
41+
ReferencedContainer = "container:iosTest.xcodeproj">
42+
</BuildableReference>
43+
</TestableReference>
44+
<TestableReference
45+
skipped = "NO"
46+
parallelizable = "YES">
47+
<BuildableReference
48+
BuildableIdentifier = "primary"
49+
BlueprintIdentifier = "633CF6B52B9EFEE4000461C9"
50+
BuildableName = "iosTestUITests.xctest"
51+
BlueprintName = "iosTestUITests"
52+
ReferencedContainer = "container:iosTest.xcodeproj">
53+
</BuildableReference>
54+
</TestableReference>
55+
</Testables>
56+
</TestAction>
57+
<LaunchAction
58+
buildConfiguration = "Debug"
59+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
60+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
61+
launchStyle = "0"
62+
useCustomWorkingDirectory = "NO"
63+
ignoresPersistentStateOnLaunch = "NO"
64+
debugDocumentVersioning = "YES"
65+
debugServiceExtension = "internal"
66+
allowLocationSimulation = "YES">
67+
<BuildableProductRunnable
68+
runnableDebuggingMode = "0">
69+
<BuildableReference
70+
BuildableIdentifier = "primary"
71+
BlueprintIdentifier = "633CF69B2B9EFEE1000461C9"
72+
BuildableName = "iosTest.app"
73+
BlueprintName = "iosTest"
74+
ReferencedContainer = "container:iosTest.xcodeproj">
75+
</BuildableReference>
76+
</BuildableProductRunnable>
77+
</LaunchAction>
78+
<ProfileAction
79+
buildConfiguration = "Release"
80+
shouldUseLaunchSchemeArgsEnv = "YES"
81+
savedToolIdentifier = ""
82+
useCustomWorkingDirectory = "NO"
83+
debugDocumentVersioning = "YES">
84+
<BuildableProductRunnable
85+
runnableDebuggingMode = "0">
86+
<BuildableReference
87+
BuildableIdentifier = "primary"
88+
BlueprintIdentifier = "633CF69B2B9EFEE1000461C9"
89+
BuildableName = "iosTest.app"
90+
BlueprintName = "iosTest"
91+
ReferencedContainer = "container:iosTest.xcodeproj">
92+
</BuildableReference>
93+
</BuildableProductRunnable>
94+
</ProfileAction>
95+
<AnalyzeAction
96+
buildConfiguration = "Debug">
97+
</AnalyzeAction>
98+
<ArchiveAction
99+
buildConfiguration = "Release"
100+
revealArchiveInOrganizer = "YES">
101+
</ArchiveAction>
102+
</Scheme>

samples/ios_sample/iosTest.xcodeproj/xcuserdata/kisg.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)