Skip to contents

The input member is decompressed once to a temporary file and its ZIP checksum is verified before any callback runs. The temporary file needs disk space equal to the uncompressed log and is removed on exit. It is read sequentially, keeping memory use bounded. Each callback receives a configured movie containing at most chunk_size observations. Its header includes firstObservation and lastObservation, using one-based positions in the original recording. Return a small summary from FUN to keep memory use bounded; returning the movie itself retains every chunk in memory.

Usage

read_bk2_chunks(
  path,
  FUN,
  chunk_size = 100000L,
  analog = "raw",
  deadzone = NULL,
  triggers = "raw",
  aliases = TRUE,
  ...
)

Arguments

path

Recording file path.

FUN

Function called with one movie chunk. Additional arguments in ... are passed to this function.

chunk_size

Maximum observations passed to each callback.

analog

Stick representation: "raw" (default), "cardinal4", "cardinal8", "angle", or "angle+magnitude". A scalar applies to both sticks; c(left = "cardinal8", right = "angle") selects them independently. Cardinal modes add separate left/right logical direction columns. Continuous modes return numeric fields through stick_channels(). Original X/Y values remain in analog_channels() in every mode. Absent sticks add no columns.

deadzone

Radial threshold in centred axis half-range units, from zero to one. One value applies to both sticks; named left/right values are allowed. NULL uses the default of the controller, whichever emulator recorded it: 0.125 for the sticks of Nintendo's consoles (Nintendo 64, GameCube, Wii extensions, 3DS) and 0.25 for all other sticks. The first is close to the 15 of 128 units that the GameCube's controller library discards on each axis (PAD_Clamp in libogc). The second covers the resting position of a released PlayStation stick, up to about 32 of 128 units from the centre (psx-spx), and is close to the 7849 and 8689 of 32767 that Microsoft gives for the thumbsticks of PC gamepads (XInput). A game applies a threshold of its own, which the recording does not store; give that value to study one game. Neutral observations have no direction and an NA angle. Magnitude is kept.

triggers

"raw" (default) or "digital". For DTM, digital additionally projects each analogue trigger at 128/255 into separate L2/R2 columns. Hardware L/R click bits remain distinct from thresholded analogue triggers.

aliases

TRUE (default) places the controls of a recording under the shared IDs that button_layout() describes. With FALSE, a control that would be placed under another control's ID keeps the key of its source, so every control of the recording has a column of its own and no two are combined.

...

Additional arguments for FUN.

Value

A list of callback results, with observations and chunks attributes giving the total processed. An empty recording gives a list with no callback results and zero observations.

Examples

path <- system.file("extdata", "expanded", "two-stick-3ds.bk2", package = "replayr")
counts <- read_bk2_chunks(path, function(chunk) n_observations(chunk), chunk_size = 2L)
sum(unlist(counts))
#> [1] 4
attr(counts, "observations")
#> [1] 4