- Added ads support for Android
- basic "message" system between JGE and java through jni - Fixed pause/resume on android/sdl
This commit is contained in:
@@ -24,10 +24,12 @@ extern "C" void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass c
|
||||
|
||||
/* Run the application code! */
|
||||
int status;
|
||||
char *argv[2];
|
||||
char *argv[4];
|
||||
argv[0] = strdup("SDL_app");
|
||||
argv[1] = NULL;
|
||||
status = SDL_main(1, argv);
|
||||
argv[1] = (char *)env;
|
||||
argv[2] = (char *)&cls;
|
||||
argv[3] = NULL;
|
||||
status = SDL_main(3, argv);
|
||||
|
||||
/* We exit here for consistency with other platforms. */
|
||||
exit(status);
|
||||
|
||||
@@ -55,6 +55,10 @@ typedef u32 LocalKeySym;
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(ANDROID)
|
||||
#include <jni.h>
|
||||
#endif
|
||||
|
||||
bool JGEGetButtonState(const JButton button);
|
||||
bool JGEGetButtonClick(const JButton button);
|
||||
void JGECreateDefaultBindings();
|
||||
@@ -121,6 +125,12 @@ class JGE
|
||||
private:
|
||||
#endif
|
||||
|
||||
#if defined (ANDROID)
|
||||
JNIEnv * mJNIEnv;
|
||||
jclass mJNIClass;
|
||||
jmethodID midSendCommand;
|
||||
#endif
|
||||
|
||||
bool mDone;
|
||||
float mDeltaTime;
|
||||
bool mDebug;
|
||||
@@ -356,6 +366,16 @@ class JGE
|
||||
|
||||
void Assert(const char *filename, long lineNumber);
|
||||
|
||||
/// Sends a message through JGE
|
||||
/// Currently used only to communicate with the JNI Layer in Android
|
||||
void SendCommand(std::string command);
|
||||
|
||||
#if defined (ANDROID)
|
||||
/// Access to JNI Environment
|
||||
void SetJNIEnv(JNIEnv * env, jclass cls);
|
||||
void sendJNICommand(std::string command);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
JGE();
|
||||
~JGE();
|
||||
|
||||
@@ -315,6 +315,11 @@ JGE::JGE()
|
||||
strcpy(mDebuggingMsg, "");
|
||||
mCurrentMusic = NULL;
|
||||
#endif
|
||||
|
||||
#if defined (ANDROID)
|
||||
mJNIEnv = NULL;
|
||||
#endif
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
@@ -567,5 +572,29 @@ void JGE::Scroll(int inXVelocity, int inYVelocity)
|
||||
}
|
||||
}
|
||||
|
||||
void JGE::SendCommand(string command)
|
||||
{
|
||||
#if defined (ANDROID)
|
||||
sendJNICommand(command);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined (ANDROID)
|
||||
/// Access to JNI Environment
|
||||
void JGE::SetJNIEnv(JNIEnv * env, jclass cls)
|
||||
{
|
||||
mJNIEnv = env;
|
||||
mJNIClass = cls;
|
||||
midSendCommand = mJNIEnv->GetStaticMethodID(mJNIClass,"jgeSendCommand","(Ljava/lang/String;)V");
|
||||
}
|
||||
|
||||
void JGE::sendJNICommand(string command)
|
||||
{
|
||||
if (midSendCommand) {
|
||||
mJNIEnv->CallStaticVoidMethod(mJNIClass, midSendCommand, mJNIEnv->NewStringUTF(command.c_str()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
std::queue< pair< pair<LocalKeySym, JButton>, bool> > JGE::keyBuffer;
|
||||
std::multimap<LocalKeySym, JButton> JGE::keyBinds;
|
||||
|
||||
@@ -50,12 +50,39 @@ uint64_t lastTickCount;
|
||||
JGE* g_engine = NULL;
|
||||
JApp* g_app = NULL;
|
||||
JGameLauncher* g_launcher = NULL;
|
||||
#ifdef ANDROID
|
||||
JNIEnv * mJNIEnv = NULL;
|
||||
jclass * mJNIClass = NULL;
|
||||
#endif
|
||||
|
||||
class SdlApp;
|
||||
|
||||
SdlApp *g_SdlApp = NULL;
|
||||
|
||||
|
||||
#ifdef ANDROID
|
||||
// Pause
|
||||
extern "C" void Java_org_libsdl_app_SDLActivity_nativePause(
|
||||
JNIEnv* env, jclass cls)
|
||||
{
|
||||
DebugTrace("Attempt pause");
|
||||
if (!g_engine)
|
||||
return;
|
||||
g_engine->Pause();
|
||||
DebugTrace("Pause done");
|
||||
}
|
||||
|
||||
// Resume
|
||||
extern "C" void Java_org_libsdl_app_SDLActivity_nativeResume(
|
||||
JNIEnv* env, jclass cls)
|
||||
{
|
||||
if (!g_engine)
|
||||
return;
|
||||
g_engine->Resume();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
class SdlApp
|
||||
{
|
||||
public: /* For easy interfacing with JGE static functions */
|
||||
@@ -89,11 +116,14 @@ public:
|
||||
|
||||
while(Running)
|
||||
{
|
||||
while(SDL_WaitEventTimeout(&Event, 0))
|
||||
if (g_engine && !g_engine->IsPaused())
|
||||
{
|
||||
OnEvent(&Event);
|
||||
while(SDL_WaitEventTimeout(&Event, 0))
|
||||
{
|
||||
OnEvent(&Event);
|
||||
}
|
||||
OnUpdate();
|
||||
}
|
||||
OnUpdate();
|
||||
}
|
||||
|
||||
OnCleanup();
|
||||
@@ -348,6 +378,16 @@ bool InitGame(void)
|
||||
g_app = g_launcher->GetGameApp();
|
||||
g_app->Create();
|
||||
g_engine->SetApp(g_app);
|
||||
#ifdef ANDROID
|
||||
DebugTrace("Can I Set JNI Params ?");
|
||||
if (mJNIEnv)
|
||||
DebugTrace("mJNIEnv is ok");
|
||||
if (mJNIEnv && mJNIClass)
|
||||
{
|
||||
DebugTrace("Setting JNI Params");
|
||||
g_engine->SetJNIEnv(mJNIEnv, *mJNIClass);
|
||||
}
|
||||
#endif
|
||||
|
||||
JRenderer::GetInstance()->Enable2D();
|
||||
lastTickCount = JGEGetTime();
|
||||
@@ -686,6 +726,15 @@ int SDL_main(int argc, char * argv[])
|
||||
int main(int argc, char* argv[])
|
||||
#endif //ANDROID
|
||||
{
|
||||
|
||||
#if (defined ANDROID)
|
||||
if (argc > 2)
|
||||
{
|
||||
mJNIEnv = (JNIEnv * )argv[1];
|
||||
mJNIClass = (jclass * )argv[2];
|
||||
}
|
||||
#endif
|
||||
|
||||
DebugTrace("I R in da native");
|
||||
|
||||
g_launcher = new JGameLauncher();
|
||||
|
||||
Reference in New Issue
Block a user