Top
Best
New

Posted by speckx 3 days ago

Game devs explain the tricks involved with letting you pause a game(kotaku.com)
414 points | 226 commentspage 3
otikik 19 hours ago|
So the simple case is using some sort of state variable:

switch(game_state):

  case(paused):
     <the paused logic goes here>

  case(gameplay)
     <updating entities and regular gameplay goes here>

You still have to be careful about how you implement "gameplay", though. For example if at any point you read the 'system clock' to do time-based stuff like animations or physics, then when you unpause you suddenly will have a couple minutes of advance in a place where you expect fractions of a second.
diath 19 hours ago|
This is why delta time accumulator is preferred over using clocks, something like this would be best:

    float accum = 0;
    while (running) {
        poll_input();
        poll_network();

        accum += delta_time;

        while (accum >= tick_time) {
            accum -= tick_time;

            update_ui(tick_time);
            update_anims(tick_time);

            if (!paused) {
                update_entities(tick_time);
            }
        }

        render();
    }
setr 17 hours ago|||
the notion of using time directly in gamedev has always confused me; it feels like the correct answer should be to simply have a notion of turns, and a real-time game simply iterates over turns automatically. And then so many turns are executed per second

It's a simulation; why should clock time be involved to begin with? The only things that should care about clock time are those that exist outside the sim, e.g audio

maxbond 15 hours ago||
Simulation can proceed in logical time but animation is necessarily tied to wall clock time in order to be perceived as smooth and consistent by a human viewer.
setr 12 hours ago||
In that case, animation belongs to the same category as audio — it exists outside the simulation state.

But I’m not 100% that’s even true; in the context of replay, I imagine it’d be more appropriately part of the sim for it to scrub properly.

In the context of networked games with client-side prediction, I think it’d probably be key frames tied to logical time and intermediate frames tied to wallclock

usea 16 hours ago||||
That's exactly how I do it. Makes the most sense to me.
AlienRobot 14 hours ago|||
This gets bugged if it takes longer than one tick to run an iteration of game loop. Afaik the typical solution is to have a maximum number of iterations that you'll run and reset accum if it exceeds that.
Lerc 21 hours ago||
I find the notion odd that this is even a problem to be solved.

It suggests a level of control way below what I would ordinarily consider required for game development.

I have made maybe around 50 games, and I think the level of control of time has only ever gone up. Starting at move one step when I say, to move a non-integer amount when I say, to (when network stuff comes into play) return to time X and then move forward y amount.

insraq 17 hours ago||
I am recently working on a "realtime with pause" style grand strategy game using my own engine (think Europa Universalis, Crusader King, Hearts of Iron).

The trick is to separate the logic simulation from other game loops (rendering, UI, input, sound, etc). So when a player pauses the game, everything else still more or less works. And the logic simulation should be able to take user "command" while being paused.

Most commands should mutate the game state and reflect in the UI immediately. A few commands that have to wait until the next tick should at least acknowledge the action result.

yawnxyz 8 hours ago||
for our game dev project in undergrad we built an rts game as our capstone, and we used the "slow stuff down" trick - except different systems had different clock/time systems! and so some things were still running while it was paused, which led to some weird side effects (eg money glitch)

i did the thing you're "not supposed to do" and attached everything to a world clock so everything ran at like 60fps in terms of events, so it was a real-time "turn based" system

dwroberts 20 hours ago||
The console cert ones are interesting but all the others are just Unity/Gamemaker/Unreal not allowing the developers to write normal code? The nonzero timestep thing is very strange
lordmauve 18 hours ago||
From a lot of game jam games with custom engines, I have a pretty standard approach: I set the game clock to zero timestep, and push a pause gamestate onto the gamestate stack, where top gamestate gets all input. The trick is that you need many clocks, clocks for the gameplay/game animations, HUD animations, menu animations.
Sharlin 19 hours ago||
I would expect pausing to bring a game’s CPU/GPU usage down to near-zero, which won’t happen if the game keeps redundantly rendering the exact same frame. A game engine can optimize this by special casing time scale zero to simply render a single textured quad under the pause menu (which is probably what one of the commenters in TFA referred to).
qwery 17 hours ago|
You would expect it to do that, and I'd say that's a desirable behaviour, but it's not really that simple and you certainly don't get that for free.

