From 8a59680175734592a460c26c4b7c75bd3cf84c60 Mon Sep 17 00:00:00 2001 From: Rohan Kuruvilla Date: Thu, 25 Apr 2013 18:21:35 -0700 Subject: [PATCH] Removing onSurfaceChange update since it was being executed after ccb_run. This resulted in frame size being changed after game was running (bug) --- .../proj.android/jni/cocosplayer/main.cpp | 32 ++----------------- .../cocosplayer/CocosPlayerSocket.java | 17 +++++++--- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/samples/Javascript/CocosPlayer/proj.android/jni/cocosplayer/main.cpp b/samples/Javascript/CocosPlayer/proj.android/jni/cocosplayer/main.cpp index 8fd7a6ad3b..ea9f6745cf 100644 --- a/samples/Javascript/CocosPlayer/proj.android/jni/cocosplayer/main.cpp +++ b/samples/Javascript/CocosPlayer/proj.android/jni/cocosplayer/main.cpp @@ -21,32 +21,6 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) return JNI_VERSION_1_4; } - -static void initRotatedView(jint w, jint h) { - if (!CCDirector::sharedDirector()->getOpenGLView()) - { - CCEGLView *view = CCEGLView::sharedOpenGLView(); - view->setFrameSize(w, h); - - AppDelegate *pAppDelegate = new AppDelegate(); - CCApplication::sharedApplication()->run(); - } - - else - { - ccDrawInit(); - ccGLInvalidateStateCache(); - - CCShaderCache::sharedShaderCache()->reloadDefaultShaders(); - CCTextureCache::reloadAllTextures(); - CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); - CCDirector::sharedDirector()->setGLDefaultValues(); - - bool isPortrait = (w < h) ? true: false; - handle_set_orient(isPortrait); - } -} - void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h) { if (!CCDirector::sharedDirector()->getOpenGLView()) @@ -74,18 +48,17 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnScreenSizeChanged(JNIEnv* env, jobject thiz, jint w, jint h) { - initRotatedView(w,h); + // handle_set_orient(w, h); } void Java_org_cocos2dx_lib_Cocos2dxGLSurfaceView_nativeRunCCB(JNIEnv* env, jobject thiz) { - LOGD("INSIDE JNI RUN CALL"); handle_ccb_run(); } void Java_org_cocos2dx_cocosplayer_CocosPlayerSocket_nativeRunCCB(JNIEnv* env, jobject thiz) { - LOGD("INSIDE JNI RUN CALL"); + LOGD("INSIDE JNI RUN CALL %d %d", gettid(), getpid()); handle_ccb_run(); } @@ -112,6 +85,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi void Java_org_cocos2dx_cocosplayer_CocosPlayerSocket_nativeSetOrientation(JNIEnv* env, jobject thiz, jboolean isPortrait) { + LOGD("INSIDE SET ORIENTATION CALL"); handle_set_orient((bool)isPortrait); } } diff --git a/samples/Javascript/CocosPlayer/proj.android/src/org/cocos2dx/cocosplayer/CocosPlayerSocket.java b/samples/Javascript/CocosPlayer/proj.android/src/org/cocos2dx/cocosplayer/CocosPlayerSocket.java index e358de49bc..c71f3b7113 100644 --- a/samples/Javascript/CocosPlayer/proj.android/src/org/cocos2dx/cocosplayer/CocosPlayerSocket.java +++ b/samples/Javascript/CocosPlayer/proj.android/src/org/cocos2dx/cocosplayer/CocosPlayerSocket.java @@ -93,10 +93,19 @@ public class CocosPlayerSocket { private static native void nativeSetOrientation(boolean isPortrait); private static native void nativeRunScript(final String script); - private static void setOrientation(String isPortrait) { - CocosPlayer.setOrientation(isPortrait.equalsIgnoreCase("true") ? - ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); - //nativeSetOrientation(isPortrait.equalsIgnoreCase("true") ? true : false); + private static void setOrientation(final String isPortrait) { + Cocos2dxGLSurfaceView.getInstance().setPreserveEGLContextOnPause(true); + Cocos2dxGLSurfaceView.getInstance().queueEvent(new Runnable() { + @Override + public void run() { + CocosPlayer.setOrientation(isPortrait.equalsIgnoreCase("true") ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + + nativeSetOrientation(isPortrait.equalsIgnoreCase("true") ? true + : false); + } + }); + } private void switchCmd(NSDictionary data) {