@preeternal/react-native-godot 0.0.0-stage → 0.2.0
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/LICENSE +22 -0
- package/Package.swift +106 -0
- package/README.md +590 -2
- package/android/build.gradle +291 -0
- package/android/consumer-rules.pro +20 -0
- package/android/fix-prefab.gradle +54 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/CMakeLists.txt +78 -0
- package/android/src/main/cpp/GodotModule.cpp +764 -0
- package/android/src/main/cpp/OnLoad.cpp +66 -0
- package/android/src/main/cpp/libgodot_android.h +73 -0
- package/android/src/main/cpp/libgodot_jni.cpp +658 -0
- package/android/src/main/cpp/libgodot_jni.h +116 -0
- package/android/src/main/cpp/native_godot_module_jni.cpp +86 -0
- package/android/src/main/cpp/native_godot_module_jni.h +58 -0
- package/android/src/main/java/com/preeternal/reactnativegodot/NativeGodotModuleModule.kt +83 -0
- package/android/src/main/java/com/preeternal/reactnativegodot/NativeGodotModulePackage.kt +41 -0
- package/android/src/main/java/com/preeternal/reactnativegodot/NativeLibraryLoader.kt +5 -0
- package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotIO.kt +123 -0
- package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotView.kt +92 -0
- package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotViewManager.kt +34 -0
- package/android/src/main/java/com/preeternal/reactnativegodot/RTNLibGodot.kt +215 -0
- package/android/src/main/res/layout/downloading_expansion.xml +165 -0
- package/android/src/main/res/layout/godot_app_layout.xml +5 -0
- package/android/src/main/res/layout/snackbar.xml +27 -0
- package/android/src/main/res/layout/status_bar_ongoing_event_progress_bar.xml +108 -0
- package/android/src/main/res/mipmap/icon.png +0 -0
- package/android/src/main/res/mipmap/icon_background.png +0 -0
- package/android/src/main/res/mipmap/icon_foreground.png +0 -0
- package/android/src/main/res/mipmap/icon_monochrome.png +0 -0
- package/android/src/main/res/mipmap-anydpi-v26/icon.xml +8 -0
- package/android/src/main/res/mipmap-anydpi-v26/themed_icon.xml +11 -0
- package/android/src/main/res/mipmap-hdpi/icon.png +0 -0
- package/android/src/main/res/mipmap-hdpi/icon_background.png +0 -0
- package/android/src/main/res/mipmap-hdpi/icon_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/icon_monochrome.png +0 -0
- package/android/src/main/res/mipmap-mdpi/icon.png +0 -0
- package/android/src/main/res/mipmap-mdpi/icon_background.png +0 -0
- package/android/src/main/res/mipmap-mdpi/icon_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/icon_monochrome.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/icon.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/icon_background.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/icon_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/icon_monochrome.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/icon.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/icon_background.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/icon_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/icon_monochrome.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/icon.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/icon_background.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/icon_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/icon_monochrome.png +0 -0
- package/android/src/main/res/values/dimens.xml +9 -0
- package/android/src/main/res/values/strings.xml +61 -0
- package/android/src/main/res/values/styles.xml +25 -0
- package/android/src/main/res/values-fa/strings.xml +14 -0
- package/android/src/main/res/values-ko/strings.xml +54 -0
- package/android/src/main/res/xml/godot_provider_paths.xml +15 -0
- package/android/src/test/java/com/preeternal/reactnativegodot/NativeGodotModulePackageTest.kt +26 -0
- package/app.plugin.js +169 -0
- package/cpp/AppleRendererPolicy.h +95 -0
- package/cpp/GodotModule.h +126 -0
- package/cpp/LibGodotABI.h +52 -0
- package/cpp/NativeGodotModule.cpp +825 -0
- package/cpp/NativeGodotModule.h +45 -0
- package/cpp/godot-log.h +64 -0
- package/ios/GodotModule.mm +695 -0
- package/ios/NativeGodotModuleProvider.h +35 -0
- package/ios/NativeGodotModuleProvider.mm +42 -0
- package/ios/RTNGodotView.h +42 -0
- package/ios/RTNGodotView.mm +671 -0
- package/ios/log.mm +38 -0
- package/lib/module/NativeNativeGodotModule.js +59 -0
- package/lib/module/NativeNativeGodotModule.js.map +1 -0
- package/lib/module/RTNGodotView.js +6 -0
- package/lib/module/RTNGodotView.js.map +1 -0
- package/lib/module/RTNGodotView.native.js +5 -0
- package/lib/module/RTNGodotView.native.js.map +1 -0
- package/lib/module/RTNGodotViewNativeComponent.ts +37 -0
- package/lib/module/index.js +30 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeNativeGodotModule.d.ts +26 -0
- package/lib/typescript/src/NativeNativeGodotModule.d.ts.map +1 -0
- package/lib/typescript/src/RTNGodotView.d.ts +7 -0
- package/lib/typescript/src/RTNGodotView.d.ts.map +1 -0
- package/lib/typescript/src/RTNGodotView.native.d.ts +3 -0
- package/lib/typescript/src/RTNGodotView.native.d.ts.map +1 -0
- package/lib/typescript/src/RTNGodotViewNativeComponent.d.ts +11 -0
- package/lib/typescript/src/RTNGodotViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +282 -4
- package/prebuilt-utils.rb +46 -0
- package/react-native-godot.podspec +41 -0
- package/react-native.config.js +16 -0
- package/scripts/check-16kb.sh +136 -0
- package/scripts/check-packaged-artifacts.sh +156 -0
- package/scripts/ci/verify-ios-simulator.py +48 -0
- package/scripts/ci/verify-prebuilt-install.cjs +41 -0
- package/scripts/download-prebuilt.js +283 -0
- package/scripts/prebuilt-config.js +80 -0
- package/scripts/spm-autolinking-plugin.js +87 -0
- package/src/NativeNativeGodotModule.ts +90 -0
- package/src/RTNGodotView.native.tsx +2 -0
- package/src/RTNGodotView.tsx +12 -0
- package/src/RTNGodotViewNativeComponent.ts +37 -0
- package/src/index.tsx +28 -0
|
@@ -0,0 +1,764 @@
|
|
|
1
|
+
/**************************************************************************/
|
|
2
|
+
/* GodotModule.cpp */
|
|
3
|
+
/**************************************************************************/
|
|
4
|
+
/* Copyright (c) 2024-2025 Slay GmbH */
|
|
5
|
+
/* */
|
|
6
|
+
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
7
|
+
/* a copy of this software and associated documentation files (the */
|
|
8
|
+
/* "Software"), to deal in the Software without restriction, including */
|
|
9
|
+
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
10
|
+
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
11
|
+
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
12
|
+
/* the following conditions: */
|
|
13
|
+
/* */
|
|
14
|
+
/* The above copyright notice and this permission notice shall be */
|
|
15
|
+
/* included in all copies or substantial portions of the Software. */
|
|
16
|
+
/* */
|
|
17
|
+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
18
|
+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
19
|
+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
20
|
+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
21
|
+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
22
|
+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
23
|
+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
24
|
+
/**************************************************************************/
|
|
25
|
+
|
|
26
|
+
#include "GodotModule.h"
|
|
27
|
+
#define LOG_TAG "GodotModule"
|
|
28
|
+
#include "godot-log.h"
|
|
29
|
+
|
|
30
|
+
#include "libgodot_android.h"
|
|
31
|
+
#include "libgodot_jni.h"
|
|
32
|
+
#include <godot_cpp/classes/display_server_embedded.hpp>
|
|
33
|
+
#include <godot_cpp/classes/gd_extension_manager.hpp>
|
|
34
|
+
#include <godot_cpp/classes/rendering_native_surface.hpp>
|
|
35
|
+
#include <godot_cpp/classes/rendering_native_surface_android.hpp>
|
|
36
|
+
#include <godot_cpp/godot.hpp>
|
|
37
|
+
|
|
38
|
+
#include <android/choreographer.h>
|
|
39
|
+
#include <android/looper.h>
|
|
40
|
+
#include <android/native_window.h>
|
|
41
|
+
#include <android/native_window_jni.h>
|
|
42
|
+
#include <dlfcn.h>
|
|
43
|
+
|
|
44
|
+
#include <unistd.h>
|
|
45
|
+
#include <map>
|
|
46
|
+
#include <queue>
|
|
47
|
+
#include <string>
|
|
48
|
+
|
|
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
|
+
}
|
|
53
|
+
|
|
54
|
+
const static char CMD_FUNCTION = 1;
|
|
55
|
+
const static char CMD_EXIT = 2;
|
|
56
|
+
|
|
57
|
+
class AndroidThread {
|
|
58
|
+
std::mutex mutex;
|
|
59
|
+
std::condition_variable started;
|
|
60
|
+
std::queue<std::function<void()>> tasks;
|
|
61
|
+
ALooper *looper = nullptr;
|
|
62
|
+
int function_queue_fd = -1;
|
|
63
|
+
bool quit = false;
|
|
64
|
+
// Keep the worker last so run() cannot access fields before their initialization.
|
|
65
|
+
std::thread thread;
|
|
66
|
+
|
|
67
|
+
public:
|
|
68
|
+
AndroidThread() :
|
|
69
|
+
thread(&AndroidThread::run, this) {
|
|
70
|
+
std::unique_lock<std::mutex> lock(mutex);
|
|
71
|
+
started.wait(lock, [this]() {
|
|
72
|
+
return function_queue_fd >= 0;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static int looper_callback(int fd, int events, void *data) {
|
|
77
|
+
char cmd;
|
|
78
|
+
AndroidThread *self = (AndroidThread *)data;
|
|
79
|
+
ssize_t res = read(fd, &cmd, sizeof(cmd));
|
|
80
|
+
if (res < 0) {
|
|
81
|
+
LOGE("Unable to read looper event from pipe: %d", errno);
|
|
82
|
+
return 1;
|
|
83
|
+
}
|
|
84
|
+
if (res == 0) {
|
|
85
|
+
LOGE("End of file event should not happen.");
|
|
86
|
+
return 1;
|
|
87
|
+
}
|
|
88
|
+
if (res != sizeof(cmd)) {
|
|
89
|
+
LOGE("Unable to read command fully from pipe");
|
|
90
|
+
return 1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
switch (cmd) {
|
|
94
|
+
case CMD_FUNCTION: {
|
|
95
|
+
std::function<void()> task;
|
|
96
|
+
{
|
|
97
|
+
std::lock_guard<std::mutex> lock(self->mutex);
|
|
98
|
+
if (self->tasks.empty()) {
|
|
99
|
+
LOGW("Empty queue when processing CMD_FUNCTION");
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
task = std::move(self->tasks.front());
|
|
103
|
+
self->tasks.pop();
|
|
104
|
+
}
|
|
105
|
+
task();
|
|
106
|
+
} break;
|
|
107
|
+
case CMD_EXIT: {
|
|
108
|
+
self->quit = true;
|
|
109
|
+
} break;
|
|
110
|
+
default: {
|
|
111
|
+
LOGE("Unknown command: %d", cmd);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return 1;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
bool is_current() const {
|
|
119
|
+
return thread.get_id() == std::this_thread::get_id();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
void enqueue(std::function<void()> f) {
|
|
123
|
+
if (is_current()) {
|
|
124
|
+
f();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
{
|
|
128
|
+
std::lock_guard<std::mutex> lock(mutex);
|
|
129
|
+
tasks.emplace(f);
|
|
130
|
+
}
|
|
131
|
+
ssize_t res = write(function_queue_fd, &CMD_FUNCTION, sizeof(CMD_FUNCTION));
|
|
132
|
+
if (res < 0) {
|
|
133
|
+
LOGE("Unable to write to pipe: %d", errno);
|
|
134
|
+
}
|
|
135
|
+
if (res != sizeof(CMD_FUNCTION)) {
|
|
136
|
+
LOGE("Unable to write command fully to pipe");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
void run() {
|
|
141
|
+
LOGI("AndroidThread Looper thread started.");
|
|
142
|
+
LibGodot::get_jni_env(); // Force attaching to Java VM
|
|
143
|
+
{
|
|
144
|
+
std::lock_guard<std::mutex> lock(mutex);
|
|
145
|
+
|
|
146
|
+
// Prepare Looper
|
|
147
|
+
looper = ALooper_prepare(0);
|
|
148
|
+
|
|
149
|
+
// Register callback for function
|
|
150
|
+
int fds[2];
|
|
151
|
+
int res = pipe(fds);
|
|
152
|
+
if (res < 0) {
|
|
153
|
+
LOGE("Unable to create pipe for ALooper: %d", errno);
|
|
154
|
+
return; // TODO: Abort app
|
|
155
|
+
}
|
|
156
|
+
ALooper_addFd(looper, fds[0], ALOOPER_POLL_CALLBACK, ALOOPER_EVENT_INPUT, AndroidThread::looper_callback, this);
|
|
157
|
+
function_queue_fd = fds[1];
|
|
158
|
+
started.notify_all();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
while (!quit) {
|
|
162
|
+
int outFd;
|
|
163
|
+
int outEvents;
|
|
164
|
+
void *outData;
|
|
165
|
+
int res = ALooper_pollOnce(10, &outFd, &outEvents, &outData);
|
|
166
|
+
if (res == ALOOPER_POLL_ERROR) {
|
|
167
|
+
LOGE("ALooper_pollOnce internal error.");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
ALooper_release(looper);
|
|
172
|
+
LOGI("AndroidThread Looper thread exited.");
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
typedef struct FuncData {
|
|
177
|
+
std::function<void()> func;
|
|
178
|
+
jobject ref;
|
|
179
|
+
FuncData() :
|
|
180
|
+
func(nullptr), ref(nullptr) {}
|
|
181
|
+
FuncData(std::function<void()> p_func, jobject p_ref) :
|
|
182
|
+
func(p_func), ref(p_ref) {}
|
|
183
|
+
} FuncData;
|
|
184
|
+
|
|
185
|
+
typedef struct WindowFuncData {
|
|
186
|
+
std::function<void(bool)> func;
|
|
187
|
+
jobject ref;
|
|
188
|
+
WindowFuncData() :
|
|
189
|
+
func(nullptr), ref(nullptr) {}
|
|
190
|
+
WindowFuncData(std::function<void(bool)> p_func, jobject p_ref) :
|
|
191
|
+
func(p_func), ref(p_ref) {}
|
|
192
|
+
} WindowFuncData;
|
|
193
|
+
|
|
194
|
+
struct AndroidPlatformData : PlatformData {
|
|
195
|
+
ANativeWindow *mainNativeWindow = nullptr;
|
|
196
|
+
godot::Ref<godot::RenderingNativeSurface> mainSurface;
|
|
197
|
+
|
|
198
|
+
void *handle = nullptr;
|
|
199
|
+
RNLibGodotCreateAndroidFunction func_libgodot_create_godot_instance_android = nullptr;
|
|
200
|
+
RNLibGodotDestroyFunction func_libgodot_destroy_godot_instance = nullptr;
|
|
201
|
+
double contentScaleFactor = 1.0;
|
|
202
|
+
std::map<std::string, WindowFuncData> windowUpdateCallbacks;
|
|
203
|
+
std::map<void *, std::string> handleToWindowName;
|
|
204
|
+
// No frames until React Native reports an active host. This does not start Godot.
|
|
205
|
+
bool in_background = true;
|
|
206
|
+
bool paused = false;
|
|
207
|
+
// Guarded by GodotModule::_mutex; kept pending across pause/resume until consumed.
|
|
208
|
+
bool frameCallbackPending = false;
|
|
209
|
+
uint64_t frameCallbackGeneration = 0;
|
|
210
|
+
AndroidThread thread;
|
|
211
|
+
std::mutex windowUpdateMutex;
|
|
212
|
+
std::mutex createMutex;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
GodotModule *GodotModule::get_singleton() {
|
|
216
|
+
static GodotModule *singleton = new GodotModule(new AndroidPlatformData());
|
|
217
|
+
return singleton;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
extern "C" {
|
|
221
|
+
|
|
222
|
+
static void initialize_default_module(godot::ModuleInitializationLevel p_level) {
|
|
223
|
+
if (p_level != godot::MODULE_INITIALIZATION_LEVEL_SCENE) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
static void uninitialize_default_module(godot::ModuleInitializationLevel p_level) {
|
|
229
|
+
if (p_level != godot::MODULE_INITIALIZATION_LEVEL_SCENE) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
GDExtensionBool GDE_EXPORT gdextension_default_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
|
|
235
|
+
godot::GDExtensionBinding::InitObject init_object(p_get_proc_address, p_library, r_initialization);
|
|
236
|
+
|
|
237
|
+
init_object.register_initializer(initialize_default_module);
|
|
238
|
+
init_object.register_terminator(uninitialize_default_module);
|
|
239
|
+
init_object.set_minimum_library_initialization_level(godot::MODULE_INITIALIZATION_LEVEL_SCENE);
|
|
240
|
+
|
|
241
|
+
return init_object.init();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
using PostFrameCallback64 = void (*)(AChoreographer *, AChoreographer_frameCallback64, void *);
|
|
246
|
+
|
|
247
|
+
struct FrameCallbackData {
|
|
248
|
+
GodotModule *module;
|
|
249
|
+
uint64_t generation;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
static void handleFrameCallback(void *data);
|
|
253
|
+
|
|
254
|
+
static void frameCallback(long, void *data) {
|
|
255
|
+
handleFrameCallback(data);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
static void frameCallback64(int64_t, void *data) {
|
|
259
|
+
handleFrameCallback(data);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
static void postFrameCallback(AChoreographer *choreographer, void *data) {
|
|
263
|
+
static auto postFrameCallback64 = reinterpret_cast<PostFrameCallback64>(
|
|
264
|
+
dlsym(RTLD_DEFAULT, "AChoreographer_postFrameCallback64"));
|
|
265
|
+
if (postFrameCallback64 != nullptr) {
|
|
266
|
+
postFrameCallback64(choreographer, frameCallback64, data);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
#pragma clang diagnostic push
|
|
271
|
+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
272
|
+
AChoreographer_postFrameCallback(choreographer, frameCallback, data);
|
|
273
|
+
#pragma clang diagnostic pop
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
static void handleFrameCallback(void *data) {
|
|
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);
|
|
282
|
+
}
|
|
283
|
+
|
|
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) {
|
|
294
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
295
|
+
|
|
296
|
+
// Make sure that we only run this method once at a time.
|
|
297
|
+
std::lock_guard createLock(data->createMutex);
|
|
298
|
+
|
|
299
|
+
{
|
|
300
|
+
std::lock_guard lock(_mutex);
|
|
301
|
+
if (_instance) {
|
|
302
|
+
return _instance;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
void *handle = nullptr;
|
|
307
|
+
RNLibGodotCreateAndroidFunction create = nullptr;
|
|
308
|
+
RNLibGodotDestroyFunction destroy = nullptr;
|
|
309
|
+
#ifndef LIBGODOT_STATIC
|
|
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
|
+
}
|
|
322
|
+
#else
|
|
323
|
+
create = libgodot_create_godot_instance_android;
|
|
324
|
+
destroy = libgodot_destroy_godot_instance;
|
|
325
|
+
#endif
|
|
326
|
+
|
|
327
|
+
std::vector<std::string> cmdline{ "apk" };
|
|
328
|
+
for (std::string arg : args) {
|
|
329
|
+
cmdline.push_back(arg);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
std::vector<const char *> cargs{};
|
|
333
|
+
for (const std::string &arg : cmdline) {
|
|
334
|
+
cargs.push_back(arg.c_str());
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
GDExtensionObjectPtr instance_ptr = nullptr;
|
|
338
|
+
{
|
|
339
|
+
std::lock_guard lock(_mutex);
|
|
340
|
+
instance_ptr = create(
|
|
341
|
+
static_cast<int>(cargs.size()),
|
|
342
|
+
(char **)cargs.data(),
|
|
343
|
+
gdextension_default_init,
|
|
344
|
+
logCallBack,
|
|
345
|
+
this,
|
|
346
|
+
LibGodot::get_jni_env(),
|
|
347
|
+
LibGodot::get_asset_manager(),
|
|
348
|
+
LibGodot::get_net_utils(),
|
|
349
|
+
LibGodot::get_dir_access_handler(),
|
|
350
|
+
LibGodot::get_file_access_handler(),
|
|
351
|
+
LibGodot::get_godot_io());
|
|
352
|
+
}
|
|
353
|
+
|
|
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();
|
|
361
|
+
if (handle) {
|
|
362
|
+
dlclose(handle);
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
if (!instance_ptr) {
|
|
366
|
+
LOGE("Unable to create GodotInstance");
|
|
367
|
+
cleanupFailedCreate();
|
|
368
|
+
return nullptr;
|
|
369
|
+
}
|
|
370
|
+
|
|
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
|
+
}
|
|
377
|
+
|
|
378
|
+
// Initialize Android Surface
|
|
379
|
+
ANativeWindow *mainNativeWindow = LibGodot::get_main_surface();
|
|
380
|
+
uint32_t width = LibGodot::get_main_width();
|
|
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
|
+
}
|
|
387
|
+
|
|
388
|
+
// TODO: Set main window surface size and position
|
|
389
|
+
// TODO: Get content scale factor from Android
|
|
390
|
+
// data->contentScaleFactor = [[UIScreen mainScreen] scale];
|
|
391
|
+
double contentScaleFactor = 1.0;
|
|
392
|
+
// TODO: Set content scale factor in the surface
|
|
393
|
+
|
|
394
|
+
godot::Ref<godot::RenderingNativeSurfaceAndroid> androidSurface = godot::RenderingNativeSurfaceAndroid::create((uint64_t)mainNativeWindow, width, height);
|
|
395
|
+
if (androidSurface.is_null()) {
|
|
396
|
+
LOGE("Unable to create the main Android rendering surface");
|
|
397
|
+
cleanupFailedCreate();
|
|
398
|
+
return nullptr;
|
|
399
|
+
}
|
|
400
|
+
godot::RenderingNativeSurface *ptr = godot::Object::cast_to<godot::RenderingNativeSurface>(androidSurface.ptr());
|
|
401
|
+
godot::Ref<godot::RenderingNativeSurface> nativeSurface(ptr);
|
|
402
|
+
|
|
403
|
+
godot::DisplayServerEmbedded::set_native_surface(nativeSurface);
|
|
404
|
+
|
|
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
|
+
}
|
|
413
|
+
bool inBackground;
|
|
414
|
+
|
|
415
|
+
{
|
|
416
|
+
std::lock_guard lock(_mutex);
|
|
417
|
+
|
|
418
|
+
data->mainNativeWindow = mainNativeWindow;
|
|
419
|
+
data->mainSurface = nativeSurface;
|
|
420
|
+
data->contentScaleFactor = contentScaleFactor;
|
|
421
|
+
data->handle = handle;
|
|
422
|
+
data->func_libgodot_create_godot_instance_android = create;
|
|
423
|
+
data->func_libgodot_destroy_godot_instance = destroy;
|
|
424
|
+
|
|
425
|
+
_instance = instance;
|
|
426
|
+
_instanceGeneration.store(++_lastInstanceGeneration);
|
|
427
|
+
inBackground = data->in_background;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (inBackground) {
|
|
431
|
+
instance->focus_out();
|
|
432
|
+
instance->pause();
|
|
433
|
+
}
|
|
434
|
+
updateState();
|
|
435
|
+
updateWindows(true);
|
|
436
|
+
|
|
437
|
+
return instance;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
double GodotModule::get_content_scale_factor() {
|
|
441
|
+
std::lock_guard lock(_mutex);
|
|
442
|
+
if (!_instance) {
|
|
443
|
+
return 1.0;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
447
|
+
|
|
448
|
+
return data->contentScaleFactor;
|
|
449
|
+
}
|
|
450
|
+
|
|
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() {
|
|
459
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
460
|
+
|
|
461
|
+
// Make sure that we only run this method once at a time.
|
|
462
|
+
std::lock_guard createLock(data->createMutex);
|
|
463
|
+
|
|
464
|
+
if (!_instance) {
|
|
465
|
+
LOGI("Godot instance is already destroyed.");
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (!data->func_libgodot_destroy_godot_instance) {
|
|
470
|
+
LOGE("Missing destroy function for the active Godot instance");
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
{
|
|
475
|
+
std::lock_guard lock(_mutex);
|
|
476
|
+
|
|
477
|
+
godot::DisplayServerEmbedded::set_native_surface(godot::Ref<godot::RenderingNativeSurface>(nullptr));
|
|
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.
|
|
482
|
+
data->mainNativeWindow = nullptr;
|
|
483
|
+
data->mainSurface = godot::Ref<godot::RenderingNativeSurface>(nullptr);
|
|
484
|
+
|
|
485
|
+
_instanceGeneration.store(0);
|
|
486
|
+
LibGodot::clear_input_state();
|
|
487
|
+
data->func_libgodot_destroy_godot_instance(_instance->_owner);
|
|
488
|
+
_instance = nullptr;
|
|
489
|
+
godot::GDExtensionBinding::deinit();
|
|
490
|
+
data->frameCallbackGeneration++;
|
|
491
|
+
data->frameCallbackPending = false;
|
|
492
|
+
|
|
493
|
+
if (data->handle) {
|
|
494
|
+
dlclose(data->handle);
|
|
495
|
+
}
|
|
496
|
+
data->handle = nullptr;
|
|
497
|
+
data->func_libgodot_create_godot_instance_android = nullptr;
|
|
498
|
+
data->func_libgodot_destroy_godot_instance = nullptr;
|
|
499
|
+
|
|
500
|
+
data->paused = false;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
godot::Ref<godot::RenderingNativeSurface> GodotModule::get_main_rendering_surface() {
|
|
505
|
+
std::lock_guard lock(_mutex);
|
|
506
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
507
|
+
return data->mainSurface;
|
|
508
|
+
}
|
|
509
|
+
void GodotModule::focus_out() {
|
|
510
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
511
|
+
{
|
|
512
|
+
std::lock_guard lock(_mutex);
|
|
513
|
+
data->in_background = true;
|
|
514
|
+
}
|
|
515
|
+
data->thread.enqueue([this]() {
|
|
516
|
+
std::lock_guard lock(_mutex);
|
|
517
|
+
if (_instance) {
|
|
518
|
+
_instance->focus_out();
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
updateState();
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
void GodotModule::focus_in() {
|
|
525
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
526
|
+
{
|
|
527
|
+
std::lock_guard lock(_mutex);
|
|
528
|
+
data->in_background = false;
|
|
529
|
+
}
|
|
530
|
+
data->thread.enqueue([this]() {
|
|
531
|
+
std::lock_guard lock(_mutex);
|
|
532
|
+
if (_instance) {
|
|
533
|
+
_instance->focus_in();
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
updateState();
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
bool GodotModule::is_paused() {
|
|
540
|
+
std::lock_guard lock(_mutex);
|
|
541
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
542
|
+
return data->paused;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
void GodotModule::appPause() {
|
|
546
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
547
|
+
{
|
|
548
|
+
std::lock_guard lock(_mutex);
|
|
549
|
+
if (data->in_background) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
data->in_background = true;
|
|
553
|
+
}
|
|
554
|
+
data->thread.enqueue([this]() {
|
|
555
|
+
godot::GodotInstance *instance = get_instance();
|
|
556
|
+
if (instance) {
|
|
557
|
+
instance->focus_out();
|
|
558
|
+
instance->pause();
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
updateState();
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
void GodotModule::appResume() {
|
|
565
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
566
|
+
{
|
|
567
|
+
std::lock_guard lock(_mutex);
|
|
568
|
+
if (!data->in_background) {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
data->in_background = false;
|
|
572
|
+
}
|
|
573
|
+
data->thread.enqueue([this]() {
|
|
574
|
+
godot::GodotInstance *instance = get_instance();
|
|
575
|
+
if (instance) {
|
|
576
|
+
instance->resume();
|
|
577
|
+
instance->focus_in();
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
updateState();
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
void GodotModule::pause() {
|
|
584
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
585
|
+
{
|
|
586
|
+
std::lock_guard lock(_mutex);
|
|
587
|
+
data->paused = true;
|
|
588
|
+
}
|
|
589
|
+
updateState();
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
void GodotModule::resume() {
|
|
593
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
594
|
+
{
|
|
595
|
+
std::lock_guard lock(_mutex);
|
|
596
|
+
data->paused = false;
|
|
597
|
+
}
|
|
598
|
+
updateState();
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
void GodotModule::updateState() {
|
|
602
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
603
|
+
data->thread.enqueue([this, data]() {
|
|
604
|
+
std::lock_guard lock(_mutex);
|
|
605
|
+
if (!_instance || !_instance->is_started() || data->in_background ||
|
|
606
|
+
data->paused || data->frameCallbackPending) {
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
data->frameCallbackPending = true;
|
|
611
|
+
const uint64_t generation = data->frameCallbackGeneration;
|
|
612
|
+
AChoreographer *choreographer = AChoreographer_getInstance();
|
|
613
|
+
postFrameCallback(choreographer, new FrameCallbackData{ this, generation });
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
class CPPCallable : public godot::CallableCustom {
|
|
618
|
+
// friend bool javascript_callable_compare_equal_func(const godot::CallableCustom *p_a, const godot::CallableCustom *p_b) {
|
|
619
|
+
// if (p_a == p_b) return true;
|
|
620
|
+
// const JavascriptCallable *a = static_cast<const JavascriptCallable *>(p_a);
|
|
621
|
+
// const JavascriptCallable *b = static_cast<const JavascriptCallable *>(p_b);
|
|
622
|
+
// return jsi::Function::strictEquals(a->_rt, a->_func, b->_func);
|
|
623
|
+
// };
|
|
624
|
+
|
|
625
|
+
std::function<void(const godot::Variant **, int, godot::Variant &, GDExtensionCallError &)> _func;
|
|
626
|
+
|
|
627
|
+
public:
|
|
628
|
+
CPPCallable(std::function<void(const godot::Variant **, int, godot::Variant &, GDExtensionCallError &)> f) :
|
|
629
|
+
_func(f) {}
|
|
630
|
+
|
|
631
|
+
uint32_t hash() const override {
|
|
632
|
+
return 0; // Use default hash function
|
|
633
|
+
}
|
|
634
|
+
godot::String get_as_text() const override {
|
|
635
|
+
return godot::String("CPPCallable");
|
|
636
|
+
}
|
|
637
|
+
CompareEqualFunc get_compare_equal_func() const override {
|
|
638
|
+
return nullptr;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
CompareLessFunc get_compare_less_func() const override {
|
|
642
|
+
return nullptr;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
bool is_valid() const override {
|
|
646
|
+
return true;
|
|
647
|
+
}
|
|
648
|
+
godot::ObjectID get_object() const override {
|
|
649
|
+
return godot::ObjectID();
|
|
650
|
+
}
|
|
651
|
+
void call(const godot::Variant **p_arguments, int p_argcount, godot::Variant &r_return_value, GDExtensionCallError &r_call_error) const override {
|
|
652
|
+
_func(p_arguments, p_argcount, r_return_value, r_call_error);
|
|
653
|
+
r_call_error.error = GDEXTENSION_CALL_OK;
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
godot::Callable GodotModule::create_callable(std::function<void(const godot::Variant **, int, godot::Variant &, GDExtensionCallError &)> f) {
|
|
658
|
+
return godot::Callable(memnew(CPPCallable(f)));
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
void GodotModule::registerWindowUpdateCallback(std::string name, void *handle, std::function<void(bool)> f, void *ref) {
|
|
662
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
663
|
+
std::lock_guard lock(data->windowUpdateMutex);
|
|
664
|
+
LOGD("Registering Window: %p, %s", handle, name.c_str());
|
|
665
|
+
if (data->handleToWindowName.contains(handle)) {
|
|
666
|
+
std::string currentName = data->handleToWindowName[handle];
|
|
667
|
+
if (currentName != name) {
|
|
668
|
+
LOGE("RegisterWindowUpdateCallback: Unable to register a different name for the same handle");
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
} else {
|
|
672
|
+
data->handleToWindowName[handle] = name;
|
|
673
|
+
}
|
|
674
|
+
data->windowUpdateCallbacks[name] = WindowFuncData(f, (jobject)ref);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
void GodotModule::unregisterWindowUpdateCallback(void *handle) {
|
|
678
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
679
|
+
std::lock_guard lock(data->windowUpdateMutex);
|
|
680
|
+
if (data->handleToWindowName.contains(handle)) {
|
|
681
|
+
std::string name = data->handleToWindowName[handle];
|
|
682
|
+
LOGD("Unregistering Window: %p, %s", handle, name.c_str());
|
|
683
|
+
WindowFuncData fd = data->windowUpdateCallbacks[name];
|
|
684
|
+
JNIEnv *env = LibGodot::get_jni_env();
|
|
685
|
+
env->DeleteGlobalRef(fd.ref);
|
|
686
|
+
data->windowUpdateCallbacks.erase(name);
|
|
687
|
+
data->handleToWindowName.erase(handle);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
void GodotModule::updateWindow(std::string name, bool adding) {
|
|
692
|
+
LibGodot::updateWindow(name);
|
|
693
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
694
|
+
std::function<void(bool)> cb;
|
|
695
|
+
{
|
|
696
|
+
std::lock_guard lock(data->windowUpdateMutex);
|
|
697
|
+
if (!data->windowUpdateCallbacks.contains(name)) {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
cb = data->windowUpdateCallbacks[name].func;
|
|
701
|
+
}
|
|
702
|
+
cb(true);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
void GodotModule::updateWindows(bool adding) {
|
|
706
|
+
LibGodot::updateWindows();
|
|
707
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
708
|
+
std::map<std::string, WindowFuncData> callbacks;
|
|
709
|
+
{
|
|
710
|
+
std::lock_guard lock(data->windowUpdateMutex);
|
|
711
|
+
callbacks = data->windowUpdateCallbacks;
|
|
712
|
+
}
|
|
713
|
+
for (const std::pair<std::string, WindowFuncData> elem : callbacks) {
|
|
714
|
+
LOGD("Updating Window: %s", elem.first.c_str());
|
|
715
|
+
elem.second.func(true);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
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
|
+
}
|
|
727
|
+
if (wait) {
|
|
728
|
+
std::mutex waitMutex;
|
|
729
|
+
std::condition_variable waitVar;
|
|
730
|
+
bool ready = false;
|
|
731
|
+
std::function<void()> runFunc = [&f, &waitMutex, &waitVar, &ready]() {
|
|
732
|
+
f();
|
|
733
|
+
std::unique_lock<std::mutex> lock(waitMutex);
|
|
734
|
+
ready = true;
|
|
735
|
+
lock.unlock();
|
|
736
|
+
waitVar.notify_one();
|
|
737
|
+
};
|
|
738
|
+
std::unique_lock<std::mutex> lock(waitMutex);
|
|
739
|
+
data->thread.enqueue(runFunc);
|
|
740
|
+
waitVar.wait(lock, [&ready] { return ready; });
|
|
741
|
+
} else {
|
|
742
|
+
data->thread.enqueue(f);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
void GodotModule::iterate(std::optional<uint64_t> frameGeneration) {
|
|
747
|
+
AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
|
|
748
|
+
godot::GodotInstance *instance = nullptr;
|
|
749
|
+
{
|
|
750
|
+
std::lock_guard lock(_mutex);
|
|
751
|
+
if (frameGeneration && *frameGeneration != data->frameCallbackGeneration) {
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
data->frameCallbackPending = false;
|
|
755
|
+
if (data->in_background || data->paused) {
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
instance = _instance;
|
|
759
|
+
}
|
|
760
|
+
if (instance && instance->is_started()) {
|
|
761
|
+
instance->iteration();
|
|
762
|
+
updateState();
|
|
763
|
+
}
|
|
764
|
+
}
|