View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# game pause - ho should be done?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

24 replies to this topic

### #1/ fir   Members

Posted 26 June 2014 - 10:33 AM

im asking here about desktop apps like windows games..(both fullscreen and windowed)

would like to do some solid good game pause

1) how it should behave for the player ? should game be paused automatic on alt+tab or maybe even on mouse going out of window and automaticaly restarted again on second alt_tab ? or are there some reasons to leave it unpaused in

such cases?

It seem to me that it better pause/restart this heavily though im not quite sure

2) how to implement that? the story is that i can just not call the game loop

when in pause state, then last frame would be lasting in the window, but

anyway i need to generate some contents view on OnPaint request that would

be sent anyway - to do so I think i would need to separate functions calculating game frame - one is like CalcFrame() and the second more like CalcFrameButNoAdvance(), first for normal game frame and the second only to refresh the wiew but with no advance movement in the game...

do people really do this? this two versions of CalcFrame? or they use some differrent approach to game pausing than this "freeze frame" im talking about?

3) can i do yet something to improve game pausing? i dont know maybe to help

system swapping unused ram to disk or the opposite do not allow him to do that thus preventing slowdowns, or what?

### #2phil_t  Members

Posted 26 June 2014 - 10:59 AM

do people really do this? this two versions of CalcFrame? or they use some differrent approach to game pausing than this "freeze frame" im talking about?

Generally something like this yes. You want to have a very clear distinction between parts of your game that should still run when paused, and those that should not. You obviously don't want your game logic to update when things are paused, but you want UI/pause menu logic to be running. You probably want your full rendering path to be running (so hopefully you don't update any game logic in there).

### #3L. Spiro  Members

Posted 26 June 2014 - 12:58 PM

POPULAR

Implementing pause is really quite trivial.
You have 2 timers. Render timer and game timer. Both of them are advanced at the same rate except when the game is paused.
When the game is paused the game timer is not advanced.

Since the game timer’s delta will be 0, nothing will move from the previous frame.

It’s quite trivial and there is no need to try your plan with having different ways of advancing/drawing the scene.

In regards to when you should pause (pause policy), this very clearly depends on the game.
Why are you even asking this without explaining something about the game you are making, if any? In fact, why are you even asking this at all? Why don’t you play a game similar to the kind you have in mind and see what they do?
Angry Birds automatically pauses when I close my iPad, but all online games remain unpaused no matter what their statuses.
It’s extremely trivial to answer this question on your own and we are not here to spoon-feed you.  If you have ever even played a game before in your life you should be able to answer this off the top of your head.

And in regards to #3, no.  Pausing is not the place to do that.
When the window is minimized or not the active window, sleep for 16 milliseconds between frames to reduce CPU load.  That is all.

L. Spiro

Edited by L. Spiro, 27 June 2014 - 02:50 PM.

### #4/ fir   Members

Posted 26 June 2014 - 01:07 PM

And in regards to #3, no.  Pausing is not the place to do that.

When the window is minimized or not the active window, sleep for 16 milliseconds between frames to reduce CPU load.  That is all.

why you asking why im asking? As always im asking to get some opinions and clarify the view..

Do you mean that when game is in 1) background 2) minimalized it should nt be paused? Im not sure but it seem to me that most games not pause there..

### #5/ fir   Members

Posted 26 June 2014 - 01:13 PM

do people really do this? this two versions of CalcFrame? or they use some differrent approach to game pausing than this "freeze frame" im talking about?

Generally something like this yes. You want to have a very clear distinction between parts of your game that should still run when paused, and those that should not. You obviously don't want your game logic to update when things are paused, but you want UI/pause menu logic to be running. You probably want your full rendering path to be running (so hopefully you don't update any game logic in there).

I got it mixed, didnt expected that i could neet to run "draw path  " without "advance path" - not hard to change though it need a bit of caution to trace both modes in both loops and events, i dislike game states :c

### #6cozzie  Members

Posted 26 June 2014 - 03:41 PM

My remarks:
- I would focus on having good and clear game states, like for example the menu state (where gameplay is paused). When you have this in place you can take any event to set this state, for example when alt+tabbinb, pressing escape, minimizing
- if all your game logics, movements etc. is based on time delta, you can easily pause everything by setting delta to zero in the case/ state you want to pause

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

### #7Artemiye  Members

Posted 26 June 2014 - 03:50 PM

I'm guessing that Spiro's asking because your question seriously lacks context.  You haven't provided any details on what you're working on, the problem(s) you encountered, and what languages/frameworks/engines you're working with.  So when you ask something like:

2) how to implement that?

After that, post some details on what I mentioned above and I'm sure people would be glad to help you.

### #8SeraphLance  Members

Posted 26 June 2014 - 11:31 PM

