Pausing my scene manager

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
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Pausing my scene manager

Post by ibax »

Hi,

I would like to enable some kind of pausing in my application. I'm working on a memory game, where the pictures are shown for 8 seconds only. During these 8 seconds no interactions are allowed... I implemented this easy method:

Code: Select all

 
void pauseIrrlicht( int _seconds )
{
    txtLog.writeLogDigit("pauseIrrlicht(): Started. Pausing for seconds: " , _seconds );
    
    int loop = 1; 
    time_t start , end;
    time( &start );
 
    while ( loop )
    {       
        time( &end );   
        if ( difftime (end,start) > (double)_seconds )  
            loop = 0;
    }
    txtLog.writeLog("pauseIrrlicht(): Finished.");
}
 
 
From my log files I see clearly, that is works correctly...

09:49:43809 pauseIrrlicht(): Started. Pausing for seconds: 8
09:49:52000 pauseIrrlicht(): Finished.

However, in some cases I experience interesting behaviour. The second picture is shown for 15 sec approx, and the third only for 1 sec... The log file shows correct timing, so maybe the issue is with some kind of screen refreshing/updating.

This is how I use the function (I call this sequence several times, based on the number of pictures to show)

Code: Select all

 
    smgr->drawAll();
    env->drawAll();
    pauseIrrlicht(8);
    Ex3_WindowMaker(    device->getGUIEnvironment() , admin._irrList[i] , admin._irrFile[i] ) ;
 
Of course there are some other code parts as well. This works in 90%, but in some cases, one picture is showing for a much longer time, and the next one is only for a moment...

What can be the reason of this behaviour?

Thanks!!!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Pausing my scene manager

Post by CuteAlien »

Don't pause your main-loop. First problem here is - you pause before front/backbuffer swaps. That happens in endScene(). So the thing you want to show is not visible yet (it will be visible next frame).

Also you basically freeze your app with an endless loop. That's not a nice thing to do. The OS might even start to complain about crashed app if you do that for too long (as you no longer process OS events). In theory you could use a sleep() call, which would at least not make the OS think your application has crashed.

The better solution is to continue drawing as usual. And if you don't want any input to happen, then you simply don't process inputs. That way you can for example play wait-animation. Or sounds. So basically your pause-function only does one thing - it checks current time and adds as many seconds as you want to it (Irrlicht also has timer functions btw). And then it remembers that future-time in some variable. Then you use a second function isPaused() which compares if time has already reached the value of that variable and if not it returns true (otherwise false). Now you can use the isPaused() function everywhere where you handle input. If it's true - then don't do anything after any input. If you want you can do additional stuff. Like hide the mouse-cursor. And set the guienvironment focus to 0 (so people can't click stuff with keyboard). Or (generally better) disable all buttons in that time so the mouse still works (users will prefer that) but you can't click gui-elements anymore. Remember you disabled gui-elements maybe in some second variable (like a bool called "ignoreInput") And if uiDisabled and !isPaused() then enable the buttons again (and set ignoreInput to false).

Or maybe even better call the function pauseInput(). As that's what you pause - not your application.
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
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Re: Pausing my scene manager

Post by ibax »

Thanks for giving me such a detailed answer, I will try out the possibilities mentioned by you.

When you are saying to use the "pauseInput()" function, are you referring to some built in function?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Pausing my scene manager

Post by CuteAlien »

No, sorry, I meant "name" the function like that. As it's a more fitting name :-)
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
Post Reply