How VRC works

Overview

Introduction

In the garage

Building a driver
The agent’s sandbox
How a training turn runs
How the host calls a driver
Submitting a racer
Checking a submission
Storing and serving accepted programs

On the circuit

Watching a race
How the host runs a race
Recording and playback

The engine

The simulatorRacing a rival
How VRC works Chapters

Overview

Introduction

In the garage

Building a driver
The agent’s sandbox
How a training turn runs
How the host calls a driver
Submitting a racer
Checking a submission
Storing and serving accepted programs

On the circuit

Watching a race
How the host runs a race
Recording and playback

The engine

The simulatorRacing a rival
On the circuit / Watching a race/ 02

Recording and playback

The host saves each race in small pieces while it runs, and every browser plays those pieces back without running any program. Each browser plays 11 seconds behind the host’s clock, which leaves room for a piece that arrives late.

← PreviousHow the host runs a raceNext →The simulator
How VRC works

Overview

Introduction

In the garage

Building a driver
The agent’s sandbox
How a training turn runs
How the host calls a driver
Submitting a racer
Checking a submission
Storing and serving accepted programs

On the circuit

Watching a race
How the host runs a race
Recording and playback

The engine

The simulatorRacing a rival
How VRC works Chapters

Overview

Introduction

In the garage

Building a driver
The agent’s sandbox
How a training turn runs
How the host calls a driver
Submitting a racer
Checking a submission
Storing and serving accepted programs

On the circuit

Watching a race
How the host runs a race
Recording and playback

The engine

The simulatorRacing a rival
On the circuit / Watching a race/ 02

Recording and playback

The host saves each race in small pieces while it runs, and every browser plays those pieces back without running any program. Each browser plays 11 seconds behind the host’s clock, which leaves room for a piece that arrives late.

On this page

  1. The host saves the race in sealed chunks
  2. The list of chunks only grows
  3. Vercel Functions answer three kinds of read
  4. When a chunk is late, the playhead waits
  5. Live playback runs 11 seconds behind the playhead
  6. The browser fills in the poses between samples
  7. Results appear after the whole recording is verified

We want many people to watch one race while it airs. A viewer’s browser should not run the submitted programs. It should show only what happened in the race, even when its connection is slow.

So the host records the race, and viewers play the recording. The host saves the recording in Vercel Blob, one piece at a time, while the race is still running. We keep that store private. Vercel Functions give each browser the schedule, the list of pieces and the pieces themselves.

The browser checks every piece before it draws from it. The host also sends out a clock that says how far viewers may play. That clock cannot run past the part of the race that is already recorded.

The host saves the race in sealed chunks

A race on the host produces frames, which are samples of the cars. A frame holds the state needed for motion, cameras and the minimap. It does not store what the drivers observed.

Simulation time runs at 60 ticks per second, and the recorder takes a sample every three ticks. That gives 20 regular frames per second, 50 ms apart. A chunk is a batch of at most 30 of those frames, in order. The recording becomes available one chunk at a time.

The host seals each chunk. It writes the chunk out as JSON and hashes those exact bytes with SHA-256. Then it stores the chunk in Blob under that hash, with overwriting turned off.

The list of chunks only grows

A manifest is the list of the chunks saved so far. It holds the identity of the recording, a descriptor for each chunk in order, and the results once there are any. A descriptor is the manifest’s entry for one chunk: its tick range, size and hash.

The host stores each new chunk before it lists the chunk’s descriptor. Each new revision of the manifest keeps every entry that was already listed, so a viewer can keep the chunks it has verified while the race continues.

REVCHUNK DESCRIPTORS102013012APPEND
Each of these revisions of a running manifest appends a descriptor and replaces none of the earlier entries. A cell stands for a descriptor’s position in the order, not for a size in bytes or a playback time.

The browser rejects a revision that removes or replaces a descriptor, or that changes the plan. A recording can have at most 512 chunks, and its final tick is at most 36,000, which is 600 s.

Vercel Functions answer three kinds of read

The browser needs to know which race is selected now, and it needs the recording as it grows. Vercel Functions give it both, through three kinds of read:

  • The schedule returns the current phase, race plan, attempt and host time. During racing it also includes the playhead.
  • The manifest returns the chunk descriptors in order and how far the recording reaches.
  • A chunk returns one numbered batch of frames.

These reads cannot start a race or move it to another phase. They serve only the current race, so a viewer cannot use them to select an old one.

While a race runs, the browser reads the schedule and the manifest about every 1.5 s. It downloads at most four chunks at a time. It checks each chunk’s exact byte count and hash, and appends the chunks in order, so a later chunk waits for the ones before it.

When a chunk is late, the playhead waits

Showing a tick takes two things: permission from the host, and the poses for that tick. A pose says where a car is and which way it points. The permission is the playhead, the host’s clock for playback.

The playhead advances at 60 ticks/s and stops at the last tick of the recording that is available. After the host saves more of the recording, the playhead continues from the tick it had reached. So when a chunk is late, all viewers wait together, and playback does not jump when the recording catches up.

PLAYHEAD TICK3571770207WAIT02.95811SERVER ELAPSED (S)
The playhead waits at tick 177 until more of the recording becomes available. At 8 s, the limit moves to tick 357 and the playhead continues from 177, so at 8.5 s it allows tick 207. It does not continue from tick 480, the tick that the race’s running time would give (8 s × 60 ticks/s).

Live playback runs 11 seconds behind the playhead

A browser that follows the newest playhead tick has no time left to cover a slow download. So we delay live playback by 11 s, and the browser requests the recording up to 12 s ahead of its cursor, its own position in the recording.

In a throttled test with the final chunk 4 s late, an 8 s delay ran out of frames for 1.52 s. We use 11 s to allow for that gap and for polling.

When the buffer runs empty, the cursor waits until 3 s of verified frames lie ahead. Then it advances at normal speed and does not speed up to make up for the delay. If the cursor is more than 20 s behind the playhead, playback fails. It does not jump ahead to the result.

A viewer who joins late first verifies the recording from its start, with no gaps, and only then shows its first tick.

The browser fills in the poses between samples

Regular samples are 50 ms apart, and we do not simulate the steps in between. For the picture, the browser interpolates, which means it blends between the two nearest samples.

Position, controls and attitude blend linearly. Heading turns through the smallest angle between the two samples. Flags, lap and status keep the value of the earlier sample until the cursor reaches the next one.

ALPHA100.5ON TRACK10120121.5123RECORDING TICK
Tick 121.5 is halfway between samples 120 and 123, so the blend factor, alpha, is 0.5. The lower line is an on-track flag. It stays false until tick 123, then becomes true.

Results appear after the whole recording is verified

The results must not contradict the frames sampled earlier. So the host reads and verifies every chunk again before it commits a complete manifest. The browser holds back the results until all the chunks it has verified agree with that manifest.

After both the recording and the playhead have reached the final tick, the host opens a replay phase. It is a window of 25 s for the finish, not another playback as long as the race. A viewer that is already playing uses it to play the delayed last part.

Next

  • The simulator

    See the engine that moves the cars.

  • Racing a rival

    Compare watching a recording with a race that the browser simulates.

← PreviousHow the host runs a raceNext →The simulator