diff --git a/cocos2dx/platform/android/Android.mk b/cocos2dx/platform/android/Android.mk index 2ce808353b..5c3129b04b 100644 --- a/cocos2dx/platform/android/Android.mk +++ b/cocos2dx/platform/android/Android.mk @@ -17,7 +17,6 @@ CCImage.cpp \ jni/nativeactivity.cpp \ jni/Java_org_cocos2dx_lib_Cocos2dxBitmap.cpp \ jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp \ -jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp \ jni/Java_org_cocos2dx_lib_Cocos2dxAccelerometer.cpp \ jni/JniHelper.cpp \ jni/IMEJni.cpp \ diff --git a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxRenderer.java b/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxRenderer.java deleted file mode 100644 index 7a4e74e2ba..0000000000 --- a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxRenderer.java +++ /dev/null @@ -1,171 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010-2011 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - ****************************************************************************/ -package org.cocos2dx.lib; - -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.opengles.GL10; - -import android.opengl.GLSurfaceView; - -public class Cocos2dxRenderer implements GLSurfaceView.Renderer { - // =========================================================== - // Constants - // =========================================================== - - private final static long NANOSECONDSPERSECOND = 1000000000L; - private final static long NANOSECONDSPERMICROSECOND = 1000000; - - private static long sAnimationInterval = (long) (1.0 / 60 * Cocos2dxRenderer.NANOSECONDSPERSECOND); - - // =========================================================== - // Fields - // =========================================================== - - private long mLastTickInNanoSeconds; - private int mScreenWidth; - private int mScreenHeight; - - // =========================================================== - // Constructors - // =========================================================== - - // =========================================================== - // Getter & Setter - // =========================================================== - - public static void setAnimationInterval(final double pAnimationInterval) { - Cocos2dxRenderer.sAnimationInterval = (long) (pAnimationInterval * Cocos2dxRenderer.NANOSECONDSPERSECOND); - } - - public void setScreenWidthAndHeight(final int pSurfaceWidth, final int pSurfaceHeight) { - this.mScreenWidth = pSurfaceWidth; - this.mScreenHeight = pSurfaceHeight; - } - - // =========================================================== - // Methods for/from SuperClass/Interfaces - // =========================================================== - - @Override - public void onSurfaceCreated(final GL10 pGL10, final EGLConfig pEGLConfig) { - Cocos2dxRenderer.nativeInit(this.mScreenWidth, this.mScreenHeight); - this.mLastTickInNanoSeconds = System.nanoTime(); - } - - @Override - public void onSurfaceChanged(final GL10 pGL10, final int pWidth, final int pHeight) { - } - - @Override - public void onDrawFrame(final GL10 gl) { - /* - * FPS controlling algorithm is not accurate, and it will slow down FPS - * on some devices. So comment FPS controlling code. - */ - - /* - final long nowInNanoSeconds = System.nanoTime(); - final long interval = nowInNanoSeconds - this.mLastTickInNanoSeconds; - */ - - // should render a frame when onDrawFrame() is called or there is a - // "ghost" - Cocos2dxRenderer.nativeRender(); - - /* - // fps controlling - if (interval < Cocos2dxRenderer.sAnimationInterval) { - try { - // because we render it before, so we should sleep twice time interval - Thread.sleep((Cocos2dxRenderer.sAnimationInterval - interval) / Cocos2dxRenderer.NANOSECONDSPERMICROSECOND); - } catch (final Exception e) { - } - } - - this.mLastTickInNanoSeconds = nowInNanoSeconds; - */ - } - - // =========================================================== - // Methods - // =========================================================== - - private static native void nativeTouchesBegin(final int pID, final float pX, final float pY); - private static native void nativeTouchesEnd(final int pID, final float pX, final float pY); - private static native void nativeTouchesMove(final int[] pIDs, final float[] pXs, final float[] pYs); - private static native void nativeTouchesCancel(final int[] pIDs, final float[] pXs, final float[] pYs); - private static native boolean nativeKeyDown(final int pKeyCode); - private static native void nativeRender(); - private static native void nativeInit(final int pWidth, final int pHeight); - private static native void nativeOnPause(); - private static native void nativeOnResume(); - - public void handleActionDown(final int pID, final float pX, final float pY) { - Cocos2dxRenderer.nativeTouchesBegin(pID, pX, pY); - } - - public void handleActionUp(final int pID, final float pX, final float pY) { - Cocos2dxRenderer.nativeTouchesEnd(pID, pX, pY); - } - - public void handleActionCancel(final int[] pIDs, final float[] pXs, final float[] pYs) { - Cocos2dxRenderer.nativeTouchesCancel(pIDs, pXs, pYs); - } - - public void handleActionMove(final int[] pIDs, final float[] pXs, final float[] pYs) { - Cocos2dxRenderer.nativeTouchesMove(pIDs, pXs, pYs); - } - - public void handleKeyDown(final int pKeyCode) { - Cocos2dxRenderer.nativeKeyDown(pKeyCode); - } - - public void handleOnPause() { - Cocos2dxRenderer.nativeOnPause(); - } - - public void handleOnResume() { - Cocos2dxRenderer.nativeOnResume(); - } - - private static native void nativeInsertText(final String pText); - private static native void nativeDeleteBackward(); - private static native String nativeGetContentText(); - - public void handleInsertText(final String pText) { - Cocos2dxRenderer.nativeInsertText(pText); - } - - public void handleDeleteBackward() { - Cocos2dxRenderer.nativeDeleteBackward(); - } - - public String getContentText() { - return Cocos2dxRenderer.nativeGetContentText(); - } - - // =========================================================== - // Inner and Anonymous Classes - // =========================================================== -} diff --git a/cocos2dx/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp b/cocos2dx/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp deleted file mode 100644 index aaa5e75682..0000000000 --- a/cocos2dx/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "text_input_node/CCIMEDispatcher.h" -#include "CCDirector.h" -#include "../CCApplication.h" -#include "platform/CCFileUtils.h" -#include "CCEventType.h" -#include "support/CCNotificationCenter.h" -#include "JniHelper.h" -#include - -using namespace cocos2d; - -extern "C" { - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender(JNIEnv* env) { - cocos2d::Director::getInstance()->mainLoop(); - } - - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnPause() { - Application::getInstance()->applicationDidEnterBackground(); - - NotificationCenter::getInstance()->postNotification(EVENT_COME_TO_BACKGROUND, NULL); - } - - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnResume() { - if (Director::getInstance()->getOpenGLView()) { - Application::getInstance()->applicationWillEnterForeground(); - } - } - - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInsertText(JNIEnv* env, jobject thiz, jstring text) { - const char* pszText = env->GetStringUTFChars(text, NULL); - cocos2d::IMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, strlen(pszText)); - env->ReleaseStringUTFChars(text, pszText); - } - - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeDeleteBackward(JNIEnv* env, jobject thiz) { - cocos2d::IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(); - } - - JNIEXPORT jstring JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeGetContentText() { - JNIEnv * env = 0; - - if (JniHelper::getJavaVM()->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK || ! env) { - return 0; - } - const char * pszText = cocos2d::IMEDispatcher::sharedDispatcher()->getContentText(); - return env->NewStringUTF(pszText); - } -}