Typically any of the common modern engines with a "time scale" variable like that are not at all optimising anything in that way. It's likely that the physics engine won't be stepped with a zero delta time, which will reduce the time spent on physics, but that's more of a byproduct of how physics engines work[0] than an optimisation.

You would have to go out of your way to capture the scene and display it "under the pause menu" in that way. Not saying nobody does that, just that it's not something the engine is giving you for free nor is it related to the time scale variable.

Further, doing that won't necessarily reduce resource usage. For example, if there isn't some sleep time inserted in the main loop when in a menu, or v-sync[1] to limit the framerate, the result of the simplified scene (just the menu and the quad with the captured scene) is an extremely high framerate, which may or may not cook the hardware more than the in-game load.

[0] Typical rigidbody physics engines are only (what I'll call) predictably stable with a constant delta time (same dt every tick). And a common way to manage this is with a time accumulator main loop, that only steps physics for whole units of dt.

[1] And v-sync isn't a silver bullet. consider refresh rates, different hardware, different drivers, driver overrides.

glaslong 13 hours ago||
Speaking of "capturing the scene and display it under the pause menu"....

acerola on YouTube has an excellent 23 minute frame rendering analysis video about what goes into drawing just the "pause menu" in Persona 3 Reload:

https://youtu.be/dVWkPADNdJ4?t=19m10s

raincole 17 hours ago||
More people should play Lobotomy Inc. Coolest pause mechanism I've ever seen.
effdee 14 hours ago||
If your game uses more than 1% CPU and 1% GPU when paused you're doing something wrong.

A damn blurred screenshot should not make the GPU consume hundreds of Watts.

Aurornis 14 hours ago||
Paused game does not equal paused process. It means the gameplay clock has paused.

The rendering loop continues to run. The GUI is immediate mode and is still rendered. In some games visual effects continue to be rendered. If it’s a networked game the network code will continue to run.

dataflow 11 hours ago||
I think the parent comment still ought to stand. Unless you're saying it's literally infeasible for some reason, which I find hard to believe?
daemin 2 hours ago||
A paused game is not like a paused video where there is no processing going on. A paused game still has all the rendering usually going on (unless the developers got time to implement something custom), audio still needs to continue, the only thing actually paused in the game logic and gameplay elements.

Given this the game needs to slow down and lock its frame rate while paused and in menus otherwise it will run at full speed and burn a lot of CPU & GPU time. Though I would say this is not usually an issue because it gets fixed pretty quickly during development.

Now more work can be done by the developers to make the paused state this efficient, but it is all a matter of priorities, and in all cases the developers would rather spend their time making the gameplay better and fixing crash bugs. If the player wants their game to run more efficiently then they should reduce the processing demands by limiting the frame rate and lowering quality settings.

dataflow 1 hour ago||
Yes, I already understood all that.

> unless the developers got time to implement something custom

As I said: the point nevertheless ought to stand.

glenneroo 6 hours ago||
See this video: https://youtu.be/dVWkPADNdJ4?t=19m10s

Taken from this comment: https://news.ycombinator.com/item?id=47825155

Obviously not every game is doing that level of styling, but often a lot of stuff might still be happening when a game is "paused" for various reasons e.g. aesthetics, or handling input for pause menus, which usually offer you the ability to change all the games settings, e.g. video resolution, volume levels, etc. and also provide you with audio/visual feedback when you make choices, which requires keeping the audio engine running as well as rendering to the screen @ 60 fps.

avereveard 20 hours ago|
> when it was time to ship, we’d read the [Technical Requirements Checklists] and have to go back and add a special pause for when you unplug the controller

article confirms my early theory I formed when reading the title about why would pause be complicated

More comments...