C ++ type support

Hello,

This is for Photon Cloud Android C ++ client.

An IOS client is sending a NSDictionary to an Android C ++ client. How do I convert the const ExitGames::Common::Object& eventContent from customEventAction to a Java Hashtable?

I believe this is explained in the “demo_typeSupport” demo. But I am using Android Studio and unable to open any of the demos. I looked at the demo code but couldn’t find anything that would explain how to handle various data types. Perhaps I missed it?

Thanks.

Comments

  • wait...you don't have to respond just yet. I just found some info in the forums. Let me try again tomorrow to see if I can do it...
  • Kaiserludi
    Kaiserludi admin
    edited May 2018
    Hi @GreenRollingHills.

    demo_Type_support sends various data inside CPhotonLib::sendData() in Photon_lib.cpp and receives it in Listener::customEventAction() in Listener.cpp.

    An NSDictionary in an objC Client is equivalent to an ExitGames::Common::Hashtable in a C++ Client.
    Hence you would need to convert 'eventContent' from an ExitGames::Common::Object to an ExitGames::Common::ValueObject<ExitGames::Common::Hashtable> and then receive the payload of that object by calling ValueObject().getDataCopy() (or getDataAddress() if you don't it to stay valid after customEventAction() has returned).

    The list of supported types can be found in the API reference at http://doc-api.photonengine.com/en/cpp/current/html/a05589.html

    PS:

    But I am using Android Studio and unable to open any of the demos.

    I would just open the iOS version of the same demo from Xcode as you use the iOS Client SDK already anyway. Except for the UI and Java/objC binding code the demo code is shared between the versions for all platforms

    Converting the C++ Hashtable to a Java Hashtable is not covered by the demo. You would simply loop over all keys and values, then convert those (keep in mind to handle the cases that a value might be another Hashtable, a Dictionary, an array, an object array, a custom type, etc, depending on what kind of data you want/need to support).

    However I would recommend to just have as much of the game code in C++ as possible and only use Java when you need to interact with some Google APIs that are not available directly in C++. The reasons for that recommendation are performance, available 3rd party libraries including engines for various purposes and that C++ is available on both, Android and iOS, so that this way you can reuse over 90% of your codebase on both OS (the last point of course also means keeping objC/Swift usage as low as possible).
    With this recommended approach you would most likely not need a Java version of the C++ Hashtable (or an objC one on the iOS side) anyway.
  • Thanks for the response. I got it to work.