debugging - 在 Haskell/Yampa 和 HOOD 中调试游戏对象的输出

标签 debugging haskell game-engine yampa

我一直坚持使用 Haskell/Yampa (=Arrows)(使用 HOOD)为我的游戏对象生成调试输出。

我的引擎基本上运行一系列游戏对象,这些对象产生输出状态(线、圆),然后进行渲染。

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

玩家对象向右移动并表示为(定位的)圆圈。

playerObject :: SF () Output -- SF is an Arrow run by time
   p <- mover (Point2 0 0) -< (Vector2 10 0)
   returnA -< (Circle p 2.0)

移动器只是一个简单的积分器(加速度->速度->位置),我想在其中观察速度并将其渲染为调试输出作为(未定位的)线。

mover :: Position2 -> SF Vector2 Position2
mover position0 = proc acceleration -> do
    velocity <- integral -< acceleration -- !! I want to observe velocity
    position <- (position0 .+^) ^<< integral -< velocity
    returnA -< position

如何为游戏对象函数的内部值创建额外的图形调试输出?

实际应该发生的是在输出中,首先渲染实际对象(圆形),但也渲染额外的调试输出(运动矢量作为线)。也许我可以使用 HOOD 来实现这一点,但我仍然不熟悉 Haskell,并且不知道如何针对我的案例采用 HOOD 教程。

最佳答案

我不知道 HOOD,但 Debug.Trace 很简单:

> import Debug.Trace
> mover position0 = proc acceleration -> do
> > velocity <- integral -< acceleration
> > position <- trace ("vel:" ++ show velocity ++ "\n") $
> > > > > > > > > > > (position0 .+^) ^<< integral -< velocity
> > returnA -< position

请注意,不应将其放在定义速度的线上。

关于debugging - 在 Haskell/Yampa 和 HOOD 中调试游戏对象的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3255334/

相关文章:

javascript - 使用 if(cond) else if(same Cond) 检查相同条件两次是什么意思?

c - 为什么 Visual Studio 2010/12 在 Debug模式下运行程序会占用大量内存和时间?

javascript - 让 tinyMCE 拼写检查器插件与 IE6 一起工作的问题

debugging - GDB `run` 命令失败并显示 "Cannot insert breakpoint 1."

haskell - 使用 GADT 自动派生类型类约束

unity-game-engine - Unity实时软阴影

c - 调试时查看源代码的宏扩展版本

python - Thrift 服务器对于简单操作来说确实很慢

haskell - 使用 FoldM 和可能的 State 编写一个简单的函数

prolog - 有没有使用过 Prolog 的商业视频游戏?