PDA

View Full Version : how to while(device->run()) loop in irrlicht?



blackMasoon
08-01-2011, 08:24 PM
Where should be a main run loop placed in an app like RT3D example?

Seth
08-01-2011, 11:06 PM
Your main "loop" is App::Draw getting called every draw cycle in App.cpp. (this is project specific, each example has its own, which inherits from BaseApp.cpp which is shared between apps) (See RTBareBones for the most simple example of this)

So, here is your main "loop", from RT3DApp:


void App::Draw()
{
//turn normal GL back on
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//draw our game stuff

GetIrrlichtManager()->IsRunning(); //let it do its own update tick
GetIrrlichtManager()->BeginScene(); //turn on irrlicht's 3d mode renderstates
GetIrrlichtManager()->Render(); //render its scenegraph
GetIrrlichtManager()->EndScene(); //tell irrlicht to go into 2d mode renderstates

g_lastBound = 0;
SetupOrtho();
//GetFont(FONT_SMALL)->Draw(0,50, " white `2Green `3Cyan `4Red `5Purp ");

//the base handles actually drawing the GUI stuff over everything else
BaseApp::Draw();
PrepareForGL();
}


The GetIrrlichtManager()->IsRunning() part is what lets Irrlicht do its device->run() update to catch up on its internal messaging.

Also: App::Update() is called every cycle before App::Draw() so I recommend doing all game logic there and just using the Draw() for the screen update.

blackMasoon
08-01-2011, 11:20 PM
Thank you very much for your answer :)

blackMasoon
08-06-2011, 08:06 PM
Well... it doesn't seem to be so easy... how can I get an access to nodes initialized in e.x. Mesh3DMenu.cpp to modify their attributes in the main loop? I can manage to to pass a method from Mesh3DMenu doing something in the loop but how do I set a condition to update only when that Mesh3DMenu is initialized?

Seth
08-07-2011, 03:43 AM
Well, I think there are many ways to do this:


In your main loop, do if (GetRootEntity()->GetEntityByName("Mesh3DMenu")) { //do stuff, it's been initted"};
Set a global flag (bool g_Mesh3DInitted = true) or whatever in Mesh3DMenu's init, check for it in your global update function
Connect the Mesh3DMenu's Update() function to a UpdateMyMeshStuff() function, it will be called every frame
Write a Component to add to Mesh3DMenu, and do your updating in its Update() function (you would connect it in your its Init, most Components do it this way when they need to update every frame)



In all cases, you always have access to the Irrlicht stuff through GetIrrlichtManager()->GetScene() and GetIrrlichtManager()->GetDriver().

If you want to save references to specific nodes and things for fast access, you should probably create your own data structures to store them when you create them.

blackMasoon
08-07-2011, 11:07 AM
Thank you :) That helped a lot :) And one more question... any idea why can't the mesh3dMenu allocate its resources again after getting back to menu and trying to enter the scene again? I have an arraylist of scenenodes. They are being initialized for the first time. But when i get back to menu and try to enter again it shows in the debugger like the whole array is a badpointer. As I see you clearthe whole scene while pressing the "back button"... What else should be cleared?

//EDIT: Ok, I've fixed it ;) I just had to clear the array ;)