【发布时间】:2020-06-09 11:44:32
【问题描述】:
谁能解释我的代码的问题?
我在程序开始时启动了两个协程。它们是:
loader = StartCoroutine(loadobjectsfromfile);
buffer = StartCoroutine(setBufferToSpesificLocation(0));
简单解释一下
loadobjectsfromfile 从文件中读取 obj 并将它们添加到 List<GameObjects> loadedObject。 Ant 它会继续读取,直到缓冲区已满。
IEnumerator loadobjectsfromfile(string filepath, List<GameObject> objs)
{ while(...)
{
// other code lines
// ...
loadedObject.Add(gam);
while (full_)
{
yield return null;
}
k++;
yield return null;
} }
setBufferTheSpesificLocation 将列表中的对象添加到 buffer[] 数组。它还会放置对象,直到缓冲区已满。
IEnumerator setBufferToSpesificLocation(int startPoint)
{
for ( foo = startPoint; foo < loadedObject.Count; foo++)
{
while (full_)
{
yield return null;
}
put(loadedObject[foo]);
yield return null;
}
}
void put(GameObject frame)
{
buff_[head_] = frame;
head_ = (head_ + 1) % bufferSize;
full_ = head_ == tail_;
}
最后一部分,我们如何清空缓冲区?我调用 display 调用的其他协程。
IEnumerator displayMesh(GameObject[] objs)
{
while (!empty())
{
// other lines
full_ = false; // have a free space
}
}
好吧,如果我启动前两个协程,然后调用最后一个协程(没有问题。我的代码运行良好。但是我遇到了一个新案例的问题。
loader = StartCoroutine(loadobjectsfromfile);
buffer = StartCoroutine(setBufferToSpesificLocation(0));
StopCoroutine(buffer);
buffer = StartCoroutine(setBufferToSpesificLocation(50)); //
play = StartCoroutine(displayMesh(buff_));
问题是,加载器在调用第二个缓冲区协程后在这种情况下不起作用。当“( foo = startPoint; foo < loadedObject.Count; foo++)”结束时,加载程序正在工作。
我不明白。我认为,如果full_ 为假,则加载器和缓冲区都必须工作,但只有缓冲区在工作,加载器正在等待“buffer for{} loop”
【问题讨论】: