Box2D
Safe HaskellNone
LanguageGHC2021

Box2D.RecPlayer

Synopsis

Documentation

create Source #

Arguments

:: Ptr ()

data: Recorded bytes, e.g. from b2Recording_GetData or a loaded file

-> Int

size: Number of recorded bytes

-> Int

workerCount: Worker count for the replay world. 0 uses the serial single-worker fallback.

-> IO (Ptr RecPlayer) 

Open a recording for incremental playback and replay up to the first step. The player copies the bytes, so you may free or destroy the source buffer immediately after this call.

Returns: A player handle, or NULL if the recording is malformed

Binds b2RecPlayer_Create.

stepFrame :: Ptr RecPlayer -> IO Bool Source #

Advance the replay by one recorded step.

Returns: true if a step executed, false once the end of the recording is reached

Binds b2RecPlayer_StepFrame.

getWorldId :: Ptr RecPlayer -> IO WorldId Source #

Get the id of the replayed world.

Binds b2RecPlayer_GetWorldId.

restart :: Ptr RecPlayer -> IO () Source #

Rewind the player to the first step, recreating the replay world from the file.

Binds b2RecPlayer_Restart.

seekFrame Source #

Arguments

:: Ptr RecPlayer 
-> Int
targetFrame
-> IO () 

Seek to a recorded step. Seeking backward rewinds and re-runs from the start, so the cost grows with the target frame. Clamps to the recording bounds.

Binds b2RecPlayer_SeekFrame.

getFrame :: Ptr RecPlayer -> IO Int Source #

Get the number of steps replayed so far.

Binds b2RecPlayer_GetFrame.

getInfo Source #

Arguments

:: Ptr RecPlayer 
-> Ptr RecPlayerInfo

Result buffer.

-> IO () 

Get static metadata for the recording (frame count, recorded tuning, time).

Binds b2RecPlayer_GetInfo.

isAtEnd :: Ptr RecPlayer -> IO Bool Source #

Returns true once the end of the recording has been reached.

Binds b2RecPlayer_IsAtEnd.

hasDiverged :: Ptr RecPlayer -> IO Bool Source #

Returns true if a recorded state hash failed to reproduce, meaning replay diverged.

Binds b2RecPlayer_HasDiverged.

getDivergeFrame :: Ptr RecPlayer -> IO Int Source #

Get the first step at which replay diverged, or -1 if it has not diverged.

Binds b2RecPlayer_GetDivergeFrame.

setKeyframePolicy Source #

Arguments

:: Ptr RecPlayer

player: the recording player

-> CSize

budgetBytes: Memory cap for the kept snapshots. The spacing widens to stay under it.

-> Int

minIntervalFrames: Finest spacing between keyframes, in frames. A zero budget or a non-positive interval keeps that value. Clears the existing ring, so call b2RecPlayer_Restart afterward to repopulate it under the new policy.

-> IO () 

Tune the keyframe ring used to speed up backward seeking. A keyframe is a periodic snapshot the player restores from instead of replaying from the start, trading memory for seek speed.

Binds b2RecPlayer_SetKeyframePolicy.

getKeyframeBudget :: Ptr RecPlayer -> IO CSize Source #

Get the keyframe memory budget in bytes.

Binds b2RecPlayer_GetKeyframeBudget.

getKeyframeMinInterval :: Ptr RecPlayer -> IO Int Source #

Get the finest keyframe spacing in frames.

Binds b2RecPlayer_GetKeyframeMinInterval.

getKeyframeInterval :: Ptr RecPlayer -> IO Int Source #

Get the current keyframe spacing in frames. Starts at the min interval and doubles as the ring evicts to stay under budget, so it reflects the effective backward-seek granularity right now.

Binds b2RecPlayer_GetKeyframeInterval.

getKeyframeBytes :: Ptr RecPlayer -> IO CSize Source #

Get the memory currently held by keyframe snapshots, in bytes.

Binds b2RecPlayer_GetKeyframeBytes.

destroy :: Ptr RecPlayer -> IO () Source #

Close a player and free its replay world and file buffer.

Binds b2RecPlayer_Destroy.

drawFrameQueries Source #

Arguments

:: Ptr RecPlayer

player: A valid player handle

-> Ptr DebugDraw

draw: Debug draw callbacks. NULL draw function pointers are skipped.

-> Int

queryIndex: Index into the frame's queries to draw, or -1 to draw all of them.

-> IO () 

Draw spatial queries recorded during the most recently replayed frame. Call after b2World_Draw so queries are layered on top of the world.

Binds b2RecPlayer_DrawFrameQueries.

getFrameQueryCount :: Ptr RecPlayer -> IO Int Source #

Get the number of spatial queries recorded for the most recently replayed frame.

Binds b2RecPlayer_GetFrameQueryCount.

getFrameQuery Source #

Arguments

:: Ptr RecPlayer 
-> Int
index
-> Ptr RecQueryInfo

Result buffer.

-> IO () 

Get a recorded query from the most recently replayed frame by index.

Binds b2RecPlayer_GetFrameQuery.

getFrameQueryHit Source #

Arguments

:: Ptr RecPlayer 
-> Int
queryIndex
-> Int
hitIndex
-> Ptr RecQueryHit

Result buffer.

-> IO () 

Get one result of a recorded query from the most recently replayed frame.

Binds b2RecPlayer_GetFrameQueryHit.

getBodyCount :: Ptr RecPlayer -> IO Int Source #

Get the number of body slots tracked for the outliner. This is the creation-order span and includes holes for destroyed bodies, so it only grows as the replay advances.

Binds b2RecPlayer_GetBodyCount.

getBodyId Source #

Arguments

:: Ptr RecPlayer 
-> Int
index
-> IO BodyId 

Get a tracked body by creation ordinal. Returns b2_nullBodyId for a destroyed slot, an ordinal not yet reached at the current frame, or an out-of-range index. Validate with b2Body_IsValid.

Binds b2RecPlayer_GetBodyId.