# game pause - ho should be done?

This topic is 1299 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites

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).

##### Share on other sites

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..

##### Share on other sites

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

##### Share on other sites
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

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites
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

##### Share on other sites

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.

##### Share on other sites

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

##### Share on other sites

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

##### Share on other sites

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.

##### Share on other sites
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

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites

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

##### Share on other sites

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

##### Share on other sites

The reason is when you alt-tab, you lose exclusive access to the graphics hardware and the device needs to be reset before you can get it back. So all dynamic resources have to be released, the device reset, and the resources re-acquired.

This is not an issue when your game is running in Windowed mode as it didn't have exclusive access in the first place.

Edited by Aardvajk

##### Share on other sites

The reason is when you alt-tab, you lose exclusive access to the graphics hardware and the device needs to be reset before you can get it back. So all dynamic resources have to be released, the device reset, and the resources re-acquired.

This is not an issue when your game is running in Windowed mode as it didn't have exclusive access in the first place.

both opengl and dx are doing it weak such way?

must the gpu ram all be freed and reloaded or something like that?

##### Share on other sites
Only DX9 does that AFAIK.

##### Share on other sites

Only DX9 does that AFAIK.

good to know ;/

##### Share on other sites

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

I've never verbalized it this way, or even visualized it as such.  This is actually somewhat amusing, as a "stack of states" is pretty much a push-down automata, and this is literally the only use for it I've ever found other than as a visual representation of context-free grammars.