4 ms·
> If game devs redraw their stuff at 100+ FPS and haven't needed mutable state Well I wouldn't quite say that... although there was a time when "dirty rectangl
by Jare 11y ago
> If game devs redraw their stuff at 100+ FPS and haven't needed mutable state
Well I wouldn't quite say that... although there was a time when "dirty rectangles" was an important feature of a graphics engine. Generally speaking, games are based on mutation of entities: to move an existing entity, we mutate their position, not recreate them in the new position.
- strictfp 11y agoSorry I should have said view state. Dirty rectangles are indeed such an optimization, you are right.
- stcredzero 11y agoGenerally speaking, games are based on mutation of entities: to move an existing entity, we mutate their position, not recreate them in the new position. Actually, games are generally an area where immutability is relatively easy to use. All of the mutation code can be isolated in one place that handles the transition to the next "tick", leaving nothing but immutables in the game logic itself. This is analogous to how ReactJS manages things through diffing.
- Jare 11y agoConceptually it's very easy: World(t+1) = Sim(World(t)) but performance in practice is going to suffer a lot compared to in-place mutation, for any simulation that has a great degree of temporal coherence. I don't know of real world examples of game developed with immutable / reactive patterns, outside of thought experiments like Carmack's (Or Tim Sweeney's), or a few simple games in Haskell, Elm, etc. But I'd love to hear of more examples. (Edit: some parts of games and game engines use this sort of "double buffer" approach for other purposes: smoothing and interpolation mostly, of visual frames in between logic ticks, or for network prediction. But in the cases I have seen or coded, most of the world state is not interpolated and not duplicated)
- stcredzero 11y agoI am not yet a professional game developer, but I did write a multiplayer server in Clojure. It had most of the features of the current version, which was ported to golang: https://secure.emergencevector.com:8000/ https://secure.emergencevector.com:8000/ (Be sure to mouse click on the map, otherwise your arrow key keystrokes may never get read due to focus.) I got pretty similar performance out of Clojure's persistent collections as I got out of mutable state in a traditional game loop in golang. (Though to be honest, in neither case was that enough performance. 150 to 250 concurrent users, potentially all in the same location, interacting.)