Freeing single-surface "sprites" (quads)

Blitz3D Forums/Blitz3D Programming/Freeing single-surface "sprites" (quads)

octothorpe(Posted 2005) [#1]
As part of my ongoing strategy to reinvent as many wheels as I possibly can, I'm writing a single-surface pixel-perfect sprites system using quads. I'm stuck on how to remove quads no longer in use.

Are there more options available than these two?

1. rebuild the entire surface without that one quad (I reckon this might be a little slow)

2. move the vertices off-screen and tag them for re-use later if I need another quad on that surface


Ross C(Posted 2005) [#2]
Not really :o)


jhocking(Posted 2005) [#3]
Recycling is generally the way to go, although for a general purpose system I'm not sure how to make sure you're moving them off-screen. Maybe move all the vertices to a single point so that the polygon isn't visible?


Stevie G(Posted 2005) [#4]
Would recommend recycling ...

If you set entityfx to 32+2 then you can set the vertexalpha on the individual vertices for the quad to 0 ... the it won't be rendered at all.

Stevie


John Pickford(Posted 2005) [#5]
I used to hide the unused ones, but I switched to rebuilding the surface every frame. Very slightly slower 'worst case' but most of the time this works out much faster.


octothorpe(Posted 2005) [#6]
Thanks for the feedback, everyone! I especially like the VertexAlpha idea as it seems very intuitive to me.

John Pickford: that seems odd to me. Do you have any theories on why rebuilding the entire surface every frame might be faster? Is it because your quads don't end up being recycled as much as was hoped and the increased triangle count slows down rendering?


John Pickford(Posted 2005) [#7]
Generally you'll be repositioning each active quad every frame anyway which isn't much different in CPU terms from building it from scratch.

Even if you alter only one vertex position the whole mesh gets re-sent to the video card anyway. Rebuilding each time means that the mesh is only ever as big as it needs to be.


big10p(Posted 2005) [#8]
John, do you free the mesh and create a new one each time, or do you keep the same mesh but just clear the verts/tris from it? Just wondered if one way was slightly faster than the other. Probably not, though.


John Pickford(Posted 2005) [#9]
I free the mesh each time.


big10p(Posted 2005) [#10]
Right. I'm just curious whether using ClearSurface would be slightly quicker. Maybe even just clear the triangles and leave the verts of 'deleted' quads unconnected, until they're needed again.


Techlord(Posted 2005) [#11]
I've performed test with single surface sprites and you cannot free them individually. You can only clear the surface and redraw as John P described.

You can hide them, but, they are still rendered (at least accounted for with TrisRendered()).


octothorpe(Posted 2005) [#12]
I just ran a comparison between repositioning 1000 quads' verticies and re-adding them after a clearsurface(). Repositioning was faster by 2fps, which on my machine is the equivilent of rendering roughly 1800 more quads.

1.6GHz P4, nVidia GeForce 4 MX 440

A combination of the two techniques would be pretty cool: queuing surfaces to be rebuilt when a threshold percentage of the quads on it are not in use - and restricting rebuilding to one surface per render.

I haven't tried freeing the entire mesh yet to see if that makes a difference. I imagine that would be even slower.

For now I'm going to go the simple route: clear my surfaces when I load a new map (this will happen frequently with my game - a 2d platformer) and hope I don't accumulate too many unused quads in the meantime!