Paste
Pasted as C++ by registered user yulf88 ( 9 years ago )
JNIEXPORT jlong JNICALL
Java_com_alipay_android_phone_alice_AliceManager_nativeStart(JNIEnv *env, jclass type,
jlong nativeObject, jobject callBack,
jobject params) {
jstring jScenePath = (jstring) getValueFromBundle(params, env, "SCENE_PATH");
if (NULL == jScenePath) {
GP_ERROR("SCENE_PATH not set");
return 0;
}
const char *scenePath = env->GetStringUTFChars(jScenePath, 0);
jstring jRoleNodeNames = (jstring) getValueFromBundle(params, env, "ROLE_NODE_NAMES");
if (NULL == jRoleNodeNames) {
GP_WARN("ROLE_NODE_NAMES not set");
}
const char *roleNodeNames =
jRoleNodeNames == NULL ? EMPTY : env->GetStringUTFChars(jRoleNodeNames, 0);
jstring jAcationNode = (jstring) getValueFromBundle(params, env, "ACTION_NODE_NAME");
const char *actionNode = jAcationNode == NULL ? EMPTY : env->GetStringUTFChars(jAcationNode, 0);
jstring jAnimationNode = (jstring) getValueFromBundle(params, env, "ANIMATION_NODE_NAME");
const char *animationNode =
jAnimationNode == NULL ? EMPTY : env->GetStringUTFChars(jAnimationNode, 0);
jstring jAnimationClipsPath = (jstring) getValueFromBundle(params, env, "ANIMATION_CLIPS_PATH");
const char *animationClipsPath =
jAnimationClipsPath == NULL ? EMPTY : env->GetStringUTFChars(jAnimationClipsPath, 0);
jstring jDefaultAnimation = (jstring) getValueFromBundle(params, env, "DEFAULT_ANIMATING");
const char *defaultAnimation =
jDefaultAnimation == NULL ? EMPTY : env->GetStringUTFChars(jDefaultAnimation, 0);
jstring jResourcePath = (jstring) getValueFromBundle(params, env, "RESOURCE_PATHS");
const char *resourcePath =
jResourcePath == NULL ? EMPTY : env->GetStringUTFChars(jResourcePath, 0);
if (env->ExceptionCheck()) { GP_ERROR(" a o"); }
GP_INFO("native Start");
Ant3dConfig *ant3dConfig = new Ant3dConfig();
ant3dConfig->_scenePath = scenePath;
ant3dConfig->_actionNode = actionNode;
ant3dConfig->_animationNode = animationNode;
ant3dConfig->_animationClips = animationClipsPath;
ant3dConfig->_animationClipName = defaultAnimation;
//拿到上下文, 替换虚拟机环境, 注册回调
surface_context *surfaceContext = (surface_context *) nativeObject;
surfaceContext->addRef();
surfaceContext->env = env;
surfaceContext->callbackObj = callBack;
ant3dConfig->_context = surfaceContext;
ant3dConfig->_onCallBack = call_back_to_java;
ant3dConfig->_resourcePaths = splite(resourcePath, ",");
ant3dConfig->_objectNodes = splite(roleNodeNames, ",");
Ant3dEngine *game = new Ant3dEngine(ant3dConfig);
// why not in init surface?
GP_INFO("before init EGL");
gameplay::initEGL();
GP_INFO("after init EGL, will run game ");
surfaceContext->game = game;
if (eglMakeCurrent(__eglDisplay, __eglSurface, __eglSurface, __eglContext) != EGL_TRUE) {
gameplay::checkErrorEGL("eglMakeCurrent");
GP_INFO("eglMakeCurrent failed");
}
if (gameplay::Game::getInstance()->getState() == gameplay::Game::UNINITIALIZED) {
gameplay::Game::getInstance()->run();
}
__initialized = true;
gameplay::Platform *platform = gameplay::Platform::create(game);
platform->enterMessagePump();
.....
.....
__________________________________________________
//Message Loop is as follows:
int Platform::enterMessagePump() {
__suspended = false;
JNIEnv *env = (JNIEnv *) __state2->env;
GP_INFO("enterMessagePump set envirement");
jboolean isCopy;
__sensorManager = ASensorManager_getInstance();
GP_INFO("AAssetManager __sensorManager");
__accelerometerSensor = ASensorManager_getDefaultSensor(__sensorManager,
ASENSOR_TYPE_ACCELEROMETER);
__gyroscopeSensor = ASensorManager_getDefaultSensor(__sensorManager,
ASENSOR_TYPE_GYROSCOPE);
// Get the initial time.
clock_gettime(CLOCK_REALTIME, &__timespec);
__timeStart = timespec2millis(&__timespec);
__timeAbsolute = 0L;
__state2->isLooping = 1;
while (__state2->isLooping) {
// Idle time (no events left to process) is spent rendering.
// We skip rendering when the app is paused.
if (__initialized && !__suspended) {
_game->frame();
// GP_INFO("get game frame");
// Post the new frame to the display.
// Note that there are a couple cases where eglSwapBuffers could fail
// with an error code that requires a certain level of re-initialization:
//
// 1) EGL_BAD_NATIVE_WINDOW - Called when the surface we're currently using
// is invalidated. This would require us to destroy our EGL surface,
// close our OpenKODE window, and start again.
//
// 2) EGL_CONTEXT_LOST - Power management event that led to our EGL _context
// being lost. Requires us to re-create and re-initalize our EGL _context
// and all OpenGL ES state.
//
// For now, if we get these, we'll simply exit.
int rc = eglSwapBuffers(__eglDisplay, __eglSurface);
// GP_INFO("swap buffer ");
if (rc != EGL_TRUE) {
EGLint error = eglGetError();
if (error == EGL_BAD_NATIVE_WINDOW) {
if (__state2->window != NULL) {
GP_INFO("destroyEGLSurface ");
destroyEGLSurface();
GP_INFO("swap buffer ");
initEGL();
GP_INFO("end buffer ");
}
__initialized = true;
}
else {
GP_INFO("eglSwapBuffers error");
break;
}
}
}
// GP_INFO("calling displayKeyboard");
// Display the keyboard.
gameplay::displayKeyboard(__state, __displayKeyboard);
}
gameplay::Game::getInstance()->shutdown();
gameplay::destroyEGLSurface();
return 0;
}
Revise this Paste