@@ -67,6 +67,13 @@ static AndroidInputHandler *input_handler = nullptr;
6767static GodotJavaWrapper *godot_java = nullptr ;
6868static GodotIOJavaWrapper *godot_io_java = nullptr ;
6969
70+ enum StartupStep {
71+ STEP_TERMINATED = -1 ,
72+ STEP_SETUP,
73+ STEP_SHOW_LOGO,
74+ STEP_STARTED
75+ };
76+
7077static SafeNumeric<int > step; // Shared between UI and render threads
7178
7279static Size2 new_size;
@@ -76,7 +83,7 @@ static Vector3 magnetometer;
7683static Vector3 gyroscope;
7784
7885static void _terminate (JNIEnv *env, bool p_restart = false ) {
79- step.set (- 1 ); // Ensure no further steps are attempted and no further events are sent
86+ step.set (STEP_TERMINATED ); // Ensure no further steps are attempted and no further events are sent
8087
8188 // lets cleanup
8289 // Unregister android plugins
@@ -203,7 +210,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, j
203210 os_android->set_display_size (Size2i (p_width, p_height));
204211
205212 // No need to reset the surface during startup
206- if (step.get () > 0 ) {
213+ if (step.get () > STEP_SETUP ) {
207214 if (p_surface) {
208215 ANativeWindow *native_window = ANativeWindow_fromSurface (env, p_surface);
209216 os_android->set_native_window (native_window);
@@ -216,7 +223,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, j
216223
217224JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext (JNIEnv *env, jclass clazz, jobject p_surface) {
218225 if (os_android) {
219- if (step.get () == 0 ) {
226+ if (step.get () == STEP_SETUP ) {
220227 // During startup
221228 if (p_surface) {
222229 ANativeWindow *native_window = ANativeWindow_fromSurface (env, p_surface);
@@ -230,7 +237,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *en
230237}
231238
232239JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back (JNIEnv *env, jclass clazz) {
233- if (step.get () == 0 ) {
240+ if (step.get () <= STEP_SETUP ) {
234241 return ;
235242 }
236243
@@ -244,20 +251,26 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ttsCallback(JNIEnv *e
244251}
245252
246253JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_step (JNIEnv *env, jclass clazz) {
247- if (step.get () == - 1 ) {
254+ if (step.get () == STEP_TERMINATED ) {
248255 return true ;
249256 }
250257
251- if (step.get () == 0 ) {
258+ if (step.get () == STEP_SETUP ) {
252259 // Since Godot is initialized on the UI thread, main_thread_id was set to that thread's id,
253260 // but for Godot purposes, the main thread is the one running the game loop
254- Main::setup2 ();
261+ Main::setup2 (false ); // The logo is shown in the next frame otherwise we run into rendering issues
255262 input_handler = new AndroidInputHandler ();
256263 step.increment ();
257264 return true ;
258265 }
259266
260- if (step.get () == 1 ) {
267+ if (step.get () == STEP_SHOW_LOGO) {
268+ Main::setup_boot_logo ();
269+ step.increment ();
270+ return true ;
271+ }
272+
273+ if (step.get () == STEP_STARTED) {
261274 if (Main::start () != EXIT_SUCCESS) {
262275 return true ; // should exit instead and print the error
263276 }
@@ -283,7 +296,7 @@ JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env,
283296
284297// Called on the UI thread
285298JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchMouseEvent (JNIEnv *env, jclass clazz, jint p_event_type, jint p_button_mask, jfloat p_x, jfloat p_y, jfloat p_delta_x, jfloat p_delta_y, jboolean p_double_click, jboolean p_source_mouse_relative, jfloat p_pressure, jfloat p_tilt_x, jfloat p_tilt_y) {
286- if (step.get () <= 0 ) {
299+ if (step.get () <= STEP_SETUP ) {
287300 return ;
288301 }
289302
@@ -292,7 +305,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchMouseEvent(JN
292305
293306// Called on the UI thread
294307JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchTouchEvent (JNIEnv *env, jclass clazz, jint ev, jint pointer, jint pointer_count, jfloatArray position, jboolean p_double_tap) {
295- if (step.get () <= 0 ) {
308+ if (step.get () <= STEP_SETUP ) {
296309 return ;
297310 }
298311
@@ -313,23 +326,23 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchTouchEvent(JN
313326
314327// Called on the UI thread
315328JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnify (JNIEnv *env, jclass clazz, jfloat p_x, jfloat p_y, jfloat p_factor) {
316- if (step.get () <= 0 ) {
329+ if (step.get () <= STEP_SETUP ) {
317330 return ;
318331 }
319332 input_handler->process_magnify (Point2 (p_x, p_y), p_factor);
320333}
321334
322335// Called on the UI thread
323336JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_pan (JNIEnv *env, jclass clazz, jfloat p_x, jfloat p_y, jfloat p_delta_x, jfloat p_delta_y) {
324- if (step.get () <= 0 ) {
337+ if (step.get () <= STEP_SETUP ) {
325338 return ;
326339 }
327340 input_handler->process_pan (Point2 (p_x, p_y), Vector2 (p_delta_x, p_delta_y));
328341}
329342
330343// Called on the UI thread
331344JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton (JNIEnv *env, jclass clazz, jint p_device, jint p_button, jboolean p_pressed) {
332- if (step.get () <= 0 ) {
345+ if (step.get () <= STEP_SETUP ) {
333346 return ;
334347 }
335348
@@ -344,7 +357,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env
344357
345358// Called on the UI thread
346359JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis (JNIEnv *env, jclass clazz, jint p_device, jint p_axis, jfloat p_value) {
347- if (step.get () <= 0 ) {
360+ if (step.get () <= STEP_SETUP ) {
348361 return ;
349362 }
350363
@@ -359,7 +372,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env,
359372
360373// Called on the UI thread
361374JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat (JNIEnv *env, jclass clazz, jint p_device, jint p_hat_x, jint p_hat_y) {
362- if (step.get () <= 0 ) {
375+ if (step.get () <= STEP_SETUP ) {
363376 return ;
364377 }
365378
@@ -396,7 +409,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(
396409
397410// Called on the UI thread
398411JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key (JNIEnv *env, jclass clazz, jint p_physical_keycode, jint p_unicode, jint p_key_label, jboolean p_pressed, jboolean p_echo) {
399- if (step.get () <= 0 ) {
412+ if (step.get () <= STEP_SETUP ) {
400413 return ;
401414 }
402415 input_handler->process_key_event (p_physical_keycode, p_unicode, p_key_label, p_pressed, p_echo);
@@ -419,15 +432,15 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env
419432}
420433
421434JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin (JNIEnv *env, jclass clazz) {
422- if (step.get () <= 0 ) {
435+ if (step.get () <= STEP_SETUP ) {
423436 return ;
424437 }
425438
426439 os_android->main_loop_focusin ();
427440}
428441
429442JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout (JNIEnv *env, jclass clazz) {
430- if (step.get () <= 0 ) {
443+ if (step.get () <= STEP_SETUP ) {
431444 return ;
432445 }
433446
@@ -516,7 +529,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_requestPermissionResu
516529}
517530
518531JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed (JNIEnv *env, jclass clazz) {
519- if (step.get () <= 0 ) {
532+ if (step.get () <= STEP_SETUP ) {
520533 return ;
521534 }
522535
@@ -528,7 +541,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed(JNI
528541}
529542
530543JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererPaused (JNIEnv *env, jclass clazz) {
531- if (step.get () <= 0 ) {
544+ if (step.get () <= STEP_SETUP ) {
532545 return ;
533546 }
534547
0 commit comments