1.  It depends on the kind of game.  Just put yourself in the player's shoes.  If you alt-tabbed out of a shooter on accident, would you want the game to autopause for you?  Probably.  What about something with Day/Night cycles, like Minecraft?  Maybe you just wanted to wait for daybreak and browse the web in the meantime.

2.  My games tend to be built as state machines.  In that context, pause is simply a state where nothing is updated, except for input.  The previous state exists as a child state, and rendering is a pass-through to that.

3.  I wouldn't try to make any of those kind of optimizations, personally.  I develop with the expectation that the user has a consistent experience -- that means no slowdown and no context-sensitive "surges" of usability outside the game.

### #9haegarr  Members

Posted 27 June 2014 - 02:06 AM

I got it mixed, didnt expected that i could neet to run "draw path  " without "advance path"

A game loop should ever be separated into at least the sections (in order)

1.) input processing,

2.) world state update,

3.) rendering.

In such a loop input processing provides abstracted desires the player has with respect to game world changes (e.g. the player's avatar should jump), that then together with the simulation time elapsed since the last pass is used to drive the world state update (the time delta actually drives AI, animation, physics). This gives a new snapshot of the world, and rendering then generates all still necessary resources and projects them onto the screen.

From this you can see that pausing a game need to influence (a) input processing because you don't want to string all input happening during pausing for the sake of avatar control, and (b) world state update. Rendering is a reflection of the current world state, and if it is run more often than once per world state update then it will show the same snapshot again.

As was already mentioned above, stopping the world state update can be done by enforcing 0 as time delta. If wanted, toying with things like avatars breathing also / although during game pausing is possible due to the the 2nd timer mentioned by LS. However, input processing need to be handled explicitly. This is because further input need not be suppressed but routed to other handlers. Here explicit game state switching may come to rescue.

Notice that the way how input is pre-processed is important. Input should be gathered, filtered, and all relevant input should be written in a unified manner into a queue from which the game loop's input handlers will read. The unified input should be tagged with a timestamp coming from the 1st timer, even if this may give you input "in the future" from the game loop's point of view. If the game gets paused and re-started, then a "discontinuity" will be introduced in the sequence of timestamps in the queue. This discontinuity helps in suppressing false detection of combos started before the pause and continued after the pause.

Edited by haegarr, 27 June 2014 - 02:08 AM.

### #10aregee  Members

Posted 27 June 2014 - 12:14 PM

It’s extremely trivial to answer this question on your own and we are not here to spoon-feed you.  If you have ever even played a game before in your life you should be able to answer this off the top of your head.

Are you serious?  I thought this was a friendly forum.  He is asking because it is not obvious to him.  If you don't like the question, you are free to not answer.  If you are starting to get annoyed at the questions here, maybe it is time you take a vacation.  I used to see you as a nice person with lots of knowledge.   You don't need to be all cocky about it.

To answer OP's question, L Spiro generally gave a good answer, but he doesn't need to be mean about it.  I would also suggest *not* to automatically pause the game every time the mouse pointer goes outside of the screen.  That will make the player a bit frustrated.  On the other hand, it is frustrating to play a game and lose track of the mouse pointer and end up clicking outside of the game window, defocusing the game.  If you can, you should also give an option to run full screen.

For pausing at all, it depends, as L Spiro said, on wether it is an online game or not.  Most online games nowadays won't ever pause the game.  I remember, however smaller multi-player games in the past had a pause function, so that if you were on a LAN party playing a game, you could signal to the others that you needed to do your 'business'.  Of course, in my experience they just unpaused the game as soon as you were out of sight and nuked the hell out of you.

Pausing in general is just about suspending certain parts of the game.  There may be different methods to do that.  In a single player game, it should be trivial, maybe as easy as not running parts of your game code while the game is paused.  In a networked multi player game, it may be a bit more involving, since you can't exactly just disappear from the face of the earth when you pause.  You need to somehow tell the other players that you want to pause the game, and also keep game state and communication going between the peers.

### #11L. Spiro  Members

Posted 27 June 2014 - 02:35 PM

POPULAR

Are you serious?  I thought this was a friendly forum.

There are certain people who often come across as abusing the forums.
If you see just this topic and my reply, you may think I am being a bit harsh, but it actually stems from something of a history in which fir posts questions of variable merit but almost always follows with, “Yes I asked this question but I don’t like your answer.” He gets a good answer on the first reply but 3 pages later, with many people backing the first answer he got, he keeps the discussion alive beyond its grave constantly insisting what basically boils down to, “Yes, that’s the answer, but that’s not the answer I want to see.”

So it’s not just me randomly being an ass. There is a precedence with this particular person.
I tend to avoid fir topics for a reason, so you can be sure there is a reason I replied in the first place, but as you can see I do have little patience for people who appear to be literally abusing the forums, and I am not the only one who believes so.  His reputation is as it is for a reason.

L. Spiro

### #12/ fir   Members

Posted 27 June 2014 - 03:16 PM

well, sometimes i would like to debate things not just got first answer ' - like there in those drawlina arg name topic - some people seem do not understand this. as to this topic in general i can do this pause by exposing this RunFrameButtNotAdvance  and partialy switching off the input - switching this 'input path' presents to me a bit obscure (as i was used to mix draw advance and input quite together) but it was worth mentioning

pausing is interesting as it is quite separate whole game state not just 1 line of code

### #13L. Spiro  Members

Posted 27 June 2014 - 04:02 PM

The reason I replied is because I struggled with over-engineering pause mechanics when I was a kid (in my first attempt I kept track of actual time and paused time and the current game time was total time - paused time), and regardless of how I feel about your topics my devotion towards helping others not struggle with the problems I had in my youth virtually forced my hand here.

I am trying to save you from the headaches I had years ago, not engage in a discussion/debate over something I’ve established to be correct enough that I would recommend it to you in the first place.

In this case, you are very clearly over-engineering pause mechanics, and not only that but your proposed idea indicates that you have flawed approaches to other problems in general game mechanics.

I am going to answer 1 more time, very slowly and very clearly.

Every frame of the game you calculate how much time has passed and then add that amount to your “game time”.
By keeping track of the current game time and the last frame’s game time you can derive a delta. The time since the last update.

Fine.
When you want to pause, all you do is update the game time by 0 microseconds/milliseconds/seconds/whatever. 0 is 0, no matter the unit.
By definition you have created a delta time of 0.

UpdateBy( DELTA ) {
LastTime = CurTime;
CurTime += DELTA; // If DELTA is 0, CurTime does not change.
}

LastTime = 3987687, CurTime = 3987687, Delta = (CurTime - LastTime = 0).

This works in every case because:

• If my position is directly derived from the current time, the current time is no longer changing and so neither is my position (I am “paused”).
• If my position is cumulative (adds change over time each frame), the delta is 0, so anything I add over time is just 0 while paused.

So:

pausing is interesting as it is quite separate whole game state not just 1 line of code

No, it literally is 1 line of code. You either advance the timer or you don’t, and it’s a single if() to implement this. You will need another line for the closing } on that statement, but that’s not a line of “code”.

