Live data from Hacker News

Game Loop

gameprogrammingpatterns.com

41–50 of 58 posts

Re: Game Loop

#41
post #11

While this book seems to get a lot of praise (as it deserves, obviously), I wish the style of teaching complex programming topics walked me through the pain of making something work, exploring a few alternative solutions, showing the tradeoffs, and then after the pain has been experienced by the learner, a proper solution is finally introduced and recommended. IMO it's a much more powerful technique for teaching if y…

For a great example of this, I'd recommend reading The Inner Game of Tennis by Tim Gallwey (or watching the lecture if you can get your hands on it).

It's essentially taking a coaching mentality towards your writing, letting the reader take the steps themselves to feel confident in it, and then only afterwards telling them what they are actually doing (e.g. in that context, properly serving).

It's a fantastic process and the book, of course, explains how it works in the context of teaching tennis.

Re: Game Loop

#42
Game loop based systems have trouble using more than one CPU effectively. This is a big problem, since we can now get more CPUs, but not faster ones. The audio guys are happy - they can finally get their own CPU, or a big piece of one, and get out of the game loop. (Audio guys liked the Cell. Nobody else did.) The AI guys are usually running on a much slower schedule than the frame rate, so they're OK with this. The rendering guys think they own the game loop. The physics guys are struggling; they always need more CPU time. The asset loading guys are I/O bound anyway. Back in the main loop, the name of the game is not getting stalled on locks on shared data.

(Somewhere in the Second Life viewers, there's a lock conflict which causes disk delays in loading assets from the local cache to stall input processing in the main loop. All the disk I/O is in other threads, and those threads can talk directly to the vertex buffer memory in the graphics card, so this shouldn't be happening. But it is.)

Re: Game Loop

#44

Implementing a game loop in JavaScript (2011) [0] [0] https://codeincomplete.com/posts/javascript-pong/

doesn't use render interpolation as the OP article describes

Re: Game Loop

#45
post #11

While this book seems to get a lot of praise (as it deserves, obviously), I wish the style of teaching complex programming topics walked me through the pain of making something work, exploring a few alternative solutions, showing the tradeoffs, and then after the pain has been experienced by the learner, a proper solution is finally introduced and recommended. IMO it's a much more powerful technique for teaching if y…

Author here.

This, I think, one of the fundamental challenges of teaching software architecture or other higher-level engineering topics. A lot of architecture boils down to:

1. Here's an obvious simple way to solve a problem, X.

2. If you do X at scale, much later, you will run into pain.

3. So here's Y, which seems weird and non-obvious but solves the same problem as X without the pain.

It's really hard to teach people step 2 when they haven't experienced it first-hand. You can walk them through scenarios, but most scenarios small enough to fit in a reasonable amount of prose feel fake and contrived.

Even when this does work, you can end up with a generation of programmers that cargo cult Y without any real understanding of the original problems it avoids from X. Look at, for example, how "goto" is now a boogeyman in programming well beyond the narrow concrete problems Dijkstra had with it.

For many of the chapters of the book, I try to walk readers through the problems of simpler approaches as well as I can, but it's a continuing challenge. There really is no substitute for experience.

Re: Game Loop

#46
post #12

After playing around with making a simple, somewhat function programming-style engine [1], I came to the conclusion (from other people's work) that the game loop is really just iterating on a pure function call that gives you the next world state given the previous world state: next_world_state = UpdateWorld(inputs, previous_world_state) Where inputs is all external inputs (user inputs and "time"). How the inputs is…

this appears to use the sleep method for the game loop described in the OP article, as opposed to a fixed update interval and interpolated render step.

Re: Game Loop

#47
post #3

The book is overall excellent. I learned way more from it (and had way more fun) than I did ever reading something like the Gang of four or its various explanations. Best book to learn programming patterns in general if you ask me

I love this book as well. I think part of what makes it so good is that the patterns are discussed in a very domain-specific context and their usage is not overly abstracted. I often find it hard to see why a particular "widget" or "foo/bar" pattern or structure is used/useful, but when you put the examples in a very specific context like this, it's much easier to understand their value and remember why/when/how to u…

The secret subtext of my book is that almost all of the patterns are perfectly useful outside of games too. Very few patterns here are specific to games (though "Game Loop" is one of them).

Maybe it's just me, but if I'm going to read a few thousand words about some piece of software architecture, I'd rather be reading about trolls and magic than employee record databases.

Re: Game Loop

#48
post #5

Extrapolating up to one physics frame is still not a good solution, it will be noticeable. For example a falling object will clip in the ground for tens of ms of displacement which is definitely visually significant. A better solution is to either only interpolate and live with the additional frames of input latency (fine for a lot of games) or resimulate the next physics frame with the new player input, and live wit…

Glenn Fiedler gives the best solution to this: https://gafferongames.com/post/fix_your_timestep/ I’ve had a great experience so far following Glenn’s suggested solution.

Yes! This article was one of my main inspirations for the chapter.

Re: Game Loop

#49
I've looked into game loop pattern discussions in the past, and (as a hobbyist doing nothing serious in gamedev, just having fun with the occasional small game) I typically find them to be overly-academic and didn't really communicate why I'd want to use a pattern, simply that I "should". I've also spoken with other developers (who, to be fair, were systems and application developers first, not game developers) over-invest themselves in the theory and architectural aspects of game development, rather than ... well, actually making a fun game.

This article presents the most cogent and approachable explanation of the topic I've seen. It's empathetic style reminds me of the excellent "Head First" design patterns book (which if your ego can get past the initially-jarring style, is IMO the best way to fully grok the patterns). Thanks to the author, to to the person who shared it!

Re: Game Loop

#50

Earlier quoted context omitted.

Glenn Fiedler gives the best solution to this: https://gafferongames.com/post/fix_your_timestep/ I’ve had a great experience so far following Glenn’s suggested solution.

Yes! This article was one of my main inspirations for the chapter.

Speaking of inspirations, looking at the sample PDF on your site, I'm getting some pretty intense Edward Tufte style vibe. Was that intentional?
Post reply on HN