分析和优化游戏 android
我正在制作我的第一个 Android 游戏,它将是一个使用 opengl es 的 3D 街机游戏。我已经为此工作了很长一段时间,主要是优化引擎以适应未来的灵活性。
无论如何,现在我已经完全完成了游戏功能和所有漂亮的东西,但它在不是我的调试手机的手机上滞后。该游戏对于手机游戏来说具有相当高质量的图形,因此预计会有一点延迟,但在 Nexus S 上运行游戏和在 MyTouch 4G 上运行游戏之间的性能差异是巨大的。该游戏甚至无法在 LG Optimus 等低端手机上玩(游戏可以运行,但玩起来太不稳定)。在我的 Nexus SI 上,很少会出现断断续续的运动(我已经在游戏中实现了与帧速率无关的运动),但在 MyTouch 4G 上,这种情况更为常见,尽管游戏仍然可以玩……但
我 很烦人从桌面游戏开发背景来看,优化以前从来不是我感兴趣的主题。您有什么建议可以帮助我加快游戏速度?
我已尝试尽可能多地优化代码,并且性能已显着提高,但似乎有一些事情我错过或忽略了。这是一款巨大的游戏,拥有完整的引擎和大量的代码。
我尝试跟踪所有分配并确保它们在运行时不会被释放或遗忘,以便在您玩游戏时不会调用 GC。这基本上就是我能想到的所有事情,我不知道还有什么可以使它滞后
而且我怀疑它的网格的多边形数量,因为即使它们是高质量的,我在游戏中添加了一个选项,可以让你选择图像质量分为低、中、高,就像电脑游戏一样,低和高之间的差异在 600-900 个顶点之间!我注意到的唯一改进是加载时间。此外,没有任何特殊的后处理效果、光照、着色器、实时 SSS 等。只是有纹理的面孔:P
我提到的“lagg”也是随机冻结。我很确定它们是 GC,但也可能是其他东西,因为我认为我已经找到并控制了所有分配(有很多)。由于我的游戏与帧速率无关,因此每当它解冻时,玩家和敌人以及一切都会“向前跳跃”以跟上,这使得本来就很困难的游戏变得更加困难!
我是分析和优化的新手。我如何使用 android 调试工具(或其他第三方工具)来更好地了解我的游戏在运行时的表现,以及它何时/为何冻结,以便我可以修复它们。
另外,额外问题:):有没有办法让我在没有实际手机或不知道拥有手机的人的情况下查看它在其他手机上的表现?比如,即使我没有 Droid X,我认识的人也没有 Droid X,它的速度会多快
I'm making my first Android game which is going to be a 3D arcade-ish game using opengl es. I've been working on it for quite a long time, mainly optimizing the engine for flexibility for the future.
Anyways now I'm completely done with the games features and all the pretty stuff, but it laggs on phones that AREN'T my debug phone. The game has pretty high-quality graphics for a mobile game so a little lagg is expected, but the difference in performance between running the game on a Nexus S and running it on a MyTouch 4G is huge. The game isn't even playable on lower-end phones like the LG Optimus(the game runs, but its too choppy to play comfortably). On my Nexus S I rarely if ever get choppy movement(I've implemented frame-rate independent movement in the game) but on the MyTouch 4G it is a lot more common, although the game is still playable....but annoying
I come from a desktop game-development background, and optimization has never been subject of interest for me before. What can you recommend to help me speed up the game?
I've tried optimizing code as much as I possibly could, and the performance has improved significantly, but there seem to be some things that I've missed or am overlooking. Its a huge game with a full engine and lots and lots of code.
I've tried tracking down all allocations and making sure they aren't deallocated or forgotten during runtime so that the GC doesn't get invoked while you are playing. Thats basically all I can think of doing, I don't know what else could make it lagg
And I doubt its the poly count of the meshes because even though they are high quality, I added an option in the game that lets you choose the quality of the graphics from Low, Medium, and High much like on a computer game, and the difference between Low and High are somewhere between 600-900 vertices! The only improvement I've noticed that gives is load time. Also there aren't any special post-processing effects, lighting, shaders, realtime SSS, or any of that. Just textured faces :P
also the "lagg" I'm reffering to are random freezes. I'm pretty sure they are the GC, but it could be something else since I think I've found and controlled all allocations(there are a lot). Since my game is frame-rate independent, whenever it unfreezes, the player and enemies and everything 'jumps forward' to keep up, and this makes an already difficult game a LOT more difficult!
I'm new to profiling, and optimization. How can I use the android debug tools(or other third-party tools) to get a better picture of how my game performs during runtime, and when/why it freezes so that I can fix them.
ALSO, bonus question :) : is there a way for me to see how it would perform on other phones without actually having the phones or knowing people who have them? Like, how fast would it go on a Droid X even though I don't have a Droid X nor does anyone I know
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过使用traceview 分析代码?
插入
在 onCreate 中
,然后在您希望它完成写入文件的位置插入。要查看结果,请将设备插入计算机并运行:
这将显示哪些课程花费了更多时间。您也许可以优化较慢的类,和/或将其移至后台线程。
您提到它在某些手机上运行良好,也许这些是具有 24mb/应用程序限制而不是 16mb/应用程序限制的较新手机?您可以尝试使用 Eclipse 中的内存分析器来检查内存泄漏或不必要的大对象。要安装,请转到“帮助”->“安装软件,然后使用
然后,当您在 DDMS 视图中进行调试时,选择转储 HPROF 文件(带有红色箭头的绿色玻璃),它应该打开内存分析器。
编辑 -
看来您现在需要转换 Android-hprof 文件,如所述在这里。
Have you tried profiling the code with traceview?
insert
in onCreate, then
where you want it to finish writing the file. To view the results, plug the device into the computer and run:
This will show what classes are taking more time. You may be able to optimize the slower classes, and/or move it to a background thread.
You mentioned it works fine in some phones, perhaps those are the newer phones with 24mb/app limit instead of 16mb/app limit? You might try the Memory Analyzer in Eclipse, to check for memory leaks or unnecessary large objects. To install, go to Help -> Install Software, and use
Then, while you are debugging in DDMS view, select Dump HPROF File (The green glass with the red arrow), it should open the memory analyzer.
Edit -
It seems you need to convert the Android-hprof file now, as described here.
很多人都会这样做,即通过尝试思考来优化。这将带你走一部分路,但只是一部分,特别是当软件很大时。
实际上,代码中的内容需要时间 通过快照暴露自己以供发现。
你不需要考虑它们。
您只需让程序显示它们即可。
这是一个示例。
A lot of people do that, which is to optimize by trying to think of things. That will take you part way, but only part way, especially if the software is large.
Actually, things in the code that take time expose themselves to discovery by snapshot.
You don't need to think of them.
You just let the program display them.
Here's an example.
首先仔细看看 logcat 所说的内容。也许您会找到解决不必要的延迟问题的答案。其次,如果您想检查方法执行的频率和时间,只需使用 DDMS。不知道你使用的是什么环境,但是 Eclipse 中有一个 Perspective,其中有一个名为“Start method profiling”的选项。只需单击它,然后等待几秒钟然后取消单击它。几分钟后,您将收到压倒性的报告。
至于设备问题,让我引用一下:“如果你想知道你的应用程序在给定设备上的执行情况,你需要在该设备上进行测试。”来自 [1]
[1] http://developer.android.com/guide/实践/设计/性能.html
First of all take a closer look what logcat is saying. Maybe you'll find the answer for unwanted lag begviour. Secondly, if you want to check how often and how much time the methods executions takes just use DDMS. Don't know what kind of environment you're using, but there is an Perspective in Eclipse which has an option called "Start method profiling". Simply click on it, than wait couple of seconds and unclick it. After a few moments you'll get the overwhelming report.
And the devices issue, let me cite: "If you want to know how your app performs on a given device, you need to test on that device." from [1]
[1] http://developer.android.com/guide/practices/design/performance.html