SceneKit - 线程 - 如何处理哪个线程? [英] SceneKit - Threads - What to do on which thread?

查看:157
本文介绍了SceneKit - 线程 - 如何处理哪个线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用SceneKit时,更新方法:

When using SceneKit, the update method:

func renderer(aRenderer: SCNSceneRenderer, updateAtTime time: NSTimeInterval)    

未在主thead上调用,但在其他线程上调用。

is not called on the main thead, but on some other thread.

我应该在主线程上做什么,以及在这个SceneKit线程上需要做什么?

What am I supposed to do on the main thread, and what has to be done on this "SceneKit thread"?

我应该在哪里添加新节点/ geometry?

Where should I add new nodes / geometry?

修改这些对象的位置/等在哪里安全?

Where is it safe to modify position / etc of these objects?

推荐答案

问题是关于scenekit。实际上,节点/几何体不会添加到主线程上,即使这是您执行此操作的位置。 Scenekit不在主线程上呈现。更改将批处理到呈现线程。如果渲染是UI,则它不在主线程上。实际上,如果你在主线程上进行了更改,那么你就会感觉不好,因为渲染线程试图渲染被破解的对象。这就是为什么removefromparent在Apples香蕉游戏中的SCNTransaction中。因此删除发生在渲染线程而不是主线程上。添加以相同的方式进行批处理。它实际上并没有添加到主线程上。

The question is about scenekit. Nodes/geometry aren't actually added on the main thread even if that's where you do it. Scenekit does not render on the main thread. Changes are batched to the rendering thread. If rendering is the UI, it's not on the main thread. In fact, if you make changes on the main thread you'll get bad exc because the rendering thread is trying to render the object that got nuked. Which is why removefromparent is inside a SCNTransaction in Apples banana game. So the removal happens on the rendering thread not the main thread. Adding gets batched the same way. It's not actually added on the main thread.

所以请注意,同时有一个渲染线程。如果你在主线程上使用scene.rootnode进行枚举,你将从渲染线程中发生崩溃,从而对rootnode进行更改。但由于事情发生的速度很快,因此可能非常罕见。一般来看看香蕉游戏,狐狸游戏,看看他们如何使用它。

So just be aware that there's a rendering thread going at the same time. If you do an enumerate with the scene.rootnode on the main thread you'll get crashes from the rendering thread making changes to the rootnode. But since things happen so fast it will probably be pretty rare. In general go check out the banana game, the fox game, and see how they use it.

这篇关于SceneKit - 线程 - 如何处理哪个线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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