When I programmed one in C#, I simply used XML and read in the values, then accessed the graphics via a hashtable; Graphic player_graphic = GraphicsMngr["Player"];
I'm not quite sure how to handle this in C++. The first problem is that I have no clue how to program an XML parser, although I suppose I could try and find a 3rd party one. Hmm, anyway...
Regardless of all this, how are *REAL* graphic managers programmed?
You can write the exact same code in C++ by writing your own GraphicsMgr class, overloading the [] operator to take a string, and looking up your graphics in a map.
So this is a library issue, not a language issue.
Like all code, you are going to have to decide upon your data structures. In C#, it sounds like that decision has been made for you. In C++, you will have to make that decision yourself, unless you find a library you wish to use.
MS has an XML parser, it is available on the Pocket PC.
I never said it was a language issue, and the data structures I used in the C# version have nothing to do with the language or the .NET framework, but rather my design decision. Obviously I can do the same thing in C++, I just don't know how. The biggest problem here is the XML parser, which I had no clue that Microsoft provided one for the Pocket PC (only ones I've heard of were 3rd party). Might you have a link and/or the name of the XML parser?
Thanks for the response.
Your data structure could be as simple as
- Code:
std::map<std::string, Graphic*>
Ah, I think hit another case of where I didn't explain myself too well (or maybe I just said something entirely different from what I ment). When I ment I didn't know how to do it in C++, I was referring to the XML aspect of it, and the fact that C++ stores resources differently than .NET (.NET uses reflection, and you access embedded resources using Namespace.FileName.ext). Sorry for the confusion.
I'll look up MSXML, thanks again for the help.
You will need a data structure in your code. Like the one I posted above, or whatever.
You will need a data format for your XML. Do you have one already or are you creating one?
Then you will need an XML parser. Try MSXML, I've never used it but it's available even on Pocket PC.
Then you will need code that is triggered by the parser and thereby fills your data For example, it might create a new Graphic object when it parses a Graphic element. It might load a surface from a file when it finds an image_name attribute. And so on.
Is that the code you are asking about?
Well, for now I'm just going to do a variation of my C# graphics manager.
http://www.danpeverill.com/gameutil.asp - scroll down to DDGameGraphics. If you're really that curious you can d/l the source.
I wasn't refering to any "code" in particular. I was however curious how other people implement graphic managers.