[英]Should I use Pools for particles if i forced to re-init every particle every time i create them
I am creating a particle system in XNA4 and I've bumped into problem. 我正在XNA4中创建一个粒子系统,但我遇到了问题。 My first particle system was a simple list of particles, whose instances are created when needed.
我的第一个粒子系统是一个简单的粒子列表,其实例是在需要时创建的。 But then I read about using pools.
但后来我读到了使用池。
My second system consists of a pool, filled with particles, and an emitter/controller. 我的第二个系统包括一个充满粒子的池和一个发射器/控制器。 My pool is pretty basic, this is the code:
我的游泳池很基本,这是代码:
class Pool<T> where T: new ()
{
public T[] pool;
public int nextItem = 0;
public Pool(int capacity)
{
pool = new T[capacity];
for (int i = 0; i < capacity; i++)
{
pool[i] = new T();
}
}
public T Create()
{
return pool[nextItem++];
}
public void Destroy(T particle)
{
pool[--nextItem] = particle;
}
}
The problem is pool system is much more hungry for CPU. 问题是池系统对CPU更加饥渴。 Every time I take out particle from pool to my emitter I'm forced to re-initialize and reset particles, due the constructor absence and this is a problem.
每次我从池中取出粒子到我的发射器时我都被迫重新初始化并重置粒子,因为构造函数不存在而且这是一个问题。
Is there any point at using pools, if I re-init those particles or I should leave pools for arrays of completely identical objects that never changes? 使用池有什么意义吗,如果我重新初始化那些粒子,或者我应该为完全相同的对象的数组留下池,这些对象永远不会改变?
In an XNA application, typically object pooling isn't supposed to speed up initialization. 在XNA应用程序中,通常不应该对象池加速初始化。 It is to speed up garbage collection.
这是为了加快垃圾收集。 The GCs on consoles are slower, and in a game where your entire update function has 16 milliseconds to run, a collection pause can be visibly noticeable.
控制台上的GC速度较慢,并且在整个更新功能运行16毫秒的游戏中,收集暂停可以明显地显着。 This may or may not a concern for your particular case, especially if this is a PC application, depending on the number and lifetimes of particles you are using.
这可能是或可能不是您特定情况的问题,特别是如果这是一个PC应用程序,取决于您使用的粒子的数量和生命周期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.