Search This Blog

Monday, May 9, 2011

Game Engine overview

When working on a game, it is important to know how your ideas will be integrated into the whole of the project.  With this in mind, I've decided to write a few articles highlighting the internal functioning of the game engine.  I'll start with an overview of the core engine, and fill in details as necessary.  Keep in mind that these are design concepts, and some of the functionality listed here is not implemented fully yet.

Program start:
Load localization settings
Locate and load startup scripts
Query graphics adapter properties
Set main window settings, and set up graphics/audio device for rendering
Main Engine Loop:
   Get keyboard/mouse inputs
   Get network packets
   Execute scripts
   Update sprite animations
   Update vectors/state data
   Send network packets
   Render audio
   Render graphics
End Main Engine Loop
Cleanup loaded game resources
Release graphics/audio adapters

And now for the explanations.

Load localization settings:
Different regions of the world process data differently, and display it to users differently.  For example, some places use commas for digit grouping, and others use a period.  These settings are saved in the operating system, but we have to retrieve them in order to use them.  This happens here.  Also, translation files are loaded at this point.

 Locate and Load startup scripts:
Because I want the engine to be as customizable as possible, all game engine activity will be governed by scripts, including the startup and initialization of the engine itself.  The script engine will be responsible for setting up the graphics and audio adapters, including choosing display resolutions and setting audio sample rates. 

Query graphics adapter properties:
At this point, the engine will collect a list of adapters and possible resolutions and color depths that can be used. 

Set main window settings, and set up graphics/audio device for rendering:
The control of the engine is turned over to the script engine at this point.  The script directs setting display properties, and getting the hardware ready for the game.

Get keyboard/mouse inputs:
Once every game frame, keyboard and mouse states are updates, and if a controller/joystick are in use, the states of them are pulled.

Get network packets:
If a script has initiated the network adapters, then at this point any newly received packets are processed, decoded, and the data is fed into the script engine ready for processing.

Execute scripts:
This is where the real work gets done in the engine.  The script engine is in charge of loading resources, discarding them, and all internal workings of the game's finite-state machine.  This part of the engine is by far the most complex, and therefore I'll write a separate article about it later.

Update sprite animations:
Many of the commands in the script language are dedicated to making it easier to write games.  Many of them are aimed at automating many things in the game, including sprite animations.  Those are handled here.

Update vectors/state data:
Just like the sprite animations, many commands handle automated motions (vectors).  These are updated here.

Send network packets:
If the network is in use, once all of our state data is processed, we then transmit any updates to this to connected client games.

Render audio:
Any sound effects that have been triggered will be started here, and any background music that is playing will be updated as well.

Render graphics:
Now that all of the state data have been updated, we can begin rendering the graphics.  This is by far the most processor time consuming part of the game engine.  An article will be devoted to this later.

Cleanup loaded game resources:
Once the scripts indicate the game should close, all the resources that have been loaded will be cleaned up, and all processing threads will be asked to close.

Release graphics/audio adapters:
All graphics/audio adapter resources that have been allocated will be released at this point.


I'll write articles later on that cover the more detailed processes, specifically the network engine, graphics rendering, and the script engine.

2 comments:

  1. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
    html5 converter

    ReplyDelete
    Replies
    1. You're very welcome.
      I'm working on a number of things right now that occupy most of my time, but I am making progress on this. I hope to have something to post soon.

      Delete