replay

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2026 License: GPL-3.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

replay

The replay package defines the on-disk format for recorded play sessions and provides a recorder (capture) and player (playback) for it. A replay captures a session's per-frame controller input and the frames at which a screenshot should be taken. The debug tool records and plays sessions.

Purpose

  • Capture controller input once, then replay it repeatedly to check for changes across builds without reproducing the inputs by hand.
  • Mark frames during recording where a screenshot is wanted.

File format

A single JSON file.

{
  "version": 1,
  "discId": "T-1234G",
  "frames": 12345,
  "input": [
    { "f": 0,   "p1": 0,    "p2": 0 },
    { "f": 120, "p1": 4096, "p2": 0 }
  ],
  "screenshots": [600, 1200, 3000]
}
Fields
  • version: format version integer (currently 1). Lets new fields be added later without breaking older readers.
  • discId: the 10-character product number from the disc IP header (offset $20 in the IP user data). Identity check only - a reader may warn or refuse if the loaded disc does not match. The disc itself is supplied separately, not embedded.
  • frames: total number of emulated frames recorded. Playback feeds recorded input for this many frames, then stops contributing.
  • input: input change-events. Each entry is { f, p1, p2 } where f is the emulated-frame index and p1/p2 are the player 1 and player 2 button bitmasks. An event is present only when the state changes, plus always at frame 0 to establish the baseline. The state holds until the next event, so a held input is a single entry.
  • screenshots: emulated-frame indices at which a screenshot should be taken. Bare integers; no labels.
Button bitmask

p1 and p2 use one bit per Saturn button:

Bit Button Bit Button Bit Button
0 Up 4 A 9 Z
1 Down 5 B 10 L
2 Left 6 C 11 R
3 Right 7 X 12 Start
8 Y

Frame indexing

All frame indices are the emulated-frame counter: the number of RunFrame calls. Recording counts only frames that actually run, so a paused frame does not advance the index and the timeline is a pure RunFrame count.

A screenshot index c means the framebuffer after RunFrame produced frame c (after c+1 frames have run).

Boot mode caveat

Input is keyed on the emulated-frame counter, and HLE versus real-BIOS boot take different numbers of frames to reach the same game state (the real BIOS boot animation runs for several seconds that the HLE path skips). A file recorded under one boot mode has its inputs land at different game moments if replayed under the other. The format supports both modes, but a given recording is practically tied to the boot mode it was made under. This is inherent to frame-keyed input. Boot mode (HLE or real BIOS) and fast-boot are selected when a session is run; the file does not record them.

API

Recording
r := replay.NewRecorder()
// once per emulated frame, with the input applied to that frame:
r.RecordFrame(p1, p2)
// to mark the most-recently-completed frame as a screenshot point:
frame := r.MarkScreenshot()
// on shutdown:
err := r.Write(path, discID)

RecordFrame appends an event only when the state changes (and always on the first frame), then advances the frame counter. MarkScreenshot records the last completed frame and returns its index.

Playback
f, err := replay.Load(path)
p := replay.NewPlayer(f)
// once per emulated frame, in order from 0:
p1, p2, active := p.Next()
if p.ShouldScreenshot() {
    // take a screenshot
}

Next returns the recorded input for the next frame and advances the player. active is false once frames is reached, at which point p1 and p2 are zero and the caller should use live input only. ShouldScreenshot reports whether the frame just produced by Next is a marked screenshot point. The recorded input can be combined with live input by bitwise OR so a user can press buttons during playback.

Documentation

Overview

Package replay defines the on-disk format for recorded play sessions along with a recorder that captures per-frame controller input and screenshot markers and a player that reproduces them.

Index

Constants

View Source
const Version = 1

Version is the replay file format version.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Version     int          `json:"version"`
	DiscID      string       `json:"discId"`
	Frames      int          `json:"frames"`
	Input       []InputEvent `json:"input"`
	Screenshots []int        `json:"screenshots"`
}

File is the full replay document.

func Load

func Load(path string) (*File, error)

Load reads and parses a replay file from path.

type InputEvent

type InputEvent struct {
	F  int    `json:"f"`
	P1 uint32 `json:"p1"`
	P2 uint32 `json:"p2"`
}

InputEvent is a controller-state change at a given frame. The state holds until the next event, so a held input is a single entry.

type Player

type Player struct {
	// contains filtered or unexported fields
}

Player walks a File's input change-events one frame at a time. It reproduces the recorded controller state: each change-event applies at its frame and holds until the next one. Frames are produced in order from 0; the player stops contributing input once the recorded frame count is reached.

func NewPlayer

func NewPlayer(f *File) *Player

NewPlayer returns a Player positioned at frame 0 for the given file.

func (*Player) Frames

func (p *Player) Frames() int

Frames returns the total number of recorded frames.

func (*Player) Next

func (p *Player) Next() (p1, p2 uint32, active bool)

Next returns the recorded input for the next frame and advances the player. It must be called once per frame in order. active is false once the recorded frame count is exhausted, at which point p1/p2 are zero and the caller should fall back to live input only.

func (*Player) ShouldScreenshot

func (p *Player) ShouldScreenshot() bool

ShouldScreenshot reports whether the frame most recently produced by Next is a marked screenshot point.

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder accumulates input change-events and screenshot markers while a session plays, then writes them to a replay file. All indices are frame counts, incremented once per recorded frame.

func NewRecorder

func NewRecorder() *Recorder

NewRecorder returns an empty recorder positioned at frame 0.

func (*Recorder) MarkScreenshot

func (r *Recorder) MarkScreenshot() int

MarkScreenshot marks the most-recently-completed frame as a screenshot point and returns its index. Before any frame has been recorded it marks frame 0.

func (*Recorder) RecordFrame

func (r *Recorder) RecordFrame(p1, p2 uint32)

RecordFrame records the input applied to the next frame and advances the frame counter. An event is appended only when the state differs from the previous frame, plus always on the first frame so the baseline state is captured at frame 0.

func (*Recorder) Write

func (r *Recorder) Write(path, discID string) error

Write snapshots the recorder and writes it as indented JSON to path.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL