My game's main loop- need help

I am using the irrlicth engine and reading the book: "GAME CODING COMPLETE third edition" by Mike McShaffry. He gave me an example of how to do the initialization and shutdown and how to write error codes like these. But I need to transfer these to my engine: Irrlicht. Anybody got any idea what to replace "gp_VideoSystem" etc with? Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//Codename: "Magic"
//Main Loop
//Programmed by James Bryce

//Initialize Program
#include <irrlicht.h>

using namespace irr; 

//A useful macro
#define SAFE_DELETE(p) {if (p) { delete (p); (p)=NULL; }}

DataFiles *gp_DataFiles = NULL;
AudioSystem *gp_AudioSystem = NULL;
VideoSystem *gp_VideoSystem = NULL;

//No data error
int main(void)
{
    //Error 001
    gp_DataFiles = new DataFiles
    if (NULL==gp_DataFiles) || (!gp_DataFiles->Initialized())
    //Error Message
    _stprintf("Error 001: Important file directories were not found."
              "Try to reinstall the game or contact customer support.");
    return (1);

//Audio Error
gp_AudioSystem = new AudioSystem
if ( (NULL==gp_AudioSystem) || (!gp_AudioSystem->Initialized()));
{
    _stprintf("Error 002: Audio not functioning."
             "Try rebooting the game or reinstalling");
             return (1);
}
//Video Error Code
gp_VideoSystem = new VideoSystem
if ((NULL==gp_VideoSystem) || (!gp_AudioSystem->Initialized()));
{
    _stprintf("Error 003: Video is not functioning."
              "Update your video card drivers.");
    return (1);
}

BOOL done = false;
while (!done)
{
    //The main game loop for the actual game!
}
SAFE_DELETE(gp_VideoSystem);
SAFE_DELETE(gp_AudioSystem);
SAFE_DELETE(gp_DataFiles);
return (0);
}
Last edited on
What I also need to know is how to write a good and stable main loop for a game using the Irrlicht engine. One that... Checks system resources, Checks CPU speed, Initializes the main random number generator, Loads programmer's options for debug, Creates the window, initializes the audio system, loads the player's game options and save files, creates the pixel drawing surface, and performs initialization for game systems such as physics, AI, and so on.

So, please give me some ideas! Thank you!
Actually, there is no audio function in IrrLicht. But i suggest you to use BASS library, just google it out.

Anyway, there's a stub:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <irrlicht.h>
using namespace irr;
IrrlichtDevice* Device; //Default Irrlicht Game Window
scene::ISceneManager* smgr;
video::IVideoDriver* Driver;
gui::IGUIEnvironment* guienv;
int main(int argc, char[] argv)
{
    Device = createDevice(video::EDT_DIRECT3D9,core::dimension2di(640,480), 32, false); //1. Driver, can be DIRECT3D9, DIRECT3D8, OPENGL, NULL, SOFTWARE... 2. Resolution 3. Bits 4. Fullscreen
    Driver = Device->getVideoDriver();
    smgr = Device->getSceneManager();
    guienv = Device->getGUIEnvironment();
    while(Device->run())
    {
         Driver->beginScene(true,true,255,255,255,255);
         smgr->drawAll();
         guienv->drawAll();
         Driver->endScene();
    }
    Device->drop();
    return 1;
}

Device is the pointer to the Main Irrlicht Device, there can be more than one.
Driver is the pointer to the video driver.
smgr is the pointer to the Scene Manager, use this to add models, etc. etc....
guienv is the pointer to the GUI Manager, use this to add buttons, listboxs...
*pointer* -> drop()
this must be called when you finish to use the pointer.
ONLY if the pointer begins with create* , like createDevice.
smgr, Driver, guienv MUST NOT BE DROPPED, as they are a getSceneManager, getVideoDriver, getGUIEnvironment pointers.
These are the basics.
There might be something wrong, it's just a stub i wrote here. anyway, you can check IrrLicht's tutorials, they're included with the Irrlicht Engine.
Last edited on
So BASS is an audio engine? How would I use it? What pointers??
BASS is an audio library.

http://www.un4seen.com/bass.html

IrrLicht is great, but not quite the beginner friendly level that SDL and SFML are (IMHO) so you maaay want to look into those.
Topic archived. No new replies allowed.