Box2D 3.2.0
A 2D physics engine for games
Loading...
Searching...
No Matches
Recording

These functions allow you to record a simulation for later playback. More...

Typedefs

typedef struct b2Recording b2Recording
 Opaque handle for a recording buffer.

Functions

b2Recording * b2CreateRecording (int byteCapacity)
 Create a recording buffer.
void b2DestroyRecording (b2Recording *recording)
 Destroy a recording buffer and free its memory.
const uint8_t * b2Recording_GetData (const b2Recording *recording)
 Get a pointer to the recorded bytes, for saving to a file or transmitting.
int b2Recording_GetSize (const b2Recording *recording)
 Get the number of recorded bytes.
void b2World_StartRecording (b2WorldId worldId, b2Recording *recording)
 Begin recording the world into recording.
void b2World_StopRecording (b2WorldId worldId)
 Stop recording.
bool b2Recording_SaveToFile (const b2Recording *recording, const char *path)
 Save a recording buffer to a file.
b2Recording * b2CreateRecordingFromFile (const char *path)
 Load a recording from a file into a new recording buffer.

Detailed Description

These functions allow you to record a simulation for later playback.

Typedef Documentation

◆ b2Recording

typedef struct b2Recording b2Recording

Opaque handle for a recording buffer.

Create one, hand it to b2World_StartRecording, then save its bytes and destroy it. The buffer grows as the world records into it.

Function Documentation

◆ b2CreateRecording()

b2Recording * b2CreateRecording ( int byteCapacity)

Create a recording buffer.

The buffer grows on demand. byteCapacity pre-sizes it to avoid reallocations during a known-length session. Pass 0 for a small default.

Returns
A recording handle, freed with b2DestroyRecording

◆ b2CreateRecordingFromFile()

b2Recording * b2CreateRecordingFromFile ( const char * path)

Load a recording from a file into a new recording buffer.

Convenience wrapper over your own file I/O. Destroy the result with b2DestroyRecording.

Returns
NULL if the file is missing or unreadable

◆ b2Recording_GetData()

const uint8_t * b2Recording_GetData ( const b2Recording * recording)

Get a pointer to the recorded bytes, for saving to a file or transmitting.

Valid until the next recording call or b2DestroyRecording.

◆ b2Recording_SaveToFile()

bool b2Recording_SaveToFile ( const b2Recording * recording,
const char * path )

Save a recording buffer to a file.

Convenience wrapper over your own file I/O.

Returns
false if the file could not be written

◆ b2World_StartRecording()

void b2World_StartRecording ( b2WorldId worldId,
b2Recording * recording )

Begin recording the world into recording.

Serializes a snapshot of the current world as the seed, then logs every mutating call. Call at a step boundary, before or after creating bodies. Start before the first step to capture the whole session. No effect if already recording or if the world is locked.

Parameters
worldIdThe world to record
recordingA recording buffer from b2CreateRecording

◆ b2World_StopRecording()

void b2World_StopRecording ( b2WorldId worldId)

Stop recording.

The recording buffer keeps its bytes. Save and destroy it yourself.

Parameters
worldIdThe world being recorded