MS VC++ : When you have many classes and structs...

Started by
4 comments, last by Waverider 21 years, 2 months ago
It takes a boatload of classes and structures to assemble a decent base game engine. Then you have to contend with all the classes and structs that make up the game you are laying on top of the engine. If you put it all down for a while and come back to it some time later, it might be hard to remember what everything does. How do you organize all of it? Is there anything in Visual Studio that helps present them in an easier fashion, other than creating folders in the structure listing? Do you use naming conventions that assist with the organization? Or do you complement it with an external document so you can come back to it later and say, "Oh, that''s what those classes are for"? How about a visual class diagramming tool so you can tell how classes are laid out from an inheritance and access standpoint, like you see in the MFC documentation? What do all of you use to help keep those gigantic projects organized, showing a clear separation between the base engine classes and the game specific classes? Or the classes that are involved in inheritance with each other? I''m currently using version 6.0. Does 7.0 offer something in this area? Thanks for any insight. This is one area of C++ programming I never really developed for myself. Any links to tools, articles or books along these lines would be appreciated! I also just wanted to find out what works well for you.
It's not what you're taught, it's what you learn.
Advertisement
I simply give the classes an obvious name. CCamera is the camera, Vector3D is a 3D vector, CTerrain is the top Terrain class and CTerrainLeaf is a leaf in the terrain. Don''t become too cryptic when it comes to class names. You won''t be typing these names all the time anyway.
I also tend to comment the *.h files a lot to explain the member functions and variables, although usually the cpp files are commented with a comment block preceding the function, but this way actually saves me a lot of scrolling, since the cpp files are often quite big (if you have complex algorithms).

Having multiple header files also helps. For example I have all of my terrain classes in the terrain.h file (CTerrain, CTerrainNode, CTerrainLeaf) and all functions that are part of the terrainclasses in Terrain.cpp.
This also helps when I want to use my class in another game/project.

At school we also learned to make class diagrams, on PAPER (yes, the stuff they used in the dark ages and so). When you design your game you usually have an idea of the structure in the back of your mind, so you write it down and prolly make a treeview of it. Keep it on paper because it''s easier to modify and easier to have as a reference.

Those are my two cents, although I still have a lot to learn in this particular area too (thanks for the submapping in the project idea BTW )
STOP THE PLANET!! I WANT TO GET OFF!!
One thing you''ll see a lot is that different parts of the project are stored as subprojects (search for subprojects in your MSVC help). So, for example, the renderer, gui, particle engine, sound engine, scripting engine, file system are all sub-projects in the main workspace. Each of these could be compiled as static libraries or DLLs and linked to main program.

Naming conventions help, I''ve noticed that especially when using DLLs lots of people tend to prefix/tag all your classes or functions with an identifier.
Seens like you need 2 little things: UML and an automatic documentation generator.

Use UML to draw the layout of your system, you don''t need to use full UML, as I doubt anyone does, class and actor diagrams are enouth for simple needs. You can grab a tool at freshmeat.net or get Rational Rose if have the $ for it.

An automatic documentation generator, like javadoc, qdoc or doxygen creates a huge doc by parsing your source files and reading special formed comments, for C++ I say doxygen is better over qdoc.

It might end that all you need is just doxygen, it really helps.
Hmm... so I could prefix all the sound, graphics and menu classes with Snd, Grp and Mnu, as an example. That might help.

I''ll experiment with splitting the code into separate LIBs or DLLS, too.

And I''ll look up the software suggestions. Thanks!
It's not what you're taught, it's what you learn.
I''ve found prefixing names with letters describing the subsystem works well for globals. For classes, I just give things an obvious name, and sometimes stick to general naming conventions.

I also use the File View in VC++/VS.NET more than the Class View. Organizing the files within folders seems to help a lot. In VC++ at least, the folder structure disappears in the Class View sometimes, which is why I don''t normally use it.

This topic is closed to new replies.

Advertisement