4 ms·
Yeah, and then at some point of time the "time" input becomes a bit too large for "%" to give accurate results and the whole thing freezes and updates only once
by Joker_vD 4y ago
Yeah, and then at some point of time the "time" input becomes a bit too large for "%" to give accurate results and the whole thing freezes and updates only once every ten seconds. Whoops!
- mrguyorama 4y agoI think in practice you eventually reset the "time" variable to 0 and just accept that one weird discontinuity, if you care about it at all. Plenty of time the "time input becomes too large" only happens after tens of hours of nonstop play.
- Joker_vD 4y agoYes, but again, if you care about accuracy, it's not as easy as "time = fmod(time, 1e6)" or something: take look at any "accurately rounding" implementation of sin(x) (e.g. in gcc) to see weird floating-math tricks used in the range reduction. Also, it is not always about time, sometimes it is about position in space! Generating an (almost) infinite world is usually done in the "animation" style (using a noise generator or some such) and with rounding/overflow errors you get e.g. Minecraft's so called "Far Lands" [0] — game physics used to break there as well. [0] https://minecraft.fandom.com/wiki/Far_Lands https://minecraft.fandom.com/wiki/Far_Lands
- dgb23 4y agoIn a game loop you can typically pass in the time (delta) since the last frame update. Everything else is a function of that plus the values since the last update.
- Joker_vD 4y ago...did you read the actual article? It's explicitly about how instead of stepping the simulation by a time delta you can instead use "animation"-style where you take the time point and derive state straight from it, without any differential calculus: def ball_position(time): if time < 0: return (0, 0) stop_time = 2 * Y_VELOCITY / GRAVITY if time > stop_time: return (X_VELOCITY * stop_time, 0) x = X_VELOCITY * time y = (Y_VELOCITY - GRAVITY * time / 2) * time return (x, y)
- pshirshov 4y agoCan you do it for the game of life? Pretty please?
- Joker_vD 4y agoI am pretty certain there is no general closed-form solution for Game of Life because it's Turing-complete; although for some initial configurations (gliders etc.) you can have a simple (or not so simple) expression, in the general case you simply have to simulate it step by step, no other way around it.