编写实时的OpenGL-ES的游戏为Android - 一些问题(优化) [英] Writing real time opengl-es game for android - some question (optimizing)

查看:116
本文介绍了编写实时的OpenGL-ES的游戏为Android - 一些问题(优化)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1

定时在游戏: 有没有办法用其他话 System.Currentmillis() - 开始时间> XX 来更新在游戏中什么?它是安全的或昂贵的CPU?

2

在我的比赛我有20个项目(移动正方形顶点),当它出现60-70的顶点时,FPS下降到30-40 FPS,60 FPS。 (测试上的Galaxy S I9000手机)。 有没有一种方法,以我的游戏FPS会30FPS?它是很好的更新我的比赛,以30 FPS,还是我不需要处理呢? (因为会有较低的FPS一个LAGG - 这将是慢)

我该怎么办我的目标运行在相同的速度,在任何时候?

3

什么是最好的办法:做phisyx,并在onDrawFrame所有stupp,或者:启动一个线程是什么做的数学给我吗?什么是更快,更好?

解决方案
  

定时在游戏:有没有办法用其他的话System.Currentmillis() - 开始时间> XX更新在游戏中什么?它是安全的或CPU贵?

您应该使用一个时间差的系统。有很多关于这个教程。这是一个非常好的教程: deWiTTERS游戏循环

  

在我的比赛我有20个项目(移动正方形顶点),当它出现60-70的顶点时,FPS下降到30-40 FPS,60 FPS。 (测试上的Galaxy S I9000手机)。有没有一种方法,以我的游戏FPS会30FPS?它是很好的更新我的比赛,以30 FPS,还是我不需要处理呢? (因为会有较低的FPS一个LAGG - 这将是慢)

这取决于你使用的方法是。如果3D,你应该考虑使用顶点缓冲对象 VBO:■)(如顶点数组,但在设备的GPU内存)。这使得一个巨大的差别,因为CPU不需要将数据从CPU复制到GPU每次迭代

如果2D,你仍然可以使用 VBO:■,但如果 draw_texture 受支持,建议在设备上。

然而,选项有:

  • 顶点数组(最慢)。
  • 顶点缓冲对象(最快在3D,比 draw_texture 在2D慢)。
  • draw_texture 扩展(最快的2D,但不渲染3D的东西)。

可以支持所有这些方法,以涵盖Android设备的整个范围,但记得要检查设备的的OpenGL 驱动程序的扩展名。有些人可能会支持所有这些,但也可以是只支持设备顶点数组 VBO:■(例如: )。

我已经回答了相关的问题<一href="http://stackoverflow.com/questions/5169338/android-deciding-between-surfaceview-and-opengl-glsurfaceview/5169425#5169425">here,但只是为了告诉你;这里是从克里斯PRUETT的讲座在谷歌I / O的一个打印:

  

我该怎么办我的目标运行在相同的速度,在任何时候?

您不能。 Android是一个多任务操作系统,你根本不知道发生了什么事情(也许另一个服务应用程序更新?)。你可以做的是使用一个时间差的系统,就像我上面提到的。

  

什么是最好的办法:做phisyx,并在onDrawFrame所有stupp,或者:启动一个线程是什么做的数学给我吗?什么是更快,更好?

它的建议,以多线程(两个的并行运行)。不久,做你的图纸里面的东西 onDrawFrame 和你自己创建的线程内更新的东西 / 的Runnable

推荐资源:

1.

TIMING in a game: Is there a way to use other then System.Currentmillis()-starttime>XX to update anything in a game? Is it safe or CPU expensive?

2.

In my game I have 20 items (moving square vertexes), when it comes up to 60-70 vertex, the FPS drop down to 30-40 FPS, from 60 FPS. (testing on a galaxy S i9000 phone). Is there a way to my game FPS will be 30FPS? Is it good for update my game to 30 FPS, or I dont need to handle this? (because there will be a lagg on lower FPS - it will be slow)

How I can do to my objects run on the same speed, at any time?

3.

what is the best way: do the phisyx, and all the stupp in onDrawFrame, or: start a Thread what is made the mathematics for me? What is faster and better?

解决方案

TIMING in a game: Is there a way to use other then System.Currentmillis()-starttime>XX to update anything in a game? Is it safe or CPU expensive?

You should use a time delta system. There are a lot of tutorials about this. This is a very good tutorial: deWiTTERS Game Loop.

In my game I have 20 items (moving square vertexes), when it comes up to 60-70 vertex, the FPS drop down to 30-40 FPS, from 60 FPS. (testing on a galaxy S i9000 phone). Is there a way to my game FPS will be 30FPS? Is it good for update my game to 30 FPS, or I dont need to handle this? (because there will be a lagg on lower FPS - it will be slow)

That's depending on which method you're using. If 3D, you should consider using Vertex Buffer Objects (VBO:s) (like a Vertex Array but in your device's GPU memory). That makes a huge difference since the CPU doesn't need to copy the data from CPU to GPU every iteration.

If 2D, you can still use VBO:s but if draw_texture is supported on the device that's recommended.

However, the options are:

  • Vertex Arrays (slowest).
  • Vertex Buffer Objects (fastest in 3D, slower than draw_texture in 2D).
  • draw_texture extension (fastest in 2D, but doesn't render 3D stuff).

You can support all of this methods to cover the whole range of Android devices but remember to check the extensions of the device's OpenGL drivers. Some might support all of these, but there can be devices that only support Vertex Arrays and VBO:s (for example).

I've answered a related question here, but just to show you; here's a print from one of Chris Pruett's lectures at Google I/O:

How I can do to my objects run on the same speed, at any time?

You can't. Android is a multi-processing operating system and you have no idea what's going on (maybe another Service application is updating?). What you can do is to use a time delta system, like I mentioned above.

what is the best way: do the phisyx, and all the stupp in onDrawFrame, or: start a Thread what is made the mathematics for me? What is faster and better?

It's recommended to multi-threading (two Thread's running in parallel). Shortly, do your drawing stuff inside onDrawFrame and update stuff inside your own created Thread/Runnable.

Recommended resources:

这篇关于编写实时的OpenGL-ES的游戏为Android - 一些问题(优化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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