game pause - ho should be done?

Started by
23 comments, last by SeraphLance 9 years, 9 months ago

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?

Advertisement


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

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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


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

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


why you asking why im asking?

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?

People aren't really going to be able to help you. I would suggest reading http://www.sloperama.com/advice/entry65.htm

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

As for your numbered questions...

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.

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.

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.

This topic is closed to new replies.

Advertisement