XCode / iOS:迭代给定类的所有实例?
我正在为 iPhone 开发 3D 游戏引擎,目前正在研究如何处理我的所有 3D 对象。我有一个类,它保存与每个 3D 对象相关的信息,例如顶点数据、纹理信息等。
我还有一个每 x 毫秒调用一次的方法,用于处理渲染 3D 场景。
在此方法内部,我想循环遍历所有 3D 对象以访问它们的渲染数据。
我意识到我可以将指向所有 3D 对象的指针存储在一个数组中并迭代该数组,但在冒险走上这条可能不必要的道路之前,我想知道是否有办法简单地迭代给定类的所有实例(即我的 3d对象类),因为这可以解决我的问题。
Pseduo:
For (obj in AEobject3D){
render obj
}
这样的事情可能吗?如果是这样,请原谅我的无知,我似乎无法在文档/互联网中找到信息,并且我仍在通过 Objective C 学习我的方法。
谢谢, - 亚当·艾斯菲尔德
I am working on a 3d game engine for the iPhone and Im currently working out how Im going to be handling all of my 3D objects. I have a class that holds information pertaining to each 3D object such as vertexdata, texture information, etc.
I also have a method that is called once every x milleseconds that handles rendering the 3d scene.
Inside of this method, I would like to loop through all of my 3D objects to get access to their render data.
I realize I could store pointers to all of my 3D objects in an array and iterate through this array, but before venturing down this possibly unnecessary road I was wondering if there was away to simply iterate through all instances of a given class (ie my 3d object class), as this would solve my problem.
Pseduo:
For (obj in AEobject3D){
render obj
}
Is something like this possible? If so please excuse the ignorance, I cant seem to find information in the docs / internet, and Im still learning my way through Objective C.
Thanks,
- Adam Eisfeld
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,没有内置的方法可以做到这一点。如果您想自己实现它,您仍然必须使用数组来跟踪对象。所以我建议你首先使用数组。
No, there's no built-in way to do this. If you wanted to implement it yourself, you'd still have to use an array to keep track of the objects. So I suggest you just use an array in the first place.
只需创建一个数组并使用它即可。例如,UIKit 也使用子视图的概念,子视图是数组中的数组。
Just make an array and be some with it. For instance, UIKit uses the concept of subviews too, which are arrays in arrays.