[Haskell-cafe] Observer pattern in haskell FRP
nathan.huesken at posteo.de
Mon Nov 26 23:17:33 CET 2012
When writing games in other (imperative) languages, I like to separate
the game logic from the rendering. For this I use something similar to
the observer pattern.
With rendering I mean anything only related to how objects are drawn to
the screen. Animation state for example.
On my journey of exploring game programming with haskell (and FRP), I
wonder what a good way of archiving something similar would be.
If the rendering has no internal state, one can just write a function
draw :: GameLogicState -> IO ()
But when the rendering of an object has an internal state (e.g.
animation frame) than this is not possible.
Now I could write a Wire/Signal (whatever FRP implementation I use) that
translates to a RenderingState:
render :: Signal GameLogicState RenderingState
draw :: RenderingState -> IO ()
which is fine, except when my game is made of many objects.
Than I need to associate the state of one object in GameLogicState with
a sub-signal in render.
That could be done by giving every object an ID and letting
GameLogicState contain a map from IDs to ObjectLogicState.
I fear that when I really have a lot of objects, assembling and
decomposing the map could become a major bottleneck.
So I am wondering: Is there (or can someone think of) a different
pattern by which this could be archived? Or asked different: How would
you do it?
More information about the Haskell-Cafe