在OpenGL Android的唯一的游戏:在C ++(NDK)与爪哇(Dalvik的)性能 [英] Android only game in OpenGL: performance in C++ (NDK) vs Java (Dalvik)

查看:167
本文介绍了在OpenGL Android的唯一的游戏:在C ++(NDK)与爪哇(Dalvik的)性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,类似的问题以前已经问过,但...

I know that similar questions have been asked before, but...

我们想开发(至少希望)一个独立的游戏,但仍然是一个游戏高品质的图形与数百如果不是thousends在屏幕上移动的物体,所以我们期待非常高的多边形和则hitTest要求也许有些AI

We want to develop (at least hope) an indie game but still a game with high quality graphics with hundreds if not thousends of moving objects on the screen so we expect very high number of polygons and requirements for hittest and perhaps some AI.

我知道基本的问题是Java的垃圾回收。但是,这不是一个问题,我们计划来分配所有的比赛开始前所需的内存和短暂的对象,我们将使用池(所以在游戏圈新的关键字将不会被写入)。我们计划使用这里提到的每一种可能的己技巧(谷歌I / O 2009 - 编写实时游戏为Android )。

I know the basic problem with java is garbage collection. But it's not an issue, we plan to allocate all of the required memory before the game starts and for transient objects we will use pooling (so in the game loop the new keyword will never be written). And we plan to use every possible techique mentioned here (Google I/O 2009 - Writing Real-Time Games for Android).

我们坚持对Java的主要的原因是部署,我们只想要开发Android的(至少目前)

The main reason we insist on Java is deployment and we only want to develop for Android (for now at least)

这样可以在一场比赛相同的性能与Java来achived(即使这意味着丑陋的/不地道code),如果我们做到了用C ++。如果不是,有什么细节?或许,如果有可能,但非常,非常不现实的这些是什么原因呢?

So can the same performance in a game be achived with Java (even if that means ugly/not idiomatic code) as if we did it with c++. If not, what are the specifics? Or perhaps if it's possible but very-very unpractical what are these reasons?

(比如我读一些有关Java缓冲区和OpenGL是不是最好的配对,但不记得细节 - 也许有些专家)

(For example I read something about java Buffers and OpenGL are not the best pairing but don't remember the specifics - maybe some expert)

推荐答案

你会得到回报每次呼叫固定的额外费用使用OpenGL Java源代码code。 Android提供各地的电话Java语言包装。例如,如果你调用调用glDrawArrays ,你调用的<一个声明的本机方法href="https://android.googlesource.com/platform/frameworks/base/+/kitkat-release/opengl/java/android/opengl/GLES20.java">GLES20.java,这是在<限定href="https://android.googlesource.com/platform/frameworks/base/+/kitkat-release/core/jni/android_opengl_GLES20.cpp">android_opengl_GLES20.cpp.您可以从code,它只是转发以最小的开销呼叫见。

You're going to be paying a fixed additional cost per call to use OpenGL from Java source code. Android provides Java-language wrappers around the calls. For example, if you call glDrawArrays, you're calling a native method declared in GLES20.java, which is defined in android_opengl_GLES20.cpp. You can see from the code that it's just forwarding the call with minimal overhead.

嗅探文件中,你可以看到,进行额外的检查,因此稍贵等电话。

Nosing around in the file, you can see other calls that perform additional checks and hence are slightly more expensive.

底线尽可能的不可避免的成本去是让很多GLES要求的价格是与Java源代码比本地源高。 (虽然看的的Andr​​oid突围,提供的 systrace 我注意到,有大量的CPU开销的驱动程序,因为我是做了很多多余的状态更新。从本地这样做的成本code会一直走低,但这样做零工作的成本小于少做工作的费用。)

The bottom line as far as unavoidable costs goes is that the price of making lots of GLES calls is higher with Java source than native source. (While looking at the performance of Android Breakout with systrace I noticed that there was a lot of CPU overhead in the driver because I was doing a lot of redundant state updates. The cost of doing so from native code would have been lower, but the cost of doing zero work is less than the cost of doing less work.)

的更深层次的问题,是因为有您是否需要写code如此不同(例如,为了避免分配),你根本无法获得相同的性能水平。你有直接的 ByteBuffer的工作对象,而不是简单的数组,这可能需要更多的管理就在你身边。但是,除了在Android上计算密集型本机和Java code之间的当前速度的差异,我不知道的事情,从根本起价严格的Java实现p $ pvents不错的表现。

The deeper question has to do with whether you need to write your code so differently (e.g. to avoid allocations) that you simply can't get the same level of performance. You do have to work with direct ByteBuffer objects rather than simple arrays, which may require a bit more management on your side. But aside from the current speed differences between compute-intensive native and Java code on Android, I'm not aware of anything that fundamentally prevents good performance from strictly-Java implementations.

这篇关于在OpenGL Android的唯一的游戏:在C ++(NDK)与爪哇(Dalvik的)性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