Sprite engine optimization question...

Started by
2 comments, last by Khaosifix 19 years, 3 months ago
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]
---http://www.michaelbolton.comI constantly dream about Michael Bolton.
Advertisement
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.
The Wild Wild West - Desperado!
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?
________________________________pro.gram.mer - an organism that turns caffeine into code
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.
---http://www.michaelbolton.comI constantly dream about Michael Bolton.

This topic is closed to new replies.

Advertisement