@preeternal/react-native-godot 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Package.swift +4 -4
- package/README.md +411 -452
- package/android/build.gradle +24 -22
- package/android/consumer-rules.pro +1 -0
- package/android/src/main/cpp/CMakeLists.txt +6 -2
- package/android/src/main/cpp/GodotModule.cpp +124 -78
- package/android/src/main/cpp/libgodot_android.h +2 -8
- package/android/src/main/cpp/libgodot_jni.cpp +364 -291
- package/android/src/main/cpp/libgodot_jni.h +2 -16
- package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotIO.kt +123 -0
- package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotView.kt +36 -25
- package/android/src/main/java/com/preeternal/reactnativegodot/RTNLibGodot.kt +19 -154
- package/app.plugin.js +4 -8
- package/cpp/AppleRendererPolicy.h +95 -0
- package/cpp/GodotModule.h +24 -1
- package/cpp/LibGodotABI.h +52 -0
- package/cpp/NativeGodotModule.cpp +1 -1
- package/ios/GodotModule.mm +142 -99
- package/ios/RTNGodotView.mm +260 -300
- package/package.json +35 -15
- package/prebuilt-utils.rb +13 -3
- package/react-native-godot.podspec +1 -1
- package/react-native.config.js +1 -0
- package/scripts/check-packaged-artifacts.sh +2 -0
- package/scripts/ci/verify-ios-simulator.py +48 -0
- package/scripts/ci/verify-prebuilt-install.cjs +5 -3
- package/scripts/download-prebuilt.js +41 -32
- package/scripts/prebuilt-config.js +80 -0
- package/scripts/spm-autolinking-plugin.js +87 -0
package/android/build.gradle
CHANGED
|
@@ -93,31 +93,41 @@ def reactNativeRootDir = resolveReactNativeDirectory()
|
|
|
93
93
|
|
|
94
94
|
def prefabHeadersDir = project.file("$buildDir/prefab-headers/rtngodot")
|
|
95
95
|
|
|
96
|
-
def
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
def selectionProcess = [
|
|
97
|
+
"node", file("$projectDir/../scripts/prebuilt-config.js").absolutePath,
|
|
98
|
+
"--app-root", rootProject.projectDir.absolutePath,
|
|
99
|
+
].execute(null, projectDir)
|
|
100
|
+
def selectionOut = new StringBuilder()
|
|
101
|
+
def selectionErr = new StringBuilder()
|
|
102
|
+
selectionProcess.consumeProcessOutput(selectionOut, selectionErr)
|
|
103
|
+
if (selectionProcess.waitFor() != 0) {
|
|
104
|
+
throw new GradleException("[RTNGodot] Unable to select LibGodot: ${selectionErr}")
|
|
105
|
+
}
|
|
106
|
+
def selectedPrebuilts = new JsonSlurper().parseText(selectionOut.toString()).prebuiltFiles
|
|
104
107
|
|
|
105
|
-
|
|
108
|
+
def getPrebuiltLibrary = { libName ->
|
|
109
|
+
def entry = selectedPrebuilts.find { it.name == libName }
|
|
106
110
|
|
|
107
111
|
if (!entry) {
|
|
108
112
|
throw new GradleException("Prebuilt entry not found for library '${libName}'. Ensure it exists in package.json.")
|
|
109
113
|
}
|
|
110
114
|
|
|
111
|
-
return entry
|
|
115
|
+
return entry
|
|
112
116
|
}
|
|
113
117
|
|
|
114
|
-
def
|
|
115
|
-
def
|
|
118
|
+
def libGodotPackage = getPrebuiltLibrary("libgodot-android")
|
|
119
|
+
def libGodotVersion = libGodotPackage.version
|
|
120
|
+
def libGodotMavenVersion = libGodotPackage.maven_version
|
|
121
|
+
def godotCppVersion = getPrebuiltLibrary("libgodot-cpp-android").version
|
|
116
122
|
def libGodotMavenRepo = file("$projectDir/libs/libgodot-android/${libGodotVersion}").canonicalFile
|
|
117
123
|
|
|
124
|
+
if (!libGodotMavenVersion) {
|
|
125
|
+
throw new GradleException("[RTNGodot] Android Maven version is missing from package.json.")
|
|
126
|
+
}
|
|
127
|
+
|
|
118
128
|
if (!libGodotMavenRepo.isDirectory()) {
|
|
119
129
|
throw new GradleException(
|
|
120
|
-
"[RTNGodot]
|
|
130
|
+
"[RTNGodot] LibGodot Maven repository was not found at ${libGodotMavenRepo}. " +
|
|
121
131
|
"Run the package's download-prebuilt command before building Android."
|
|
122
132
|
)
|
|
123
133
|
}
|
|
@@ -136,7 +146,6 @@ rootProject.allprojects { targetProject ->
|
|
|
136
146
|
}
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
|
-
|
|
140
149
|
}
|
|
141
150
|
|
|
142
151
|
buildscript {
|
|
@@ -257,13 +266,6 @@ android {
|
|
|
257
266
|
}
|
|
258
267
|
|
|
259
268
|
repositories {
|
|
260
|
-
maven {
|
|
261
|
-
name = "libgodot"
|
|
262
|
-
url = uri(libGodotMavenRepo)
|
|
263
|
-
content {
|
|
264
|
-
includeGroup("com.migeran.libgodot")
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
269
|
mavenCentral()
|
|
268
270
|
google()
|
|
269
271
|
}
|
|
@@ -271,7 +273,7 @@ repositories {
|
|
|
271
273
|
dependencies {
|
|
272
274
|
implementation 'com.facebook.react:react-native'
|
|
273
275
|
implementation project(':react-native-worklets')
|
|
274
|
-
api "com.migeran.libgodot:godot:${
|
|
276
|
+
api "com.migeran.libgodot:godot:${libGodotMavenVersion}"
|
|
275
277
|
testImplementation 'junit:junit:4.13.2'
|
|
276
278
|
}
|
|
277
279
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# those calls and would otherwise remove or rename the entry points.
|
|
3
3
|
-keep,allowoptimization class com.preeternal.reactnativegodot.NativeGodotModuleModule { *; }
|
|
4
4
|
-keep,allowoptimization class com.preeternal.reactnativegodot.RTNLibGodot { *; }
|
|
5
|
+
-keep,allowoptimization class com.preeternal.reactnativegodot.RTNGodotIO { *; }
|
|
5
6
|
|
|
6
7
|
-keep,allowoptimization class org.godotengine.godot.Dictionary { *; }
|
|
7
8
|
-keep,allowoptimization class org.godotengine.godot.Godot { *; }
|
|
@@ -33,14 +33,18 @@ find_package(react-native-worklets REQUIRED CONFIG)
|
|
|
33
33
|
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../../build/generated/source/codegen/jni" generated)
|
|
34
34
|
set(LIBGODOT_CPP_VERSION ${GODOT_CPP_VERSION})
|
|
35
35
|
set(LIBGODOT_CPP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/libgodot-cpp-android/${LIBGODOT_CPP_VERSION}/godot-cpp-android)
|
|
36
|
+
set(LIBGODOT_CPP_ABI_DIR ${LIBGODOT_CPP_DIR}/${ANDROID_ABI})
|
|
37
|
+
if(NOT EXISTS "${LIBGODOT_CPP_ABI_DIR}/include/godot_cpp/variant/string_name.hpp")
|
|
38
|
+
message(FATAL_ERROR "LibGodot requires generated headers for ${ANDROID_ABI}. Install the selected ABI-specific godot-cpp package.")
|
|
39
|
+
endif()
|
|
36
40
|
|
|
37
41
|
add_library(
|
|
38
42
|
godot-cpp
|
|
39
43
|
STATIC
|
|
40
44
|
IMPORTED
|
|
41
45
|
)
|
|
42
|
-
set_target_properties(godot-cpp PROPERTIES IMPORTED_LOCATION ${
|
|
43
|
-
target_include_directories(godot-cpp INTERFACE ${
|
|
46
|
+
set_target_properties(godot-cpp PROPERTIES IMPORTED_LOCATION ${LIBGODOT_CPP_ABI_DIR}/libgodot-cpp.a)
|
|
47
|
+
target_include_directories(godot-cpp INTERFACE ${LIBGODOT_CPP_ABI_DIR}/include)
|
|
44
48
|
|
|
45
49
|
file(GLOB rtngodot_SRC CONFIGURE_DEPENDS *.cpp)
|
|
46
50
|
file(GLOB rtngodot_cpp_SRC CONFIGURE_DEPENDS ../../../../cpp/*.cpp)
|
|
@@ -46,8 +46,10 @@
|
|
|
46
46
|
#include <queue>
|
|
47
47
|
#include <string>
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
static void logCallBack(RNLibGodotLogCallbackData p_data, const char *p_log_message, bool p_err) {
|
|
50
|
+
GodotModule *module = static_cast<GodotModule *>(p_data);
|
|
51
|
+
module->log(p_log_message, p_err);
|
|
52
|
+
}
|
|
51
53
|
|
|
52
54
|
const static char CMD_FUNCTION = 1;
|
|
53
55
|
const static char CMD_EXIT = 2;
|
|
@@ -113,8 +115,12 @@ public:
|
|
|
113
115
|
return 1;
|
|
114
116
|
}
|
|
115
117
|
|
|
118
|
+
bool is_current() const {
|
|
119
|
+
return thread.get_id() == std::this_thread::get_id();
|
|
120
|
+
}
|
|
121
|
+
|
|
116
122
|
void enqueue(std::function<void()> f) {
|
|
117
|
-
if (
|
|
123
|
+
if (is_current()) {
|
|
118
124
|
f();
|
|
119
125
|
return;
|
|
120
126
|
}
|
|
@@ -190,8 +196,8 @@ struct AndroidPlatformData : PlatformData {
|
|
|
190
196
|
godot::Ref<godot::RenderingNativeSurface> mainSurface;
|
|
191
197
|
|
|
192
198
|
void *handle = nullptr;
|
|
193
|
-
|
|
194
|
-
|
|
199
|
+
RNLibGodotCreateAndroidFunction func_libgodot_create_godot_instance_android = nullptr;
|
|
200
|
+
RNLibGodotDestroyFunction func_libgodot_destroy_godot_instance = nullptr;
|
|
195
201
|
double contentScaleFactor = 1.0;
|
|
196
202
|
std::map<std::string, WindowFuncData> windowUpdateCallbacks;
|
|
197
203
|
std::map<void *, std::string> handleToWindowName;
|
|
@@ -200,6 +206,7 @@ struct AndroidPlatformData : PlatformData {
|
|
|
200
206
|
bool paused = false;
|
|
201
207
|
// Guarded by GodotModule::_mutex; kept pending across pause/resume until consumed.
|
|
202
208
|
bool frameCallbackPending = false;
|
|
209
|
+
uint64_t frameCallbackGeneration = 0;
|
|
203
210
|
AndroidThread thread;
|
|
204
211
|
std::mutex windowUpdateMutex;
|
|
205
212
|
std::mutex createMutex;
|
|
@@ -237,6 +244,11 @@ GDExtensionBool GDE_EXPORT gdextension_default_init(GDExtensionInterfaceGetProcA
|
|
|
237
244
|
|
|
238
245
|
using PostFrameCallback64 = void (*)(AChoreographer *, AChoreographer_frameCallback64, void *);
|
|
239
246
|
|
|
247
|
+
struct FrameCallbackData {
|
|
248
|
+
GodotModule *module;
|
|
249
|
+
uint64_t generation;
|
|
250
|
+
};
|
|
251
|
+
|
|
240
252
|
static void handleFrameCallback(void *data);
|
|
241
253
|
|
|
242
254
|
static void frameCallback(long, void *data) {
|
|
@@ -262,11 +274,23 @@ static void postFrameCallback(AChoreographer *choreographer, void *data) {
|
|
|
262
274
|
}
|
|
263
275
|
|
|
264
276
|
static void handleFrameCallback(void *data) {
|
|
265
|
-
|
|
266
|
-
self->
|
|
277
|
+
FrameCallbackData *callback = static_cast<FrameCallbackData *>(data);
|
|
278
|
+
GodotModule *self = callback->module;
|
|
279
|
+
const uint64_t generation = callback->generation;
|
|
280
|
+
delete callback;
|
|
281
|
+
self->iterate(generation);
|
|
267
282
|
}
|
|
268
283
|
|
|
269
284
|
godot::GodotInstance *GodotModule::get_or_create_instance(std::vector<std::string> args) {
|
|
285
|
+
godot::GodotInstance *result = nullptr;
|
|
286
|
+
runOnGodotThread([this, &args, &result]() {
|
|
287
|
+
result = get_or_create_instance_on_godot_thread(std::move(args));
|
|
288
|
+
},
|
|
289
|
+
true);
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
godot::GodotInstance *GodotModule::get_or_create_instance_on_godot_thread(std::vector<std::string> args) {
|
|
270
294
|
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
271
295
|
|
|
272
296
|
// Make sure that we only run this method once at a time.
|
|
@@ -280,31 +304,25 @@ godot::GodotInstance *GodotModule::get_or_create_instance(std::vector<std::strin
|
|
|
280
304
|
}
|
|
281
305
|
|
|
282
306
|
void *handle = nullptr;
|
|
283
|
-
|
|
284
|
-
|
|
307
|
+
RNLibGodotCreateAndroidFunction create = nullptr;
|
|
308
|
+
RNLibGodotDestroyFunction destroy = nullptr;
|
|
285
309
|
#ifndef LIBGODOT_STATIC
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
return nullptr;
|
|
299
|
-
}
|
|
310
|
+
handle = dlopen("libgodot_android.so", RTLD_LAZY | RTLD_LOCAL);
|
|
311
|
+
if (!handle) {
|
|
312
|
+
LOGE("Unable to open libgodot_android.so: %s", dlerror());
|
|
313
|
+
return nullptr;
|
|
314
|
+
}
|
|
315
|
+
create = reinterpret_cast<RNLibGodotCreateAndroidFunction>(dlsym(handle, "libgodot_create_godot_instance_android"));
|
|
316
|
+
destroy = reinterpret_cast<RNLibGodotDestroyFunction>(dlsym(handle, "libgodot_destroy_godot_instance"));
|
|
317
|
+
if (!create || !destroy) {
|
|
318
|
+
LOGE("LibGodot requires both create and destroy symbols");
|
|
319
|
+
dlclose(handle);
|
|
320
|
+
return nullptr;
|
|
321
|
+
}
|
|
300
322
|
#else
|
|
301
|
-
|
|
323
|
+
create = libgodot_create_godot_instance_android;
|
|
324
|
+
destroy = libgodot_destroy_godot_instance;
|
|
302
325
|
#endif
|
|
303
|
-
{
|
|
304
|
-
std::lock_guard lock(_mutex);
|
|
305
|
-
data->func_libgodot_create_godot_instance_android = func_libgodot_create_godot_instance_android;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
326
|
|
|
309
327
|
std::vector<std::string> cmdline{ "apk" };
|
|
310
328
|
for (std::string arg : args) {
|
|
@@ -319,40 +337,53 @@ godot::GodotInstance *GodotModule::get_or_create_instance(std::vector<std::strin
|
|
|
319
337
|
GDExtensionObjectPtr instance_ptr = nullptr;
|
|
320
338
|
{
|
|
321
339
|
std::lock_guard lock(_mutex);
|
|
322
|
-
instance_ptr =
|
|
323
|
-
cargs.size(),
|
|
340
|
+
instance_ptr = create(
|
|
341
|
+
static_cast<int>(cargs.size()),
|
|
324
342
|
(char **)cargs.data(),
|
|
325
343
|
gdextension_default_init,
|
|
344
|
+
logCallBack,
|
|
345
|
+
this,
|
|
326
346
|
LibGodot::get_jni_env(),
|
|
327
347
|
LibGodot::get_asset_manager(),
|
|
328
348
|
LibGodot::get_net_utils(),
|
|
329
349
|
LibGodot::get_dir_access_handler(),
|
|
330
350
|
LibGodot::get_file_access_handler(),
|
|
331
|
-
LibGodot::get_godot_io()
|
|
332
|
-
LibGodot::get_godot_engine(),
|
|
333
|
-
LibGodot::get_class_loader());
|
|
351
|
+
LibGodot::get_godot_io());
|
|
334
352
|
}
|
|
335
353
|
|
|
336
|
-
if
|
|
337
|
-
|
|
338
|
-
|
|
354
|
+
// Raw teardown must work even if godot-cpp cannot bind the returned object.
|
|
355
|
+
// Call only after releasing every local Godot Ref/Variant/Callable.
|
|
356
|
+
auto cleanupFailedCreate = [&]() {
|
|
357
|
+
if (instance_ptr) {
|
|
358
|
+
destroy(instance_ptr);
|
|
359
|
+
}
|
|
360
|
+
godot::GDExtensionBinding::deinit();
|
|
339
361
|
if (handle) {
|
|
340
362
|
dlclose(handle);
|
|
341
|
-
handle = nullptr;
|
|
342
|
-
{
|
|
343
|
-
std::lock_guard lock(_mutex);
|
|
344
|
-
data->func_libgodot_create_godot_instance_android = nullptr;
|
|
345
|
-
}
|
|
346
363
|
}
|
|
364
|
+
};
|
|
365
|
+
if (!instance_ptr) {
|
|
366
|
+
LOGE("Unable to create GodotInstance");
|
|
367
|
+
cleanupFailedCreate();
|
|
347
368
|
return nullptr;
|
|
348
369
|
}
|
|
349
370
|
|
|
350
371
|
godot::GodotInstance *instance = reinterpret_cast<godot::GodotInstance *>(godot::internal::get_object_instance_binding(instance_ptr));
|
|
372
|
+
if (!instance) {
|
|
373
|
+
LOGE("Unable to bind GodotInstance returned by LibGodot");
|
|
374
|
+
cleanupFailedCreate();
|
|
375
|
+
return nullptr;
|
|
376
|
+
}
|
|
351
377
|
|
|
352
378
|
// Initialize Android Surface
|
|
353
379
|
ANativeWindow *mainNativeWindow = LibGodot::get_main_surface();
|
|
354
380
|
uint32_t width = LibGodot::get_main_width();
|
|
355
381
|
uint32_t height = LibGodot::get_main_height();
|
|
382
|
+
if (mainNativeWindow == nullptr || width == 0 || height == 0) {
|
|
383
|
+
LOGE("Main Android surface is unavailable");
|
|
384
|
+
cleanupFailedCreate();
|
|
385
|
+
return nullptr;
|
|
386
|
+
}
|
|
356
387
|
|
|
357
388
|
// TODO: Set main window surface size and position
|
|
358
389
|
// TODO: Get content scale factor from Android
|
|
@@ -361,13 +392,24 @@ godot::GodotInstance *GodotModule::get_or_create_instance(std::vector<std::strin
|
|
|
361
392
|
// TODO: Set content scale factor in the surface
|
|
362
393
|
|
|
363
394
|
godot::Ref<godot::RenderingNativeSurfaceAndroid> androidSurface = godot::RenderingNativeSurfaceAndroid::create((uint64_t)mainNativeWindow, width, height);
|
|
364
|
-
|
|
395
|
+
if (androidSurface.is_null()) {
|
|
396
|
+
LOGE("Unable to create the main Android rendering surface");
|
|
397
|
+
cleanupFailedCreate();
|
|
398
|
+
return nullptr;
|
|
399
|
+
}
|
|
365
400
|
godot::RenderingNativeSurface *ptr = godot::Object::cast_to<godot::RenderingNativeSurface>(androidSurface.ptr());
|
|
366
401
|
godot::Ref<godot::RenderingNativeSurface> nativeSurface(ptr);
|
|
367
402
|
|
|
368
403
|
godot::DisplayServerEmbedded::set_native_surface(nativeSurface);
|
|
369
404
|
|
|
370
|
-
instance->start()
|
|
405
|
+
if (!instance->start()) {
|
|
406
|
+
LOGE("Unable to start GodotInstance");
|
|
407
|
+
godot::DisplayServerEmbedded::set_native_surface(godot::Ref<godot::RenderingNativeSurface>());
|
|
408
|
+
nativeSurface.unref();
|
|
409
|
+
androidSurface.unref();
|
|
410
|
+
cleanupFailedCreate();
|
|
411
|
+
return nullptr;
|
|
412
|
+
}
|
|
371
413
|
bool inBackground;
|
|
372
414
|
|
|
373
415
|
{
|
|
@@ -377,8 +419,11 @@ godot::GodotInstance *GodotModule::get_or_create_instance(std::vector<std::strin
|
|
|
377
419
|
data->mainSurface = nativeSurface;
|
|
378
420
|
data->contentScaleFactor = contentScaleFactor;
|
|
379
421
|
data->handle = handle;
|
|
422
|
+
data->func_libgodot_create_godot_instance_android = create;
|
|
423
|
+
data->func_libgodot_destroy_godot_instance = destroy;
|
|
380
424
|
|
|
381
425
|
_instance = instance;
|
|
426
|
+
_instanceGeneration.store(++_lastInstanceGeneration);
|
|
382
427
|
inBackground = data->in_background;
|
|
383
428
|
}
|
|
384
429
|
|
|
@@ -404,6 +449,13 @@ double GodotModule::get_content_scale_factor() {
|
|
|
404
449
|
}
|
|
405
450
|
|
|
406
451
|
void GodotModule::destroy_instance() {
|
|
452
|
+
runOnGodotThread([this]() {
|
|
453
|
+
destroy_instance_on_godot_thread();
|
|
454
|
+
},
|
|
455
|
+
true);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
void GodotModule::destroy_instance_on_godot_thread() {
|
|
407
459
|
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
408
460
|
|
|
409
461
|
// Make sure that we only run this method once at a time.
|
|
@@ -415,50 +467,35 @@ void GodotModule::destroy_instance() {
|
|
|
415
467
|
}
|
|
416
468
|
|
|
417
469
|
if (!data->func_libgodot_destroy_godot_instance) {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
void *handle = nullptr;
|
|
421
|
-
|
|
422
|
-
{
|
|
423
|
-
std::lock_guard lock(_mutex);
|
|
424
|
-
handle = data->handle;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
if (handle == nullptr) {
|
|
428
|
-
LOGI("Unable to open libgodot_android.so: %s", dlerror());
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
func_libgodot_destroy_godot_instance = (libgodot_destroy_godot_instance_type)dlsym(handle, "libgodot_destroy_godot_instance");
|
|
432
|
-
|
|
433
|
-
if (func_libgodot_destroy_godot_instance == nullptr) {
|
|
434
|
-
LOGE("Unable to load libgodot_destroy_godot_instance symbol: %s", dlerror());
|
|
435
|
-
dlclose(handle);
|
|
436
|
-
handle = nullptr;
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
#else
|
|
440
|
-
func_libgodot_destroy_godot_instance = libgodot_destroy_godot_instance;
|
|
441
|
-
#endif
|
|
442
|
-
{
|
|
443
|
-
std::lock_guard lock(_mutex);
|
|
444
|
-
data->func_libgodot_destroy_godot_instance = func_libgodot_destroy_godot_instance;
|
|
445
|
-
}
|
|
470
|
+
LOGE("Missing destroy function for the active Godot instance");
|
|
471
|
+
return;
|
|
446
472
|
}
|
|
447
473
|
|
|
448
474
|
{
|
|
449
475
|
std::lock_guard lock(_mutex);
|
|
450
476
|
|
|
451
477
|
godot::DisplayServerEmbedded::set_native_surface(godot::Ref<godot::RenderingNativeSurface>(nullptr));
|
|
452
|
-
|
|
478
|
+
// The window map owns the ANativeWindow reference returned by
|
|
479
|
+
// ANativeWindow_fromSurface. RenderingNativeSurfaceAndroid keeps only a
|
|
480
|
+
// borrowed pointer, so releasing it here would double-release the map's
|
|
481
|
+
// reference during cleanup.
|
|
453
482
|
data->mainNativeWindow = nullptr;
|
|
454
483
|
data->mainSurface = godot::Ref<godot::RenderingNativeSurface>(nullptr);
|
|
455
484
|
|
|
485
|
+
_instanceGeneration.store(0);
|
|
486
|
+
LibGodot::clear_input_state();
|
|
456
487
|
data->func_libgodot_destroy_godot_instance(_instance->_owner);
|
|
457
488
|
_instance = nullptr;
|
|
458
489
|
godot::GDExtensionBinding::deinit();
|
|
490
|
+
data->frameCallbackGeneration++;
|
|
491
|
+
data->frameCallbackPending = false;
|
|
459
492
|
|
|
460
|
-
|
|
493
|
+
if (data->handle) {
|
|
494
|
+
dlclose(data->handle);
|
|
495
|
+
}
|
|
461
496
|
data->handle = nullptr;
|
|
497
|
+
data->func_libgodot_create_godot_instance_android = nullptr;
|
|
498
|
+
data->func_libgodot_destroy_godot_instance = nullptr;
|
|
462
499
|
|
|
463
500
|
data->paused = false;
|
|
464
501
|
}
|
|
@@ -571,8 +608,9 @@ void GodotModule::updateState() {
|
|
|
571
608
|
}
|
|
572
609
|
|
|
573
610
|
data->frameCallbackPending = true;
|
|
611
|
+
const uint64_t generation = data->frameCallbackGeneration;
|
|
574
612
|
AChoreographer *choreographer = AChoreographer_getInstance();
|
|
575
|
-
postFrameCallback(choreographer, this);
|
|
613
|
+
postFrameCallback(choreographer, new FrameCallbackData{ this, generation });
|
|
576
614
|
});
|
|
577
615
|
}
|
|
578
616
|
|
|
@@ -679,6 +717,13 @@ void GodotModule::updateWindows(bool adding) {
|
|
|
679
717
|
}
|
|
680
718
|
|
|
681
719
|
void GodotModule::runOnGodotThread(std::function<void()> f, bool wait) {
|
|
720
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
721
|
+
// enqueue executes inline on this thread. Bypass the waiting wrapper
|
|
722
|
+
// before it locks its own mutex.
|
|
723
|
+
if (data->thread.is_current()) {
|
|
724
|
+
f();
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
682
727
|
if (wait) {
|
|
683
728
|
std::mutex waitMutex;
|
|
684
729
|
std::condition_variable waitVar;
|
|
@@ -691,20 +736,21 @@ void GodotModule::runOnGodotThread(std::function<void()> f, bool wait) {
|
|
|
691
736
|
waitVar.notify_one();
|
|
692
737
|
};
|
|
693
738
|
std::unique_lock<std::mutex> lock(waitMutex);
|
|
694
|
-
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
695
739
|
data->thread.enqueue(runFunc);
|
|
696
740
|
waitVar.wait(lock, [&ready] { return ready; });
|
|
697
741
|
} else {
|
|
698
|
-
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
699
742
|
data->thread.enqueue(f);
|
|
700
743
|
}
|
|
701
744
|
}
|
|
702
745
|
|
|
703
|
-
void GodotModule::iterate() {
|
|
746
|
+
void GodotModule::iterate(std::optional<uint64_t> frameGeneration) {
|
|
704
747
|
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
705
748
|
godot::GodotInstance *instance = nullptr;
|
|
706
749
|
{
|
|
707
750
|
std::lock_guard lock(_mutex);
|
|
751
|
+
if (frameGeneration && *frameGeneration != data->frameCallbackGeneration) {
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
708
754
|
data->frameCallbackPending = false;
|
|
709
755
|
if (data->in_background || data->paused) {
|
|
710
756
|
return;
|
|
@@ -37,13 +37,7 @@ extern "C" {
|
|
|
37
37
|
#define LIBGODOT_API __attribute__((visibility("default")))
|
|
38
38
|
#endif // if defined(_MSC_VER)
|
|
39
39
|
|
|
40
|
-
#
|
|
41
|
-
#include "core/extension/gdextension_interface.h"
|
|
42
|
-
#elif __has_include("gdextension_interface.h")
|
|
43
|
-
#include "gdextension_interface.h"
|
|
44
|
-
#else
|
|
45
|
-
#error gdextension_interface.h is required
|
|
46
|
-
#endif
|
|
40
|
+
#include "../../../../cpp/LibGodotABI.h"
|
|
47
41
|
|
|
48
42
|
#include <jni.h>
|
|
49
43
|
|
|
@@ -59,7 +53,7 @@ extern "C" {
|
|
|
59
53
|
*
|
|
60
54
|
* @return A pointer to created \ref GodotInstance GDExtension object or nullptr if there was an error.
|
|
61
55
|
*/
|
|
62
|
-
LIBGODOT_API GDExtensionObjectPtr libgodot_create_godot_instance_android(int p_argc, char *p_argv[], GDExtensionInitializationFunction p_init_func, JNIEnv *env, jobject p_asset_manager, jobject p_net_utils, jobject p_directory_access_handler, jobject p_file_access_handler, jobject p_godot_io_wrapper
|
|
56
|
+
LIBGODOT_API GDExtensionObjectPtr libgodot_create_godot_instance_android(int p_argc, char *p_argv[], GDExtensionInitializationFunction p_init_func, RNLibGodotLogCallbackFunction p_log_func, RNLibGodotLogCallbackData p_log_data, JNIEnv *env, jobject p_asset_manager, jobject p_net_utils, jobject p_directory_access_handler, jobject p_file_access_handler, jobject p_godot_io_wrapper);
|
|
63
57
|
|
|
64
58
|
/**
|
|
65
59
|
* @name libgodot_destroy_godot_instance
|