3

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 は単純なインテグレータ (加速度 -> 速度 -> 位置) であり、速度を観察し、デバッグ出力として (位置付けされていない) ラインとしてレンダリングします。

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 チュートリアルを採用する方法がわかりません。

4

2 に答える 2

2

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

速度を定義するライン上に置くべきではないことに注意してください。

于 2010-07-15T13:15:58.287 に答える
1

おそらくやりたいことは、帯域外のデバッグ情報 ( の値) を追加してレンダリングするmoverことをサポートするために、より柔軟にすることです。velocity継続的に変化する値を処理するための FRP フレームワークが既にあるため、HOOD が問題に関連しているとは思いません。速度が出力されるように調整するだけです。

何かのようなもの:

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]
于 2011-07-02T02:47:43.370 に答える