• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

DevLog Google Play Realtime Multiplayer wrapper

Rich

Well-known member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
3rd Party Tool Dev
Joined
Sep 9, 2017
Messages
451
For the past few evenings Ive been looking into this. So far, its going quite well

I have completed the following:
  • Join a quick game. Currently this is fixed to 2 players. It should be able to support 8 players.
  • Send unreliable messages between the 2 android devices. Some of these messages are clashing, so need to look into this.
Its early days yet, so the code is very messy with lots of debug output.

Development hasnt been quick on this due to the limitations when developing.
For Google Play to work, it requires a non debug apk uploading to google play dev console and multiplayer enabling.
As the signing has to match whats on google play, each test has to be compiled in Release mode.
On my laptop release builds dont automatically upload to a physical evice or emulator (it maybe a feature and the same for you), so I need to upload the apk manually to both devices and install for each test. Its been very time consiming.

Apart from that, its looking very promising
 
On my laptop release builds dont automatically upload to a physical evice or emulator (it maybe a feature and the same for you), so I need to upload the apk manually to both devices and install for each test. Its been very time consiming.

On old time Monkey, we can compile release version and automatic send to device and run. I miss this features ;(
When trying something like SDK implementation like this, the situation sometime need to be real, so compile as release and run on device is needed otherwise very time consuming.
 
@Rich Which platform are you developing on?

Btw. I remember it working every other build time in MX.
 
@Rich Which platform are you developing on?

Btw. I remember it working every other build time in MX.
I'm on windows.
I remember it working I MX too. Inn release it does send the intent through to the device to start the app, just doesn't send the APK first
It must me a security thing in the sdk
 
example use of wrapper
Code:
Import mojo
Import gameservices

Function Main:Int()
    New game()
    Return 0
End Function

Class game Extends App    
    Field counter:Int

    Field gms:GameService
    Field online:GameServiceGame
    Field message:GameServiceMessage
                
    Field opponent_id:String    
    Field opponent_x:Float,opponent_y:Float
    
    
    Method OnCreate:Int()
        ' set a message format for transfering data
        message = New GameServiceMessage()
        message.SetValues(2)
        
        ' new Google Play service
        gms = New GameService()
        ' new Google Play service Multiplayer Game
        online = New GameServiceGame()
                
        opponent_id = ""
        
        counter=0
                
        Return True
    End

    
    Method OnUpdate:Int()
        If KeyDown(KEY_ESCAPE)
            Error ""
        End
                    
        UpdateGame()

        counter = counter + 1
                
        Return True
    End

    Method OnRender:Int()
        DrawGame()

        DrawText counter,20,20
        
        Return True
    End

    Method OnResume:Int()
        Return True
    End
    
    Method UpdateGame:Void()

        online.Update()        

        
        If MouseHit(MOUSE_LEFT)

            If MouseY()<200
                ' sign in/out
                If gms.IsSignedIn()
                    gms.SignOut()
                Else
                    gms.SignIn()
                End
            Else
                Select online.GetStatus()
                Case GameServiceGame.GAME_NOTCONNECTED
                    If MouseY()<400
                        online.StartQuickGame(gms,2,2)
                    End
                End
            End            
        End


        If online.GetStatus() = GameServiceGame.GAME_STARTED
            If opponent_id="" Then opponent_id = GetOtherPlayersName()
            
            If MouseDown(MOUSE_LEFT)
                If MouseY()>400
                    'load message with coordinates
                    message.SetValue(0,MouseX())
                    message.SetValue(1,MouseY())
                    'send message of coordinates
                    message.Send(online)
                End
            End            
    
            ' got message?
            If message.Get(online)
                opponent_x = message.GetValue(0)
                opponent_y = message.GetValue(1)
            End

        End
    End

    Method GetOtherPlayersName:String()
        Local ids:String[] = online.GetPlayerIDs()
        
        For Local i:Int = 0 To ids.Length()-1
            If ids[i] <> online.MyPlayerID() Then Return ids[i]
        Next
        Return ""
    End
    
    Method DrawGame:Void()
        Cls 0,0,0

        ' draw sign in button
        If gms.IsSignedIn()
            SetColor 255,0,0
            DrawRect 0,0,DeviceWidth(),200
            SetColor 255,255,255
            DrawText "SIGN OUT",0,100
        Else
            SetColor 0,255,0
            DrawRect 0,0,DeviceWidth(),200
            SetColor 255,255,255
            DrawText "SIGN IN",0,100
        End
        
        If gms.IsSignedIn()
            If online.GetStatus() = GameServiceGame.GAME_NOTCONNECTED
                ' draw start game button
                SetColor 255,128,0
                DrawRect 0,200,DeviceWidth(),200
                SetColor 255,255,255
                DrawText "START QUICK GAME",0,300
            Else
                ' write your name
                DrawText online.PlayerName(online.MyPlayerID()),0,300
                
                ' draw opponents character and name
                DrawRect opponent_x-20,opponent_y-20,40,40
                DrawText online.PlayerName(opponent_id),opponent_x+20,opponent_y-10
            End
        
        End

        DrawOval MouseX()-20,MouseY()-20,40,40
    End
End
Wrapper works for 2 players...
Class and method names could change espsecially I try to wrap it for 3+ player multiplayer
Also on my list is to cleanly detect network and player drop out
 
Wrapper works for 2 players...
Class and method names could change espsecially I try to wrap it for 3+ player multiplayer
Also on my list is to cleanly detect network and player drop out
Sounds great. Regarding installing of a release app. So far what I read on the net was that gradle doesn't support that by default. But I have an idea to work around this using adb in between.
 
3 player demo test..
In this test I have 3 devices. 2 real and one emulator. I'm running out of physical devices ;-)

As you can see in the demo there is lag from the emulator. Not sure if this is cause of the emulator, CPU or lack of fps timing code in the demo. Either way it does send all the messages through and each physical device picks up the relevant message

Sorry for the quality.. the wife is right, I'm not good at doing 4 things at once ;-)
 
Last edited:
Need some advice on coding standards and peoples preferences...
How do people like their methods naming?
Code:
online.GetPlayerName(id)
or
Code:
online.PlayerName(id)
Both do the same thing and 'get the players name'
In this case I dont have a SetPlayersName but in some cases I do..

which one do you prefer here?
Code:
message.SetValue(index,value)
message.GetValue(index)
or
Code:
message.SetValue(index,value)
message.Value(index)
 
I use version one in my framework. But i would now go with how the official modules do it.
 
Wait... Don't they also use version one? o_O

My personal preference is SetX / GetX
 
Is that a preference to GetPlayerName then?
 
What about:

Code:
message.set(index,value)
message.get(index)

No need to use setValue / getValue, unless you can set/get something else? Unless that 'message' is something like a messageController, than setMessage, getMessage would make sense :)

As for casing, I'm always for camelCase. But the 'official' libs are all CamelCase, so... whatever you think is best :)
 
  • Like
Reactions: mag
You can .get() a message already, but not sure the terminology is correct. Don't want to use .retreive() as I always get the I and E the wrong way round :)
I like camelCase but am keeping everything CamelCase so it follows CX
 
Back
Top Bottom