It’s 1 thing to not know what pausing is, but it is another thing to “know what it is not”.
When you assume it is not just 1 line of code it means you have an idea as to what it should be. Since you seem to have an idea about it, but in fact it actually is literally 1 line of code, it indicates you have a much larger problem somewhere else within your overall approach to game development—1 line of code should work perfectly but because of your approach it won’t.

It is really this simple:

• All game objects move based on the time since the last update (velocity * time).
• All game objects are updated within the scene manager.  The scene manager receives a value indicating the time since the last update (by how much each object should update).
• All objects update by the given time.  If that time is 0, then all motion those objects have is cancelled out and all objects stop moving.

The delta time you pass to the scene manager is just derived from the timer’s current time and its last time, and it is literally 1 line of code to add a check within the timer to not update when paused, which creates implicitly a 0 delta, which causes all objects to freeze.

The reason I replied is to make sure this is clear.  No one needs to endure what I did in my youth by over-engineering pauses.

L. Spiro

Edited by L. Spiro, 27 June 2014 - 04:05 PM.

### #14SeraphLance  Members

Posted 27 June 2014 - 06:47 PM

To be fair, pausing can often be a totally separate game state.  Yes, you could just stop the timer, but pause menus are usually more sophsticated than that.  You might want to show a menu.  You might want to change the background color to grayscale, apply a radial blur, and then show the word "pause" on the screen.  I'd argue that it's worthwhile to create a state for something like that.

Obviously you still want to not advance the timer, so as a barebones answer this is still correct.

### #15L. Spiro  Members

Posted 27 June 2014 - 07:28 PM

This is why I said in my first post that you maintain 2 timers.
The second one is for visual effects.

But if you pause Conker’s Bad Fur Day yes you see some nice visuals.
That is basically a state on top of the gameplay state (if you implement states as a stack).
You have many options in regards to what you display during pausing, states or no states, but the mechanic for pausing along with a rendering timer are unchanged.

L. Spiro

Edited by L. Spiro, 27 June 2014 - 08:35 PM.

### #16aregee  Members

Posted 27 June 2014 - 07:33 PM

That is really a great answer on pause mechanics.

I got a +0 points popup for my post above, so I am assuming that the system here didn't catch the case where you positives and negatives add up to zero on a post.

I am sorry for lashing out on you L Spiro.  To be fair, I guess it is equally frustrating to be on both ends: one end answering a lot of 'simple' questions about one topic, but it is equally frustrating to struggle with a topic you want to learn more about too.  I guess we are different in where our 'bottle necks' in learning are.  20 years ago, it was me struggling understanding pointers in Turbo Pascal.  Today, fir was struggling with pause functionality here, and actually, L. Spiro's answer taught me a bit too.  It is a clever way to pause rather than skipping parts of your code or having different states in a state machine.

