Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Google Android

How to use S3DClient_SendEventToCurrentUser in Eclipse

Google Play Store, Amazon Kindle, Nook, and so many more

How to use S3DClient_SendEventToCurrentUser in Eclipse

Postby miyudreams » 09 May 2012, 09:59

Hi,

I have a case where I share a Twitter message in the Eclipse Java project. If it's successful or errors out, I want ShiVa to popup my custom message hud. How do I make a call using S3DClient_SendEventToCurrentUser to send that request to ShiVa?

I looked at the Hooks and Callback tutorial: http://www.stonetrip.com/developer/wiki/index.php?title=Hooks_and_Callbacks

The tutorial seems like it's only when ShiVa calls a function, this will then call a Java function.
But I want it to work the other way, from Java to ShiVa.

Thank you
miyudreams
Senior Boarder
Senior Boarder
 
Posts: 61

Re: How to use S3DClient_SendEventToCurrentUser in Eclipse

Postby Nicko » 09 May 2012, 13:53

Hi,

This took my a while to figure out. Firstly create a new JNI Export Function in your S3DClient.cpp let's say DisplayMyHUD. Then create a new .h & .cpp file I called mine Connector. #include your Connector.h file at the top of your S3DCLient.cpp just under the wrapper.h . Inside the Connector.h add void CallDisplayMyHUD(); then save it. Next add

#include "Connector.h"
#include "S3DClient_Wrapper.h"
#include "S3DX/S3DXAIModel.h"

to your JavaConnector.cpp file and add.

void CallDisplayMyHUD()
{
S3DX::AIVariable args[1];
args[0].SetNumberValue(iVal);
S3DClient_SendEventToCurrentUser("MainAI","onDisplayCustomHUD",1,&args);
}

this will allow you to call onDisplayCustomHUD and pass an integer value if you want to.

In your JNI Export simply add CallDisplayMyHUD();

Now say your JNI Exported function was called DisplayMyHUD() just before you call it in the java function of your choice. This is the important bit
Add public static native void DisplayMyHUD( ); above the function. This will allow the application to find DisplayMyHUD() in the S3DClient.

Hope that helps you and everyone else trying to figure this out, it drove me nuts.

Nicko.
Nicko
Senior Boarder
Senior Boarder
 
Posts: 60

Re: How to use S3DClient_SendEventToCurrentUser in Eclipse

Postby vaclav.mazany » 05 Sep 2012, 10:04

Hi Nicko,
I'm trying to get grasp on this, but I'm getting a bit lost.
Could you please post something like a step by step, with copy&paste code, please ?
I'm completely new to this shiva -> c++ -> java and back.
User avatar
vaclav.mazany
Expert Boarder
Expert Boarder
 
Posts: 145

Re: How to use S3DClient_SendEventToCurrentUser in Eclipse

Postby Shaderman » 29 Sep 2012, 23:33

I've just used this code to pass a bool from Java to ShiVa:

In my jni .c file:

Code: Select all
   extern "C" void SmanScoreloop_onAskUserToAcceptTermsOfService ( bool accepted ) ;

   JNIEXPORT void JNICALL Java_com_shaderman_ssdemo_SmanScoreloop_onAskUserToAcceptTermsOfService ( JNIEnv *_pEnv, jobject obj, jboolean bAccepted )
   {
      S3DX::AIVariable arg;
      arg.SetBooleanValue(bAccepted);
      S3DClient_SendEventToCurrentUser("SmanScoreloopAI", "onAskUserToAcceptTermsOfService_Callback", 1, &arg);
   }


Here's the .java part (you probably won't need this to be static):

Code: Select all
public static native void onAskUserToAcceptTermsOfService( boolean rejected );

Now I can call my Java function like this, passing a bool value:

Code: Select all
onAskUserToAcceptTermsOfService( true );


And in Shiva, I have these two functions:

Code: Select all
SmanScoreloopAI.onAskUserToAcceptTermsOfService ( accepted )

and the one which is called is

Code: Select all
SmanScoreloopAI.onAskUserToAcceptTermsOfService_Callback ( accepted )


Done.

Hope it helps.
User avatar
Shaderman
Platinum Boarder
Platinum Boarder
 
Posts: 621
Location: Heidelberg, Germany


Return to Google Android