
Braid Code Cleanup (part 1) - cpeterso
http://number-none.com/blow/blog/programming/2016/07/16/braid_code_cleanup_1.html
======
JoshTriplett
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).

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

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

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

~~~
ball_of_lint
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?

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

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

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

------
robin_reala
See also part 2 ([http://number-
none.com/blow/blog//programming/2016/07/17/bra...](http://number-
none.com/blow/blog//programming/2016/07/17/braid_code_cleanup_2.html)) and
part 3 ([http://number-
none.com/blow/blog//programming/2016/07/18/bra...](http://number-
none.com/blow/blog//programming/2016/07/18/braid-cleanup-part-3.html))

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

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

~~~
faitswulff
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-...](http://www.eurogamer.net/articles/2012-03-06-indie-game-the-movie-
review)

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

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

------
aidos
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](https://www.firemaplegames.com/thelostcity.html)

~~~
lfowles
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/](http://store.steampowered.com/app/210970/)
[1]:
[http://store.steampowered.com/app/257510/](http://store.steampowered.com/app/257510/)

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

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

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

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

~~~
Mithaldu
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".

------
nstj
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!

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

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

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

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

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

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

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

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

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

~~~
SmellyGeekBoy
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!

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

~~~
pmoleri
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](https://news.ycombinator.com/item?id=9737156)

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

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

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

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

