문제

im currently developing a multiplayer cardgame for android and i'd like to use the google game services realtime multiplayer api. From reading the documentation i know that in the end, every message a client receives will call the RealTimeMessageReceivedListener() . My question is, WHEN is the method called if my application is currently in a working state?

Cause currently i split the application in model view controller with the gui running in its own thread. The controller polls the gui for input and calls the model interface to change the data.

So if i run the multiplayer part in the controller thread, will my application flow just stop when the MessageReceiver is called, will do some stuff in it, and after that continue at its old position, like a software interrupt, or is the MessageReceiver call buffered and called after everything else finishes. If thats the case i guess i have to use a third thread.

Im currently working with libgdx, so no android specific stuff has been touched. Maybe someone combined libgdx with the multiplayer aspect of the goggle game services and can tell me more, cause currently im a little bit lost, on how to get these things together. I know there is tutorial out there for implementing the gameservices with libgdx, but its not touching the multiplayer part.

Thanks in advance.

도움이 되었습니까?

해결책

I think you are asking which thread will the RealTimeMessageReceivedListener async callback run on. As far as I can tell, the callbacks will run on the main Android UI thread (*1). This thread is different from the Libgdx main UI thread (*2).

This means the Google Play Service callbacks can run independently of your main Libgdx logic. If you have your GPS callbacks use the Libgdx Application.postRunnable API, you can get your main Libgdx thread to deal with all the incoming changes serially with everything else (queued runnables are executed at the beginning of each render loop).

(*1) search for 'thread' in this Google Developers blog post. I couldn't find any better reference.

(*2) http://www.badlogicgames.com/forum/viewtopic.php?f=21&t=1298

다른 팁

This Listener listen to messages from the function sendReliableMessage u can check all those send message here RealTimeMultiplater

u send the message to "Google" and it fowards to the other GoogleApiClients which exist in the same Room

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top