Results 1 to 6 of 6

Thread: how to while(device->run()) loop in irrlicht?

  1. #1

    Default how to while(device->run()) loop in irrlicht?

    Where should be a main run loop placed in an app like RT3D example?

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    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:

    Code:
    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.
    Seth A. Robinson
    Robinson Technologies

  3. #3

    Default

    Thank you very much for your answer

  4. #4

    Default

    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?

  5. #5
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    Well, I think there are many ways to do this:

    1. In your main loop, do if (GetRootEntity()->GetEntityByName("Mesh3DMenu")) { //do stuff, it's been initted"};
    2. Set a global flag (bool g_Mesh3DInitted = true) or whatever in Mesh3DMenu's init, check for it in your global update function
    3. Connect the Mesh3DMenu's Update() function to a UpdateMyMeshStuff() function, it will be called every frame
    4. 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.
    Seth A. Robinson
    Robinson Technologies

  6. #6

    Default

    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

Similar Threads

  1. Irrlicht OpenGL ES 2.0
    By Yogi in forum Proton SDK
    Replies: 3
    Last Post: 11-06-2012, 12:49 PM
  2. 2d in irrlicht
    By Egerexy in forum Proton SDK
    Replies: 0
    Last Post: 07-07-2011, 11:17 AM
  3. Replies: 3
    Last Post: 01-09-2011, 09:50 PM
  4. Main loop - best practice
    By spin in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 01-08-2011, 09:31 AM
  5. Big update comitted, Irrlicht updated
    By Seth in forum Proton SDK
    Replies: 1
    Last Post: 12-29-2010, 10:05 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •