Live data from Hacker News

Game devs explain the tricks involved with letting you pause a game

kotaku.com

241–250 of 273 posts

Re: Game devs explain the tricks involved with letting you pause a game

#241
Pausing a game is a source of many bugs. In many games some subsystems aren't paused, like particles or animated materials. In some games I even saw that the character moves forward if the forward moving button was pressed at the moment when the pause button was hit.

It surprises me, that it's so hard to do properly.

Re: Game devs explain the tricks involved with letting you pause a game

#242

One of the things that impressed me in Quake (the first one) was the demo recording system. The system was deterministic enough that it could record your inputs/the game state and just play them back to get a gameplay video. Especially given that Quake had state of the art graphics at the time, and video playback on computers otherwise was a low-res, resource intensive affair at the time, it was way cool. It always s…

> The system was deterministic enough ... I wrote about it here many times over the years but in 1991 I wrote a little DOS game (and I had a publisher and a deal but it never came out and yet it's how my career started but that's another story) and at some point I had an "impossible to find" bug because it was so hard to reproduce. So I modified my game engine to be entirely deterministic: I'd record "random seed + p…

The problem is that you have to recalculate the world at each update. In Clojure you have immutable datastructures that help. On the webstack you have React and reconciliation. All solutions come with a performance overhead. There are some interesting hybrid systems where you can try to isolate derived states and cache intermediate states (ex: Pathom for declarative state management and caching, and extension lifecycles in CLJFX for isolating UI subtrees)

Re: Game devs explain the tricks involved with letting you pause a game

#243
post #51

Earlier quoted context omitted.

It wasn't really that much to do with determinism. Quake uses a client-server network model all the time, even when you're only playing a local single-player game. What the demo recording system does is capture all of the network packets that are being sent from the server to the client. When playing back a demo, all the game has to do is run a client and replay the packets that it originally received from the server…

I don't see why it makes a difference for this purpose that you're replaying network packets or controller inputs or any other interface to the game engine. The important thing is that there is some well-defined interface. I guess designing for networked multiplayer does probably necessitate that, but if the engine isn't deterministic it still isn't going to work. There was a twitter thread years ago (which appears t…

Using a client-server model for single-player allows it to lean on that system for replaying state changes.

Re: Game devs explain the tricks involved with letting you pause a game

#244
post #32

Earlier quoted context omitted.

Interesting you mention StarCraft. The replay feature could diverge off due to the non deterministic nature of the game. https://news.ycombinator.com/item?id=21920508

The comment you linked to doesn't know what they are talking. (Edit: given the context, they know what they're talking about, but you don't) A game having random mechanisms has absolutely nothing to do with whether it's deterministic. Slay the spire is 100% deterministic, gameplay-wise. All the online poker games too.

Good call, thnaks for the correction. But there definitely was a sync bug.

Here's an old forum post discussing it

https://tl.net/forum/brood-war/352588-my-replays-are-broken

Here's a hacky patch that also documents some of the possible issues

https://liquipedia.net/starcraft/Replay_Fix_for_1.16.1

It seems like the bug is related to pausing the game.

Re: Game devs explain the tricks involved with letting you pause a game

#245
post #154

Seems like a solved problem for consoles, at least. On the Nintendo switch you can "pause" any game regardless of if the devs implemented it by pressing the home button which suspends the entire game at the OS level

Nintendo, like all other platform-owners (e.g. Meta/Quest, Sony, Microsoft) is VERY strict about games released on their platform and have very strict requirements before anything is allowed to be sold with the Nintendo label. I very highly doubt they let devs NOT implement the pause ability. AFAIK you can't just OS-pause a game and expect it to run fine when it resumes, there are soooo many systems at play: animatio…

This used to be true, but one trip to any modern e-store front should dispell the notion. So much slop. Even for arguable non-slop, so much that just rapidly crashes and is unplayable. The extent of platform certifying these days for most titles seems to be: can launch, can back out to the console top level, and maybe doesn't crash if a controller is added/removed.

Re: Game devs explain the tricks involved with letting you pause a game

#246

When I present TLA+ [0], I am referencing game pauses (pause buffer / item duplication Legend of Zelda exploit, Dark Souls menuing to cancel animations) and deliberate crashes as mechanics to exploit games, as those are still valid actions that can be modeled, and not doing that allows such exploits to happen. A system is only correct relative to the transition system you wrote down. If the real system admits extra t…

Do you have any of these presentations available publicly? I'm always amused by the glitch names people come up with (force quit wrong warps, skirtless parry-walks...) and it'd be fun to see them in a TLA+ context.

Re: Game devs explain the tricks involved with letting you pause a game

#247
post #128

Earlier quoted context omitted.

Look into dead reckoning vs lock step for networking. Lockstep requires determinism at the simulation layer, dead reckoning can be much more tolerant of differences and latency. Quake and most action games tend to be dead reckoning (with more modern ones including time rewind and some other neat tricks). Very common that replay/demo uses the network stack of it's present in a game.

I used to be a professional sailor, and love finding nautical terminology in programming. At sea dead reckoning is navigating using the speed and direction of the ship, and adding tide and wind to calculate a fix based on the last known position. The term dates back to the 1600s. It is fun to point at a chart and confidently state “We’re here! I reckon...”

[deleted]

Re: Game devs explain the tricks involved with letting you pause a game

#248

Pausing is unintuitive in Unity because you don't control the main loop - all active objects get updated every frame. The recommended way to do it is to set the "time scale" to zero and have menu animations use special timers that ignore time scale. If you control the game loop, you can usually just get away with an "if (paused)" [0]. [0] https://github.com/rameshvarun/marble-mouse/blob/8b25684a815...

ScriptX had a clock hierarchy, similar to a 2d or 3d transform hierarchy, but instead of each node just inheriting and modifying translation/scale/rotation, they also inherited and modified the "timebase" (time offset and scale).

https://en.wikipedia.org/wiki/ScriptX

So time scale 0 meant paused relative to the parent time scale, and time scale -1 meant time flowed backwards, which was actually quite useful!

https://news.ycombinator.com/item?id=41283223

DonHopkins on Aug 18, 2024 | root | parent | next [–]

The QuickTime API supported reverse play around 1993 or so, when I enjoyed using it for "back and forth" animated sprites, and playing music videos backwards to reveal the satanic messages with demonic backmasking.

Reverse / Backwards Moonwalk - Michael Jackson - Better Than The Original!!!

https://www.youtube.com/watch?v=IT_Aq2FjJo0

Here's the documentation and code I wrote when working at Kaleida Labs (a joint venture of Apple and IBM) on a ScriptX animation library that used QuickTime and other renderers, and depended on QuickTime's support for playing videos backwards, and single stepping forward and backwards of course:

ScriptX Animation Library:

https://www.donhopkins.com/home/catalog/lang/scriptx/anim.ht...

ScriptX Animation Implementation Module:

https://donhopkins.com/home/archive/scriptx/animimp.sx

ScriptX's QuickTime renderer would even play audio backwards and at whatever speed, too. ScriptX had excellent multimedia clock synchronization, and we would have considered it a terrible bug if ScriptX was not able to seamlessly and transparently synchronize video and audio with any arbitrary clock, time offset, and time scale, no matter what the speed and direction.

I'm sad that 31 years later, web browser video and audio players (not to mention VLC) don't support hierarchical clocks like ScriptX did for multimedia synchronization. (Each child clock can have a time offset and time scale relative to its parent, and everything's automatically kept in sync, from the simulation to the renderer.)

Here is Kaleida's (then Apple's) 1993 patent on "Synchronized clocks and media players", which has long since expired in 2013:

https://patents.google.com/patent/US5452435A/en

>Abstract: A media player and the clock which controls it are integrated into a single object. This integration may be achieved by the construct of inheritance between objects in an object oriented programming environment. A software class for player objects is established which inherits from a software class for clock objects. In this way, a player "is a" clock. This integration provides improved synchronization among different media, and simplifies design of applications which employ player objects and clock objects. Each object is synchronized to a RootClock object which operates at the speed of the fastest media player in the system. The RootClock may be separated into "low" order and "high" order components and a compare register in order to reduce interrupt overhead.

>[...] QuickTime essentially allows a multimedia player to process timebased data. Since the data are time based, QuickTime provides for the description of "time" (called time basis) for the data as well as a definition of the context for evaluating that "time." In QuickTime, a movie's or media's time basis is called its "timebase."

>A timebase is essentially a vector that defines the direction and velocity of time for a movie or media. The context for a timebase is called its time coordinate system. Conceptually, a time coordinate system provides an axis for measuring time. The time coordinate system, like a geometrical axis, is divided into units of measurement by a measurement system, called a time scale. [...]

https://news.ycombinator.com/item?id=18781950

DonHopkins on Dec 29, 2018 | parent | context | favorite | on: Steve Jobs hired a career juggler to teach program...

Oh, of course I wish Apple and IBM had made it free! But it included Apple's "crown jewels", the QuickTime player source code, and they were't going to give that away in 1995. Apple were even trepidatious about IBM having access to that source code.

Besides having proprietary decoders, it could also do some things you can't even do well with the Flash player or html video component today: like smoothly playing videos and music backwards!

Ever since the music industry switched from vinyl to CD, listening to demonic backmasking in Devil Music like the Beatles and Led Zeppelin's promotion of Satanism became much less convenient. ScriptX solved that important problem elegantly with its synchronized clock system, but today's HTML video player still hasn't, alas.

https://en.wikipedia.org/wiki/Backmasking

https://www.youtube.com/watch?v=5BDh_j5qAJ4

Here's a description of ScriptX's clock system:

https://news.ycombinator.com/item?id=18350511

>Kaleida Lab's ScriptX (a multimedia programing language kinda like Dylan with classes) had built-in support for hierarchal clocks within the container (in the sense of "window" not "vm") hierarchy. The same way every window or node has a 2D or 3D transformation matrix, each clock has a time scale and offset relative to its parent, so anything that consumes time (like a QuickTime player, or a simulation) runs at the scaled and offset time that it inherits through its parent container. And you can move and scale each container around in time as necessary, to pause movies or simulations.) You could even set the scale to a negative number, and it played QuickTime movies backwards! (That was pretty cool in 1995 -- try playing a movie backwards in the web browser today!)

Is it possible to play HTML5 video in reverse?

https://stackoverflow.com/questions/5277293/is-it-possible-t...

Kinda, but it's not smooth enough to sing along while dancing backwards and worshiping Satan to:

https://codepen.io/adrianparr/pen/qmCek

Re: Game devs explain the tricks involved with letting you pause a game

#249
post #244

Earlier quoted context omitted.

The comment you linked to doesn't know what they are talking. (Edit: given the context, they know what they're talking about, but you don't) A game having random mechanisms has absolutely nothing to do with whether it's deterministic. Slay the spire is 100% deterministic, gameplay-wise. All the online poker games too.

Good call, thnaks for the correction. But there definitely was a sync bug. Here's an old forum post discussing it https://tl.net/forum/brood-war/352588-my-replays-are-broken Here's a hacky patch that also documents some of the possible issues https://liquipedia.net/starcraft/Replay_Fix_for_1.16.1 It seems like the bug is related to pausing the game.

more specifically, the bug is due to a buffer overflow during paused chat, and presumably deviant undefined behavior between the original execution and the replayed execution.

and most importantly, it has nothing to do with the non-deterministic nature of the game -- non-determinism is trivial to account for, because PCRNGs are not actually non-deterministic; they're (pseudo)random, and deterministically so. They're just random enough to be equivalent to non-deterministic to the user.

As long as seeds are synced, it's trivially managed. But this kind of cause-for-desync is the reason deterministic engines are such a PITA to actually write. Any source of actual non-determinism wrecks everything, and there's always some miserably rare cases.

Re: Game devs explain the tricks involved with letting you pause a game

#250
post #118

Like a lot of issues in gamedev, pausing the game is a surprisingly difficult problem to solve. It's especially difficult to provide a one size fits all solution which would obviously be desirable for the popular modern engines that try to be a general solution. I see a lot of comments here saying something along the lines of "isn't it just a state in the state machine?" which isn't wrong, but is an extremely simplis…

I read your comment and the article and I’m still not really clear on why this isn’t as simple as saving the current state or pausing the render or time loop.

The short answer is: because of all the complexity that you're not seeing. I'll try to explain:

My '1983' example above is a simple way to implement a pause state -- when the game is paused, don't run the game logic. The sprites disappearing that I described (a real quirk, if not a bug, of games of that era) is a side effect of that. The sprites disappear because the set of objects to draw each frame is determined by the game logic, which is being skipped in order to pause the action.

Is it wrong that the game logic submits the drawables? I would say that it's inflexible, but not wrong. After all, the sprites are representing the state of the game, so they must be derived from it in some way.

You can do more engineering to support a more robust & elegant pausing system. You can build that system such that pausing the game feels like simply "pausing the loop". But that's more code, more complexity, less simple.

I'm not exactly sure what "pausing the render loop" means to you, but let me ask you this: how do you render the pause menu? When there is no time passing, how does the little bouncy cursor in the menu continue to bounce?

You'd want sound effects to pause while the game is paused, and ideally resume from where they were when the game is unpaused. But does the pause menu make sounds? Is there music? Does the pause menu play different music or continue the in-game music?

And this is the most obvious, simplistic idea of what pausing the game is -- to show a pause menu. What about in-game cutscenes: do the NPCs in the background keep running around while you're talking to another one? Inventory management: the items the player has are a gameplay system but you access it while the game is paused?

This pattern applies to every system in the game. You can't just cut out the xyz altogether, you need a sufficiently complicated xyz system in order to simply pause what you want to pause.

Post reply on HN