Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Godot reinstantiation on iOS for embedding in a single view #99705

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

louis-prudhomme
Copy link

Partially adresses : godotengine/godot-proposals#1473.

The goal is to be able to run Godot from within a classically-made mobile app (think Snapchat Games). As underlined in the umbrella issue, several things will still be missing after this PR is merged :

  1. boot splashscreen management : a way to enable / disable the boot splashscreen at will
  2. export configuration : supporting project export as either an embeddable or a full-fledged standalone app

We faced many issues related to instanciating Godot several times. We fixed all of them, but are unsure for some fixes ; specificially, we came up using a queue to store StringName references. We are iOS developers and we're humble about our C++ knowledge, but we're committed to make this work ; any feedback is therefore much appreciated.

While the ability to embed Godot is functional with this PR, some manual adjustments are still required. An example implementation demonstrating how to embed Godot in a basic mobile app is available in our repository: here.

@AThousandShips
Copy link
Member

AThousandShips commented Nov 26, 2024

You have a lot of TODOs in your code, was this supposed to be a draft? Is this ready for review?

@louis-prudhomme
Copy link
Author

You have a lot of TODOs in your code, was this supposed to be a draft? Is this ready for review?

The several TODOs in the code are all linked to the same root cause. This is the part we're unsure of, but couldn't find a better way to make it work.

It could definitely be seen as a draft, but we're at our wits' end on this, so any feedback would be much appreciated. Not sure about the etiquette here, let me know if it should be converted to a draft.

@AThousandShips
Copy link
Member

If it's ready to be reviewed and is in a form you would be comfortable merging it it should be marked as ready, if there are several issues still to resolve I'd suggest marking it as draft

Especially seeing how there's parts of the feature you haven't worked out how to solve yet

Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra cleanup is probably fine, but I'm not sure what you are trying to do with static StringNames. What's the purpose of reinitialization of StringNames or class info? It (and most low level stiff like OS) probably can be preserved and reused, you only need to reinitialize scene tree and view/view controller.

static StringName _class_name_static; \
if (unlikely(!_class_name_static)) { \
StringName::assign_static_unique_class_name(&_class_name_static, #m_class); \
static std::queue<StringName> _class_name_statics; \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@louis-prudhomme louis-prudhomme marked this pull request as draft November 29, 2024 09:07
@adamscott adamscott requested a review from m4gr3d December 1, 2024 18:40
@m4gr3d
Copy link
Contributor

m4gr3d commented Dec 1, 2024

cc @kisg @migueldeicaza

@Xseuguh
Copy link

Xseuguh commented Dec 2, 2024

Extra cleanup is probably fine, but I'm not sure what you are trying to do with static StringNames. What's the purpose of reinitialization of StringNames or class info? It (and most low level stiff like OS) probably can be preserved and reused, you only need to reinitialize scene tree and view/view controller.

The purpose of reinitializing StringName is to enable embedding Godot within an existing iOS app as an external module. Our goal is to ensure that all objects created by the Godot instance are removed when exiting its view. To do so, we initialize Godot when launching it via a button and deinitialize it when exiting the Godot view.
To achieve this, the start and cleanup methods from the main Godot code are used. However, invoking the cleanup method results in a reference error during the next launch attempt.
To address this error, we reinitialize StringName.

@migueldeicaza
Copy link
Contributor

We did originally try the clear approach a year ago, but found it very brittle, but it did serve as a good proof-of-concept that we could relaunch Godot multiple times.

For the stated goal of this PR, we ended up going with a more robust approach which is the libgodot/DisplayServerEmbedded approach patch that @kisg and his team developed and you can see in action here, and solves the iOS embedding problem, but also allows for not just embedding one view, but can support multiple views in the same screen (among other things):

#90510

You can take it for a spin on iOS with both Swift or Godot-cpp with the samples here:

https://github.com/migeran/libgodot_project

The patches here won't hurt, but in our view, are neither sufficient or desirable for the intended goal. They did spot the challenging StringName issue, which is the ugliest part of the reset approach, but from memory, this is about a third of the static state that needs to be properly reset, there are plenty more globals and statics that need to be worked on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants