Jump to content
  • Advertisement
Sign in to follow this  
BNY

Faster table generation?

This topic is 3896 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 = pTexture
	INCREMENT m_textureCount
	break
    }
    else
    {
	if (textureList == pTexture) 
	{
	    INCREMENT textureList
	    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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!