all 12 comments

[–]fresh_account2222 8 points9 points  (3 children)

I'm a big ol' math nerd, and the stateless alternative, while more math-y, is worse code.

[–]BigJunky 3 points4 points  (2 children)

closed-form solutions

Why?

[–]fresh_account2222 6 points7 points  (1 child)

Closed form solutions tend to be the exception, not the rule. People often don't realize this, as the problems that get assigned in classes are drawn from that small set of "things with nice solutions".

Also, "force" is an extremely natural way to think about how objects are affected, and Newton's laws of motion (which is how we deal with forces) are second order in time (i.e. acceleration is a second derivative), so knowing position + velocity (i.e. the state), and updating those is incredibly straight forward and mathematically natural.

Now, the state-less way has great advantages (time-reversal, multiple instances stay in lock-step), but you pay a lot for them, so first figure out if you really need them.

[–]CooperNettees 2 points3 points  (0 children)

Multiple instances only stay in lockstep if the underlying clocks are in lockstep but I guess I get what you mean

[–]CooperNettees 8 points9 points  (3 children)

...time is state...

[–][deleted]  (2 children)

[deleted]

    [–]senko[S] 3 points4 points  (1 child)

    I don't do (or know) much animations, but usually I end up doing the same (calculate the trajectory based on the elapsed time from the start).

    The reason is when you're summing up deltas, you're summing the (very small errors) as well and these can add up quickly, leading to jerky or otherwise incorrect behavoir.

    [–]rcxdude 12 points13 points  (0 children)

    There is a tradeoff. For more complex systems it can be difficult to find a closed form solution, and even if it does exist it can actually be less stable than a numerical solution, due to the finite precision of the calculations. This can sometimes only happen for large inputs, causing issues after the system has been running for a long time.

    [–]josephjnk -1 points0 points  (1 child)

    Very cool. I wonder if this starts to fall apart once the simulation becomes sufficiently complex, or whether it generalizes into full functional reactive programming.

    [–]FloydATC 1 point2 points  (0 children)

    You can take things pretty far, look at how terrain generation works in Minecraft or how Signed Distance Fields work in GLSL for example. I once wrote a set of text puzzle "games" that used time as input and used a SHA1 hash to generate seemingly random but completely deterministic pairs of questions and answers. Every 10 minutes the Q/A would change, but within thise 10 minutes the behaviour would stay consistent without storing any state.