How do ParticleSystems do efficient batch rendering? I was skimming through the source code and I saw that they're internally stored as a doubly linked list (the way random insertion is implemented is really clever by the way), but I don't see the drawing code anywhere in ParticleSystem.cpp. I kind of assumed that SpriteBatch could use the same storage/rendering techniques that ParticleSystem does, which allows for constant-time insertion/removal.
S0lll0s wrote:edit: what the hell? am I hallucinating or was that post removed just now?
No, you're not hallucinating. I deleted it because I wanted to recheck my facts.
Anyway, is insertion/removal efficiency the only criticism of my proposal? Because I'm pretty sure it would be possible to make an implementation with good performance. For example, you could store the data in an array with gaps (that have alpha = 0) and use the gaps to coalesce the insertions and removals, so the memory layout might look like: [X1,X2,X3,_,_,_,X4,X5,X6,_,_,_,...,Xn] and inserting Y after X2 would cause the memory layout to look like [X1,X2,Y,X3,_,_,X4,X5,X6,_,_,_,...,Xn], and removing Y would similarly not shift very many of the values. If you removed or added enough things, it would propagate a shift to adjacent chunks, but I'm pretty sure you could balance it so that it would be amortized constant insertion/removal time from arbitrary points. Or you could just have a linked list of blocks size K, so that there are N/K OpenGL draw calls per SpriteBatch, but insertion/removal is O(K) instead of O(N). Both of these cause OpenGL to do a little bit more work, but it sounds like it would improve the drawing performance of ParticleSystems.