2010-07-15 55 views
3

我一直使用Haskell/Yampa(= Arrows)(與HOOD)爲我的遊戲對象生成調試輸出。在Haskell/Yampa和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) 

動機只是一個簡單的積分器(加速 - >網速度>位置)其中,I想觀察速度並使其作爲調試輸出作爲(unpositioned)線。

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教程。

回答

1

我不知道,但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

注意,它不應該被提上定義速度的線。

+0

這不會給圖形輸出,不過,在控制檯上只是文本,並且一般有點有限。有時候'unsafePerformPrintfDebugging'就是你真正需要的,但我認爲這裏的提問者不止於此。 – 2010-07-15 13:50:38

1

您可能想要做的就是讓mover更靈活,以支持添加要呈現的帶外調試信息(值爲velocity)。我不認爲HOOD與你的問題有關,因爲你已經有FRP框架來處理不斷變化的值。只需安排速度輸出。

喜歡的東西:

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

playerObject :: SF() [Output] 
    (p, v) <- mover (Point2 0 0) -< (Vector2 10 0) 
    returnA -< [Circle p 2.0, Line v] 
+1

改變和打破界面正是我想要避免的。函數的簽名應該保持不變,但函數體中數據流之間的一些額外註釋會傳遞給外部系統並以視覺樣式呈現。像GHood一樣,但具有交互式程序功能。 – 2011-07-03 09:42:47

+0

如果您不介意重新計算(不幸的是,Yampa原則上應該能夠避免這種情況,但是不會),您可以將Veloctiy計算分解爲自己的標識符,然後從頂層訪問它。或者你可以在遠處做一些不安全的行爲,將相關位傳播到頂層。 – 2011-07-03 15:58:21