Calling Photon updates on Android NDK w Cocos2Dx

victor
edited July 2013 in Native
Hi, I'm facing a problem with integrating Photon Android NDK with Cocos2dx project. Basically, I've natively threaded the regular Photon update calls, but they are returning in midst of the the Cocos2dx draw calls.

In a particular Photon return call, it asks to pop up a Dialogue box. This affects the render stack of Cocos2dx and causes a crash, since the Photon update returns in the midst of a scene draw. In IOS there's no problem since AppController is used and the Photon calls resolve in between Cocos2dx draw calls.

I'm hoping to get advice on how I can call Photon on Android safely with Cocos2dx.

Barring that, is there advice on how to store/buffer data from the Photon update responses? I used flags to block Message box popup calls in between Cocos2dx draw calls, but the resulting Photon update response data that triggered the call in the first place got thrown away and the popup did not appear.

Comments

  • Hi victor.

    The problem here is not that a Photon callback is called while cocos2d-x is rendering. That has to be expected when using them on different threads. If you don't want that then you have to stay single threaded. The actual problem is, that you are popping up a dialogue box in that callback. Instead just set a flag that the dialogue box has to popup and don't actually execute the popup code in the callback.
    Then in some code that's guaranteed to not interfere with the cocos rendering , for example because its running on the same thread like cocos, check that flag and if its true then trigger the popup and set the flag back to false.
  • I still haven't managed to get the flag solution working (some issues along the way). I managed to get the single threaded version working though.

    Place the update call at the end of the Cocos2dxRenderer.java onDrawFrame() function, found in the org.cocos2dx.lib package in the Android project.

    Cocos2dx's internal draw functions are natively wrapped in this function. Placing Photon update in this function means that the call resolves within the render thread of the Android device, after each draw scene.

    Since this the PhotonAndroidNDK version, you'll have to do the JNI bridging etc to call C++ functions via java etc.
    (JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_UpdatePhoton(JNIEnv* env, jobject obj) ...)

    Hope this helps someone as well. Probably will look into the flag solution, since its more flexible. Thanks KaiserLudi!