我应该在我的OpenGL ES游戏中使用多个线程吗? [英] Should I use multiple threads within my OpenGL ES game?

查看:158
本文介绍了我应该在我的OpenGL ES游戏中使用多个线程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款包含一名玩家和许多敌人的iPhone游戏。我使用OpenGL ES来显示游戏视觉效果。

I am developing an iPhone game which contains one player and many enemies. I use OpenGL ES to display the game visuals.

我对是否应该只使用一个线程或使用多个线程来移动和控制播放器感到困惑敌人你对这个基本的游戏架构有什么建议?

I am a little confused as to whether I should only use one thread or use multiple threads for moving and controlling the player and the enemies. What do you recommend for this basic game architecture?

推荐答案

我会在这个问题上与Max不同意并说你不应该完全忽略在您的应用程序中使用多线程。 OpenGL ES可以从后台线程中获取,但是您一次只能使用一个线程与OpenGL ES上下文进行通信。

I'm going to disagree with Max on this one and say that you shouldn't completely ignore using multithreading in your application. OpenGL ES can be drawn to from a background thread, but you can only communicate to an OpenGL ES context using a single thread at a time.

Apple有一整段标题并发和OpenGL ES 在他们的iOS OpenGL ES编程指南中。在这里,他们描述了几种使用多线程提高OpenGL ES应用程序性能的方案。

Apple has an entire section entitled "Concurrency and OpenGL ES" in their OpenGL ES Programming Guide for iOS. In that, they describe several scenarios for improving performance of an OpenGL ES application using multithreading.

一般情况下,建议您从主线程中移除耗时的操作。主线程处理应用程序的用户界面,如果阻止,则会阻止标准UI元素更新和触摸事件注册。根据游戏幕后(物理,人工智能等)的处理程度,您可能需要将其中的大部分内容移动到后台主题。

In general, it's recommended that you move time-consuming operations off of the main thread. The main thread handles the user interface of your application, and if you block that you will prevent standard UI elements from updating and touch events from registering. Depending on how much processing is being done behind the scenes for your game (physics, AI, etc.), you may need to move significant chunks of that to a background thread.

多线程不是一个简单的主题,但Apple通过Grand Central Dispatch使这一过程变得更加容易,因此我强烈建议您阅读并发编程指南,描述了在您的应用程序中实现多线程的这一技术和其他技术。另外,我在iOS开发课程中教授了多线程和GCD课程,其中的视频可以是在iTunes U上找到

Multithreading is not a simple topic, but Apple has made this a lot easier through Grand Central Dispatch, so I highly recommend reading their Concurrency Programming Guide which describes this and other techniques for achieving multithreading in your application. Additionally, I taught a class on multithreading and GCD as part of my course on iOS development, the video of which can be found on iTunes U.

随着Apple推出多核设备,利用多线程和GCD现在将在未来为您带来巨大回报。

As Apple rolls out multicore devices, taking advantage of multithreading and GCD now will greatly pay off for you in the future.

这篇关于我应该在我的OpenGL ES游戏中使用多个线程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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