Irrlicht device in header

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
axeves
Posts: 12
Joined: Tue Jun 21, 2011 5:13 pm
Location: Sweden

Irrlicht device in header

Post by axeves »

Yeah, i want to basically keep my main.cpp clean, 'cause it's more than a thousand lines, and therefore just make a header containing like:

Code: Select all

 
void init() {
            irrlichtDevice *device = createDevice();
            //init gui, scenemanager, and video driver.
            //handle input
}
 
and just run init(); in my main.cpp. But i don't get that to work, i always get errors that say that scenemanager, device, driver, guienv doesn't exist. But isn't this copied to main.cpp when i call init(); from it?

So, that's what i need help with.

Any answer is helpful, even if it's just "STUPID NOOB JUST SEARCH: ______"

Yeah, if you need clarification, just ask.
axeves
Posts: 12
Joined: Tue Jun 21, 2011 5:13 pm
Location: Sweden

Re: Irrlicht device in header

Post by axeves »

There is probably an example using that somewhere, if you could say which, i would be most grateful.
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Irrlicht device in header

Post by smso »

I think the init code of irrlicht engine is not very lengthy. You should split up (or refactor) other parts of codes in main.cpp into different classes (.cpp and corresponding .h files).

If the program failed to compile, showing some error logs would be useful in the forum.

Regards
smso
CuteAlien
Admin
Posts: 9986
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Irrlicht device in header

Post by CuteAlien »

axeves wrote: But i don't get that to work, i always get errors that say that scenemanager, device, driver, guienv doesn't exist. But isn't this copied to main.cpp when i call init(); from it?
No, what have to understand for this is the scope in which a variable in valid in c++. Maybe check this tutorial about scope: http://www.cplusplus.com/doc/tutorial/variables/

A function only has access to variables declared inside, variabled passed to it and global variables.
Memberfunctions of classes can also access the member-variables of a class.

For an example how you can split it up see here (my post at the bottom): http://irrlicht.sourceforge.net/forum/v ... 7&p=262710
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
axeves
Posts: 12
Joined: Tue Jun 21, 2011 5:13 pm
Location: Sweden

Re: Irrlicht device in header

Post by axeves »

CuteAlien wrote:
axeves wrote: But i don't get that to work, i always get errors that say that scenemanager, device, driver, guienv doesn't exist. But isn't this copied to main.cpp when i call init(); from it?
No, what have to understand for this is the scope in which a variable in valid in c++. Maybe check this tutorial about scope: http://www.cplusplus.com/doc/tutorial/variables/

A function only has access to variables declared inside, variabled passed to it and global variables.
Memberfunctions of classes can also access the member-variables of a class.

For an example how you can split it up see here (my post at the bottom): http://irrlicht.sourceforge.net/forum/v ... 7&p=262710

Thanks, i managed to get it working using the example you referenced in that link, and it also seems like i have to better my knowledge of C++, and use classes more often. :)
Mel
Competition winner
Posts: 2293
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Irrlicht device in header

Post by Mel »

Your main has 1000 lines? now that's a LONG main file, are you sure you can't split it somehow? ^^U

You should definately use more classes and splitting your code, basically because of maintenance tasks and debugging, it isn't the same to have a search in a 1000 lines file than in one of just 200 or so. I don't say that you modularize every function inside a single .cpp file, that is overkill, but that you split each part of your program according to its functionality.

The good thing is that the amount of flexibility you win is enormous.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply