This thread on Hacker News terrifies me
Dennis
dkorpel at gmail.com
Sat Sep 1 11:34:28 UTC 2018
On Saturday, 1 September 2018 at 08:18:03 UTC, Walter Bright
wrote:
> On 8/31/2018 7:28 PM, tide wrote:
>> I'm just wondering but how would you code an assert to ensure
>> the variable for a title bar is the correct color? Just how
>> many asserts are you going to have in your real-time game that
>> can be expected to run at 144+ fps ?
>
> Experience will guide you on where to put the asserts.
>
> (...)
>
> Apply common sense and assert on unreasonable results, because
> your code is broken.
Your examples are valid, but I just wanted to say the game
development is a bit of a 'special' case in software engineering
because there is often no clear 'correct' output for an input.
The desired output is simply one that makes the players happy,
which is subjective.
Take for example a 3D game where a car gets stuck between
bollards and launches into the air. The problem is that real-time
physics engines work in discrete steps and try to solve
constraints by adding force to push overlapping bodies away from
each other. When a rigid body gets stuck inside another rigid
body, the force it generates can be comically large. This problem
is well known but a 'proper' fix is not easy, it's often solved
by designing the geometry so that cars can't get stuck like that.
Would an `assert(car.yVelocity < 200 m/s)` that causes the game
to crash when that happens really make the game better? Many
players actually enjoy such glitches. They don't like when their
character randomly clips through the floor and falls into a void
however. But how would you assert that doesn't happen? There's no
formal definition for it.
By the way, I'm sure the way the Unity game engine treats asserts
will make you cry:
"A failure of an assertion method does not break the control flow
of the execution. On a failure, an assertion message is logged
(LogType.Assert) and the execution continues."[1]
That's in debug builds, in release builds they are removed
completely. So my `Assert.IsNotNull()` fails but the assert
message quickly gets buried under a slew of errors. Note that the
game keeps running, the 'C# script component' of the entity in
question just ceases to work. "The show must go on!"
[1]
https://docs.unity3d.com/ScriptReference/Assertions.Assert.html
More information about the Digitalmars-d
mailing list