Skip to content

loopcut ​

Tool tools/live/loopcut.py (program, The running game). Cut a recorded path into one closed loop: a racing line, a patrol, a lap of a level.

Run it with ./gameframe run loopcut ARGS or python3 tools/live/loopcut.py. Source on GitHub.

Its own help ​

This is the help text in the tool itself, as ./gameframe tool loopcut prints it.

text
Cut a recorded path into one closed loop: a racing line, a patrol, a lap of a level.

Usage: loopcut.py FILE --x NAME --y NAME [--z NAME] [--index I] [--gap D] [--out FILE]

  FILE     a memrec.py recording (JSON Lines), longer than one loop
  --x/--y  the values that hold the position (--z for a third axis); an array value takes
           --index I (default 0), such as the player's car in an array of eight
  --gap D  how close the path must come back to its first point to close (default: 2% of the
           path's largest extent)
  --out    write the kept samples as JSON Lines (default: print only the summary)

It walks the path from its first sample, waits until the path has gone well away from the
start (more than four gaps), and cuts at the first sample that comes back within the gap. It
prints how many samples it kept, the loop's length, and the distance between its ends. It
exits 1 when the path never comes back: the recording is shorter than a loop.

Why: a line-following driver that aims along a recorded path wedges at the path's end when
the path is less than a loop, because the next aim point is the start, far across the level
(docs/knowhow/racing-line-must-be-a-closed-lap.md). Record more than a loop and cut it here.

It does not smooth the path, resample it, or find a loop that starts elsewhere than the first
sample. Standard library only.

Code: Apache 2.0. Content: CC0 1.0. No game material: bring your own copy.