Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
63 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

Contents
 Introduction
 Class Structure
 The Problem
 The Solution

 Printable version
 Discuss this article
 in the forums


Class Structure

My entire game engine was, at some level, contained within or managed by my Cb3dEngine class.

My Engine class contained:

  • A SoundSystem class, which managed my sounds and music classes.
  • A pointer to a ViewportSet class, which in turn contained:
    • A series of pointers to Viewport classes, which in turn contained:
      • A series of pointers to renderable objects (meshes, text, sprites…)
      • A series of lights
      • A ParticleSystem class, which contained all of the particle emitters, particle textures, animations, etc.
  • A Keyboard, Mouse, and Joystick class

It seemed to be fine. My initialization could be extremely short, allowing me to develop DirectX applications very quickly. For instance, my initialization could have looked like this:

InitSettings.UpdateFrame = MainLoop; //app-defined main loop
InitSettings.KeyHandler = KeyHandler; //app-defined handler functions
InitSettings.MouseHandler = MouseHandler;
InitSettings.Hinst = hInst;
InitSettings.Windowed = true;
InitSettings.Width = 640;
InitSettings.Height = 480;

Cb3dEngine* g_pB3DEngine = new Cb3dEngine;
g_pB3DEngine->Initialize(InitSettings);

Cb3dViewportSet* MainSet = new Cb3dViewportSet();
g_pB3DEngine->SetViewportSet(MainSet);

Cb3dMilkshapeMesh* msm = new Cb3dMilkshapeMesh("mesh.txt");
Cb3dMeshObject* msmObject = new Cb3dMeshObject(msm);
msmObject->MyCoords.SetPosition(D3DXVECTOR3(0,0,220));
MainSet->ViewportByNumber(0)->AddObject(msmObject);

D3DLIGHT8 Light;
ZeroMemory((void*)&Light, sizeof(D3DLIGHT8));
Light.Type = D3DLIGHT_DIRECTIONAL;
Light.Diffuse.r = Light.Diffuse.g = Light.Diffuse.b = 1.0f;
Light.Specular.r = Light.Specular.g = Light.Specular.b = 1.0f;
Light.Ambient.r = Light.Ambient.g = Light.Ambient.b = 0.3f;
Light.Direction = D3DXVECTOR3(1,0,0);

MainSet->ViewportByNumber(0)->AddLight(&Light);

g_pB3DEngine->Run();

Just like that, I was up and running in a 640x480 windows DirectX application with a keyboard and a mouse and a Milkshape mesh all ready to go, lit by my one light. Everything was wonderful, except that somehow some of my objects were not getting destroyed during the execution of the program.



Next : The Problem