Room Configuration did not work properly in google real time multiplayer services for android
Asked Answered
D

2

2

i am trying to build a real time multi-player game and now i am exploring sample game provided by google for multi-player. Link is ...

https://github.com/playgameservices/android-samples/tree/master/ButtonClicker

issue is that when i change auto-match criteria configuration as per my requirement

void startQuickGame() {
final int MIN_OPPONENTS = 1, MAX_OPPONENTS = 3;
   Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(MIN_OPPONENTS,
           MAX_OPPONENTS, 0);
   RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);
   rtmConfigBuilder.setMessageReceivedListener(this);
   rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
   rtmConfigBuilder.setRoomStatusUpdateListener(this);

   getGamesClient().createRoom(rtmConfigBuilder.build());
}

then this code not wait for 3rd or 4rh player in room (as i set in MAX_OPPONENTS ) and game starts immediately with 2 player(1 opponent). i want to add timer here and game starts after that specified time.

and surprisingly after room creation MIN_PLAYER value dose'nt work at all in this code that is for default room UI.

   final int MIN_PLAYERS = 2;
   Intent i = getGamesClient().getRealTimeWaitingRoomIntent(room, MIN_PLAYERS);

   // show waiting room UI
   startActivityForResult(i, RC_WAITING_ROOM);

my requirement is that after room creation i want to wait for a specific time and then game starts with joined player. no matter they are 2 , 3 or 4.

Dateline answered 27/5, 2013 at 14:19 Comment(0)
S
0

The automatching algorithm doesn't try very hard to maximize the number of players in the match -- if you set min to 1 and max to 3, getting a 2 player game is possible.

What you should do in this case is set MIN_OPPONENTS and MAX_OPPONENTS to 3, and handle the game start logic from your code.

If you want to implement this timer logic, you can't use our built-in waiting room UI, because it doesn't support starting a game early based on time. So, instead, implement your own waiting room with this logic:

  1. Start your timer.

  2. Show the progress on screen as you see peers being connected or disconnected via onPeerConnected() and onPeerDisconnected(), and other callbacks. See RoomStatusListener and RoomStatusUpdateListener.

  3. When the timer expires, decide what you're going to do. For example, if there are 2+ players connected, start the game. If not, wait longer, give up, etc.

  4. Handle the case when someone joins the game late. This will happen if 2 players joined, the timer expired, the game started and then a 3rd or 4th player shows up. Make sure the experience is not terrible for them (don't just kick them out) :-) If you can't integrate them into the ongoing game, you could have them stay in "spectator mode" and join in the next round/match/etc.

Important: remember that the timers for different players won't be in sync in the logic above -- so you should send a real time reliable message to all peers when you decide to start the game, to let them know that the game is starting and that they should move to the game screen.

If the logic gets more complicated, it might make sense to elect a "server". You can do that, for example, by saying that the client with the lowest Participant ID (lexicographically) is the server. Saying "whoever created the game is the server" is no good, because when automatching, everyone thinks they created the game.

I hope this helped!

Shillyshally answered 28/5, 2013 at 21:58 Comment(7)
i have tried this as you explained and i am using my own waiting room UI but main and surprising issue is that)when i set MIN_OPPONENT= 2 or 3. game play service did not try to search player one by one for room. i did not receive any call back for each single player in my game like in onPeerConnected(). but google play service send me collective callback for all players if they available. witch includes total participants that is set in MIN_OPPONENTS(no matter it is 1 , 2 or 3).Dateline
mean until play service did not find all opponent as per room configuration, it did not send me any call back.or in other words it send me all or nothing opponents as per room configuration. ideally it should notify me via call back if any player available for the room and send me call back. but this is never happen. please guide me if i am going wrong in any direction.Dateline
@dani, did you manage to solve it ? I am facing the same issue! I only get notified when all the matched players are connected, not one by oneFife
Same here. Each player creates his own room until google sees there are 4 rooms with 1 player each and joins them all.Preparatory
Has anyone successfully implemented this concept?Succedaneum
I'm also seeing the problem where callbacks do not fire as players are added one at a time, only when max players is reached. I tried saving the Room object that is returned in onRoomCreated and polling to see if the participants in that room change as players are added, but it does not update. Anybody know a way to work around this issue and figure out when players are added one at a time?Dosser
I am experiencing the same as @dani. The onPeersConnected is not called when each automatched player is connected. Instead, it will wait for enough automatch players to join/create and then trigger the callback.Bardo
M
-1

Just came across this excerpt from here that might be interesting to others regarding your issue:

The second parameter in getRealTimeWaitingRoomIntent() indicates the number of players that must be connected in the room before the Start playing option is displayed. In the example, we specify MAX_VALUE which indicates that the Start playing option is never displayed. Instead, the waiting room UI automatically exits when all players are connected.

So if you don`t set a MAX_VALUE when using the built-in waiting room intent, you can leave up to the player if he will start the game with the minimum players, or wait for more people to join.

Messaline answered 18/8, 2013 at 17:4 Comment(1)
You can't elect to not specify a MAX_VALUE; it's a required parameterScarito

© 2022 - 2024 — McMap. All rights reserved.