From 87f41d342f3eea934a341bb16d75259e650222ea Mon Sep 17 00:00:00 2001
From: pepperstm
Date: Thu, 12 Nov 2026 10:12:10 +0000
Subject: [PATCH] Add Herne Hill Velodrome as a built-in track
The 450 m track at its real place, ridden anticlockwise or clockwise: banked
from 7 to 26 degrees, painted with the cote d'azur and the measuring, sprinters'
and stayers' lines, with the finish, 200 m and pursuit lines across it. Round it
are the railing with plain boards, the floodlights, the pavilion, the bleachers,
the containers and canopy, and the junior track in the infield. The grounds are
levelled and kept clear of trees and map buildings.
The route matches OpenBikeNet's herne-hill-450. VP_SMOKE_ROUTE picks the route
for the smoke run.
---
HANDOFF.md | 1 +
README.md | 2 +
crates/core/src/lib.rs | 1 +
crates/core/src/velodrome.rs | 149 +++++++
crates/core/src/world/barriers.rs | 4 +
crates/core/src/world/height.rs | 21 +-
crates/core/src/world/mod.rs | 56 ++-
crates/core/src/world/structures.rs | 3 +
crates/core/src/world/surface.rs | 3 +
crates/core/src/world/venue.rs | 657 ++++++++++++++++++++++++++++
crates/core/tests/velodrome.rs | 91 ++++
src-tauri/src/commands.rs | 9 +
src-tauri/src/main.rs | 1 +
src-tauri/src/native/mod.rs | 3 +-
src-tauri/src/session.rs | 31 +-
web/src/App.tsx | 8 +-
web/src/bridge.ts | 3 +
web/src/types.ts | 2 +
web/src/ui/Home.tsx | 13 +-
web/src/ui/Ride.tsx | 3 +-
web/src/ui/RideSetup.tsx | 32 +-
web/src/world/scene.ts | 5 +-
web/src/world/surfaces.ts | 31 +-
23 files changed, 1101 insertions(+), 28 deletions(-)
create mode 100644 crates/core/src/velodrome.rs
create mode 100644 crates/core/src/world/venue.rs
create mode 100644 crates/core/tests/velodrome.rs
diff --git a/HANDOFF.md b/HANDOFF.md
index 6f7cd2b..893687c 100644
--- a/HANDOFF.md
+++ b/HANDOFF.md
@@ -23,6 +23,7 @@ It started on 2026-10-13 as "WinterMiles" (an icTrainer alternative for riding G
| **Trainers and sensors** | Protocols unit-tested against the specs. The first real trainer — a **Tacx Vortex Smart (T2180) over Bluetooth** — connected but **kept dropping out and showed no power**. Not yet diagnosed: a diagnostics report from a ride is needed. This is the top priority. |
| **Virtual gears** | The maths is unit-tested and shifting was checked with the demo rider and the smoke harness (`VP_SMOKE_SHIFT`), but it has **never been felt on a real trainer**. |
| **OpenBikeControl controllers** | Button decoding and the choice of one action per press are unit-tested; never connected to a real controller. |
+| **Herne Hill Velodrome** | Built-in track. The route is in `crates/core/src/velodrome.rs`; the banked track, its paint and the buildings are in `world/venue.rs`. Tested in code, and I've checked a live preview in demo mode on both renderers, each way round (`VP_SMOKE_ROUTE=herne-hill` or `herne-hill-clockwise`). Nobody has ridden it with a trainer yet. |
| **Laps on loop routes** | Lap engine, bests, segments and renderers unit-tested in `crates/core`; smoke-run across the line on Linux with three.js, not yet with the native renderer (macOS). Group standings don't show who is a lap up. |
| **Strava** (OAuth, upload, segments, activities as ghosts) | Never run against the live API. Users must create their own API key (open source can't ship a secret). Scope is `read,activity:read_all,activity:write`. |
| **Windows and Linux** | Built and packaged by CI on every push (and Arch's package is installed in a container and its libraries checked), but **never run by a person**. |
diff --git a/README.md b/README.md
index 281e900..a667b4f 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,7 @@ Free and open source ([GPLv3](LICENSE)) for **Windows, macOS and Linux**. Writte
- **GPX in, virtual ride out.** Import routes from Strava, Komoot, RideWithGPS or a bike computer. Routes with no elevation data (planner exports) get it filled in automatically.
- **A 3D version of the real place.** The road follows your GPX; the surrounding landscape is built from open elevation data, so the mountains on the horizon are the real ones. OpenStreetMap supplies the rest: the towns and villages you pass through, forests where the real forests are, lakes, rivers and streams, the side roads, lanes, footpaths and railways around you, and the bridges and tunnels of the real road — you ride over the river on a bridge deck, into the hillside through a lit tunnel, and under the motorway or railway that crosses overhead. A live OpenStreetMap minimap and a gradient-coloured elevation profile sit alongside. Works offline with generated hills.
- **Laps.** On a closed route, ride it once, for 2, 3, 5, 10 or 20 laps, or until you stop. The HUD counts the laps and the distance ridden, and the profile, landmarks and riders carry on across the line.
+- **Herne Hill Velodrome, built in.** The 450 m outdoor track in south London where the 1948 Olympic track events were raced, at its real place: banked to 26° in the bends, painted with the côte d'azur and the sprinters' and stayers' lines, and ringed by the railing and floodlights, with the 2018 pavilion, the bleachers, the club's containers and canopy, and the junior track in the middle. Ride it anticlockwise as raced, or clockwise. It is the same track as OpenBikeNet's `herne-hill-450` route.
- **A closed road, race-day style.** The road you ride is set apart from the map's road network: steel crowd barriers line both sides (with banners on some, each section standing on its feet and leaning with the road on hills, and orange netting round the outside of tight hairpins instead), its surface is the real one — tarmac, concrete slabs, cobbles, gravel or dirt — and so is its width: a 7 m main road, a 5 m village street, a 3 m farm track. Both come from OpenStreetMap's tags for the roads along the route (`surface`, `width`, `lanes`, and the road class), or are guessed from the road class when those can't be fetched. Where the route leaves the mapped roads for 100 m or more — across a field, along an unmapped trail — it becomes a dirt track. Widths change gradually, and buildings, signs, other riders and the barriers all follow them. Ride the Arenberg trench on its setts and the Strade Bianche on white gravel — and feel them: rougher surfaces roll heavier, so you slow down on screen and the trainer gets harder.
- **Mountain-bike trails.** Where the route follows an unpaved path, a bridleway, a walking trail or a trail graded for mountain bikes (OpenStreetMap's `mtb:scale`, S0–S6, or estimated from the hiking grade), you ride a narrow earth singletrack with no barriers, the HUD shows the grade, and the harder the grade the heavier it rolls — on screen and on the trainer.
- **Find a route in the app.** Search for a place, click waypoints on the map and get a route along bike-friendly roads with real elevation (BRouter), or pick one of eight famous climbs (Alpe d'Huez, Mont Ventoux, Stelvio, Galibier, Tourmalet, Mortirolo, Zoncolan, Box Hill). Mountain bikers can plan along trails, or pick from the **waymarked MTB routes** mapped in the area on screen.
@@ -70,6 +71,7 @@ Be aware of what has and has not been proven:
| Waymarked MTB routes | Listed and joined from the live Overpass API around Finale Ligure (a 23 km route joined with no gaps); the joining is unit-tested. The screen itself was only type-checked, not clicked through |
| Strava segments and ghosts from Strava | Matching is unit-tested; the Strava calls have **not** been made against the live API |
| Street-level photos | Selection unit-tested and a bad token is reported correctly; not tried with a real Mapillary token |
+| Herne Hill Velodrome | Tested in code: a lap is 450 m from the line, the bends bank to 26°, the ground is level, and it works both ways round. Checked a live preview in demo mode on both renderers, riding each direction. Not yet ridden with a trainer. The buildings are sized from the map and photos, so they're close to the real ones but not exact |
| Native renderer | Screenshots from the automated run match the built-in renderer (day, dusk with rain fog, high camera, the leaning barriers and tree sprites of 0.3.6, and the hedge banks of 0.3.7). The HUD on top of it was not checked in a screenshot of the real window |
| FIT export | Unit-tested by decoding the output with an independent FIT parser |
| Bluetooth and ANT+ **protocol** encoding/decoding (FTMS, Cycling Power, CSC, HR, ANT framing, ANT+ HR/power/speed/cadence/FE-C pages) | Unit-tested against hand-built packets |
diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs
index ed99f85..6389c0f 100644
--- a/crates/core/src/lib.rs
+++ b/crates/core/src/lib.rs
@@ -13,6 +13,7 @@ pub mod physics;
pub mod ride;
pub mod segments;
pub mod types;
+pub mod velodrome;
pub mod waymarked;
pub mod workout;
pub mod world;
diff --git a/crates/core/src/velodrome.rs b/crates/core/src/velodrome.rs
new file mode 100644
index 0000000..ff9e7c7
--- /dev/null
+++ b/crates/core/src/velodrome.rs
@@ -0,0 +1,149 @@
+//! Velodromes: real cycling tracks built into the app as routes, ridden in laps.
+//!
+//! A track is an oval of two straights and two semicircles round its measuring line, placed
+//! at its real location. Its route is the measuring line itself, so a lap is the track's
+//! official length; the world round it (the banked track, its markings, the stands) is drawn
+//! by `world::venue`. Herne Hill's oval is the one in OpenBikeNet's `herne-hill-450` route
+//! file (fitted to the track's outline in OpenStreetMap), so riders from other apps line up.
+
+use crate::gpx::{build_route_with_step, RawPoint, Route, M_PER_DEG};
+
+/// A track's shape and place.
+#[derive(Debug, Clone, Copy)]
+pub struct Track {
+ /// Route ID for riding it anticlockwise, as track races go; `-clockwise` the other way.
+ pub id: &'static str,
+ pub name: &'static str,
+ /// One lap on the measuring line, in metres.
+ pub length: f64,
+ /// Radius of the bends on the measuring line.
+ pub radius: f64,
+ /// The middle of the oval, as (lat, lon).
+ pub centre: (f64, f64),
+ /// Direction of the long axis, in degrees anticlockwise from east.
+ pub axis: f64,
+ /// The start/finish line is this far from the middle of the home straight, against the
+ /// direction of riding anticlockwise.
+ pub start_offset: f64,
+ /// The riding surface from inside edge to outside edge, côte d'azur included.
+ pub width: f64,
+ /// Banking at the steepest part of the bends, and along the straights, in degrees.
+ pub bend_banking: f64,
+ pub straight_banking: f64,
+}
+
+/// Herne Hill Velodrome, London: opened in 1891, the track events of the 1948 Olympics, 450 m.
+/// Sources give its banking as anything from 18° to 30°; 26° (the 1992 rebuild) has the most behind it.
+pub const HERNE_HILL: Track = Track {
+ id: "herne-hill",
+ name: "Herne Hill Velodrome",
+ length: 450.0,
+ radius: 45.3,
+ centre: (51.45105, -0.09142),
+ axis: -76.8,
+ start_offset: 13.0,
+ width: 7.4,
+ bend_banking: 26.0,
+ straight_banking: 7.0,
+};
+
+pub const TRACKS: [Track; 1] = [HERNE_HILL];
+
+/// Points along the bends, about this far apart.
+const BEND_STEP: f64 = 2.5;
+/// The route is sampled this often, in metres (roads are every 5 m).
+pub const ROUTE_STEP: f64 = 1.0;
+
+impl Track {
+ /// Length of each straight on the measuring line.
+ pub fn straight(&self) -> f64 {
+ (self.length - 2.0 * std::f64::consts::PI * self.radius) / 2.0
+ }
+
+ /// The route ID for riding it this way round.
+ pub fn route_id(&self, clockwise: bool) -> String {
+ if clockwise {
+ format!("{}-clockwise", self.id)
+ } else {
+ self.id.to_string()
+ }
+ }
+
+ pub fn route_name(&self, clockwise: bool) -> String {
+ if clockwise {
+ format!("{} (clockwise)", self.name)
+ } else {
+ self.name.to_string()
+ }
+ }
+
+ /// The measuring line as `(a, b)` metres from the middle of the oval, `a` along the long
+ /// axis and `b` across it, the home straight at `b = +radius`: from the start/finish line
+ /// round anticlockwise and back to it.
+ pub fn outline(&self) -> Vec<(f64, f64)> {
+ let (r, half) = (self.radius, self.straight() / 2.0);
+ let steps = (std::f64::consts::PI * r / BEND_STEP).round() as usize;
+ let mut points = vec![(-self.start_offset, r), (-half, r)];
+ for k in 1..steps {
+ let t = std::f64::consts::FRAC_PI_2 + std::f64::consts::PI * k as f64 / steps as f64;
+ points.push((-half + r * t.cos(), r * t.sin()));
+ }
+ points.extend([(-half, -r), (half, -r)]);
+ for k in 1..steps {
+ let t = -std::f64::consts::FRAC_PI_2 + std::f64::consts::PI * k as f64 / steps as f64;
+ points.push((half + r * t.cos(), r * t.sin()));
+ }
+ points.push((half, r));
+ points.push(points[0]);
+ points
+ }
+
+ /// `(a, b)` metres in the oval's frame as (lat, lon), stretched by `scale`.
+ fn lat_lon(&self, (a, b): (f64, f64), scale: f64) -> (f64, f64) {
+ let (c, s) = (self.axis.to_radians().cos(), self.axis.to_radians().sin());
+ let (east, north) = ((a * c - b * s) * scale, (a * s + b * c) * scale);
+ (self.centre.0 + north / M_PER_DEG, self.centre.1 + east / (M_PER_DEG * self.centre.0.to_radians().cos()))
+ }
+
+ /// The route: the measuring line at its real place, flat, exactly `length` round (as the
+ /// app measures distance), from the start/finish line and back. Sampled every metre, so the
+ /// bends are smooth and rounding off corners takes nothing measurable off a lap.
+ pub fn route(&self, clockwise: bool) -> Route {
+ let outline = self.outline();
+ let build = |scale: f64| {
+ let mut points: Vec = outline
+ .iter()
+ .map(|&q| {
+ let (lat, lon) = self.lat_lon(q, scale);
+ RawPoint { lat, lon, ele: Some(0.0) }
+ })
+ .collect();
+ if clockwise {
+ points.reverse();
+ }
+ build_route_with_step(&self.route_name(clockwise), &points, ROUTE_STEP).expect("a track is a valid route")
+ };
+ // Scaled until the route as built, smoothing and all, is the track's length.
+ let first: f64 = outline.windows(2).map(|w| (w[1].0 - w[0].0).hypot(w[1].1 - w[0].1)).sum();
+ let mut scale = self.length / first;
+ let mut route = build(scale);
+ for _ in 0..3 {
+ scale *= self.length / route.total;
+ route = build(scale);
+ }
+ route
+ }
+}
+
+/// The track and which way round, for a built-in track's route ID.
+pub fn track_for(route_id: &str) -> Option<(Track, bool)> {
+ TRACKS.iter().find_map(|t| {
+ if route_id == t.id {
+ Some((*t, false))
+ } else if route_id == t.route_id(true) {
+ Some((*t, true))
+ } else {
+ None
+ }
+ })
+}
diff --git a/crates/core/src/world/barriers.rs b/crates/core/src/world/barriers.rs
index 879d441..248906c 100644
--- a/crates/core/src/world/barriers.rs
+++ b/crates/core/src/world/barriers.rs
@@ -258,6 +258,10 @@ impl World {
/// on the inside of a bend too tight to stand them; round a tight bend, fence panels
/// (look `FENCE`) on the outside instead.
pub fn barriers(&self) -> Vec<[f32; 7]> {
+ // A velodrome has its own railing.
+ if self.venue.is_some() {
+ return Vec::new();
+ }
let r = &self.route;
let kinds = self.field.kinds();
let blocked = |i: usize| kinds.get(i).is_some_and(|&kind| kind != OPEN) || self.scene.trails.get(i).is_some_and(Option::is_some);
diff --git a/crates/core/src/world/height.rs b/crates/core/src/world/height.rs
index 63c037b..2a7464e 100644
--- a/crates/core/src/world/height.rs
+++ b/crates/core/src/world/height.rs
@@ -120,6 +120,8 @@ pub struct HeightField {
/// For open samples, 1 at a tunnel mouth falling to 0 away from it; for bridge
/// samples, how far the ground must stay below the deck.
shape: Vec,
+ /// Grounds laid level, such as a velodrome's: the ground there is at their height.
+ grounds: Option,
}
impl HeightField {
@@ -165,7 +167,7 @@ impl HeightField {
_ => 0.0,
})
.collect();
- Self { route, dem, dem_offset, grid, coarse, lattice: Mutex::new(HashMap::new()), mean_ele, kinds, shape }
+ Self { route, dem, dem_offset, grid, coarse, lattice: Mutex::new(HashMap::new()), mean_ele, kinds, shape, grounds: None }
}
pub fn kinds(&self) -> &[u8] {
@@ -253,7 +255,24 @@ impl HeightField {
(p.surface, p.road)
}
+ /// Lays the ground level over `grounds`, blending back into the land round them.
+ pub(super) fn set_grounds(&mut self, grounds: super::venue::Grounds) {
+ self.grounds = Some(grounds);
+ }
+
pub fn probe(&self, x: f64, z: f64, roughness: f64) -> Probe {
+ let mut p = self.probe_land(x, z, roughness);
+ if let Some(g) = &self.grounds {
+ let level = g.levelled(x, z);
+ if level > 0.0 && !p.trench {
+ p.ground = mix(p.ground, g.height, level);
+ p.surface = p.ground;
+ }
+ }
+ p
+ }
+
+ fn probe_land(&self, x: f64, z: f64, roughness: f64) -> Probe {
let route = &self.route;
let (cx, cz) = (cell(x, HASH_CELL), cell(z, HASH_CELL));
// Per kind of road: inverse-distance weights, weighted elevation, and the nearest sample.
diff --git a/crates/core/src/world/mod.rs b/crates/core/src/world/mod.rs
index a54c8ea..75b99e7 100644
--- a/crates/core/src/world/mod.rs
+++ b/crates/core/src/world/mod.rs
@@ -17,6 +17,7 @@ mod scenery;
mod structures;
mod surface;
mod trees;
+mod venue;
pub use barriers::{barrier_model, BANNER_COLOURS, FENCE as BARRIER_FENCE, LOOKS as BARRIER_LOOKS, SECTION_M as BARRIER_SECTION_M};
pub use buildings::{overpass_query, parse_overpass, BuildingMesh, Buildings, Footprint};
@@ -31,9 +32,10 @@ pub use scenery::{route_structures, Area, AreaKind, Crossing, Deck, Overbridge,
pub use structures::Structures;
pub use surface::{
highway_marked, highway_width, hiking_grade, is_trail, mtb_grade, parse_ways, runs as surface_runs, smooth_widths, tagged_width, way_query, MappedWay, Surface, Trail, FORD, SINGLETRACK,
- SINGLETRACK_WIDTH, TIMBER, UNMARKED, WAY_TAGS,
+ SINGLETRACK_WIDTH, TIMBER, TRACK, UNMARKED, WAY_TAGS,
};
pub use trees::{sprite_frame, tree_model, Climate as TreeClimate, BIRCH, BROADLEAF, BUSH, COLUMN, KINDS as TREE_KINDS, PINE, SPRITES_FROM, SPRITE_SPREAD, SPRUCE, TREE_FLOATS};
+pub use venue::Venue;
use std::sync::Arc;
@@ -118,6 +120,8 @@ pub struct World {
pub buildings: Buildings,
pub scene: Scene,
tree_line: f64,
+ /// A velodrome round the route, when the route is a built-in track.
+ pub venue: Option,
}
/// Made-up field boundaries are drawn in chunks whose middle is this close to the route.
@@ -170,7 +174,7 @@ impl World {
// Rough alpine tree line, falling with latitude.
let tree_line = (3600.0 - route.lat0.abs() * 38.0).max(600.0);
let field = HeightField::new(route.clone(), dem, dem_offset);
- Self { route, field, buildings: Buildings::default(), scene: Scene::default(), tree_line }
+ Self { route, field, buildings: Buildings::default(), scene: Scene::default(), tree_line, venue: None }
}
/// A world with OpenStreetMap scenery (forests, water, bridges, tunnels) and buildings.
@@ -180,7 +184,28 @@ impl World {
let scene = Scene::new(&route, scenery);
let tree_line = (3600.0 - route.lat0.abs() * 38.0).max(600.0);
let field = HeightField::with_kinds(route.clone(), dem, dem_offset, scene.kinds.clone());
- Self { route, field, buildings: Buildings::default(), scene, tree_line }.with_buildings(footprints)
+ Self { route, field, buildings: Buildings::default(), scene, tree_line, venue: None }.with_buildings(footprints)
+ }
+
+ /// Makes the route a velodrome's track: banked, painted and as wide as the track, with its
+ /// grounds laid level and built on. Before the buildings, which stand on the ground.
+ pub fn with_venue(mut self, track: crate::velodrome::Track, clockwise: bool) -> Self {
+ let venue = Venue::new(track, clockwise, &self.route);
+ let n = self.route.n;
+ self.scene.widths = vec![track.width; n];
+ self.scene.marked = vec![false; n];
+ self.scene.trails = vec![None; n];
+ self.scene.surfaces = vec![Surface::Asphalt; n];
+ self.scene.fords.clear();
+ self.scene.banks = venue.banks(&self.route);
+ self.field.set_grounds(venue.grounds.clone());
+ self.venue = Some(venue);
+ self
+ }
+
+ /// Whether `(x, z)` is on a velodrome's grounds, where nothing grows or is made up.
+ fn on_grounds(&self, x: f64, z: f64) -> bool {
+ self.venue.as_ref().is_some_and(|v| v.grounds.outside(x, z) < 2.0)
}
/// Adds buildings (OpenStreetMap footprints) to the landscape.
@@ -205,8 +230,10 @@ impl World {
}
mix([0.5, 0.48, 0.45], steep.max(high * 0.7));
mix([0.95, 0.96, 1.0], smoothstep(self.tree_line + 1000.0, self.tree_line + 1500.0, height) * (1.0 - steep));
- // A worn verge beside the tarmac.
- mix([0.47, 0.44, 0.3], (1.0 - smoothstep(4.0, 13.0, road_distance)) * 0.6);
+ // A worn verge beside the tarmac; a velodrome's grass is kept right up to the track.
+ if !self.on_grounds(x, z) {
+ mix([0.47, 0.44, 0.3], (1.0 - smoothstep(4.0, 13.0, road_distance)) * 0.6);
+ }
// The palette is authored in sRGB; vertex colours are linear.
c.map(|v| v.powf(2.2) as f32)
}
@@ -414,7 +441,7 @@ impl World {
// Over a tunnel the mesh is the floor of its trench; the trees belong on the land above.
let (ty, d) = if corners.iter().any(|&c| trench[c]) { self.field.surface(tx, tz) } else { (on_mesh(&h, pad, fx, fz), on_mesh(&near, pad, fx, fz)) };
let drop = corners.iter().map(|&c| h[c]).fold(f64::MIN, f64::max) - corners.iter().map(|&c| h[c]).fold(f64::MAX, f64::min);
- (d >= 9.0 && ty <= self.tree_line && (drop <= 8.0 || corners.iter().any(|&c| trench[c])) && !self.buildings.covers(tx, tz)).then_some(ty)
+ (d >= 9.0 && ty <= self.tree_line && (drop <= 8.0 || corners.iter().any(|&c| trench[c])) && !self.buildings.covers(tx, tz) && !self.on_grounds(tx, tz)).then_some(ty)
};
let mapped = scene.covers(&self.route, x0 + CHUNK / 2.0, z0 + CHUNK / 2.0);
@@ -468,7 +495,7 @@ impl World {
if ways.clone().any(|s| [p, mid, q].iter().any(|&e| scenery::to_segment(e, s.a, s.b) < s.half + margin(s))) || streams.iter().any(|s| scenery::to_segment(mid, s.a, s.b) < s.half + 1.0) {
return false;
}
- if self.buildings.covers(mid.0, mid.1) {
+ if self.buildings.covers(mid.0, mid.1) || self.on_grounds(mid.0, mid.1) {
return false;
}
let drop = corners.iter().map(|&c| h[c]).fold(f64::MIN, f64::max) - corners.iter().map(|&c| h[c]).fold(f64::MAX, f64::min);
@@ -687,8 +714,10 @@ impl World {
let kinds = self.field.kinds();
// Texture columns: gravel shoulder on the outer 20/256ths, tarmac between.
let us = [0.0f32, 0.0, 20.0 / 256.0, 236.0 / 256.0, 1.0, 1.0];
+ let venue = self.venue.as_ref();
let looks = (0..n)
.map(|i| match self.scene.surfaces.get(i) {
+ _ if venue.is_some() => TRACK,
_ if self.timber(i) => TIMBER,
// Stones under the water, from a sample before the crossing to one after.
_ if self.scene.fords.iter().any(|&f| f.abs_diff(i) <= 1) => FORD,
@@ -719,7 +748,16 @@ impl World {
let slim = self.timber(i) || self.timber(i.saturating_sub(1)) || self.timber((i + 1).min(n - 1));
let edge = self.half_width(i);
let (foot, beyond) = if slim { (edge + 0.3, 0.05) } else { (edge + 2.6, 0.4) };
- let offsets = [-foot - beyond, -foot, -edge, edge, foot, foot + beyond];
+ let mut offsets = [-foot - beyond, -foot, -edge, edge, foot, foot + beyond];
+ // A velodrome's grass bank falls away from the raised outside edge as steeply as it
+ // rises; on the inside the infield meets the track almost at once.
+ if let Some(v) = venue {
+ let outside = edge + 0.6 + 1.0 * self.surface_lift(i, -v.inside() * edge);
+ let inside = edge + 0.8;
+ let (minus, plus) = if v.inside() > 0.0 { (outside, inside) } else { (inside, outside) };
+ offsets = [-minus - 0.4, -minus, -edge, edge, plus, plus + 0.4];
+ }
+ let mirrored = venue.is_some_and(|v| v.clockwise);
for k in 0..ROAD_SECTION {
let offset = if offsets[k] * curvature > 0.0 { offsets[k].signum() * offsets[k].abs().min(inside) } else { offsets[k] };
// A berm raises the outside edge of the riding surface; the embankment falls from it.
@@ -738,7 +776,7 @@ impl World {
}) as f32,
(r.z[i] - tx * offset) as f32,
]);
- mesh.uvs.extend_from_slice(&[us[k], (j as f64 * r.step / 12.0) as f32]);
+ mesh.uvs.extend_from_slice(&[if mirrored { 1.0 - us[k] } else { us[k] }, (j as f64 * r.step / 12.0) as f32]);
}
}
mesh
diff --git a/crates/core/src/world/structures.rs b/crates/core/src/world/structures.rs
index 846c6ad..056d40c 100644
--- a/crates/core/src/world/structures.rs
+++ b/crates/core/src/world/structures.rs
@@ -84,6 +84,9 @@ impl World {
for deck in &self.scene.decks {
self.deck(&mut out.lit, deck);
}
+ if let Some(venue) = &self.venue {
+ venue.dress(self, &mut out.lit);
+ }
out
}
diff --git a/crates/core/src/world/surface.rs b/crates/core/src/world/surface.rs
index efae930..0baddac 100644
--- a/crates/core/src/world/surface.rs
+++ b/crates/core/src/world/surface.rs
@@ -211,6 +211,9 @@ pub const TIMBER: u8 = 6;
pub const SINGLETRACK: u8 = 7;
/// …or `FORD` for the stones of a ford's bed, under its water.
pub const FORD: u8 = 8;
+/// …or `TRACK` for a velodrome's track: the côte d'azur, the measuring, sprinters' and stayers'
+/// lines, painted with the inside of the track at the +offset edge (mirrored when ridden clockwise).
+pub const TRACK: u8 = 9;
/// Earth trails narrower than this are singletrack; the off-map dirt track (3 m) is wider.
pub const SINGLETRACK_WIDTH: f64 = 2.5;
diff --git a/crates/core/src/world/venue.rs b/crates/core/src/world/venue.rs
new file mode 100644
index 0000000..39ccb46
--- /dev/null
+++ b/crates/core/src/world/venue.rs
@@ -0,0 +1,657 @@
+//! A velodrome round a built-in track's route: the banked track itself (widths, banking and
+//! the look of the road ribbon, set on the world), its markings, the railing and floodlights
+//! round it, and the grounds laid level with the stands and buildings on them.
+//!
+//! Positions are worked out in the track's own frame: `a` metres along its long axis from the
+//! middle of the oval and `b` across it, the home straight at `b = +radius`. The riding surface
+//! is centred on the measuring line (the route), so it lies a few metres inside the real
+//! track's footprint; the buildings are placed by their distance from the drawn outside edge,
+//! so what stands beside the track stands as close to it as it really does.
+
+use super::height::smoothstep;
+use super::mesh::TriMesh;
+use super::scenery::to_segment;
+use super::{World, ROAD_LIFT};
+use crate::gpx::Route;
+use crate::velodrome::Track;
+
+type P3 = [f64; 3];
+
+fn rgb(c: [f64; 3]) -> [f32; 3] {
+ c.map(|v| v.powf(2.2) as f32)
+}
+
+// Colours, authored in sRGB.
+const GALVANISED: [f64; 3] = [0.72, 0.74, 0.75];
+const KERB: [f64; 3] = [0.66, 0.65, 0.62];
+const LINE_WHITE: [f64; 3] = [0.93, 0.93, 0.91];
+const LINE_BLACK: [f64; 3] = [0.06, 0.06, 0.07];
+const LINE_RED: [f64; 3] = [0.80, 0.16, 0.16];
+const LAMP_HEAD: [f64; 3] = [0.24, 0.25, 0.27];
+const PAVING: [f64; 3] = [0.60, 0.59, 0.56];
+const ASPHALT: [f64; 3] = [0.34, 0.34, 0.36];
+const JUNIOR: [f64; 3] = [0.40, 0.41, 0.44];
+const BRICK: [f64; 3] = [0.60, 0.28, 0.21];
+const CONCRETE: [f64; 3] = [0.72, 0.71, 0.68];
+const COPING: [f64; 3] = [0.50, 0.52, 0.55];
+const TIMBER: [f64; 3] = [0.76, 0.55, 0.33];
+const TIMBER_DARK: [f64; 3] = [0.70, 0.50, 0.30];
+const SOFFIT: [f64; 3] = [0.86, 0.70, 0.48];
+const ROOF: [f64; 3] = [0.56, 0.58, 0.61];
+const FASCIA: [f64; 3] = [0.62, 0.64, 0.67];
+const GLASS: [f64; 3] = [0.17, 0.22, 0.27];
+const MULLION: [f64; 3] = [0.13, 0.13, 0.14];
+const COLUMN: [f64; 3] = [0.16, 0.18, 0.20];
+const DOOR: [f64; 3] = [0.42, 0.47, 0.50];
+const STAND: [f64; 3] = [0.45, 0.47, 0.50];
+const SEAT: [f64; 3] = [0.07, 0.07, 0.08];
+const MEMBRANE: [f64; 3] = [0.95, 0.95, 0.93];
+const SHELTER_ROOF: [f64; 3] = [0.92, 0.92, 0.90];
+/// The pavilion's track emblem, outside stripe first: purple, light blue, white and red.
+const EMBLEM: [[f64; 3]; 4] = [[0.33, 0.27, 0.58], [0.40, 0.70, 0.93], [0.96, 0.96, 0.96], [0.85, 0.25, 0.42]];
+/// Plain advertising boards on the railing, as runs of colour.
+const BOARDS: [[f64; 3]; 8] = [[0.12, 0.66, 0.63], [0.95, 0.95, 0.93], [0.16, 0.56, 0.35], [0.08, 0.08, 0.09], [0.91, 0.78, 0.29], [0.78, 0.20, 0.23], [0.17, 0.35, 0.63], [0.90, 0.90, 0.90]];
+const CONTAINERS: [[f64; 3]; 8] = [[0.55, 0.22, 0.16], [0.18, 0.33, 0.55], [0.22, 0.42, 0.28], [0.80, 0.45, 0.15], [0.85, 0.82, 0.72], [0.45, 0.47, 0.49], [0.15, 0.45, 0.47], [0.45, 0.16, 0.20]];
+
+/// The railing stands this far outside the riding surface; its posts this far apart.
+const RAIL_OUT: f64 = 0.15;
+const RAIL_EVERY: f64 = 2.5;
+/// Floodlights: how far apart round the track, how far outside it, how tall above its edge.
+const LIGHT_EVERY: f64 = 15.0;
+const LIGHT_OUT: f64 = 1.1;
+const LIGHT_HEIGHT: f64 = 8.5;
+/// Herne Hill's outside edge on the ground, metres from the middle of the oval across the home
+/// straight (from OpenStreetMap). The buildings are placed by their distance from it.
+const REAL_OUTSIDE: f64 = 53.0;
+
+/// A capsule: a segment's ends and the distance round it, in local metres.
+type Zone = ((f64, f64), (f64, f64), f64);
+
+/// Ground laid level: capsules (a segment and the distance round it, in local metres).
+#[derive(Clone)]
+pub struct Grounds {
+ zones: Vec,
+ pub height: f64,
+ blend: f64,
+}
+
+impl Grounds {
+ /// How far `(x, z)` is outside the grounds, in metres (negative inside).
+ pub fn outside(&self, x: f64, z: f64) -> f64 {
+ self.zones.iter().map(|&(a, b, r)| to_segment((x, z), a, b) - r).fold(f64::INFINITY, f64::min)
+ }
+
+ /// 1 on the grounds, falling to 0 over the blend distance beyond them.
+ pub fn levelled(&self, x: f64, z: f64) -> f64 {
+ 1.0 - smoothstep(0.0, self.blend, self.outside(x, z))
+ }
+}
+
+pub struct Venue {
+ pub track: Track,
+ pub clockwise: bool,
+ /// The middle of the oval in local metres, and unit vectors along and across it.
+ centre: (f64, f64),
+ along: (f64, f64),
+ across: (f64, f64),
+ /// The height of the grounds (and the track: it is flat).
+ pub height: f64,
+ pub grounds: Grounds,
+}
+
+impl Venue {
+ pub fn new(track: Track, clockwise: bool, route: &Route) -> Self {
+ let centre = route.to_local(track.centre.0, track.centre.1);
+ let (c, s) = (track.axis.to_radians().cos(), track.axis.to_radians().sin());
+ // East is +x and north is -z locally.
+ let (along, across) = ((c, -s), (-s, -c));
+ let height = route.ele.first().copied().unwrap_or(0.0) as f64;
+ let mut venue = Venue { track, clockwise, centre, along, across, height, grounds: Grounds { zones: Vec::new(), height, blend: 30.0 } };
+ let (half, edge) = (track.straight() / 2.0, venue.outside_edge());
+ venue.grounds.zones = vec![
+ // The track and its infield, with a margin round the outside.
+ (venue.at(-half, 0.0), venue.at(half, 0.0), edge + 16.0),
+ // The pavilion, stands and stores beside the home straight.
+ (venue.at(-40.0, edge + 11.0), venue.at(24.0, edge + 11.0), 18.0),
+ ];
+ venue
+ }
+
+ /// Local `(x, z)` of a point in the track's frame.
+ pub fn at(&self, a: f64, b: f64) -> (f64, f64) {
+ (self.centre.0 + a * self.along.0 + b * self.across.0, self.centre.1 + a * self.along.1 + b * self.across.1)
+ }
+
+ /// A point in the track's frame, `y` metres above the grounds.
+ fn p(&self, a: f64, b: f64, y: f64) -> P3 {
+ let (x, z) = self.at(a, b);
+ [x, self.height + y, z]
+ }
+
+ /// `(a, b)` of a local point.
+ pub fn frame(&self, x: f64, z: f64) -> (f64, f64) {
+ let (dx, dz) = (x - self.centre.0, z - self.centre.1);
+ (dx * self.along.0 + dz * self.along.1, dx * self.across.0 + dz * self.across.1)
+ }
+
+ /// The side the inside of the track is on, as the sign of a sideways offset from the route.
+ pub fn inside(&self) -> f64 {
+ if self.clockwise {
+ -1.0
+ } else {
+ 1.0
+ }
+ }
+
+ fn half_width(&self) -> f64 {
+ self.track.width / 2.0
+ }
+
+ /// `b` of the drawn track's outside edge along the straights.
+ fn outside_edge(&self) -> f64 {
+ self.track.radius + self.half_width()
+ }
+
+ /// `b` in the drawn frame of something `real` metres across the home straight on the ground.
+ fn beside(&self, real: f64) -> f64 {
+ real - REAL_OUTSIDE + self.outside_edge()
+ }
+
+ /// The cross-slope at every route sample: the straights' banking along them, rising
+ /// through the start of each bend to the bends' and easing off again, the outside high.
+ pub fn banks(&self, route: &Route) -> Vec {
+ let half = self.track.straight() / 2.0;
+ (0..route.n)
+ .map(|i| {
+ let (a, _) = self.frame(route.x[i], route.z[i]);
+ let share = smoothstep(-8.0, 14.0, a.abs() - half);
+ let degrees = self.track.straight_banking + (self.track.bend_banking - self.track.straight_banking) * share;
+ -self.inside() * degrees.to_radians().tan()
+ })
+ .collect()
+ }
+
+ /// Route distance of the spot `physical` metres round from the line the way races go.
+ fn along_route(&self, total: f64, physical: f64) -> f64 {
+ if self.clockwise {
+ (total - physical).rem_euclid(total)
+ } else {
+ physical.rem_euclid(total)
+ }
+ }
+}
+
+// ── Mesh helpers ───────────────────────────────────────────────────────────
+
+fn quad(m: &mut TriMesh, p: [P3; 4], facing: P3, c: [f64; 3]) {
+ let k = rgb(c);
+ m.quad(p, facing, [k; 4]);
+}
+
+fn sub(a: P3, b: P3) -> P3 {
+ [a[0] - b[0], a[1] - b[1], a[2] - b[2]]
+}
+
+fn add(a: P3, b: P3) -> P3 {
+ [a[0] + b[0], a[1] + b[1], a[2] + b[2]]
+}
+
+fn scale(a: P3, k: f64) -> P3 {
+ [a[0] * k, a[1] * k, a[2] * k]
+}
+
+fn cross(a: P3, b: P3) -> P3 {
+ [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]]
+}
+
+fn unit(a: P3) -> P3 {
+ let len = (a[0] * a[0] + a[1] * a[1] + a[2] * a[2]).sqrt().max(1e-9);
+ scale(a, 1.0 / len)
+}
+
+/// A bar from `a` to `b`, `w` wide and `h` deep, with its ends closed.
+fn beam(m: &mut TriMesh, a: P3, b: P3, w: f64, h: f64, c: [f64; 3]) {
+ let d = unit(sub(b, a));
+ let side = cross(d, [0.0, 1.0, 0.0]);
+ let side = if side.iter().map(|v| v * v).sum::() < 1e-6 { [1.0, 0.0, 0.0] } else { unit(side) };
+ let up = unit(cross(side, d));
+ let (s, u) = (scale(side, w / 2.0), scale(up, h / 2.0));
+ let corner = |p: P3, i: f64, j: f64| add(add(p, scale(s, i)), scale(u, j));
+ let ring = [(1.0, 1.0), (-1.0, 1.0), (-1.0, -1.0), (1.0, -1.0)];
+ for k in 0..4 {
+ let (p, q) = (ring[k], ring[(k + 1) % 4]);
+ let facing = add(scale(s, p.0 + q.0), scale(u, p.1 + q.1));
+ quad(m, [corner(a, p.0, p.1), corner(b, p.0, p.1), corner(b, q.0, q.1), corner(a, q.0, q.1)], facing, c);
+ }
+ quad(m, ring.map(|(i, j)| corner(a, i, j)), scale(d, -1.0), c);
+ quad(m, ring.map(|(i, j)| corner(b, i, j)), d, c);
+}
+
+/// An upright post `w` square from `base` up by `height`.
+fn post(m: &mut TriMesh, base: P3, height: f64, w: f64, c: [f64; 3]) {
+ beam(m, base, add(base, [0.0, height, 0.0]), w, w, c);
+}
+
+impl Venue {
+ /// A box in the track's frame, from `a0` to `a1`, `b0` to `b1` and `y0` to `y1`: its sides
+ /// in one colour and its top in another.
+ #[allow(clippy::too_many_arguments)]
+ fn block(&self, m: &mut TriMesh, (a0, a1): (f64, f64), (b0, b1): (f64, f64), (y0, y1): (f64, f64), sides: [f64; 3], top: [f64; 3]) {
+ let ring = [(a0, b0), (a1, b0), (a1, b1), (a0, b1)];
+ let (ca, cb) = ((a0 + a1) / 2.0, (b0 + b1) / 2.0);
+ for k in 0..4 {
+ let (p, q) = (ring[k], ring[(k + 1) % 4]);
+ let out = self.dir((p.0 + q.0) / 2.0 - ca, (p.1 + q.1) / 2.0 - cb);
+ quad(m, [self.p(p.0, p.1, y0), self.p(q.0, q.1, y0), self.p(q.0, q.1, y1), self.p(p.0, p.1, y1)], out, sides);
+ }
+ quad(m, ring.map(|(a, b)| self.p(a, b, y1)), [0.0, 1.0, 0.0], top);
+ }
+
+ /// A horizontal direction in the track's frame as a local vector.
+ fn dir(&self, da: f64, db: f64) -> P3 {
+ [da * self.along.0 + db * self.across.0, 0.0, da * self.along.1 + db * self.across.1]
+ }
+
+ /// A flat patch of ground cover in the track's frame, `y` above the grounds.
+ fn patch(&self, m: &mut TriMesh, (a0, a1): (f64, f64), (b0, b1): (f64, f64), y: f64, c: [f64; 3]) {
+ quad(m, [self.p(a0, b0, y), self.p(a1, b0, y), self.p(a1, b1, y), self.p(a0, b1, y)], [0.0, 1.0, 0.0], c);
+ }
+}
+
+// ── The track ──────────────────────────────────────────────────────────────
+
+impl World {
+ /// A point on the track's surface (or its extension sideways) `d` metres along the route and
+ /// `offset` across, `up` above it.
+ fn on_track(&self, d: f64, offset: f64, up: f64) -> P3 {
+ let r = &self.route;
+ let d = d.rem_euclid(r.total);
+ let p = r.sample_at(d);
+ let (q0, q1) = (r.sample_at((d - 0.5).max(0.0)), r.sample_at((d + 0.5).min(r.total)));
+ let (tx, tz) = (q1.x - q0.x, q1.z - q0.z);
+ let len = tx.hypot(tz).max(1e-9);
+ let (tx, tz) = (tx / len, tz / len);
+ [p.x + tz * offset, p.ele + ROAD_LIFT + self.bank_at(d, offset).1 + up, p.z - tx * offset]
+ }
+
+ /// The direction across the track at `d`, toward +offset, as a local vector.
+ fn across_track(&self, d: f64) -> P3 {
+ let (a, b) = (self.on_track(d, 0.0, 0.0), self.on_track(d, 1.0, 0.0));
+ unit([b[0] - a[0], 0.0, b[2] - a[2]])
+ }
+}
+
+impl Venue {
+ /// Everything round the track, for `World::structures`.
+ pub fn dress(&self, world: &World, m: &mut TriMesh) {
+ self.markings(world, m);
+ self.railing(world, m);
+ self.floodlights(world, m);
+ if self.track.id == crate::velodrome::HERNE_HILL.id {
+ self.herne_hill(m);
+ }
+ }
+
+ /// A band painted across the track at `physical` metres round from the line, `long` along
+ /// it, from `from` to `to` metres across measured from the inside edge.
+ #[allow(clippy::too_many_arguments)]
+ fn band(&self, world: &World, m: &mut TriMesh, physical: f64, long: f64, (from, to): (f64, f64), lift: f64, c: [f64; 3]) {
+ let d = self.along_route(world.route.total, physical);
+ let (inside, half) = (self.inside(), self.half_width());
+ let (o0, o1) = (inside * (half - from), inside * (half - to));
+ let p = [world.on_track(d - long / 2.0, o0, lift), world.on_track(d + long / 2.0, o0, lift), world.on_track(d + long / 2.0, o1, lift), world.on_track(d - long / 2.0, o1, lift)];
+ quad(m, p, [0.0, 1.0, 0.0], c);
+ }
+
+ /// The lines painted across the track: the finish line (white with a black line down the
+ /// middle), the 200 m line, and the red pursuit lines half-way along each straight.
+ fn markings(&self, world: &World, m: &mut TriMesh) {
+ let (total, width) = (world.route.total, self.track.width);
+ self.band(world, m, 0.0, 0.72, (0.0, width), 0.012, LINE_WHITE);
+ self.band(world, m, 0.0, 0.05, (0.0, width), 0.018, LINE_BLACK);
+ self.band(world, m, total - 200.0, 0.05, (0.0, width), 0.012, LINE_WHITE);
+ let home = total - self.track.start_offset;
+ for at in [home, home - total / 2.0] {
+ self.band(world, m, at, 0.05, (0.0, width / 2.0), 0.012, LINE_RED);
+ }
+ }
+
+ /// A low kerb along the outside edge with a galvanised railing on it, and advertising
+ /// boards hung along the straights.
+ fn railing(&self, world: &World, m: &mut TriMesh) {
+ let total = world.route.total;
+ let out = -self.inside() * (self.half_width() + RAIL_OUT);
+ let n = (total / RAIL_EVERY).round() as usize;
+ let every = total / n as f64;
+ let half = self.track.straight() / 2.0;
+ for k in 0..n {
+ let (d0, d1) = (k as f64 * every, (k + 1) as f64 * every);
+ let (b0, b1) = (world.on_track(d0, out, 0.0), world.on_track(d1, out, 0.0));
+ beam(m, add(b0, [0.0, 0.08, 0.0]), add(b1, [0.0, 0.08, 0.0]), 0.25, 0.3, KERB);
+ post(m, add(b0, [0.0, 0.2, 0.0]), 1.0, 0.05, GALVANISED);
+ for y in [0.62, 1.15] {
+ beam(m, add(b0, [0.0, y, 0.0]), add(b1, [0.0, y, 0.0]), 0.05, 0.05, GALVANISED);
+ }
+ // Boards along the straights only, facing the track.
+ let (a, _) = self.frame(b0[0], b0[2]);
+ if a.abs() < half - 6.0 {
+ let board = BOARDS[(k / 2) % BOARDS.len()];
+ let toward = scale(world.across_track(d0), self.inside());
+ let face = |d: f64, y: f64| add(world.on_track(d, out, y), scale(toward, 0.04));
+ let (e0, e1) = (d0 + 0.1, d1 - 0.1);
+ quad(m, [face(e0, 0.22), face(e1, 0.22), face(e1, 1.05), face(e0, 1.05)], toward, board);
+ // A paler block in the middle, where the lettering would be.
+ let lettering = if board.iter().sum::() > 2.0 { [0.25, 0.27, 0.30] } else { [0.93, 0.93, 0.90] };
+ let (l0, l1) = (e0 + (e1 - e0) * 0.2, e1 - (e1 - e0) * 0.2);
+ let lift = scale(toward, 0.05);
+ quad(m, [add(face(l0, 0.5), lift), add(face(l1, 0.5), lift), add(face(l1, 0.78), lift), add(face(l0, 0.78), lift)], toward, lettering);
+ }
+ }
+ }
+
+ /// Floodlights round the outside: tall galvanised columns with an arm reaching out over the
+ /// track and a lamp at its end.
+ fn floodlights(&self, world: &World, m: &mut TriMesh) {
+ let total = world.route.total;
+ let n = (total / LIGHT_EVERY).round() as usize;
+ let out = -self.inside() * (self.half_width() + LIGHT_OUT);
+ let edge = -self.inside() * self.half_width();
+ for k in 0..n {
+ let d = (k as f64 + 0.5) * total / n as f64;
+ let base = world.on_track(d, out, 0.0);
+ // None in front of Herne Hill's pavilion and stands, where the seats come up to the rail.
+ let (a, b) = self.frame(base[0], base[2]);
+ if self.track.id == crate::velodrome::HERNE_HILL.id && b > 0.0 && (-36.0..7.0).contains(&a) {
+ continue;
+ }
+ let top = world.on_track(d, edge, LIGHT_HEIGHT)[1];
+ let foot = [base[0], self.height - 0.3, base[2]];
+ post(m, foot, top - foot[1], 0.18, GALVANISED);
+ let toward = scale(world.across_track(d), self.inside());
+ let head = [foot[0], top, foot[2]];
+ let reach = add(add(head, scale(toward, 2.4)), [0.0, 0.35, 0.0]);
+ beam(m, head, reach, 0.1, 0.1, GALVANISED);
+ beam(m, reach, add(add(reach, scale(toward, 0.7)), [0.0, 0.05, 0.0]), 0.36, 0.16, LAMP_HEAD);
+ }
+ }
+}
+
+// ── Herne Hill's grounds ───────────────────────────────────────────────────
+
+/// The pavilion's roof in section, front to back: (metres from the front of the seating, height
+/// of the top). It sweeps down over the viewing terrace, rises to the back and curls over.
+const ROOF_PROFILE: [(f64, f64); 13] =
+ [(0.9, 7.25), (2.5, 6.95), (4.5, 6.8), (6.5, 6.95), (8.5, 7.35), (10.5, 7.85), (12.5, 8.3), (14.0, 8.5), (15.0, 8.45), (15.6, 8.15), (16.0, 7.6), (16.15, 6.9), (16.15, 6.6)];
+const ROOF_THICK: f64 = 0.3;
+
+impl Venue {
+ fn herne_hill(&self, m: &mut TriMesh) {
+ let edge = self.outside_edge();
+ // Paving beside the home straight, and the car park behind the pavilion.
+ self.patch(m, (-45.0, 26.0), (edge + 1.6, edge + 27.0), 0.03, PAVING);
+ self.patch(m, (6.0, 26.0), (self.beside(72.5), edge + 27.0), 0.06, ASPHALT);
+ for k in 0..8 {
+ let a = 7.5 + k as f64 * 2.5;
+ self.patch(m, (a, a + 0.1), (self.beside(73.5), self.beside(78.0)), 0.08, LINE_WHITE);
+ }
+ self.pavilion(m);
+ self.grandstand(m);
+ self.stores(m);
+ self.infield(m);
+ }
+
+ /// The pavilion (2018): brick below, cedar above with a glazed club room facing the track,
+ /// seating steps up to a viewing terrace, and a wave of a roof curling over at the back.
+ fn pavilion(&self, m: &mut TriMesh) {
+ let (a0, a1) = (-12.5, 4.6);
+ let front = self.beside(55.8);
+ let b = |x: f64| front + x;
+ // Seating steps up to the terrace, with a narrower stair at each end.
+ let (s0, s1) = (a0 + 1.3, a1 - 1.3);
+ for k in 0..6 {
+ let x = k as f64 * 0.75;
+ self.block(m, (s0, s1), (b(x), b(x + 0.75)), (0.0, 0.5 * (k + 1) as f64), BRICK, CONCRETE);
+ }
+ for (e0, e1) in [(a0, s0), (s1, a1)] {
+ for k in 0..12 {
+ let x = k as f64 * 0.375;
+ self.block(m, (e0, e1), (b(x), b(x + 0.375)), (0.0, 0.25 * (k + 1) as f64), CONCRETE, CONCRETE);
+ }
+ let outer = if e0 == a0 { a0 + 0.05 } else { a1 - 0.05 };
+ beam(m, self.p(outer, b(0.0), 1.0), self.p(outer, b(4.5), 4.0), 0.05, 0.05, GALVANISED);
+ for x in [0.2, 1.6, 3.0, 4.4] {
+ post(m, self.p(outer, b(x), 0.25 * ((x / 0.375).floor() + 1.0)), 0.9, 0.05, GALVANISED);
+ }
+ }
+ // Brick below the terrace and the club room, with a grey band at first-floor level.
+ self.block(m, (a0, a1), (b(4.5), b(16.0)), (0.0, 3.0), BRICK, CONCRETE);
+ self.block(m, (a0 - 0.05, a1 + 0.05), (b(4.45), b(16.05)), (2.95, 3.1), COPING, CONCRETE);
+ // A door and a window in the brick at the south end.
+ let mut south = |x0: f64, x1: f64, y0: f64, y1: f64, c: [f64; 3]| {
+ quad(m, [self.p(a1 + 0.02, b(x0), y0), self.p(a1 + 0.02, b(x1), y0), self.p(a1 + 0.02, b(x1), y1), self.p(a1 + 0.02, b(x0), y1)], self.dir(1.0, 0.0), c);
+ };
+ south(8.6, 9.8, 0.0, 2.2, DOOR);
+ south(11.8, 14.2, 0.9, 2.2, GLASS);
+ // Terrace railing, open where the steps come up.
+ for k in 0..=10 {
+ let a = a0 + 0.1 + k as f64 * (a1 - a0 - 0.2) / 10.0;
+ post(m, self.p(a, b(4.6), 3.1), 1.0, 0.05, GALVANISED);
+ }
+ for (r0, r1) in [(a0 + 0.1, s0 + 1.5), (s1 - 1.5, a1 - 0.1)] {
+ beam(m, self.p(r0, b(4.6), 4.1), self.p(r1, b(4.6), 4.1), 0.05, 0.05, GALVANISED);
+ }
+
+ // The roof: its section swept along the building, a little past each end.
+ let underside = |x: f64| -> f64 {
+ let i = ROOF_PROFILE.windows(2).position(|w| x <= w[1].0).unwrap_or(ROOF_PROFILE.len() - 2);
+ let (p, q) = (ROOF_PROFILE[i], ROOF_PROFILE[i + 1]);
+ p.1 + (q.1 - p.1) * ((x - p.0) / (q.0 - p.0)).clamp(0.0, 1.0) - ROOF_THICK
+ };
+ let normals: Vec<(f64, f64)> = (0..ROOF_PROFILE.len())
+ .map(|i| {
+ let (p, q) = (ROOF_PROFILE[i.saturating_sub(1)], ROOF_PROFILE[(i + 1).min(ROOF_PROFILE.len() - 1)]);
+ let (dx, dy) = (q.0 - p.0, q.1 - p.1);
+ let len = dx.hypot(dy).max(1e-9);
+ (-dy / len, dx / len)
+ })
+ .collect();
+ let top: Vec<(f64, f64)> = ROOF_PROFILE.to_vec();
+ let inner: Vec<(f64, f64)> = ROOF_PROFILE.iter().zip(&normals).map(|(p, n)| (p.0 - n.0 * ROOF_THICK, p.1 - n.1 * ROOF_THICK)).collect();
+ let (r0, r1) = (a0 - 0.5, a1 + 0.5);
+ for i in 0..top.len() - 1 {
+ let up = |n: (f64, f64)| [self.dir(0.0, n.0)[0], n.1, self.dir(0.0, n.0)[2]];
+ let (p, q) = (top[i], top[i + 1]);
+ quad(m, [self.p(r0, b(p.0), p.1), self.p(r1, b(p.0), p.1), self.p(r1, b(q.0), q.1), self.p(r0, b(q.0), q.1)], up(normals[i]), ROOF);
+ let (p, q) = (inner[i], inner[i + 1]);
+ quad(m, [self.p(r0, b(p.0), p.1), self.p(r1, b(p.0), p.1), self.p(r1, b(q.0), q.1), self.p(r0, b(q.0), q.1)], scale(up(normals[i]), -1.0), SOFFIT);
+ for (a, side) in [(r0, -1.0), (r1, 1.0)] {
+ let (t0, t1, n0, n1) = (top[i], top[i + 1], inner[i], inner[i + 1]);
+ quad(m, [self.p(a, b(t0.0), t0.1), self.p(a, b(t1.0), t1.1), self.p(a, b(n1.0), n1.1), self.p(a, b(n0.0), n0.1)], self.dir(side, 0.0), FASCIA);
+ }
+ }
+ let (t, n) = (top[0], inner[0]);
+ quad(m, [self.p(r0, b(t.0), t.1), self.p(r1, b(t.0), t.1), self.p(r1, b(n.0), n.1), self.p(r0, b(n.0), n.1)], self.dir(0.0, -1.0), FASCIA);
+ // Slender dark columns under the front of the canopy, with timber beams on them.
+ for k in 0..6 {
+ let a = a0 + 0.6 + k as f64 * (a1 - a0 - 1.2) / 5.0;
+ post(m, self.p(a, b(4.9), 3.1), underside(4.9) - 3.1, 0.14, COLUMN);
+ let mut x: f64 = 1.0;
+ while x < 6.4 {
+ let next = (x + 1.0).min(6.4);
+ beam(m, self.p(a, b(x), underside(x) - 0.14), self.p(a, b(next), underside(next) - 0.14), 0.16, 0.26, SOFFIT);
+ x = next;
+ }
+ }
+
+ // The glazed club room facing the track, cedar boards round the rest.
+ let (g0, g1) = (6.4, 15.95);
+ quad(m, [self.p(a0, b(g0), 3.1), self.p(a1, b(g0), 3.1), self.p(a1, b(g0), underside(g0)), self.p(a0, b(g0), underside(g0))], self.dir(0.0, -1.0), GLASS);
+ let mut a = a0;
+ while a < a1 - 0.01 {
+ post(m, self.p(a + 0.04, b(g0 - 0.03), 3.1), underside(g0) - 3.1, 0.08, MULLION);
+ a += 1.7;
+ }
+ beam(m, self.p(a0, b(g0 - 0.03), 5.7), self.p(a1, b(g0 - 0.03), 5.7), 0.06, 0.08, MULLION);
+ // Boards on the back wall and on each end, up to the underside of the roof.
+ let boards = 0.5;
+ let mut a = a0;
+ let mut k = 0;
+ while a < a1 - 1e-6 {
+ let next = (a + boards).min(a1);
+ let c = if k % 2 == 0 { TIMBER } else { TIMBER_DARK };
+ quad(m, [self.p(a, b(g1), 3.1), self.p(next, b(g1), 3.1), self.p(next, b(g1), 6.7), self.p(a, b(g1), 6.7)], self.dir(0.0, 1.0), c);
+ a = next;
+ k += 1;
+ }
+ for (end, side) in [(a0, -1.0), (a1, 1.0)] {
+ let mut x = g0;
+ let mut k = 0;
+ while x < g1 - 1e-6 {
+ let next = (x + boards).min(g1);
+ let c = if k % 2 == 0 { TIMBER } else { TIMBER_DARK };
+ quad(m, [self.p(end, b(x), 3.1), self.p(end, b(next), 3.1), self.p(end, b(next), underside(next)), self.p(end, b(x), underside(x))], self.dir(side, 0.0), c);
+ x = next;
+ k += 1;
+ }
+ }
+ self.emblem(m, a1 + 0.03, b(13.4), 5.0);
+ }
+
+ /// The track emblem on the pavilion's south end: four stripes round a tall loop, running on
+ /// along the wall toward the front.
+ fn emblem(&self, m: &mut TriMesh, a: f64, centre: f64, y: f64) {
+ let (half_w, half_h, stripe) = (0.8, 1.55, 0.085);
+ let facing = self.dir(1.0, 0.0);
+ let at = |x: f64, y: f64| self.p(a, x, y);
+ for (k, colour) in EMBLEM.iter().enumerate() {
+ let r = half_w - k as f64 * 0.1;
+ let reach = half_h - half_w;
+ // The loop as a stadium: round at top and bottom, straight up the sides.
+ let mut line: Vec<(f64, f64)> = Vec::new();
+ for j in 0..=12 {
+ let t = std::f64::consts::PI * j as f64 / 12.0;
+ line.push((centre + r * t.cos(), y + reach + r * t.sin()));
+ }
+ for j in 0..=12 {
+ let t = std::f64::consts::PI + std::f64::consts::PI * j as f64 / 12.0;
+ line.push((centre + r * t.cos(), y - reach + r * t.sin()));
+ }
+ line.push(line[0]);
+ for w in line.windows(2) {
+ let ((x0, y0), (x1, y1)) = (w[0], w[1]);
+ let (dx, dy) = (x1 - x0, y1 - y0);
+ let len = dx.hypot(dy).max(1e-9);
+ let (nx, ny) = (-dy / len * stripe / 2.0, dx / len * stripe / 2.0);
+ quad(m, [at(x0 - nx, y0 - ny), at(x1 - nx, y1 - ny), at(x1 + nx, y1 + ny), at(x0 + nx, y0 + ny)], facing, *colour);
+ }
+ // And along the wall from the bottom of the loop.
+ let low = y - reach - r;
+ quad(
+ m,
+ [at(self.beside(55.8) + 6.6, low - stripe / 2.0), at(centre, low - stripe / 2.0), at(centre, low + stripe / 2.0), at(self.beside(55.8) + 6.6, low + stripe / 2.0)],
+ facing,
+ *colour,
+ );
+ }
+ }
+
+ /// Open steel bleachers with black benches, north of the pavilion by the finish line.
+ fn grandstand(&self, m: &mut TriMesh) {
+ let (a0, a1) = (-33.5, -13.5);
+ let front = self.outside_edge() + 1.9;
+ for k in 0..5 {
+ let (b0, b1) = (front + 1.1 * k as f64, front + 1.1 * (k + 1) as f64);
+ let y = 0.45 * (k + 1) as f64;
+ self.block(m, (a0, a1), (b0, b1), (0.0, y), STAND, STAND);
+ self.block(m, (a0 + 0.2, a1 - 0.2), (b0 + 0.25, b0 + 0.7), (y, y + 0.42), SEAT, SEAT);
+ }
+ let back = front + 5.5;
+ let top = 0.45 * 5.0;
+ for k in 0..=8 {
+ let a = a0 + k as f64 * (a1 - a0) / 8.0;
+ post(m, self.p(a, back - 0.05, top), 1.1, 0.05, GALVANISED);
+ }
+ beam(m, self.p(a0, back - 0.05, top + 1.1), self.p(a1, back - 0.05, top + 1.1), 0.05, 0.05, GALVANISED);
+ }
+
+ /// The club's stores behind the bleachers: a row of shipping containers, and a white
+ /// tensile canopy on three masts over the space behind them.
+ fn stores(&self, m: &mut TriMesh) {
+ let (b0, b1) = (self.beside(59.0), self.beside(65.06));
+ for k in 0..8 {
+ let a = -33.5 + 2.5 * k as f64;
+ let c = CONTAINERS[k % CONTAINERS.len()];
+ self.block(m, (a, a + 2.44), (b0, b1), (0.0, 2.59), c, c.map(|v| v * 0.85));
+ // Ribs down the sides, a shade darker.
+ for r in 1..10 {
+ let b = b0 + (b1 - b0) * r as f64 / 10.0;
+ for (side, aa) in [(-1.0, a - 0.02), (1.0, a + 2.46)] {
+ quad(m, [self.p(aa, b - 0.08, 0.1), self.p(aa, b + 0.08, 0.1), self.p(aa, b + 0.08, 2.5), self.p(aa, b - 0.08, 2.5)], self.dir(side, 0.0), c.map(|v| v * 0.78));
+ }
+ }
+ }
+ // The canopy: a membrane pulled up into a peak over each mast.
+ let (c0, c1, d0, d1) = (-33.5, -13.5, self.beside(65.4), self.beside(76.0));
+ let masts = [-28.5, -23.5, -18.5].map(|a| (a, (d0 + d1) / 2.0));
+ let height = |a: f64, bb: f64| -> f64 {
+ let peak = masts.iter().map(|&(ma, mb)| (1.0 - (a - ma).hypot(bb - mb) / 6.5).max(0.0).powi(2)).fold(0.0, f64::max);
+ 3.0 + 4.2 * peak
+ };
+ let (na, nb) = (40, 20);
+ let grid = |i: usize, j: usize| {
+ let (a, bb) = (c0 + (c1 - c0) * i as f64 / na as f64, d0 + (d1 - d0) * j as f64 / nb as f64);
+ self.p(a, bb, height(a, bb))
+ };
+ for i in 0..na {
+ for j in 0..nb {
+ quad(m, [grid(i, j), grid(i + 1, j), grid(i + 1, j + 1), grid(i, j + 1)], [0.0, 1.0, 0.0], MEMBRANE);
+ }
+ }
+ for &(a, bb) in &masts {
+ post(m, self.p(a, bb, 0.0), 7.4, 0.16, GALVANISED);
+ }
+ for a in [c0, (c0 + c1) / 2.0, c1] {
+ for bb in [d0, d1] {
+ post(m, self.p(a, bb, 0.0), 3.0, 0.12, GALVANISED);
+ }
+ }
+ }
+
+ /// In the middle: the junior track with hard standing inside it, the path in from the
+ /// tunnel under the main track, and a small white shelter.
+ fn infield(&self, m: &mut TriMesh) {
+ let (ca, cb, half, r, w) = (-17.7, -0.4, 21.9, 25.5, 4.5);
+ let n = 120;
+ let point = |k: usize, off: f64| -> (f64, f64) {
+ // Round a stadium: along the straight at +b, the bend at -a, back along -b, the bend at +a.
+ let s = k as f64 / n as f64 * (4.0 * half + 2.0 * std::f64::consts::PI * r);
+ let bend = std::f64::consts::PI * r;
+ let rr = r + off;
+ if s < 2.0 * half {
+ (ca + half - s, cb + rr)
+ } else if s < 2.0 * half + bend {
+ let t = std::f64::consts::FRAC_PI_2 + (s - 2.0 * half) / r;
+ (ca - half + rr * t.cos(), cb + rr * t.sin())
+ } else if s < 4.0 * half + bend {
+ (ca - half + (s - 2.0 * half - bend), cb - rr)
+ } else {
+ let t = -std::f64::consts::FRAC_PI_2 + (s - 4.0 * half - bend) / r;
+ (ca + half + rr * t.cos(), cb + rr * t.sin())
+ }
+ };
+ for k in 0..n {
+ let (p0, p1, q0, q1) = (point(k, -w / 2.0), point(k, w / 2.0), point(k + 1, -w / 2.0), point(k + 1, w / 2.0));
+ quad(m, [self.p(p0.0, p0.1, 0.03), self.p(q0.0, q0.1, 0.03), self.p(q1.0, q1.1, 0.03), self.p(p1.0, p1.1, 0.03)], [0.0, 1.0, 0.0], JUNIOR);
+ for off in [-w / 2.0 + 0.1, w / 2.0 - 0.1] {
+ let (e0, e1, f0, f1) = (point(k, off - 0.04), point(k, off + 0.04), point(k + 1, off - 0.04), point(k + 1, off + 0.04));
+ quad(m, [self.p(e0.0, e0.1, 0.045), self.p(f0.0, f0.1, 0.045), self.p(f1.0, f1.1, 0.045), self.p(e1.0, e1.1, 0.045)], [0.0, 1.0, 0.0], LINE_WHITE);
+ }
+ }
+ self.patch(m, (-33.0, -5.0), (-14.0, 14.0), 0.03, PAVING);
+ self.patch(m, (-11.0, -6.5), (cb + r + w / 2.0, self.track.radius - self.half_width()), 0.03, PAVING);
+ for (a, bb) in [(-21.0, 31.0), (-15.0, 31.0), (-15.0, 35.5), (-21.0, 35.5)] {
+ post(m, self.p(a, bb, 0.0), 2.6, 0.1, COPING);
+ }
+ self.block(m, (-21.2, -14.8), (30.8, 35.7), (2.6, 2.8), SHELTER_ROOF, SHELTER_ROOF);
+ }
+}
diff --git a/crates/core/tests/velodrome.rs b/crates/core/tests/velodrome.rs
new file mode 100644
index 0000000..bda15fb
--- /dev/null
+++ b/crates/core/tests/velodrome.rs
@@ -0,0 +1,91 @@
+//! Built-in velodromes: the route round the measuring line, and the track drawn round it.
+
+use velopopuli_core::gpx::haversine;
+use velopopuli_core::velodrome::{track_for, HERNE_HILL};
+
+#[test]
+fn herne_hill_is_a_flat_450_m_loop_from_the_line() {
+ for clockwise in [false, true] {
+ let route = HERNE_HILL.route(clockwise);
+ assert!((route.total - 450.0).abs() < 0.05, "a lap is {} m", route.total);
+ assert!(route.closed, "the route ends where it starts");
+ assert!(route.ele.iter().all(|&e| e == 0.0), "the track is flat");
+ assert!(route.climbs.is_empty());
+ // The line is on the home straight, just north of the pavilion: within a few metres of
+ // where it is on the ground (51.45125, -0.09082).
+ assert!(haversine(route.lat[0], route.lon[0], 51.45125, -0.09082) < 3.0, "start at {}, {}", route.lat[0], route.lon[0]);
+ assert_eq!(route.name, if clockwise { "Herne Hill Velodrome (clockwise)" } else { "Herne Hill Velodrome" });
+ }
+}
+
+#[test]
+fn anticlockwise_heads_north_from_the_line_and_clockwise_south() {
+ let (anti, clock) = (HERNE_HILL.route(false), HERNE_HILL.route(true));
+ assert!(anti.lat[10] > anti.lat[0], "anticlockwise rides north up the home straight");
+ assert!(clock.lat[10] < clock.lat[0], "clockwise rides south");
+ // Signed area of the outline in (east, north): positive is anticlockwise.
+ let area = |r: &velopopuli_core::gpx::Route| -> f64 { (0..r.n - 1).map(|i| r.x[i] * -r.z[i + 1] - r.x[i + 1] * -r.z[i]).sum() };
+ assert!(area(&anti) > 0.0 && area(&clock) < 0.0);
+}
+
+#[test]
+fn track_ids_say_which_way_round() {
+ assert!(track_for("herne-hill").is_some_and(|(t, cw)| t.id == "herne-hill" && !cw));
+ assert!(track_for("herne-hill-clockwise").is_some_and(|(_, cw)| cw));
+ assert!(track_for("demo").is_none());
+}
+
+mod track {
+ use std::sync::Arc;
+ use velopopuli_core::velodrome::HERNE_HILL;
+ use velopopuli_core::world::{World, CHUNK, TRACK};
+
+ fn world(clockwise: bool) -> World {
+ World::new(Arc::new(HERNE_HILL.route(clockwise)), None, 0.0).with_venue(HERNE_HILL, clockwise)
+ }
+
+ #[test]
+ fn the_track_is_banked_up_to_the_outside_steepest_in_the_bends() {
+ for clockwise in [false, true] {
+ let w = world(clockwise);
+ let half = HERNE_HILL.width / 2.0;
+ // Which side is the inside: the anticlockwise centre of the oval is on the left (+offset).
+ let inside = if clockwise { -1.0 } else { 1.0 };
+ let degrees: Vec = (0..w.route.n).map(|i| w.bank(i).abs().atan().to_degrees()).collect();
+ let steepest = degrees.iter().copied().fold(0.0, f64::max);
+ let flattest = degrees.iter().copied().fold(90.0, f64::min);
+ assert!((steepest - HERNE_HILL.bend_banking).abs() < 0.5, "bends banked at {steepest:.1}°");
+ assert!((flattest - HERNE_HILL.straight_banking).abs() < 0.5, "straights banked at {flattest:.1}°");
+ for i in (0..w.route.n).step_by(25) {
+ assert!(w.surface_lift(i, -inside * half) > w.surface_lift(i, inside * half) + 0.5, "outside higher at sample {i}");
+ assert!(w.surface_lift(i, inside * half).abs() < 1e-9, "the inside edge stays on the ground");
+ }
+ // The line is on the home straight, so it is banked as a straight.
+ assert!((degrees[0] - HERNE_HILL.straight_banking).abs() < 0.5);
+ }
+ }
+
+ #[test]
+ fn the_track_is_drawn_as_a_track_with_its_paint_inside_whichever_way_round() {
+ let (anti, clock) = (world(false), world(true));
+ let (a, c) = (anti.road(), clock.road());
+ assert!(a.looks.iter().all(|&l| l == TRACK));
+ // Texture across: the inside's markings are at the high end. Anticlockwise the inside is
+ // at +offset (the fourth vertex across); clockwise it is mirrored.
+ assert!(a.uvs[3 * 2] > 0.5 && c.uvs[3 * 2] < 0.5);
+ assert!(anti.barriers().is_empty(), "a railing, not race barriers");
+ assert!(anti.structures().lit.vertices() > 20_000, "the grounds are built on");
+ }
+
+ #[test]
+ fn the_grounds_are_level_and_kept_clear() {
+ let w = world(false);
+ let route = &w.route;
+ // The middle of the oval and the pavilion's spot, at the track's height.
+ let (cx, cz) = route.to_local(HERNE_HILL.centre.0, HERNE_HILL.centre.1);
+ assert!(w.field.probe(cx, cz, 1.0).ground.abs() < 1e-6);
+ let chunk = w.chunk((cx / CHUNK).floor() as i32, (cz / CHUNK).floor() as i32);
+ let trees_in_infield = chunk.trees.chunks(8).filter(|t| (t[0] as f64 - cx).hypot(t[2] as f64 - cz) < 40.0).count();
+ assert_eq!(trees_in_infield, 0);
+ }
+}
diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs
index a57d417..cbc609c 100644
--- a/src-tauri/src/commands.rs
+++ b/src-tauri/src/commands.rs
@@ -136,6 +136,12 @@ pub fn demo_meta() -> RouteMeta {
meta_for(DEMO_ROUTE_ID.into(), &demo_route(), 0)
}
+/// The built-in velodromes, each as its route ridden the usual way round (anticlockwise).
+#[tauri::command]
+pub fn tracks_meta() -> Vec {
+ velopopuli_core::velodrome::TRACKS.iter().map(|t| meta_for(t.id.into(), &t.route(false), 0)).collect()
+}
+
#[tauri::command]
pub fn badges() -> &'static [Badge] {
&BADGES
@@ -892,6 +898,8 @@ pub struct SmokeConfig {
scroll: Option,
/// Laps to ride on a closed route (VP_SMOKE_LAPS, 0 = until stopped).
laps: Option,
+ /// Ride this route instead of the newest in the library (VP_SMOKE_ROUTE, e.g. `herne-hill`).
+ route: Option,
}
/// Automated check only: saves window frame `index` as `.frames/NNNN.png`, for demo clips.
@@ -922,6 +930,7 @@ pub fn smoke_config() -> Option {
shift: std::env::var("VP_SMOKE_SHIFT").ok().and_then(|v| v.parse().ok()),
scroll: std::env::var("VP_SMOKE_SCROLL").ok(),
laps: std::env::var("VP_SMOKE_LAPS").ok().and_then(|v| v.parse().ok()),
+ route: std::env::var("VP_SMOKE_ROUTE").ok(),
})
}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index e9dfc35..a987ff0 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -96,6 +96,7 @@ fn main() {
commands::routes_import_dialog,
commands::routes_import_text,
commands::demo_meta,
+ commands::tracks_meta,
commands::badges,
commands::choose_dir,
commands::reveal_file,
diff --git a/src-tauri/src/native/mod.rs b/src-tauri/src/native/mod.rs
index bc8afc1..3e86236 100644
--- a/src-tauri/src/native/mod.rs
+++ b/src-tauri/src/native/mod.rs
@@ -20,7 +20,7 @@ use serde::Deserialize;
use tauri::{AppHandle, Manager};
use velopopuli_core::ride::{RideEngine, RivalKind};
use velopopuli_core::world::{
- barrier_model, sprite_frame, surface_runs, tree_model, GridMesh, Surface, World, BARRIER_LOOKS, FORD, LAYOUT, SINGLETRACK, SPRITES_FROM, TIMBER, TREE_FLOATS, TREE_KINDS, UNMARKED,
+ barrier_model, sprite_frame, surface_runs, tree_model, GridMesh, Surface, World, BARRIER_LOOKS, FORD, LAYOUT, SINGLETRACK, SPRITES_FROM, TIMBER, TRACK, TREE_FLOATS, TREE_KINDS, UNMARKED,
};
use wgpu::util::DeviceExt;
@@ -1447,6 +1447,7 @@ impl SceneMeshes {
_ if look == UNMARKED => "road_lane",
_ if look == TIMBER => "road_timber",
_ if look == SINGLETRACK => "road_singletrack",
+ _ if look == TRACK => "road_track",
_ if look == FORD => "road_ford",
Some(Surface::Concrete) => "road_concrete",
Some(Surface::Cobbles) => "road_cobbles",
diff --git a/src-tauri/src/session.rs b/src-tauri/src/session.rs
index b2d82bd..3509235 100644
--- a/src-tauri/src/session.rs
+++ b/src-tauri/src/session.rs
@@ -66,6 +66,9 @@ pub fn load_route(store: &Store, id: &str) -> Result {
if id == DEMO_ROUTE_ID {
return Ok(demo_route());
}
+ if let Some((track, clockwise)) = velopopuli_core::velodrome::track_for(id) {
+ return Ok(track.route(clockwise));
+ }
let stored: StoredRoute = store.get(&format!("route-{id}")).ok_or("This route is no longer in your library.")?;
build_route(&stored.name, &parse_gpx(&stored.gpx)?.1)
}
@@ -98,6 +101,8 @@ pub struct RideInit {
landmarks: Vec,
/// Laps as the engine understands them (none on an open route).
laps: Option,
+ /// The route is a velodrome's track: no start and finish arches, it has its own line.
+ venue: bool,
}
#[derive(Serialize)]
@@ -212,7 +217,27 @@ impl Session {
let pb: Option = store.get(&format!("pb-{route_id}"));
let route = Arc::new(route);
let real_terrain = dem.is_some();
- let mut world = World::with_map(route.clone(), dem, dem_offset, map.scenery.as_ref(), &map.footprints);
+ // A built-in track: the velodrome round it takes the place of what the map has there.
+ let track = velopopuli_core::velodrome::track_for(route_id);
+ let mut world = match track {
+ Some((track, clockwise)) => {
+ let world = World::with_map(route.clone(), dem, dem_offset, map.scenery.as_ref(), &[]).with_venue(track, clockwise);
+ let grounds = &world.venue.as_ref().expect("just added").grounds;
+ let footprints: Vec<_> = map
+ .footprints
+ .iter()
+ .filter(|f| {
+ let n = f.ring.len().max(1) as f64;
+ let (lat, lon) = (f.ring.iter().map(|p| p[0]).sum::() / n, f.ring.iter().map(|p| p[1]).sum::() / n);
+ let (x, z) = route.to_local(lat, lon);
+ grounds.outside(x, z) > 0.0
+ })
+ .cloned()
+ .collect();
+ world.with_buildings(&footprints)
+ }
+ None => World::with_map(route.clone(), dem, dem_offset, map.scenery.as_ref(), &map.footprints),
+ };
// Automated check only: VP_SMOKE_SURFACE=<0–4> lays the whole route in one surface.
if let Some(s) = std::env::var("VP_SMOKE_SURFACE")
.ok()
@@ -332,8 +357,10 @@ impl Session {
let t = Local::now();
t.hour() as f64 + t.minute() as f64 / 60.0
},
- landmarks: if settings.look.landmarks { landmarks(&route, map.scenery.as_ref()) } else { Vec::new() },
+ // No village signs on a velodrome's track.
+ landmarks: if settings.look.landmarks && track.is_none() { landmarks(&route, map.scenery.as_ref()) } else { Vec::new() },
laps: engine.laps,
+ venue: track.is_some(),
};
if std::env::var_os("VP_SMOKE").is_some() {
for m in &init.landmarks {
diff --git a/web/src/App.tsx b/web/src/App.tsx
index 8f37b51..ed910e3 100644
--- a/web/src/App.tsx
+++ b/web/src/App.tsx
@@ -35,7 +35,13 @@ async function runSmoke(setScreen: (s: Screen) => void): Promise {
await api.devices.demoAdd()
setScreen({
name: 'ride',
- request: { routeId: routes?.[0]?.id ?? 'demo', workoutId: smoke.workout, groupRoom: smoke.room, ghostIds: smoke.ghosts ?? [], laps: smoke.laps ?? null }
+ request: {
+ routeId: smoke.route ?? routes?.[0]?.id ?? 'demo',
+ workoutId: smoke.workout,
+ groupRoom: smoke.room,
+ ghostIds: smoke.ghosts ?? [],
+ laps: smoke.laps ?? null
+ }
})
} else if (
smoke.screen === 'devices' ||
diff --git a/web/src/bridge.ts b/web/src/bridge.ts
index 50bb971..66edc6f 100644
--- a/web/src/bridge.ts
+++ b/web/src/bridge.ts
@@ -39,6 +39,8 @@ export const api = {
importDialog: () => invoke<{ added: RouteMeta[]; problems: string[] }>('routes_import_dialog'),
importText: (name: string, text: string) => invoke('routes_import_text', { name, text }),
demoMeta: () => invoke('demo_meta'),
+ /** The built-in velodromes, each as ridden anticlockwise (its ID with `-clockwise` the other way). */
+ tracksMeta: () => invoke('tracks_meta'),
isLoop: (routeId: string) => invoke('route_is_loop', { routeId })
},
badges: () => invoke('badges'),
@@ -164,6 +166,7 @@ export const api = {
shift: number | null
scroll: string | null
laps: number | null
+ route: string | null
} | null>('smoke_config'),
frame: (index: number) => invoke('smoke_frame', { index }),
done: (png: string | null, info: string) => invoke('smoke_done', { png, info })
diff --git a/web/src/types.ts b/web/src/types.ts
index 1ce4819..47761b4 100644
--- a/web/src/types.ts
+++ b/web/src/types.ts
@@ -344,6 +344,8 @@ export interface RideInit {
landmarks: Landmark[]
/** Laps the ride was started with, as the engine understood them; null on a ride without laps. */
laps: number | null
+ /** The route is a velodrome's track, which has its own finish line rather than arches. */
+ venue: boolean
}
export interface Landmark {
diff --git a/web/src/ui/Home.tsx b/web/src/ui/Home.tsx
index 1a7c5c9..adeb8eb 100644
--- a/web/src/ui/Home.tsx
+++ b/web/src/ui/Home.tsx
@@ -33,10 +33,12 @@ export function Home({ onRide }: { onRide: (request: RideRequest) => void }): Re
const [error, setError] = useState('')
const [dragging, setDragging] = useState(false)
const [demo, setDemo] = useState(null)
+ const [tracks, setTracks] = useState([])
const [setup, setSetup] = useState<{ route: RouteMeta; room?: string } | null>(null)
const [joining, setJoining] = useState(false)
const [room, setRoom] = useState('')
useEffect(() => void api.routes.demoMeta().then(setDemo), [])
+ useEffect(() => void api.routes.tracksMeta().then(setTracks), [])
const add = (added: RouteMeta[], problems: string[]): void => {
if (added.length) saveRoutes([...added, ...(routes ?? [])])
@@ -83,7 +85,15 @@ export function Home({ onRide }: { onRide: (request: RideRequest) => void }): Re
{r.climbs} climb{r.climbs === 1 ? '' : 's'}
-