Sponsored By

The Hinterlands Mining Game: Finishing adding Google Play services for more accessible multiplayer

I’ve been working on trying to add more accessible multiplayer to my game for about 7 months now. Google Play game services(GPGS) multiplayer was announced not long after I released my mining game on the Google Play store, and it sounded like a blessing.

Chris Moeller, Blogger

June 11, 2014

6 Min Read

I’ve been working on trying to add more accessible multiplayer to my game for about 7 months now. Google Play game services(GPGS) realtime multiplayer was announced not too long after I released my mining game on the Google Play store, and it sounded like a blessing.

I re-worked the entire backend of my game to abstract sending and receiving messages. I had originally finally found a method of having multiplayer over wifi/lan using Nate’s great little program KryoNet, and for the most part it worked beautifully.

But it did require people to either be on the same router for easy multiplayer, or connect to someone that had setup port forwarding on their router, to host games. And a lot of users didn’t understand this, and I had several comment that they “waited until 100 retries and still couldn’t connect to multiplayer”(which was just trying to connect to the IP, failing, waiting a couple seconds and re-trying).

So I had two ways to solve this - a server to help with matchmaking (which Google Play services offered), and creating a master server to match up clients to servers who had set up port forwarding. But GPGS would allow users to play together more easily, not needing a server to be setup.

So I set it up mostly at the end of last year- so that my game packed up all the messages needed, converted to a byte array via Kryo (not net), and then either handed it off to KryoNet for sending over wifi/Lan, or directly to the client for single player (inefficient, but allows me to test quickly), or directly to GPGS.

Originally GPGS using reliable messaging was horribly slow. The chunks of the world would take 5s or so to come in (22x22x2, so 968bytes, or about 1 message due to a limit of having about a kb as the max message size). I was about to give up at that point, but tried unreliable messaging, which worked beautifully, and gave me hope.

So, over the last months, I’ve been working on updates for the game, and trying to find time to create a reliable messaging backend. I am fairly new to networking, and haven’t found too many resources on it for lag compensation (handling delays), aside from mainly valves articles, which were helpful in understanding the concepts behind it, but still wasn’t enough for me to solve getting entities to move smoothly + consistant over the network/ with delays, and I’m still struggling to get that worked out to a reasonable level.

But I finally had a chance to flush out my reliable messaging system, adding ID’s to messages so that I could verify receipt on each end and remove the message from the list of needing to be sent, or re-send it at set intervals.

I tested it out on GPGS, and had some glaring issues (probably bugs in my system), and although it worked, I needed to do a lot more testing and refine my system more. But then I tried reliable messaging on a whim, and it worked fast enough! The game only runs a 20 tick rate, and thats how often I was sending messages (if they are needed). GPGS says to use unreliable if sending faster than 50 messages/ second, so I plan to finish my reliable messaging system in the future, but the game officially works on GPGS, and is playable.

But I did discover after release (being able to play with more people, with greater latencies), it sometimes will take several seconds(10-20) to load chunks after you’ve been playing for a bit/wandering around (maybe 5 minutes), definitely to an unacceptable level.

I had been worrying about running into GPGS quota, which is 50million messages a day, but looking into it further, the default settings for GPGS is to limit users to 5 messages/ second. So I wonder if the 50 messages/second is split across all users?

Either way, it will throttle the messages down, which I suspect is why the chunks take longer to come in after a while of playing. The messages seem to eventually arrive which is good, but with an extreme delay.

I could raise the message limit for users, but I still worry about the quota, and cutting off my users completely, so I’ll try to instead try to get the game working with 5 messages/ second, and see how close to the quota I get over time, but try to allow it to handle faster messaging for wifi/lan, or GPGS if I never get close to the quota.

Overall the GPGS is a blessing for other developers like myself, who have always loved LAN/multiplayer games. It was difficult to get setup, and now they seem to have completely changed a lot of their code from 6 months ago, so only one of their current demos can actually be run. And originally when testing it, it would crash often, and not allow you to play again for several hours because it would leave people logged into a “room” and lock them from joining another.

But it allows accessible multiplayer to Android (and apparently now iOS) users!

Check out my game(https://play.google.com/store/apps/details?id=com.ackmi.the_hinterlands), and let me know if you know other resources for a newer network developer for lag compensation, or if you have more info on using GPGS with real time games! The game is still in long term alpha- I started working on it in around January last year as side project, because I wanted to play a game like that on mobile. It was great to find that other people were interested in that kind of gameplay too, but I've spent 90% of my development time on networking. I hope to soon finish it so I can work primarily on game play/ content.

The other resources I have used so far for networking help are:

  • ActionScript for Multiplayer Games and Virtual Worlds (book, using electroserver, but was a good introduction to problems faced for network programming, and introducing lag compensation)

  • http://gafferongames.com/ (mainly for understanding tick rates, and how to have frame rate independent physics)

  • stackoverflow.... so many helpful questions/answers  (but also so many unanswered ones that I would have loved to have found the answer for )

  • Minecraft blog and Wiki. (Helped to hear to add multiplayer early in development to save a lot of time later, and helpful for networking/ file info)

(I also hope to review the Doom 3 source code in the future, once I have enough time set aside)

Read more about:

Featured Blogs
Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like