Page 1 of 1

program structure

Posted: Mon Aug 21, 2006 5:09 pm
by izguit
Heya
How your apps are organized?
cause global vars are not advised
thx

(sorry for my poor and bad english)

Posted: Tue Aug 22, 2006 12:03 pm
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

Posted: Tue Aug 22, 2006 12:12 pm
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 )

Posted: Tue Aug 22, 2006 12:12 pm
by Spintz
research polymorphism, forward class declarations and class scope in C++

Posted: Tue Aug 22, 2006 12:32 pm
by kornerr
Either I don't understand your question, or you can simply use
gameLoop (ISceneManager *smgr);
then UpdatePlayerPos (ISceneManager *smgr) {
smgr->addBlahBlahBlah (smth);
}

Posted: Tue Aug 22, 2006 4:38 pm
by izguit
thx i had not thinked to this solution

Posted: Tue Aug 22, 2006 7:09 pm
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.

Posted: Tue Aug 22, 2006 10:09 pm
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