How do I properly communicate with a custom Server?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ricard Rovira

I’m currently working on my project on top of the 4.0 branch, and running my simulation on the background using standard C++ threads, and communicating both ways between Godot and my threads using a concurrent queue (GitHub - cameron314/concurrentqueue: A fast multi-producer, multi-consumer lock-free concurrent queue for C++11). Currently in the middle of a refactoring, I’m beginning to wonder if it wouldn’t be smoother to just implement my simulation in one or multiple servers (divided by responsibilities) such as what currently exists for graphics and physics.

I’ve been investigating the official docs (the Hilbert Hotel example) and the implementation of the visual server, but there are still some details that I’m not understanding, mainly in the server ↔ scene tree communication channels.

My main question is: what is the best way to get information from the sceneTree/godot to the server? The Hilbert hotel example functions just lock the conflictive data, and this does not seem very useful if I want to run asynchronously. I’d rather receive the requests through some sort of asynchronous queue, so every server processes information when it sees fit, not through an external locking call. What’s the proper way of doing this with servers?

To get information from the server to the sceneTree/godot thread: The recommended way is through the MessageQueue. Any pitfalls that I should avoid here? Or should I use something else?

Probably I’m just missing something obvious here. I’d like to have a clearer picture of the servers communication channels and what do the servers need to implement to support those channels than the documentation currently offers…

PS: How would this server communicate directly with another server without going through the scene tree / gdscript?

Thank you all :smiley: