Skip to main content
gamedev.net
🔒 Locked

Game code arhictecture

Started by n3Xus Aug 23, 2011 at 10:26 AM 1 replies 1.3k views
Original Post
n3Xus
n3Xus
Hello,

I've been thinking about "game engine code design" a lot, lately I've shifted to just "game code design".

Obviously you can have a entire game engine which is quite flexible and allows you to do many stuff, versus a less flexible architecture suited just for the game you are currently making.


What I came up so far is that you have a couple of totally independent modules, which can be reused no matter what kind of a game you make:

-physics simulator (could be a wrapper around something like Havok or PhysX)
-AI simulator (make something very simple on my own) - well for this one you would obviously add new AI behaviour based on the game type
-renderer (wrapper around directX, openGL or whatever)
-user input (keyboard,mouse)


The thing I want your opinion on is how to design the "glue" code, the code the connects all modules into a game (so the code that makes the actual game & gameplay mechanics).


Right now I'm working on a simple top-down space shooter for Android.
The player is in control of a base that can rotate around and shoot incoming enemies, but it cannot move.

So how would you go and design the glue code?

The most obvious way that I saw it was to create a common class for everything that does something/is visible in the game world (so a super class like "Entity" or "Actor").
Then I would use single inheritance and derive all of my game objects from it, for example:
-ActorPlayerBase
-ActorEnemyWeak
-ActorEnemyStrong
-ActorLaserWeaponBullet
-ActorPlasmaWeaponBullet

These Actors then contain objects of the Renderer, Physics, AI and user input modules.

So for example, the enemies: I read the stuff from the AI module (in which direction the enemy should go or whatever), apply this to the physics object of this Actor and then use the physics object to move the Renderer object of this Actor.

What do you think of this? Would this be a "proper" way to use object oriented design since it is just single inheritance (and don't forget that the game is meant to be very simple)?


I hear a lot about the data driven approach, could you explain to me how the data driven approach could be used in a simple top-down shooter like the one I'm making?
Computercodemonkey
Computercodemonkey



The thing I want your opinion on is how to design the "glue" code, the code the connects all modules into a game (so the code that makes the actual game & gameplay mechanics).



well id say fast and modular with simple easy to use interfaces
on the other hand i could also say there are excellent 2d engines already in development that would im sure love a extra hand
look up Orx engine very promising but they have from what i can tell 1 programmer working on it now so if you just wanna build a bad ass engine try Orx Project
i would love to use orx but it misses the mark on just enough functions that im building a proprietary single use engine
haegarr
haegarr

...
The thing I want your opinion on is how to design the "glue" code, the code the connects all modules into a game (so the code that makes the actual game & gameplay mechanics).

Right now I'm working on a simple top-down space shooter for Android.
The player is in control of a base that can rotate around and shoot incoming enemies, but it cannot move.

So how would you go and design the glue code?

The most obvious way that I saw it was to create a common class for everything that does something/is visible in the game world (so a super class like "Entity" or "Actor").
Then I would use single inheritance and derive all of my game objects from it, for example:
-ActorPlayerBase
-ActorEnemyWeak
-ActorEnemyStrong
-ActorLaserWeaponBullet
-ActorPlasmaWeaponBullet

These Actors then contain objects of the Renderer, Physics, AI and user input modules.

That seems me wrong. On the one hand you want compositing game objects (i.e. "objects of the Renderer, Physics,"...) and on the other hand you want do create the fateful inheritance tree. Although it is possible to mix both approaches, you should IMHO favor the one or the other. And to be precise, you should IMHO favor compositing.


So for example, the enemies: I read the stuff from the AI module (in which direction the enemy should go or whatever), apply this to the physics object of this Actor and then use the physics object to move the Renderer object of this Actor.

What do you think of this? Would this be a "proper" way to use object oriented design since it is just single inheritance (and don't forget that the game is meant to be very simple)?

This sounds like the sub-systems being libraries but not active parts of the game, and the entire control flow is based on the game objects itself. That will probably not work well. Please notice that it is in general better to update game objects in functional blocks. E.g. collision detection requires all objects to have updated placement and poses. Collision correction may influence placement and/or pose. Rendering then can be done only if collision processing has concluded. Similarly, physics updates are usually run at a fixed rate different to the frame rate.

Not that I urge you to follow the design in detail, but you may want to read the excerpt about game loops from the book Game Engine Architecture by Jason Gregory. It gives IMHO an insight of how control flow should be managed in general.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.