axmol/cocos2dx/platform/android/CCApplication_android.cpp

107 lines
2.4 KiB
C++
Raw Normal View History

2011-03-08 13:49:58 +08:00
#include "CCApplication.h"
#include "CCDirector.h"
2011-03-08 13:49:58 +08:00
#include "CCEGLView.h"
#include "Cocos2dJni.h"
#include <android/log.h>
#include <jni.h>
2011-03-08 13:49:58 +08:00
#define LOG_TAG "CCApplication_android Debug"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
NS_CC_BEGIN;
// sharedApplication pointer
2011-03-08 13:49:58 +08:00
CCApplication * CCApplication::sm_pSharedApplication = 0;
2011-03-08 13:49:58 +08:00
CCApplication::CCApplication()
{
2011-03-08 13:49:58 +08:00
CC_ASSERT(! sm_pSharedApplication);
sm_pSharedApplication = this;
}
2011-03-08 13:49:58 +08:00
CCApplication::~CCApplication()
{
2011-03-08 13:49:58 +08:00
CC_ASSERT(this == sm_pSharedApplication);
sm_pSharedApplication = NULL;
}
2011-03-08 13:49:58 +08:00
int CCApplication::run()
{
// Initialize instance and cocos2d.
if (! initInstance() || ! applicationDidFinishLaunching())
{
return 0;
}
return -1;
}
2011-03-08 13:49:58 +08:00
void CCApplication::setAnimationInterval(double interval)
{
jmethodID ret = 0;
JNIEnv *env = 0;
jclass classOfCocos2dxRenderer = 0;
if (! gJavaVM)
{
LOGD("have not java vm");
return;
}
// get jni environment and java class for Cocos2dxActivity
if (gJavaVM->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK)
{
LOGD("Failed to get the environment using GetEnv()");
return;
}
if (gJavaVM->AttachCurrentThread(&env, 0) < 0)
{
LOGD("Failed to get the environment using AttachCurrentThread()");
return;
}
classOfCocos2dxRenderer = env->FindClass("org/cocos2dx/lib/Cocos2dxRenderer");
if (! classOfCocos2dxRenderer)
{
LOGD("Failed to find class of org/cocos2dx/lib/Cocos2dxRenderer");
return;
}
if (env != 0 && classOfCocos2dxRenderer != 0)
{
ret = env->GetStaticMethodID(classOfCocos2dxRenderer, "setAnimationInterval", "(D)V");
if (ret != 0)
{
env->CallStaticVoidMethod(classOfCocos2dxRenderer, ret, interval);
}
}
}
2011-03-08 13:49:58 +08:00
CCApplication::Orientation CCApplication::setOrientation(Orientation orientation)
{
return orientation;
}
2011-03-08 13:49:58 +08:00
void CCApplication::statusBarFrame(CCRect * rect)
{
if (rect)
{
// android doesn't have status bar.
2011-03-08 13:49:58 +08:00
*rect = CCRectMake(0, 0, 0, 0);
}
}
//////////////////////////////////////////////////////////////////////////
// static member function
//////////////////////////////////////////////////////////////////////////
2011-03-08 13:49:58 +08:00
CCApplication& CCApplication::sharedApplication()
{
2011-03-08 13:49:58 +08:00
CC_ASSERT(sm_pSharedApplication);
return *sm_pSharedApplication;
}
NS_CC_END;