migeran / libgodot_project

57 stars 7 forks source link

Design patterns for communicating with the embedded Godot app #5

Open kisg opened 4 months ago

kisg commented 4 months ago

From @raminf:

Another thing that isn't clear is how to best communicate between the embedded Godot view and the native app (and vice-versa). For example, to pass a username down into the Godot view, and have the scores from the mini-games bubble back up to the main application. I can file that as a separate issue if easier to track.

kisg commented 4 months ago

There are many options, depending on your needs. One way we like to do it is to define a GDExtension node class and on startup register it on /root/ as if it was an autoloader singleton.

Then you can call methods on this class or use signals both from inside Godot and also from the host application.

We will extend the samples with an example that shows how it can be done.

raminf commented 4 months ago

@kisg That sounds like a good approach.

Another way might be to transparently route signals back out to Swift, maybe with an easy way to register and/or filter events for performance. Going the other way, function calls are good, but I imagine marshaling/pickling might become an issue. Conversion to string or JSON is one way out, but being able to send binary buffers means media could also be exchanged. There's also tying into @observable, so a SwiftUI button press can magically migrate into Godot world.

FWIW, the only comparable system I've come across is the Unity embedding model:

A few other embedding notes:

pluviamtonitrus commented 2 months ago

Any update on this @kisg?