Everybody starts from the beginning.

### #17LennyLen  GDNet+

Posted 27 June 2014 - 07:42 PM

To be fair, I guess it is equally frustrating to be on both ends: one end answering a lot of 'simple' questions about one topic, but it is equally frustrating to struggle with a topic you want to learn more about too.

Actually, if you look through fir's posting history, you'll see people are frustrated with him not because he asks a lot of questions (which is an ok thing to do), but because of the way he treats the people who answer his questions.  He's very lucky he gets any responses at all these days as he doesn't really deserve any.

### #18/ fir   Members

Posted 28 June 2014 - 02:58 AM

Answering is free.. I do not force anyone to answer - this is big forum and if even 20 people would not want to answer some other my find to talk..

So feel free to not answer, if you dont like my questions or statements (or mistypes, im doin to much of it but i had some problem with that even in my native language and here in english it is 3 times worse)  feel free to ignore me at all than i can talk with some rest who not shares this view

ps. dont exaggerate the value of some answers, im not a 100% newbie, im about moderately experienced, (about 6 hard years of hard c coding in my back) and sometimes i find a situation when some forum user gives me an answers worse than my knowledge - when im searching for some more advanced talk (then im a bit bored or angry - but what should i do in such case? answer that ;\

Edited by fir, 28 June 2014 - 03:06 AM.

### #19Juliean  Members

Posted 28 June 2014 - 04:46 AM

POPULAR

ps. dont exaggerate the value of some answers, im not a 100% newbie, im about moderately experienced, (about 6 hard years of hard c coding in my back) and sometimes i find a situation when some forum user gives me an answers worse than my knowledge - when im searching for some more advanced talk (then im a bit bored or angry - but what should i do in such case? answer that ;\

You should take it as the constructive feedback to your question that it is, and thank the person for at least answering - thats what you should do. Seriously,  there is just so much wrong with that whole statement of yours. If you think you have more knowledge than 99% of the forum users, why are you even asking? To get different opinions I quess, but if you reject most of them because you think the user knows much less than you and the answer is crap, than you clearly do not care about seeing different points of views. It appears to me you just want to hear answers that exactly match with whatever you yourself have in mind.

See, there is nothing wrong with disagreeing with an answer you have been given - I also used to discuss on some of the topics I asked with the repliers, but try to at least pretend to value that people took time to answer you, and don't act all like "I know better than you, so p*ss off". Also, I can quarantee you that if you really have to ask a question about "how to implement game-pause" and can't figure it out yourself that almost every answer you get is going to be better that what you might think is.

PS: Not trying to be offensive, apologies if it sounded that way.

@Topic: It might also be worth mentioning that depending on the type of game, there is not only rendering that can run while paused. Tower-defense games e.g. sometimes allow you to pause the action, but still keep placing towers, upgrading, etc... In RTS, you can sometimes still move the camera, select units, give commands... this also is true for other kinds of games like the Kotor-Series, where you can give commands to your characters while everything else freezes in a pause mode. So depending the type of your game, you might want to be able to selectively pause/unpause parts of it.

Also:

1) how it should behave for the player ? should game be paused automatic on alt+tab or maybe even on mouse going out of window and automaticaly restarted again on second alt_tab ? or are there some reasons to leave it unpaused in

such cases?

This IMHO has nothing to do with pausing per se, in that case you could probably just stop the game-loop:

	void BaseEngine::GameLoop(void)
{
while(!m_bQuit)
{
MessageLoop();
if(!m_bMessage)
{
const double dt = m_tGameLoopTimer.Duration();
m_tGameLoopTimer.Reset();

if(GetForegroundWindow() == m_pWindow->GethWnd()) // windows-function to get the current active window, don't progress in case thats not this apps window handle.
{
if(!m_bQuit)
Render();

Update(dt);

m_pRenderer->Finish();
}
}
}
}


Reasons to leave it run in the background? Everything multiplayer-related comes to mind, from MMORPG to RTS.

### #20/ fir   Members

Posted 28 June 2014 - 06:27 AM

Reasons to leave it run in the background? Everything multiplayer-related comes to mind, from MMORPG to RTS.

i rarely see the pause maybe this is becouse im playing heavy

games and when I alt + tam them i dont even se what this games

do - are they pausing or not? can i assume they pausing? ;/ this alt_tabbing is always some probloem  usually it works ok - but not so rare cases it crashes the game (even if this is AAA title) and if not crashes it can take a bit slow

what is the reason of this? windows swpaping mechanizm (this is probably activated on alt_tab?

Edited by fir, 28 June 2014 - 06:40 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.