game with irrlicht

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Unforgivable.Course
Posts: 46
Joined: Tue Feb 07, 2006 6:28 pm

game with irrlicht

Post by Unforgivable.Course »

hi
i written all of my codes that in need for my game in irrlicht . in this case i want to create levels of the game . the only problem in this is :

i know that for all section of the game i must write a class for doing it better in main loop . but i have some problems in variables and globality of it . please help it's impotant . do you have any article about writting classes in games ?? my codes is messup and i cann't write all of the game with my codes like this .
Get Ready For an Amazing Journey Into the World of Game Development
CuteAlien
Admin
Posts: 9682
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I think the best way is to check out some other OpenSource games. You can find a lot of them for example at http://sourceforge.net/

Try to find one that is already working and preferably similar to your own game.

Otherwise I can just give some common hints when building classes. Like "if it does not belong together put it in different classes". Class design is an art itself and you will have to refactor your classes a lot until you learn it.

I can give an example of some classes which i used to split up my project. They can be nearly used like globals, but it's still a good idea to wrap them somehow. I create them all in my main class and have there pointers to access them. Could also be done by using singletons. Important is only you have all globals in one place so you know where you have to look to find them. Most of the classes have empty constructors and an extra Init() function, but that depends on your layout. Also some of them have Update() functions and are called in my main loop (InputManager, Game, Editor and GUI do that).

The main class itself is nearly empty, except the pointers to access those other classes.
It does the initialization of the other classes and it's responsible for switching different modes in which my application can be.

Those are the classes (there are more - it's just to give you an idea):

/* Access to irrlicht classes and some additional functions like game-specific engine initialization and some functions which do some stuff needed for example when i load models (like flipping surfaces for .obj files).
*/
class IrrlichtManager;

/*
Handle all the input devices (which have their own classes). Converts user-input in Controller information (when button x pressed -> increase power axis)
*/
class InputManager;

/*
Wrap all the classes for dialogs and menues
*/
class Gui;

/*
Basically a wrapper around the tinyXml which i use for configuration data. Has mainly access functions to get specific xml nodes, like GetCamerasSettings().
*/
class Config;

/*
Music & Soundeffects
*/
class Sound;

/*
Has all the levelsettings and can load specific levels. Has the pointers to some engine-classes for the currently active level (mesh-node, skybox).
*/
class LevelManager;

/*
The class for stuff which is needed when the game itself does run (not menues or intro - but the stuff i needed for playing). For example players, physics a game timer (which all have theire own classes)
*/
class Game;

/*
Here's the stuff i need when i fire up my editor
*/
class Editor;
Last edited by CuteAlien on Mon Oct 13, 2008 11:50 am, edited 1 time in total.
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Post by kburkhart84 »

I usually in my main function or globally have pointers to most of my objects(window, input manager, timer, sound manager). In the init function, I call new for my objects and initialize them, at the end, I delete them. Any class that needs any of these objects will have a pointer to object as a member, and in the constuctor or init function of these classes, the pointer to object is assigned using a parameter of the init function. Example, quickly done, not accurate(no copy-paste)

Code: Select all


main()
{
    window* pwindow;
    pwindow=new window;//creates window
    window.Init(ScreenX, ScreenY, blah, blah)//inits window
    objectthatneedswindow* pobj=new objectthatneedswindow;
    /creates object
    pobj->Init(pwindow);//inits object with original window
    etc...
}

class objectthatneedswindow
{
    public:
         void Init(window* thewindow)
         {
              pwindow = thewindow;//class now has pointer to  same window
          }
    private:
    window* pwindow;
}

This isn't perfect, but it should give an idea of how to avoid the singleton pattern if you are like me and don't feel like doing it. You just have to make sure you init and destroy all of your classes only once and don't access them before you 'new' them or after you 'delete' them.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

And one more thing don'T make a class for every level!!!! It will be hard to add levels later on and u have to recompile every time.
You should write a level class that can load text or binary files that hold informations about ur level and then build the levels out of this information.
This way u can simple write ur levels with wordpad and load them in ur game and u can even write a level editor.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Unforgivable.Course
Posts: 46
Joined: Tue Feb 07, 2006 6:28 pm

Post by Unforgivable.Course »

thanks guys . it's useful .

my target of writting irrlich manager is switching with some codes . for example been switching been 2 level or situation . i said it in other topic but i can't catch their mean . can you give me just your switch manager code for doing this problem ?? thank you verry much :)
Get Ready For an Amazing Journey Into the World of Game Development
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

What?
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

What?
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Ced666
Posts: 86
Joined: Fri Jan 13, 2006 10:29 am
Location: Belgium

Post by Ced666 »

my target of writting irrlich manager is switching with some codes . for example been switching been 2 level or situation .
Uuuuhh ??? What are you speaking about ? I guess it is probably about changing states in a game (switching from your main menu to the play 'state' or to the game over 'state', ...). If that's what you are speaking about, you can take a look at the state pattern (a specific design pattern). More info here: http://www.codeproject.com/cpp/statepattern3.asp
Post Reply