Original Post
Ok, I''m in the very beginning of putting together a class structure that one day, far down the road, will hopefully develop into a nice cross-platform(Win, PS2, XBox, etc) game engine. And so I''m wondering, what are people''s general thoughts/practices on the class hierarchy design of such a beast.
In other words, which things are general enough that you''d put it in the base class? Which things would you put in the base class, but declare as virtual? And how would you setup the build process for multi-platform use. My current thinking has been along these lines:
1. Declare a base "CGameEngine" class that has a few virtual functions....Init(), Shutdown(), and Update()
2. Derive my "CGame" class from "CGameEngine"
3. Assign the target platform to a member variable of CGame, like "m_TargetPlatform"
4. CGame would then implement the Init, Shutdown, and Update functions & call the appropriate stuff depending on the target platform
Now, the only problem is that I now have a bad feeling that by using the target platform in at such a high level in the hierarchy that I''m gonna run into all kinds of scenarios where I have almost-duplicate code all over the place for each platform since for many tasks things will basically work the same except for a small detail here or there.
So now, I''m thinking that it might be better to still assign CGame a "m_TargetPlatform" but not use it right away. Instead, I hold on to that assignment until I get to much lower level things, like SetupGraphics, or SetupPolys() or Render() and switch based on the target platform there.
However, the problem I see with this approach (trying to keep things abstracted away from the platform for as long as possible) is that I may be backing myself into a corner where I''m forced to represent data in an odd manner in order to meet the varied needs of each platform.
Perhaps in the end there is no perfect answer, but I''m curious as to what you guys all think about this kinda thing?
-John
PS: On a somewhat related tangent, is there any advantage or disadvantage to declaring functions as virtual in a class when in doubt as to whether you''ll want to change the implemenation further down the line? For instance, is there any kind of speed/size penalty hit for making them virtual?