[Haskell-cafe] Observer pattern in haskell FRP

Тимур Амиров timur.deteam at gmail.com
Tue Nov 27 05:08:55 CET 2012


Not sure, but maybe you can define a Drawable  class with a method in
converting inner state to something draw func could use, so it would be
like this:

draw :: Drawable a => a -> IO ()

вторник, 27 ноября 2012 г. пользователь Nathan Hüsken писал:

> Hey,
>
> 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?
>
> Thanks!
> Nathan
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org <javascript:;>
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


-- 
Best
Timur DeTeam Amirov
Moscow, Russia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121127/0dee50a0/attachment.htm>


More information about the Haskell-Cafe mailing list