program structure

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
izguit
Posts: 12
Joined: Thu Mar 02, 2006 8:20 pm
Contact:

program structure

Post by izguit »

Heya
How your apps are organized?
cause global vars are not advised
thx

(sorry for my poor and bad english)
kornerr
Posts: 245
Joined: Thu Jul 06, 2006 9:57 am
Location: Russia, Siberia, Kemerovo
Contact:

Post by kornerr »

You can read The C++ Programming Language (3rd Ed or Special) by Stroustrup. He describes really cool application structure (I'm now reading about Derived classes).
Globals must die :P
Open Source all the way, baby ;)
OSRPG
izguit
Posts: 12
Joined: Thu Mar 02, 2006 8:20 pm
Contact:

Post by izguit »

yep I know c++ (i begin but it isn't the first programming language i have learnt). However, because of local vars, i can't write :

Code: Select all

int main {
  ....
  gameLoop();
}

void gameLoop {
  updatePlayerPos();
}

void updatePlayerPos {
  ....
}
'cause scene manager (and the others elements of the engine) can't be reached in gameLoop for example, he has been declared in the main function... :? And i cannot use global vars as we said. So, how are your games/3d apps using IrrLicht structured/organized?
Thx

(yes, it's a strange question, i know :D )
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

research polymorphism, forward class declarations and class scope in C++
Image
kornerr
Posts: 245
Joined: Thu Jul 06, 2006 9:57 am
Location: Russia, Siberia, Kemerovo
Contact:

Post by kornerr »

Either I don't understand your question, or you can simply use
gameLoop (ISceneManager *smgr);
then UpdatePlayerPos (ISceneManager *smgr) {
smgr->addBlahBlahBlah (smth);
}
Open Source all the way, baby ;)
OSRPG
izguit
Posts: 12
Joined: Thu Mar 02, 2006 8:20 pm
Contact:

Post by izguit »

thx i had not thinked to this solution
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

You can simply make a main game class and call and intialize it in main and then declare the device and all objects in the game class, then all you have to do is make different classes like player and level and when you initialize them youll pass them a pointer to device.
area51
Posts: 338
Joined: Thu Mar 18, 2004 10:20 pm
Location: UK
Contact:

Post by area51 »

You can have a look at the structure IrrWizard uses, no global variables in sight, so you might like it.

But if that freaks you out too much, then have a look at the ICE Framework which is solving a similar problem but has a much smaller code base.
________
Motorcycle tires
Post Reply