Sign in to follow this  
BNY

Faster table generation?

Recommended Posts

What I am programming is a sprite buffer similar to ID3DXSprite. You prepare it, add as many sprites as you need in any order, and then tell it to draw them sorted by texture and group so the calls to DrawPrimitive and SetTexture are minimal. It has a maximum limit of 5,000 sprites and 32 textures at a time. The slowest part of my implimentation is generating a texture table... When you add a sprite, you give it a pointer to a texture that is associated with it. The code searches the table for a match, and increments the count for that texture, and if there is no match, it just adds a new entry for that pointer. Here's a general idea of the code looks like:
for (USHORT i = 0; i <= m_textureCount; INCREMENT i)
{
    if (i == m_textureCount)
    {
	if (m_textureCount >= MAX_SPRITE_TEXTURES) return E_FAIL
	textureList[i] = pTexture
	INCREMENT m_textureCount
	break
    }
    else
    {
	if (textureList[i] == pTexture) 
	{
	    INCREMENT textureList[i]
	    break
	}
    }
}
In the worst case scenario, 32 textures are used and the sprite buffer has 5,000 sprites added and the 32nd texture is used most of the time. This leads to slightly less than 160,000 checks in the table. Does this seem like an unreasonable way to generate a table? This will happen only once per frame.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this