JNIEXPORT jstring JNICALL Java_net_asantee_gs2d_GS2DJNI_mainLoop(JNIEnv* env, jobject thiz, jstring inputStr) { jboolean isCopy; g_inputStr = env->GetStringUTFChars(inputStr, &isCopy); video->HandleEvents(); input->Update(); // if the splash screen has already been shown, do the regular engine loop if (g_splashShown) { // if the engine hasn't been started yet (which means the previous frame was the splash screen frame), // start the engine machine before performing the regular loop if (!application) { StartApplication(); } application->Update(Min(static_cast<unsigned long>(1000), ComputeElapsedTime(video))); application->RenderFrame(); } else { // draw the splash screen and prepare the engine start DrawSplashScreen(); g_splashShown = true; } return env->NewStringUTF(AssembleCommands().c_str()); }
int main() { VideoPtr video; BaseApplicationPtr application = CreateBaseApplication(); if ((video = CreateVideo(480, 854, L"GS2D", true, true, L"assets/fonts/"))) { InputPtr input = CreateInput(0, true); AudioPtr audio = CreateAudio(0); application->Start(video, input, audio); Video::APP_STATUS status; while ((status = video->HandleEvents()) != Video::APP_QUIT) { if (status == Video::APP_SKIP) continue; input->Update(); application->Update(Min(static_cast<unsigned long>(1000), ComputeElapsedTime(video))); application->RenderFrame(); } } application->Destroy(); #ifdef _DEBUG #ifdef WIN32 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif #endif return 0; }
JNIEXPORT void JNICALL Java_net_asantee_gs2d_GS2DJNI_start( JNIEnv* env, jobject thiz, jstring apkPath, jstring externalPath, jstring globalPath, jint width, jint height) { g_splashShown = false; jboolean isCopy; const char* strApk = env->GetStringUTFChars(apkPath, &isCopy); const char* strExt = env->GetStringUTFChars(externalPath, &isCopy); const char* strGlo = env->GetStringUTFChars(globalPath, &isCopy); zip = boost::shared_ptr<Platform::ZipFileManager>(new Platform::ZipFileManager(strApk)); Platform::FileIOHubPtr fileIOHub(new Platform::AndroidFileIOHub(zip, strExt, strGlo, ETHDirectories::GetBitmapFontDirectory())); video = CreateVideo(width, height, fileIOHub); input = CreateInput(&g_inputStr, true); audio = CreateAudio(0); video->ResetVideoMode(width, height, Texture::PF_DEFAULT, false); audio->SetGlobalVolume(g_globalVolume); splashSprite = video->CreateSprite(GS_L("assets/data/splash.bmp")); // if the application is already initialized, let's reset the device if (application) { application->Start(video, input, audio); } }
JNIEXPORT jstring JNICALL Java_net_asantee_gs2d_GS2DJNI_runOnUIThread(JNIEnv* env, jobject thiz, jstring inputStr) { jboolean isCopy; const std::string str = env->GetStringUTFChars(inputStr, &isCopy); const std::string outStr = application->RunOnUIThread(str); return env->NewStringUTF(outStr.c_str()); }
JNIEXPORT jstring JNICALL Java_net_asantee_gs2d_GS2DJNI_destroy(JNIEnv* env, jobject thiz) { application->Destroy(); video->Message(GS_L("Application resources destroyed"), GSMT_INFO); g_globalVolume = audio->GetGlobalVolume(); return env->NewStringUTF(GS_L("")); }
JNIEXPORT void JNICALL Java_net_asantee_gs2d_GS2DJNI_restore(JNIEnv* env, jobject thiz) { if (application) { application->Restore(); } }
static void StartApplication() { if (!application) application = CreateBaseApplication(); application->Start(video, input, audio); }