2011-08-31 3 views
2

나는 Irrlicht의 안드로이드 포트를 http://gitorious.org/irrlichtandroid/에서 컴파일하여 SkyBox를로드하는 애플리케이션을 만들었습니다. 그러나 예측할 수없는 프레임 속도를 얻습니다. 에뮬레이터에서 fps는 5를 넘지 않습니다. eclair를 사용하는 DELL XCD35에서는 일반적으로 10 fps를 넘지 않지만 10 회 중 약 1 회에 60fps로 실행됩니다. 활동이 전체 화면 가로 모드로 구성되었습니다.안드로이드에서 Irrlicht를 사용한 낮은 프레임 속도

다음 코드는 클래스 헤더 파일을 생략하여 게시물을 짧게 유지합니다.

BlueStoneActivity.java

public class BlueStoneActivity extends Activity { 
    static { 
     System.loadLibrary("irrlicht"); 
     System.loadLibrary("bluestone"); 
    } 

    GLSurfaceView glView; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     glView=new GLSurfaceView(this); 
     glView.setRenderer(new IrrlichtRenderer(this)); 
     setContentView(glView); 
     Debug.startMethodTracing("bstone"); 
     nativeOnCreate(); 
    } 

    @Override 
    protected void onDestroy() { 
     nativeOnDestroy(); 
     super.onDestroy(); 
     Debug.stopMethodTracing(); 
    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
    } 

    public native void nativeOnCreate(); 
    public native void nativeOnDestroy(); 
    public native void nativeOnPause(); 
    public native void nativeOnResume(); 
    public native void nativeOnResize(int w, int h); 
    public native void nativeDrawIteration(); 
} 

IrrlichtRender.java

public class IrrlichtRenderer implements Renderer { 
     BlueStoneActivity activity; 

     IrrlichtRenderer(BlueStoneActivity activity){ 
      this.activity=activity; 
     } 

     @Override 
     public void onDrawFrame(GL10 arg0) { 
      activity.nativeDrawIteration(); 
     } 

     @Override 
     public void onSurfaceChanged(GL10 gl, int width, int height) { 
      activity.nativeOnResize(width, height); 
     } 

     @Override 
     public void onSurfaceCreated(GL10 arg0, EGLConfig arg1) { 
     } 
    } 

JNI 래퍼

#include <jni.h> 
#include <android/log.h> 
#include "EngineManager.h" 
#include "InputManager.h" 

game::EngineManager *engine; 

int importGLInit(); 
void importGLDeinit(); 

#ifndef _Included_com_devin_BlueStoneActivity 
#define _Included_com_devin_BlueStoneActivity 
#ifdef __cplusplus 
extern "C" { 
#endif 

JNIEXPORT void JNICALL Java_com_devin_BlueStoneActivity_nativeOnCreate 
    (JNIEnv *, jobject){ 
    engine=new game::EngineManager(); 
} 


JNIEXPORT void JNICALL Java_com_devin_BlueStoneActivity_nativeOnDestroy 
    (JNIEnv *, jobject){ 
    engine->device->drop(); 
    importGLDeinit(); 
} 

JNIEXPORT void JNICALL Java_com_devin_BlueStoneActivity_nativeOnResize 
    (JNIEnv *env, jobject thiz, jint width, jint height){ 
    __android_log_print(ANDROID_LOG_INFO, "NDK", "ONRESIZE - [%d %d]", width, height); 
    engine->mWidth=width; 
    engine->mHeight=height; 
    importGLInit(); 
    engine->glInit(); 
} 


JNIEXPORT void JNICALL Java_com_devin_BlueStoneActivity_nativeDrawIteration 
    (JNIEnv *, jobject){ 
    engine->drawIteration(); 
} 


JNIEXPORT void JNICALL Java_com_devin_BlueStoneActivity_nativeOnPause 
    (JNIEnv *, jobject){ 
} 


JNIEXPORT void JNICALL Java_com_devin_BlueStoneActivity_nativeOnResume 
    (JNIEnv *, jobject){ 

} 


#ifdef __cplusplus 
} 
#endif 
#endif 

EngineManager.cpp

#include <irrlicht.h> 
#include "EngineManager.h" 

namespace game { 

EngineManager::EngineManager() { 
    input=new game::InputManager(); 
    app=new game::ApplicationManager(input); 
} 

EngineManager::~EngineManager() { 
} 

void EngineManager::glInit(){ 
    device=createDevice(video::EDT_OGLES1, core::dimension2d<u32>(mWidth, mHeight), 16, false, false, false, 0); 
    driver=device->getVideoDriver(); 
    scenegraph=device->getSceneManager(); 
    guienv=device->getGUIEnvironment(); 

    app->initApp(device); 
} 

void EngineManager::drawIteration(){ 
    device->run(); 
    driver->beginScene(true, true, app->clearColor); 

    app->drawIteration(); 

    scenegraph->drawAll(); 
    guienv->drawAll(); 
    driver->endScene(); 
} 

} /* namespace game */ 

ApplicationManager.cpp

#include "ApplicationManager.h" 
#include "InputManager.h" 

namespace game { 

ApplicationManager::ApplicationManager(InputManager *in) { 
    this->input=in; 
} 

ApplicationManager::~ApplicationManager() { 
} 

void ApplicationManager::initApp(IrrlichtDevice *device){ 
    this->device=device; 
    this->driver=device->getVideoDriver(); 
    this->scenegraph=device->getSceneManager(); 
    this->guienv=device->getGUIEnvironment(); 

    // Camera setup 
    camera=scenegraph->addCameraSceneNode(); 
    camera->setPosition(core::vector3df(20.0f, 15.0f, 15.0f)); 
    camera->setTarget(core::vector3df(0.0f, 0.0f, 0.0f)); 

    // Sample objects 
    bool sceneLoaded=scenegraph->loadScene("/sdcard/BlueStone/redsky.irr"); 
    if(sceneLoaded) 
     __android_log_print(ANDROID_LOG_INFO, "NDK", "SceneLoaded"); 
    else 
     __android_log_print(ANDROID_LOG_INFO, "NDK", "SceneLoaded false"); 

    clearColor=video::SColor(255, 20, 40, 40); 
    statsText=L"START"; 
    text=guienv->addStaticText(statsText.c_str(), core::recti(50,50,50+100,50+60), true, true, 0, 18, false); 
    text->setOverrideColor(video::SColor(255, 64, 20, 20)); 
} 

void ApplicationManager::drawIteration(){ 
    statsText=L"FPS: "; 
    statsText+=driver->getFPS(); 
    text->setText(statsText.c_str()); 
} 

} /* namespace game */ 

도와주세요!

답변

5

마침내 발견되었습니다!

Android SDK에는 버그가있는 것으로 보입니다. 'android : screenOrientation = "landscape"'를 사용하여 AndroidManifest.xml에서 화면 방향을 가로 방향으로 설정하려고하면 GLSurfaceView에서 프레임 속도가 느려집니다. 코드에서 사용

this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

는 모든 문제를 해결했다. 이제 내 코드가 일관된 60fps로 실행됩니다.

+0

안드로이드 플랫폼에서 Irrlicht 및 Bullet 물리 엔진을 설정하는 좋은 지침을 알고 있습니까? 또는 설치하기 위해 내가해야 할 일을 말해 줄 수 있습니까? http://gamedev.stackexchange.com/questions/17572/how-do-you-setup-the-irrlicht-and-bullet-engines-for-android-development에서 저에게 연락하십시오. – Metropolis

관련 문제