By David Wulff [dwulff_emtut@bttlxe.co.uk]
Contains sections of GDemo and RabidGamesFramework source code

Welcome to my thrid tutorial. This one will teach you how to implement a fully-working effect manager in GTest as seen in Eclipse's GDemo. It will also show you how you can port any of the GDemo effects to GTest with relative ease.

This tutorial is aimed at the begginer/newbie, but you should be fairly proficient in C/C++ and the GTest and GDemo sources if you want to port the effects. To use this tutorial you will need:

Right, before we start, I'll give you a quick overview of what we are going to do.

  1. We will create a manager for all of the effects in each of your levels.
  2. We will create three example effects from GDemo - rain, sprites, and spouts (used ro create fire/smoke, etc).
  3. The effects will be loaded at run-time from entities, and created and destroyed automatically by the manager.
  4. All of the effects you've seen in GDemo can be easily ported to work with the new effect manager.
  5. There will be minimal changes to your source code, and to avoid errors often gained by creating source files from an HTML image, I have zipped up all of the files, which you can grab at the bottom.
  6. New/Modified code is indicated by being green. Existing code is yellow.

Step 1 - Download the zipped source files from the base of this document. The content will not be listed here (it would take up about 2,000 lines!), but all the files are there - I have checked.

 

Step 2 - Add all the files to your project. - Sounds obvious, but you'd be amazed how many times you overlook this simple step.

 

Step 3 - In GameMgr.c, add:

#include "EffManager.h"
#include "e_rain.h"
#include "e_spout.h"
#include "e_sprite.h"

Then near the top where the GameMgr struct is defined, add the following line to the end, eg:

Eff_Manager *EM; // EffectManager Handle

GameMgr *SelfCheck2; // Tail self valid check
} GameMgr;

Now in the GameMgr_Frame() function, add the following as shown:


//
// Do an fx system frame
//
if (GMgr->FxSystem)
{
if (!Fx_SystemFrame(GMgr->FxSystem, Time))
GenVS_Error("GameMgr_Frame: Fx_SystemFrame failed.\n");
}

if (GMgr->EM)
{
if (!EM_Tick(GMgr->EM))
GenVS_Error("GameMgr_Frame: EM_Tick failed.\n");
}

Then, later on in the GameMgr_SetWorld() function, add the following towards the end of the function, as shown:


// Create the dynlight interface
if (!DynLight_Init(GameMgr_GetEngine(GMgr), GameMgr_GetWorld(GMgr), PakFS))
GenVS_Error("GameMgr_SetWorld: DynLight_Init failed.\n");

// Update the progress Bar.
LoadingBar_Draw(Engine, Camera, 90);

// Create the ModelCtl interface
if (!ModelCtl_Init())
GenVS_Error("GameMgr_SetWorld: ModelCtl_Init failed.\n");

// Set up the new Effects System
GMgr->EM = EM_Create(Engine, Camera, GameMgr_GetWorld(GMgr));

if(!GMgr->EM)
GenVS_Error("GameMgr_SetWorld: EM_Create failed.\n");

if(!Rain_Create(GMgr->EM->Engine, GMgr->EM))
GenVS_Error("GameMgr_SetWorld: Rain_Create failed.\n");

if(!Sprite_Create(GMgr->EM->Engine, GMgr->EM))
GenVS_Error("GameMgr_SetWorld: Float_Create failed.\n");

if(!Spout_Create(GMgr->EM->Engine, GMgr->EM))
GenVS_Error("GameMgr_SetWorld: Spout_Create failed.\n");

You will need to add a call to the create function of each new effect you create through the manager here. (You will also need to #include the header of each new effect).

Now do a search accross all your source files for "bttlxe\\gfx\\fx" and replace it with the path to your fx folder. You will need to copy the bitmaps in the enclosed zip file into your fx folder.

That's it.

Honestly - that is it! This must be one of the shortest tutorials out their, but go ahead and compile GTest and you will see that it works (providing you have added the new entities - env_rain, env_spout, and env_sprite - to your level).

After fideling about with the settings in GEdit, you will soon learn the best valuse to create the different effects, so you will be creating realsistic fire, steam, smoke, rain, snow (or anything else which falls from the sky), bubbles, etc - effects in your levels, all with only a few lines of code on your behalf!

 

To add the rest of the effects to GTest, see the source for the three effects I have ported for you and then follow the same steps when creating the new effect in GTest. Please DO NOT email me for help in porting the effects. After readsing through the code I have given you, you should be able to do it error-free yourslef, and if you can't, I suggest you get a book on "How not to kid yourself by thinking you can program". - Sad but true.

(Sorry about that, but I don't want mass emails asking me the same thing, and it is obvious how I did it).

 

All credit for this tutorial goes to me, David Wulff, the guy's over at RabidGames (link at top) and obviously Eclipse Entertainment for creating DTest and GDemo in the first place. I would appreciate a mention on your games website and/or credits screen, etc, just so that I get some credit for my work. As to RabidGames, you will have to contact them to find out. Eclipse require no crediting, as their splash screen liscence is all tey ever ask.

See the top of the document for links. The zip file you require is here.

Good luck!

- David Wulff
Battleaxe Studios


Please visit -

RabidGames @ http://www.rabidgames.com

Battleaxe Studios @ http://www.bttlxe.co.uk

PlanetSurvival (Our game) @ http://www.planetsurvival.co.uk

Gnesis3D Forum @ http://www.gewnesis3d.com/board.htm