Sign in to follow this  

Sprite engine optimization question...

This topic is 4725 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

Hello, I've come to realize that having 50 sprite class objects that loads in the same exact image is a waste of memory. I want to make it so that any future sprite class object that loads in a image which already resides in memory to point to the memory location of which the already loaded sprite resides....
class cShip : cObject
{

   // Same stuff as cObject but defined.

   cSprite m_sTexture ;

} ;

std::vector<cObject*> g_EnemyShips( 50 ) ;

GLvoid cGame::SetupData( )
{

   // define all 50 elements in a loop obviously
   // The problem lies here though. When 50 cObject/cShip objects
   // are defined here 50 of the same texture/image are loaded 
   // via cSprite. From my judgment it is a bad idea to have 50
   // of the game images loaded into memory. Any suggestions?
}



[Edited by - Khaosifix on January 10, 2005 12:13:06 PM]

Share this post


Link to post
Share on other sites
Use some sort of texture manager.
As a simple one this could be a simple list. Check if you have already loaded this texture. If yes, then return a pointer to the loaded texture.

Share this post


Link to post
Share on other sites
He's not necessarily using a 3D API, what if each ship has its own surface?
You could point to the already loaded image, but you would still have to blit the image onto each surface.. or?

Share this post


Link to post
Share on other sites
I'm using SDL for this. I am, however, very familiar with OpenGL and plan on using it for future projects. I think OpenGL using a similar texture manager system since each texture you load has a 32-bit ID. Maybe I should construct a system similar to that.

Share this post


Link to post
Share on other sites

This topic is 4725 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.

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