orginization of a gamelib / simple engine

Started by
2 comments, last by TheGibberingFool 18 years, 9 months ago
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
Advertisement
Quote:
.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.
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:
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.
__________________________________Peter Lewis ([email=me_AT_pjblewis.com]E-mail[/email] | Portfolio)

This topic is closed to new replies.

Advertisement