Steve's Roc Apps roc-apps on GitHub

Safari Ride Chapters

Chapter 39

Zooming back out

Safari Ride is a loop. It carries four things from step to step, derives a frame from them, and steps again. Every part of that loop now has a chapter, so this one puts the parts back together.

RideInstant the rider, the truck, the clock, the encounter plan  RideInstant.next_or_restart  makes the next moment FrameView the backdrop, the mountains, the road and the scene  FrameView.frame_view_at  derives the frame List(Shapes.Shape)  leaned_shapes  flattens it RideInstant the rider, the truck, the clock, the encounter plan  RideInstant.next_or_restart  makes the next moment FrameView the backdrop, the mountains, the road and the scene  FrameView.frame_view_at  derives the frame List(Shapes.Shape)  leaned_shapes  flattens it
The loop

Four things carried §

Here's the whole of what the ride carries:

RideInstant.roc, in RideInstant
# ...
RideInstant := {
	rider : Rider,
	truck : TruckJourney.TruckProgress,
	clock : Clock,
	encounter_plan : EncounterPlan,
}.{
# ...

We derive everything else on the screen from those four fields and the road, afresh in every frame: the sky's colors, the sun, the beacons, the headlights, the cat's pose and the bird's, every sighting and every shape. Tour keeps the moments before this one, for stepping back, and each of those is the same record of four fields.

One step, in order §

The four read each other, so the order inside a step matters. As the “The ride instant” chapter showed, RideInstant.next takes them in this order:

  1. The rider moves, reading where the encounter on its segment has got to at the old clock. A cat in the road holds the throttle.
  2. The clock ticks.
  3. The truck aims at how far along the route the rider now is.
  4. The step keeps the encounter plan, drops it at a new segment, or makes one from the rider who has just moved.

The rider reacts to the cat on every step. The cat reacts to the rider once, when its plan is made, and after that it plays on the clock alone. Swap the truck's line with the rider's, and the truck aims at where the rider was a step ago. Stepping back reuses a moment instead: Tour.step_back takes an earlier moment off its list.

Where each thing comes from §

Ask of each thing on the screen where it comes from:

What you see Where it comes from
The rider's view Derived from the rider, the route, the encounter plan and the clock
The sky Derived from the clock
The sun and the mountains Derived from the clock and the camera
The beacons Derived from the clock and the tower each one tops
The trees and the herds Derived from the world, built once, the camera, and the clock, whose darkness dims them
The cat and the bird Derived from the encounter plan, the clock and the camera
The truck Derived from its progress, one of the four, and the camera
Its headlights Derived from the clock, through the sky's darkness
Its brake lights Derived from the truck, which says whether its last step slowed it

Every row comes from the four and the road. Even the truck, whose progress the ride carries, reaches the frame through the camera like everything else. The book has shown one design: a small state carried from step to step, everything else derived from it, and types that allow only right states. Get the types right, and everything else follows.