Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Braid Code Cleanup (part 1) (number-none.com)
173 points by cpeterso on July 19, 2016 | hide | past | favorite | 97 comments


The whole section on physics is particularly worth learning from carefully. Don't make your physics timestep depend on your rendering timestep. And if you want to have any hope of reproducible results, don't make your physics have a variable timestep at all. Pick a reasonable quantum of time, run your physics engine on that fixed timestep, and render at whatever rate you want. If the graphics framerate is slower than the physics, repeat the physics step. If the graphics framerate runs faster than physics, just render the same frame repeatedly (or update things that don't interact with physics, like decorative elements).


> run your physics engine on that fixed timestep, and render at whatever rate you want.

I think that works well for parallelizing game subsystems, too. Physics and the renderer can run at their own rates on different cores and then publish (read-only) global snapshots of their state for other subsystems to consume.


True. And that's not too hard a version of parallelism to handle: never access the same data at the same time, just run physics on frame N to produce frame N+1 while rendering frame N, and don't publish frame N+1 until after physics finishes, at which point physics never writes to it again.


In theory that sounds nice and all, however in practice this leads to jitter, since the delta between the time the physics were done, and the time the frame is shown, keeps changing. In the worst case it skews slowly over time, leading to very ugly frame skips when the counter "flows over", despite the system running at full framerate.

In practice you must always have at least a smaller version of your physics engine, that your rendering loop needs to run before actually creating the frame, to do one of these two things:

- interpolate between the last and the previous physics state, accepting a constant additional latency between input and result

- extrapolate forward from the last physics state, accepting that what is displayed will occasionally be slightly wrong for a frame

Both of these come with their own problems, which may be bad enough to completely invalidate their use depending on whatever game type they're being used for.

So even if you decouple and parallelize your loops, you end up with 3 ways to handle the result, neither of them being without disadvantages. There are no silver bullets.


Would there be any big issues to rounding the framerate to the nearest number evenly divisible by the physics rate on the fly? I'm meaning run it mostly like how he does but allow any framerate and eat the small changes in speed?


Monitor framerates are kinda "fixed". That is, there is no protocol to seamlessly change the framerate.


Though newer gaming screens are adding G-Sync (Nvidia) and FreeSync (AMD) to allow flexible monitor framerates. On a compatible GPU and screen you can display at whatever framerate you need, even a varying one, up to the maximum rate. The screen draws a new frame whenever you give it one.

On that sort of hardware (and I'm assuming only in fullscreen mode) you should be able to match your render framerate to a multiple of your physics framerate.

Whether you'd want to is arguable. If people noticed it they'd probably complain that maxing render at 140 Hz (assuming 20 Hz physics) on their 144 Hz screen is wasting their hardware. If you're doing it dynamically as physics perf varies up and down, the abrupt shifts in render framerate might be noticeable.


> physics perf varies up and down

That sounds like you're advocating variable-length physics steps. Just a warning that that can be hilariously disastrous. Due to the way physics are simulated on computers, the simulation is never perfect, and the same timeframe simulated in 5 steps can give very different results than 1 step.


Can't this be solved by keeping two copies of each value, and lerping between them based on the render timestep, essentially trading one frame of physics lag for zero jitter?


That is what i described as the "interpolate" step. Anything doing that however will still need to have a rudimentary understanding of the physics, particularly since anything not moving in a straight line won't be lerped correctly.


This rings a bell, wasn't this one of the innovations of the original Quake engine?


Rendering the same frame multiple times is terrible.

Standard solution is to interpolate position between two known physics states. This means physics is one tick behind in the normal case.

There's a clever approach I read recently. It's to trrat physics like fighting games test netcode. Extrapolate physics (usually a huge no no) and fix up in the unusual case that it's wrong.

Now that 144Hz and even 165Hz monitors are common I expect to see more experimentation with this type of thing.


I think we tend to see extrapolation as a no-no because we're thinking in terms of hundreds of milliseconds. If you know the physics of your system quite well and your interval is small enough and regular enough you can get a significant boost from extrapolation.

More: https://developer.oculus.com/blog/the-latent-power-of-predic...


> I think we tend to see extrapolation as a no-no because we're thinking in terms of hundreds of milliseconds.

Exactly. Doing physics at 30Hz and rendering at 60Hz seems like a bad idea. Doing physics at 60Hz and rendering at 120Hz seems completely fine.


> Extrapolate physics (usually a huge no no)

Why is it usually a huge no no?


For a text scroller I once made this didn't work out well. A motion of constant velocity manifests worse jitters with a fixed timestep (if timestep * velocity > 1px).

But scrolling text is a very special use case (and not physics) and probably nobody should want to scroll text at 60Hz/100dpi/arbitrary velocity...


One way to avoid that problem is to use interpolation between two frames computed by the physics engine.


That can work, but take care to avoid making the controls feel laggy in that case: if the player feels like their input doesn't immediately take effect, such as because the input gets processed on a physics timestep but the player character kept moving through interpolation, the controls can feel "floaty".



Jeez, his "day's worth of work" in part 2 sounds more like what I did in the most productive week of my life.


I'm pretty sure this is the guy who said in the "Indie Game: the Movie" documentary something akin to: "If my game doesn't succeed I'm going to kill myself" in a sincere fashion.

EDIT: It was the game developer named Fez who made the statement [1].

[1]: 39:00 mark of Indie Game: the Movie .


I think that was the guy behind Fez, Phil Fish:

> Fish, meanwhile, is heartbreakingly invested in a game he can't finish for his own perfectionism. "It's me, my ego. My identity is at risk. It's my perception of myself," he says of Fez. In the film's most startling moment, he's asked what he will do if he doesn't finish the game. "I will kill myself," he replies, meaning it. "That's my incentive to finish it." The flash of black humour relieves the tension, but it's an alarming vision of a man in desperate times.

http://www.eurogamer.net/articles/2012-03-06-indie-game-the-...


Yup you're right, got them mixed up. I rewatched the movie and the particular quote you mentioned was near the 39:00 mark. I'm going to leave the comment (with an edit) because I think it's a sentiment prevalent in a lot of game developers and is extremely alarming and should be a deterrent (or at least a consideration) to aspiring game developers.


That was especially depressing because the long series of missed deadlines and public demo disasters in the movie (as well as the very buggy eventual release when I later bought the game) gave the impression that his programming skill left a lot to be desired.


He wasn't the coder. It was another guy called Renaud Bedard


It even goes on in part 3...

> In the previous posting I said it “was a good place to stop for the night”. And I had decided to, but as sometimes happens, I changed my mind

I wonder if all his days are like that.


His progress on his language/compiler are also very impressive.


The true "10xer".


I don't really play games often but I played Braid and loved it. Does anyone have recommendations of other interesting games (probably puzzly, like Braid) that I might enjoy.

Funny story, my 4yo finished (with lots of assistance) her first adventure game (The Lost City [1]) the other day and immediately broke down in tears because it was over. Honestly, for the next couple of days she cried whenever she remembered about it.

Actually, would love to hear of about great tablet games for young kids too.

[1] https://www.firemaplegames.com/thelostcity.html


Here are a couple games you and your daughter might enjoy:

FEZ - also a puzzle-platformer, featured with Braid and Super Meat Boy in Indie Game: The Movie

Portal/Portal 2 - a first-person platform/puzzler with a sci-fi atmosphere

The Long Dark - a single-player adventure/survival game that takes place in the Canadian wilderness. Not a puzzler, but has a painterly art style like Braid and a sense of discovery exploring new locations.

Terraria/Minecraft - these games are already immensely popular among kids. Mining/crafting adventure games in 2-d and 3-d, respectively. There is a creative component in building forts/bases.

FTL: Faster than Light - a spaceship rogue-like game. Too complex for a young child, but fun gameplay if you're into Star Trek/Battlestar Galactica sci-fi themes.

Kerbal Space Program - THE game to learn rocket science and orbital mechanics [1]. Fun, engaging, and tremendously educational. If you've ever dreamed of orbiting the planet or landing on the moon, this is an incredible game. I recommend starting with Science or Career mode, because Sandbox is just overwhelming with the number of parts available. You will probably need to design the rockets at first, but your child can be involved with launching/staging (just requires pressing space bar at the right time).

[1] https://xkcd.com/1356/


Jonathan Blow released The Witness[0] not too long ago. An exploration game based on puzzles and meta-puzzles involving tracing lines. The Talos Principle[1] scratched the same itch. It involves directing laser beams to ... laser beam receptacles :)

EDIT: Disclaimer for The Witness: Go in without reading much about it. It's got plenty of puzzles about connecting paths, but that's all you really need to know. The game is as much about discovery and thinking outside/around/underneath the box as it is solving the explicit puzzles.

[0]: http://store.steampowered.com/app/210970/ [1]: http://store.steampowered.com/app/257510/


The Witness and The Talos Principle are both excellent. I loved Braid too, but there's something about the zen nature of The Witness and fiendish puzzles that really appealed to me. The final challenge was so much fun.


Fair warning: The Witness has some unsolvable puzzles for people who're bad of hearing or colorblind.

Additionally the puzzles mostly revolve around moving around in the game world until you can see the "solution" to the board in the surroundings, at which point you then simply input it; while working out the solution based on rules inherent to the puzzle is often impossible.

For example there are two entire sections where the puzzle boards offer zero hints as to the solution and the player has to move around so ----------, which one then follows or redraws with the mouse. Other puzzles involve around walking ---------------------------- so that ---------------- form continuous lines which one then traces with the mouse.

I found myself utterly bored because even 10+ hours in i still felt like playing a really elaborate game of "find the easter egg" instead of actually using my brain.

YMMV.


Man, that's a lot of spoilers. And also not a fair representation of the content of the game at all.


It soon becomes obvious that you cannot always find the solution within the puzzles themselves. Given that fact, it's no spoiler that if the solution isn't contained within the puzzle, maybe you should look to things outside the puzzle (like your environment) for clues. I will agree that saying specifics beyond that might spoil the "aha" moment for some.

Additionally, after playing through the game I felt the same way about it. Particularly the "post (meta?) game" puzzles. Perhaps some enjoyed solving those, but for me it was a tedious exercise that brought little satisfaction to the point that I ended up looking up most of them in walkthroughs.


How is it unfair? I made an effort to portray only the truth.

Also, spoilers? In a game that does not have a story?

I'd love to hear which parts of my post you consider spoilers, since i only see "align --------- and trace them" and "walk ----------- and trace lines -----------" as possible spoilers, and puzzle-wise they're incredibly mundane.


It's not really up to you to decide if a puzzle is mundane for all players. Maybe it was for you, but there was a real aha moment for me on some of those puzzles.


In the general case, you are right. However then it becomes hard to even talk about the game and particularly the difference between finding what amounts to an easter egg, or solving a problem. As puzzles you don't spend a lot of time thinking about them, trying to work out the solution. Either you notice them or you don't. That's why i qualified it with the word "puzzle-wise".


Please delete that third paragraph. However minor you think it is, they spoil some of the serendipitous experiences that are important to the game.


Since you said please. And mentioned the serindipitousness. I realized that i was mostly fine just wandering around not thinking much, until the game broke the experiences on its own by presenting me with puzzles that were physically unsolvable for my body, forcing me to youtube.

Hope the censoring i did neutralizes it enough.


Limbo is another good platformer, it's fairly short like braid and you'll die a lot but it's very forgiving, mainly placing you to right before the moment you died.

A few more suggestions are:

Fez: Similar to braid, it's a very well done puzzle platformer with a unique gameplay mechanic.

In braid it was time travel, in fez it's warping the perspective of the level to reach places you couldn't.

It has a heavy pixel art style and lasts longer than braid just because of the crazy number of secrets hidden everywhere.

The level warping affect might feel strange but after 20-30 minutes your brain will just accept it and you'll be able to move along.

Antichamber: I'd consider this a mix of braid meets open-world portal.

It's first person, but each area has its own little mechanics you'll need to learn to get through it.

Don't worry about the harsh looking visual style, it was much less than I thought once I started playing.

Portal: Since I've mentioned it, portal & portal 2 for obvious reasons. Often considered "THE" first person puzzle game.

Hyper light drifter: An unusual one, I'm putting it here not because of the gameplay, but because of the art and story.

This is an atmospheric top down exploration game with short difficult fast paced combat segments that are very forgiving, doesn't matter if you die you can just try again or walk away.

The art style is super vivid pixel art and its story is just like braid where you don't quite get it until the end then you'll end up watching an explanation video on youtube and preceed to go "Aah" for the next week.


> Antichamber: I'd consider this a mix of braid meets open-world portal.

Seconded. It's brain-breaking in a fun way, playing with your expectations.


And it gives you hints to the puzzles you just solved, which I find hilarious.


Take a look at Machinarium. Not sure about the age level but it might be similar

http://amanita-design.net/games/machinarium.html


Another vote for Machinarium here .. my family love the game and have played through it a couple of times, from the 5 year old to the 9 year old to the wife .. they love the aesthetics of the game, which is really peaceful in parts but devilishly tricky in others .. would love to know of similar games in this genre.


`Limbo` and the new `Inside` are amazing puzzle platformers. Creepy as all hell, though.


Totally different genre, but The Talos Principle is another beautiful puzzle game with a thoughtful story.

http://store.steampowered.com/app/257510/



You might like Fez and Antichember. Both are available on steam.


For anyone reading, this is 1 part of a 4 part series he has on his blog (over around as many days).

And Blow is an animal! I wish this guy was on my team and not an indie developer. His output level (and pragmatism) are insane! Change the fundamental structure of a ~100k loc project in a few days? No problem!


>Visual Studio 2015 / Add notelemetry.obj to link line to reduce Microsoft adware potential.

It's quite sad that you need to proactively add a notelemetry.obj to your link line to turn off telemetry when generating your code.


It's for ETW. It's not doing any telemetry unless you use it for telemetry. Also I think they removed the initialization code from being linked in by default in the latest update.


Is he re-releasing this or something? Curious why he's going back through the code.


From http://number-none.com/blow/blog/programming/2016/07/07/brai...:

The game Braid originally shipped to the world in 2008, and after some ports in 2009, I have only worked significantly with the code on a few occasions. But I want to maintain this game indefinitely into the future; in the back of my mind, there have always been some clean-ups that I have wanted to perform on the code. Often when shipping a game, the best answer to a problem isn’t evident, and we are under time pressure, so we solve the problem in some way that is sufficient but sub-optimal. Other times, we need to design the game to meet technical constraints of systems we want to deploy on, but as the years go on, these systems become irrelevant, so the code can be cleaned up. I figured it would be interesting to talk about some of these things in a blog (and the blog will help motivate me to think about these situations and clean some of them up!)


As a game developer in a semi-previous life, this sounds like such fantastic luxury.

Game code is often (not always, and in larger studios that maybe have their own engines even less so) fire-and-forget.

I'm almost kind of jealous. :)


After a few days of working on it, it seems like he’s been able to cut about 25k lines of code from the original ~95k, taking it down to about 70k lines. Pretty nice!

Throwing away never-called functions, chopping out hacks for now-outdated platforms, de-duplicating subsystems, switching to easier-to-reason-about data structures, making assets and related code use more standard formats, etc. must be pretty satisfying, like peeling old faded cracking paint off a wall and refinishing it.

I wonder where he’ll end up.


Maybe doing a sequel or using the tech as a base for a new game?


Sadly, no. He's spoken about this in length on Twitter. He's working on a new game written in Jai. He's going back and retouching the Braid code because it crashes frequently on Windows 10. He wants to keep selling it, so he has to fix it.


Like the other thousands of people, I absolutely loved Braid. I think this comment gets my hopes up, but wow would I love to see a sequel.


The game felt like a pretty thorough exploration of the time-rewind mechanic, and Blow was obviously careful that each puzzle served a unique purpose. I doubt he feels like he has anything interesting to put in a Braid II that wasn't already in the first game.


I'd even buy some extra levels with just the original Braid's gameplay.

I think, though, that he could come up with some new creative power-ups and such to add to the gameplay.

I keep thinking like a Mario vs Mario 3 idea. Sure it still had firepower and such, but adding the flying added a lot to the game.


The problem with sequels in games this good is that the game is so much better than anything else when it is released, that a sequel can't be anything other than an incremental update, and thus feels lackluster.

The same thing will happen with the Deadpool movie sequel. The first movie was innovative in that it was the first mainstream movie to break the fourth wall, have tons of R-rated jokes, etc, but you can only do that once.


Counterexample: Portal 2. Same basic concept, innovated on the original in every conceivable way. Sure, I like the original better because nostalgia glasses, but I can objectively state that the sequel is a fucking excellent game.


> The first movie was innovative in that it was the first mainstream movie to break the fourth wall,

You're either very young, or haven't watched very many movies.


I think what he meant to say was that it was the first mainstream movie to combine breaking the fourth wall with lots of R-Rated jokes and certain other unspecified features that is, the list of features was a unit, not a list of things that Deadpool was first at individually.

At least, that's the charitable interpretation that makes the claim not-laughable-on-its-face.


> The problem with sequels in games this good is that the game is so much better than anything else when it is released, that a sequel can't be anything other than an incremental update, and thus feels lackluster.

Depends on the sequel. If the sequel is just an additional collection of levels, then just provide a fun "additional levels pack" as an add-on, and/or provide a way to share community-produced levels. That doesn't have the same expectations as a sequel.

If you're going to actually make a sequel, put enough effort, new mechanics, and story into it to make it a new game in its own right. For examples of sequels that put enough effort in to be a new game while still feeling like a sequel to the original, look at Portal 2, or Super Mario Bros 3 (by contrast to Lost Levels, which was fundamentally just a level pack). Numerous sequels pull this off, even of innovative indie games.

But it's also possible that the new game will end up with entirely new mechanics and story to the point that it isn't a sequel, and instead becomes "a new game from the makers of ...". And that's awesome too.


> first mainstream movie to break the fourth wall

What's it all about, Alfie?

https://en.wikipedia.org/wiki/Alfie_(1966_film)#Reception


> The first movie was innovative in that it was the first mainstream movie to break the fourth wall, have tons of R-rated jokes, etc,

Check out Naked Gun kiddo.


> The first movie that I care about to break the fourth wall, have tons of R-rated jokes, etc,

What he probably meant to say. So often we forget that literally everything is an "overdone trope" at this point, unless you do it well.


True. The first movie I 'care about' that fits this description is probably Austin Powers then. Watch it again if you haven't in years, you'll catch all the jokes that flew over your head as a kid.


I loved it as a teenager but watched it again recently (now in my early 30s) and thought it was truly awful. Some things are better left in the past!


Also Blazing Saddles.


I don't think that is gonna happen though. He'd would want Braid to stand in its own right.


Or an eventual source release?


This would be freaking awesome. I've always wanted to know how the physics in that game work.


I wouldn't be that surprised if he turns it into an example Jai project.


> But then, toward the end of the project, it became clear that the game would not fit in memory on the Xbox 360 (which had 512MB of physical RAM, but of course a game could not use all of that)

Wow. Less than 512MB. I can't imagine how they fit stuff like Destiny and Halo: Reach into that.


I always wonder how saving a few dollars in RAM pays off for the effort game developers have to make to ship games. I mean the consoles sales are tens of millions, but I guess games titles are in the thousands and they spend a lot of money to cope with these limitations.

Interesting reading: How Naughty Dog Fit Crash Bandicoot into 2MB of RAM on the PS1 https://news.ycombinator.com/item?id=9737156


They actually lose money on the consoles and hope to make it back up with games. And to be totally fair, the entire 512MB was made of GDDR3.

That's right. The entire RAM bank was made of chips designed for graphics. So it's no wonder it was so expensive.

Edit: and this was necessary to decrease the latency between graphical operations and processor operations. You can load graphics directly into what is essentially VRAM, rather than having to pull it through regular RAM first. Because there is no regular RAM.

The tradeoffs made sense at that point in time, because DDR1/2 sucked a lot, and pulling data through multiple stages would drag down performance.


For the manufacturer, it really does make a difference to their bottom line. The "software tie ratio" of console games in the 360/PS3 era was modest - somewhere between 3 and 8 according to this graph [0]. Getting unit cost down matters a lot when you aren't selling a lot of additional content, and the hardware got optimized around whatever game developers could soak up the most.

As such it was conventional for game consoles to have fast-but-small RAM. The reasoning is that console games mostly bottleneck on the rendering of a scene at acceptable framerates, vs. simulating all aspects of a complex scene or achieving maximum detail as a movie would. Since ROM cartridges were fast and optical allowed data to be streamed in "fast enough", there were plenty of ways to achieve the right effect under tight RAM conditions. One exceptional case where tight RAM did not play out well is the N64's 4kB texture cache, which imposed a large burden on the entire art pipeline(if you wanted a high res texture, you had to resort to tricks like tiling it across additional geometry).

Today what is demanded from a console is much more in lock step with every other consumer device - they do more computer-like things, they can multi-task some and scenes are doing more memory-intensive things so they're more well-rounded, and get more RAM.

[0] http://vignette2.wikia.nocookie.net/vgsales/images/c/ce/Esti...


Answer: Mipmaps(+ LoDs) and streaming, lots and lots of streaming.


That would explain why Halo: Reach required a hard drive for local multiplayer. It couldn't stream fast enough from the DVD for two+ viewports.


AND that's 512MB shared with graphics, AND that was the higher of the two options Microsoft was considering for the 360:

https://forums.epicgames.com/archive/index.php/t-553976.html


Yikes. Makes bad console ports especially underwhelming. Just recently have I encountered any games that even pretend to use the abundant resources available to them on PC - and of course they are PC exclusives, like Total War Warhammer.


Yup, you wouldn't believe the amount of pain you see from doing a port from PC -> X360. Malloc is not heavily optimized since with limited memory you usually allocate up front. Lots of PC games are allocation heavy since it's fast on the desktop and large parts of major subsystems need to be rewritten to be console friendly.


I was thinking more the other way around. Slow, clunky, low-res console-first games that labor to get 30 fps while using a tiny fraction of the available CPU, GPU and RAM when ported to PC.


Ah, I misread it. There's a very good chance you're just seeing the development engine that has very little optimization since ports are usually an afterthought.

Either way they're very different environments. For instance you usually have a unified memory model on most consoles where on PC you have to shuffle textures across a memory bus to the GPU. Leads you to optimize for different things(although most ports I know of were done with a skeleton team).


> Also, demos are not really necessary today; if people want to find out about a game, they can look on YouTube or read what many many people have to say about the game on the internet.

Just no. And the steam refund if played less than 2 hours doesn't help. For most games, 2 hours is not enough.


Demos sounds good in theory, but I think you'll find that they adversely decrease sales in the long run. They take effort to put together, and serves only to stop the player from buying.

The reason is that if you are interested enough to try the demo, you'll only be swayed to not buy the game if you're dissatisfied, it obtained enough from the demo that you're no longer interested in the actual game. If you're already going to buy, you won't try the demo. In both cases, it's bad for the developer.


I've seen this argument and I strongly disagree. Speaking anecdotally, I've bought plenty of games after trying the demo that I wouldn't have even considered otherwise. (Or would have waited to go on sale.) Also, I think it's just the right thing to do — though with Steam refunds, it's probably not as big of a deal anymore.


On the flip side games like Battlefield and Overwatch which are entirely multiplayer driven and have various balancing and load-testing requirements benefit immensely from (free) alpha and beta stages which are essentially demos. With the increased prevalence of such games I can only imagine demos remain prominent (even if they are called "alpha/beta periods" instead.


I agree that reading reviews and watching videos are a poor substitute for demos, but what games do you play for 2 hours and not realize that they're not worth the asking price?

Sure, you might realize after 10 hours that it's not as great as you had hoped - but that's still (usually) quite a lot cheaper entertainment (per hour) than buying a CD or going to the movies?

[ed: to clarify, if you had a great time playing a game for 10 hours - even if you then find that it has less replay value, or too little content compared to what you would like - hopefully you've then had fun for 10 hours playing it...]


Steam sales and Humble bundles give an incredibly low-cost chance to try out games that you wouldn't ever take a flyer on at full price. I've found a few gems, but there's a lot of stuff that I haven't played, or have put in under an hour on, but hey, it was $2. Cheaper than a cup of coffee.


[flagged]


Please don't post snarky dismissals to HN.


This comment is the definition of the word "ignorant". Braid is a mindblowing puzzle game and nothing like it had ever been released before.


Just play it. The first level you will think you were right, if I remember correctly it even has some references to Mario, but if you continue it will surprise you and realize that is far from a 2d scrolling. The Last few levels are really challenging.


Appearances can be deceiving. It might look crude and simple, but it's not.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: