Sign in to follow this  

orginization of a gamelib / simple engine

Recommended Posts

Ok lets see if i can make sense out of all these thought running through my head tonight.... my question is regarding OOP and good design.. lets say you have these classes IWINDOW // wrapper for windows creation IDIRECT3D // wrapper for D3D INIT ID3DSOUND // wrapper Direct sound IDINPUT // wrapper Direct input ISPRITE // wrapper for textured quad ITEXTURE // wrapper for texter // There would be others similar to the last to IENGINE // wrapper for all of the above IMATH // class for math and other helper functions -or- maybe just functions no class?? // the users class IGAME // used to create the game so heres what i am thinking IDIRECT3D should inherit IWINDOW IENGINE would have member variables to.. IDIRECT3D \ ID3DSOUND \ IDINPUT \ ISPRITE \ ITEXTURE IGAME shoud inherit IENGINE ..basically To inherit or just make member variables... any thoughts thanks :p

Share this post

Link to post
Share on other sites

.basically To inherit or just make member variables...
any thoughts

Don't know what are you planning to do, but generally, composition is preferred to inheritance. Please give more informations :-)

Btw, if you're writing general engine, not bound to any specific game, it's better to strive for max. flexibility and don't make too much assumptions.

Btw, letter I that stands before class name, suggests that this class is abstract, and designed to be implemented in derived classess. In your case, it doesn't look like ie. IMATH should be made abstact.

Another btw, here are some good "articles" regarding OOP and good design.

One last btw, here's link to short description of my engine: Sculpture Clay.

Share this post

Link to post
Share on other sites
Thanks for the reply

I liked reading through the design of you engine .... it really got me thinking about other things that i will have to add to mine...

basically i was working on a game in D3D ... so far the whole game is pretty much done C-style... (all in 1 file) ;(

I fully intended from the begining to write it using classes...
but now I am writting wrapper classes for Windows And D3d .. and other useful function i have come up with...

so you are saying that I should use inheritance opposed to making instatiation of objects.. even the ENGINE class ..hmm

ok well thanks again.. q:

Share this post

Link to post
Share on other sites
Koshmaar is correct - The prefix 'I' typically stands for interface, meaning that the class is pure abstract. For non-abstract classes people generally use 'C'. Of course, you're free to use whatever notation you're comfortable with.

He's also right in saying that composition is preferred to inheritance. Here is an example of a composition (from here).

Instead of a IDirect3D interface I would suggest an IRenderer interface that will be an intermetiate step to an CDirect3D class object, or something similar. This benefits you in that you can simply plug in a new renderer (such as OpenGL) at any time. Same goes for input and sound.

Regarding the window, you can probably get away with just 'CWindow' unless you're doing this multiplatform - which you're not if you're using DirectX. Also, the IMath interface should probably changed to a namespace. I can't see any benefit on having a central math class, but instead you can have a namespace of grouped math classes such as CVector, CMatrix, etc etc.

I'd also rethink your IEngine and IGame interfaces. Depending on where you want to go with this, you can approach this in many ways. For example, you could have them both as namespaces, singletons, etc. My suggestion is to have some sort of Kernel class (a small one! Nothing overkill.) and a vast selection of supporting classes that as a group form your engine and game. This article will probably help you.

When thinking about object oriented design I try to follow one guideline that a wise man once told me. If you have a class or function that does 'this' AND 'that', it should be two separate classes/functions: one for 'this' and the other for 'that'.

Hope that helps.

/Edit: Also, avoid any abuse of singletons. They're pretty much the 'modern-day global' if used recklessly. Only use them when absolutely necessary and when you are sure that there's no alternative.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this