Research Coding Projects 3D

Engine Architecture

Description

This is only an example of what a game-engine architecture could look like.
I provided an example project and a PDF file witch explain how the engine works.
Basically the framework that I'm explaining could be used for any hardware acceleration rendering framework.
The example code is stripped to his bones so everybody can add things as they please to experiment with a game-engine framework.

The framwork exists out of several components.
  • Window
  • System
  • Forms
  • Graphics
  • Network
  • Sound
  • Resources
  • Game

each of them is explained in the document.
  • What the object does
  • How you should implement it
  • Advantages/Disadvantages

Every component will have a sample code at the end.
The example code that will be downloadable are all the samples togheter.

Engine

  • Own Framework

Language

  • C++

Download Document Download Documentation Download SampleDownload Source Code

Some Details

General Info

At start I would like to tell that designing a basic engine is all about modifying and replacing customized pieces of your code.
The core of the game engine will stay the same. This will reduce development time dramatically.
Best way to keep a program reusable is to build it in pieces, and by pieces I mean classes.
We will split our code into "global objects".
Wherever there is a need for a function within a component class that might change from game to game always use a "virtual function" in your base class.
The base class will never change.
Simply derive a class specific to each game you develop. The best solution is to provide blank functions as "virtual functions" so the programmer knows which functions need to be developed.

Window


The first component is the window component.
The window component contains the primary window creation routines and sets up the "WndProc" function.
The idle loop is the primary loop for the entire application.


// Window.h: interface for the Window class.
//
//////////////////////////////////////////////////////////////////////
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class Window
{
public:
	void RunWindow(void); Window();
	
	virtual ~Window();
private:
	bool CreateWindow(void);
};		

System


The second component is the system component
This object contains information about the system itself. Keyboard, mouse, joystick, and controller also the system clock will be stored in here.


// System.h: interface for the System class.
//
//////////////////////////////////////////////////////////////////////
#if _MSC_VER > 1000
#pragma once
#endif // MSC_VER > 1000
class System
{
public:
	bool Initialize(void); bool PollControls(void);
	
	System();
	virtual ~System();
protected:
	virtual bool CustomInitialization(void);
};		

Form


The third component is the form component
The forms class controls scenes to render. It makes use of the graphics class and also refers to the resources class for the images and fonts.
The complete version of the forms class should support multiple forms and have the ability to make them appear and disappear with simple function calls.
So the form object contains all menu's and controls that will be displayed in the application.


// Forms.h: interface for the Forms class.
//
//////////////////////////////////////////////////////////////////////
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class Forms
{
public:
	bool Initialize(void); 
	bool RenderForms(void);
	
	Forms();
	virtual ~Forms();
protected:
	virtual bool CustomInitialization(void);
};		

Graphics


The fourth component is the graphics component.
Operation from this class that can be performed are:
  • DrawModel()
  • DrawRect()
Deep inside the graphics object are the actual API calls to the various render routines (DirectX and OpenGL).
This class will support switching resolution and rendering API.
The reason why the API calls need to be deep in the graphics object is because the forms objects can tell the graphics object what to render with simple function calls.


// Graphics.h: interface for the Graphics class.
//
//////////////////////////////////////////////////////////////////////
#if _MSC_VER > 1000
#pragma once
#endif // MSCVER > 1000
class Graphics
{
public:
	bool RenderNumber(int p_Value); bool Initialize(void);
	
	Graphics();
	virtual ~Graphics();
protected:
	virtual bool CustomInitialization(void);
};		

Network


The fifth component is the network component.
The base version contains routines to handle rudimentary messages that deal with synching session time and player statues.
Its derived versions will have custom routines for handling what should happen when connections and disconnections occur, as well as a routine that handles the messages specific to your game.
The actual network API is hidden within the class shielding the programmer from being familiar with it.


// Network.h: interface for the Network class.
//
//////////////////////////////////////////////////////////////////////
#if _MSC_VER > 1000
#pragma once
#endif // MSCVER > 1000
class Network
{
public:
	bool Initialize(void);
	bool ReceiveMessages(void);
	
	Network();
	virtual ~Network();
protected:
	virtual bool CustomReceiveMessage(void *p_Message); virtual bool
	CustomInitialization(void);
	
	// Other types of functions
	// JoinSession( Session ID ) 
	// HostSession()
};		

Sound

The sixth component is the sound component.
This class loads sounds into memory, monitor sounds being played, and automatically interrupt sounds to make room for other sounds that are being queued up.
There will naturally be a sound-based APO embedded within the sound class.

Resource

The secenth component is the resource component.
This class will contain types of data:
  • Bitmaps
  • Fonts
  • 3D Models
  • Animations
An idea to code this class is to tell the resources class where to get the date when it is actually needed,
but you could also make some kind of loading mechanism.
It will also be necessary for very large projects to release data to make room for more to keep memory from running out.

Game

The final(eigth) component is the game componenent.
The base class of this class contains data common among all games.
It contains the loop routine with all the functions to be called. The loop is called by the window class.
Classes derived from this class contain data member’s specific to a particular game being developed.


// Game.h: interface for the Game class.
//
//////////////////////////////////////////////////////////////////////
#if _MSC_VER > 1000
#pragma once
#endif // MSCVER > 1000
class Game
{
public:
	bool Initialize(void);
	bool Loop(void);
	
	Game();
	virtual ~Game();

	// This would NOT be here in the final version!!!
	// It represents a game item, that would be in a different class, referenced
	// by a class derived off Game
	
	int itemValue;
protected:
	// Overridable
	virtual bool CustomInitialization(void);
};