Advertisement

Keeping a global cache of Bitmaps

Started by February 26, 2000 11:01 PM
1 comment, last by Ratman 24 years, 6 months ago
Im still new to programming in an OO style, so I''d like some advice on how to do this: In my game, to avoid different actors loading the same image twice, I decided to make a class CGraphicManager. And to use it, you would call GetGraphic(Filename). If the image was already loaded, it will return a pointer to that image. If it hasnt, it will load it, and return a pointer. What Im not sure how to do, is, well 2 things: 1)Should my CGraphicManager have the methods of loading a bitmap from a file, and putting it on a surface (CImage in my case), or should I put that in my CImage class (which basically is a surface with some manipulation functions). Basically, should I do CGraphicManager::LoadImage(filename, CImage) or just CImage::Load(filename) 2)How should I get my CGraphicManager to each Actor class. I could pass it down to it (couldnt it just take a pointer to CGraphicManager, and then discard it?..the pointer that is, or should I keep it in the class?). Or, this is what Im not sure if this good programming practice, if I made CGraphicManager global, and the methods in my Actor classes call the CGraphicManager by instance name. like extern CGraphicManager GraphicManager, then my Actor methods (and anything else) would just use GraphicManager->GetGraphic(filename)? Any help on either question would be appreciated. Thanks Dave
There are really no good answers to the questions. Every time u develop with OOP, u have these problems, because it''s the nature of OOP. And for different architectures, u can get different answers to the same questions.
Try to sit down, and think about future development. Think about the pro''s and con''s of each method, and what problems might each method bring in the future. Then, make a decision, whatever u think is best.
Advertisement
1) I''d put it in the CImage class... that way it could hold eather a static(non-animation) image or an animation. then CGraphicsManager realy wouldn''t care wich it is as long as the Animation class was inherited from CImage.

2)this is more or less up to you... I don''t like a lot of lose globals in my code so I would pass CGraphicManager pointer to the class then store the pointer in the class... doing this way than just discarding it would help if the actor class wants to get another image from the Manager...

Great Milenko

Words Of Wisdom:
"Never Stick A Pretzel In Your Butt It Might Break Off In There."


http://www.crosswinds.net/~milenko
http://www.crosswinds.net/~pirotech

The Great Milenko"Don't stick a pretzel up your ass, it might get stuck in there.""Computer Programming is findding the right wrench to hammer in the correct screw."

This topic is closed to new replies.

Advertisement