I'm stuck with generating debug output for my game objects using Haskell/Yampa (=Arrows) (with HOOD).
My engine basically runs a list of game objects which produce Output states (line, circle) which are then rendered.
data Output = Circle Position2 Double | Line Vector2
output :: [Output] -> IO ()
output oos = mapM render oos
render :: Output -> IO ()
render (Circle p r) = drawCircle p r
render (Line vec) = drawLine (Point2 0 0) vec
The player object just moves to the right and is represented as a (positioned) circle.
playerObject :: SF () Output -- SF is an Arrow run by time
p <- mover (Point2 0 0) -< (Vector2 10 0)
returnA -< (Circle p 2.0)
mover is just a simple integrator (acceleration->velocity->position) where I want to observe the velocity and render it as debug output as an (unpositioned) Line.
mover :: Position2 -> SF Vector2 Position2
mover position0 = proc acceleration -> do
velocity <- integral -< acceleration -- !! I want to observe velocity
position <- (position0 .+^) ^<< integral -< velocity
returnA -< position
How can I create additional graphical debug output for internal values of my game object functions?
What actually should happen is in output, first render the actual object (circle) but also render additional debug output (movement vector as line). Probably I can achieve this with HOOD but I'm still not fluent in Haskell and don't know how do adopt the HOOD tutorial for my case.
I don't know HOOD but Debug.Trace is easy:
> import Debug.Trace
> mover position0 = proc acceleration -> do
> > velocity <- integral -< acceleration
> > position <- trace ("vel:" ++ show velocity ++ "\n") $
> > > > > > > > > > > (position0 .+^) ^<< integral -< velocity
> > returnA -< position
Note that it shouldn't be put on the line defining velocity.