From f5e08b76e8d2d7390b0fa137c5053a00a9346135 Mon Sep 17 00:00:00 2001 From: SamG-Coder <13449963+SamG-Coder@users.noreply.github.com> Date: Fri, 13 Nov 2026 07:17:15 +1100 Subject: [PATCH 1/3] Game: autopilot changes gear in a manual car; C is the car's view while playing; settings given twice are mistakes A manual car handed to the autopilot stayed in the gear it was in, as the autopilot never asks for a change: its driver now has the automatic gearbox while it drives, and the player's own back when they take over. In the native viewer C was both the car's next view and the next weather, and T moved the clock: while someone is played, and not flying, those keys are the game's. A .vehicle file took a second mass, gears or front spring=, and the last silently won; a .track file took a second name, or l= twice on a point. Each is now an error naming the line the first was on. Co-Authored-By: Claude Opus 5.5 --- README.md | 3 +- apps/viewer/src/main.rs | 13 +++++-- crates/solstice-game/src/play.rs | 12 +++++++ crates/solstice-game/src/track.rs | 27 ++++++++++++++- crates/solstice-game/tests/driving.rs | 49 +++++++++++++++++++++++++++ crates/solstice-vehicle/src/spec.rs | 46 +++++++++++++++++++++++++ docs/gameplay.md | 8 +++-- 7 files changed, 151 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3c5930f..8e8237a 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,8 @@ turns the sky around the scene. The page also takes `?time=HH:MM` and `?day-leng The native viewer takes `--weather NAME` or a weather file, and **C** moves to the next kind of weather. `--time HH:MM` starts a clock, with `--day N` (day of the year), `--latitude DEGREES` and -`--day-length SECONDS`; **T** moves the clock on an hour. +`--day-length SECONDS`; **T** moves the clock on an hour. While a game is played, C and T are the +game's keys, as **C** changes a car's view; they are the viewer's again while flying (**V**). ## Your own models diff --git a/apps/viewer/src/main.rs b/apps/viewer/src/main.rs index 8e30368..c303b67 100644 --- a/apps/viewer/src/main.rs +++ b/apps/viewer/src/main.rs @@ -1655,6 +1655,15 @@ mod native { } } } + // While someone is played, and not left to fly the camera, the keys + // are the game's: C changes a car's view, so it is not the weather's. + let played = self + .state + .as_ref() + .and_then(|s| s.play.as_ref()) + .is_some_and(|(play, _)| { + play.play.has_player() && !play.play.flying() + }); match event.state { ElementState::Pressed => { self.keys.insert(code); @@ -1662,11 +1671,11 @@ mod native { self.set_mouse_capture(false); } // Cycles through the built-in weather, easing into each. - if code == KeyCode::KeyC { + if code == KeyCode::KeyC && !played { self.next_weather(); } // Moves the clock on an hour, starting one if there is none. - if code == KeyCode::KeyT { + if code == KeyCode::KeyT && !played { let fixed = self.options.environment; let clock = self.options.clock.get_or_insert_with(|| { let mut clock = DayClock::new(TimeOfDay::default(), 0.0); diff --git a/crates/solstice-game/src/play.rs b/crates/solstice-game/src/play.rs index 7d93f87..876ef82 100644 --- a/crates/solstice-game/src/play.rs +++ b/crates/solstice-game/src/play.rs @@ -350,6 +350,8 @@ impl Play { let circuit = track.clone(); // Whether the car is driving itself round the circuit, and where on it it last was. let (mut itself, mut last_at) = (false, None); + // Whether the player's own gearbox is automatic, while the car drives itself. + let mut players_gearbox = true; schedule.add(TickGroup::PrePhysics, "driving", move |world| { let Some(entity) = driven else { return; @@ -366,6 +368,16 @@ impl Play { if !away && world.input().pressed("autopilot") { itself = !itself; last_at = None; + // The driver it is handed to changes gear itself, whatever gearbox the + // player had; handed back, the player has their own again. + if let Ok(mut car) = world.entities.get::<&mut Car>(entity) { + if itself { + players_gearbox = car.driver.automatic; + car.driver.automatic = true; + } else { + car.driver.automatic = players_gearbox; + } + } } if let (true, Some(track)) = (itself, &circuit) { let car = world diff --git a/crates/solstice-game/src/track.rs b/crates/solstice-game/src/track.rs index fb969ea..000142d 100644 --- a/crates/solstice-game/src/track.rs +++ b/crates/solstice-game/src/track.rs @@ -135,10 +135,19 @@ impl Track { let mut name = String::new(); let mut samples = Vec::new(); let mut sectors = Vec::new(); + let mut named = None; for (line, words) in lines(text) { let error = |message: String| FileError { line, message }; match words[0] { - "name" if words.len() >= 2 => name = words[1..].join(" "), + "name" if words.len() >= 2 => { + if let Some(first) = named { + return Err(error(format!( + "a second name: the first is on line {first}" + ))); + } + named = Some(line); + name = words[1..].join(" "); + } "name" => return Err(error("expected `name NAME`".to_owned())), "sector" => { let [_, index] = words[..] else { @@ -180,6 +189,11 @@ impl Track { Some(("r", bands)) => (&mut sample.right_bands, bands), _ => return Err(error(format!("`{word}` should be l=... or r=..."))), }; + if !side.is_empty() { + return Err(error(format!( + "`{word}`: a side's bands are given once, as l=A,B" + ))); + } for band in bands.split(',') { side.push(parse_band(band).map_err(&error)?); } @@ -537,6 +551,17 @@ pub(crate) mod tests { ("p 0 0 0 1 0 0 6 6 x=kerb:3", 1, "l=... or r=..."), ("p 0 0 0 1 0 0 6 6 l=kerb", 1, "SURFACE:WIDTH"), ("lap 3", 1, "unknown line `lap`"), + ( + "name A +name B", + 2, + "a second name: the first is on line 1", + ), + ( + "p 0 0 0 1 0 0 6 6 l=kerb:1 l=grass:3", + 1, + "a side's bands are given once", + ), ( "p 0 0 0 1 0 0 6 6\np 1 0 0 1 0 0 6 6", 1, diff --git a/crates/solstice-game/tests/driving.rs b/crates/solstice-game/tests/driving.rs index 20fcba1..61b345a 100644 --- a/crates/solstice-game/tests/driving.rs +++ b/crates/solstice-game/tests/driving.rs @@ -504,6 +504,55 @@ actor car.actor -200 0 30 0 instances=1+6 assert!(car_at(&play).1 < before, "coasting"); } +#[test] +fn a_manual_car_driving_itself_changes_gear_and_the_player_gets_their_gearbox_back() { + let track_text = square_track(); + let scene = "input keys.input +track square.track +actor car.actor -200 0 30 0 instances=1+6 +"; + let manual = CAR.replace("vehicle gt.vehicle", "vehicle gt.vehicle manual"); + let mut play = Play::load( + &files(&[ + (GAME_FILE, scene), + ("car.actor", &manual), + ("gt.vehicle", ""), + ("keys.input", KEYS), + ("square.track", &track_text), + ]), + |id| baked(id).map(|at| Mat4::from_translation(Vec3::new(-200.0, 0.0, 30.0)) * at), + Some(&floor()), + ) + .unwrap_or_else(|e| panic!("{e:?}")); + let gearbox = |play: &Play| { + let world = &play.world().entities; + let mut query = world.query::<&Car>(); + let car = query.iter().next().expect("a car"); + (car.driver.automatic, car.vehicle.gear()) + }; + let mut devices = Devices::new(); + run(&mut play, &mut devices, 0.5); + assert!(!gearbox(&play).0, "the player's car is manual"); + devices.key("KeyP", true); + run(&mut play, &mut devices, 0.1); + devices.key("KeyP", false); + let mut highest = 0; + for _ in 0..(12.0 / STEP_SECONDS) as u32 { + play.frame(STEP_SECONDS, &mut devices, |_, _| {}); + highest = highest.max(gearbox(&play).1); + } + assert!(gearbox(&play).0, "its own driver changes gear"); + assert!(highest >= 3, "it got no higher than gear {highest} in 12 s"); + // Handed back, the gearbox is the player's again, and stays in the gear it was in. + devices.key("KeyP", true); + run(&mut play, &mut devices, 0.1); + devices.key("KeyP", false); + let (automatic, now) = gearbox(&play); + assert!(!automatic); + run(&mut play, &mut devices, 2.0); + assert_eq!(gearbox(&play).1, now, "nothing changes gear for the player"); +} + #[test] fn a_car_that_falls_far_below_its_track_is_put_back_on_it() { // The square circuit forty metres up, over a floor at nought: the car is put down beside diff --git a/crates/solstice-vehicle/src/spec.rs b/crates/solstice-vehicle/src/spec.rs index 56afb68..5469deb 100644 --- a/crates/solstice-vehicle/src/spec.rs +++ b/crates/solstice-vehicle/src/spec.rs @@ -23,6 +23,7 @@ use crate::tyre::Tyre; use glam::Vec3; +use std::collections::HashMap; use std::fmt::{self, Write as _}; /// A mistake in a `.vehicle` file, and the line it is on. @@ -348,6 +349,8 @@ impl VehicleSpec { pub fn parse(text: &str) -> Result { let mut spec = Self::gt(); let mut torque: Vec<(f32, f32)> = Vec::new(); + // Each setting, and the line it was given on: a second would silently win. + let mut given: HashMap = HashMap::new(); for (index, line) in text.lines().enumerate() { let words: Vec<&str> = line .split('#') @@ -368,6 +371,25 @@ impl VehicleSpec { } values.iter().map(|w| number(w).map_err(&error)).collect() }; + let settings: Vec = match keyword { + // A line for each point of the curve. + "torque" => Vec::new(), + "front" | "rear" | "tyre" | "engine" | "gearbox" | "diff" | "aero" | "steering" + | "geometry" | "assists" => values + .iter() + .filter_map(|word| word.split_once('=')) + .map(|(key, _)| format!("{keyword} {key}")) + .collect(), + _ => vec![keyword.to_owned()], + }; + for setting in settings { + if let Some(first) = given.get(&setting) { + return Err(error(format!( + "`{setting}` is given twice: first on line {first}" + ))); + } + given.insert(setting, index + 1); + } match keyword { "mass" => spec.mass = numbers(1, "KILOGRAMS")?[0], "inertia" => spec.inertia = Vec3::from_slice(&numbers(3, "PITCH YAW ROLL")?), @@ -987,6 +1009,30 @@ mod tests { ("body 1 1 1", 1, "body SX SY SZ at"), ("tyre along=2.5,0", 1, "C between 1 and 2"), ("aero balance=1.4", 1, "share"), + ( + "mass 1200 +mass 1300", + 2, + "`mass` is given twice: first on line 1", + ), + ( + "gears 3 2 + +gears 3 2 1", + 3, + "`gears` is given twice", + ), + ( + "front spring=1 +front spring=2", + 2, + "`front spring` is given twice", + ), + ( + "engine idle=900 idle=950", + 1, + "`engine idle` is given twice", + ), ]; for (text, line, part) in cases { let error = VehicleSpec::parse(text).unwrap_err(); diff --git a/docs/gameplay.md b/docs/gameplay.md index 14e7edc..2a95462 100644 --- a/docs/gameplay.md +++ b/docs/gameplay.md @@ -1070,8 +1070,9 @@ Built for a racing game on the engine, - Anti-lock brakes, traction control and stability control, each a line in the car's file. Stability control watches the rear tyres' slip angle: past the angle they grip best at, it eases the engine, lets go of the rear brakes and brakes the outside front wheel. - - A `.vehicle` file holds a car's numbers. `tests/gt.vehicle` is a rear-engined GT racing - car, and its tests hold it to what its class does (`tests/rear_engined.rs`). + - A `.vehicle` file holds a car's numbers, each given once. `tests/gt.vehicle` is a + rear-engined GT racing car, and its tests hold it to what its class does + (`tests/rear_engined.rs`). - **The driver** (`driver.rs`) is between the player and the car, as in every driving game. A key is a wheel hard over; a wheel hard over at speed is a spin. So steering eases, a full push gives less lock the faster the car goes, and past a few degrees of slide the wheel @@ -1093,7 +1094,8 @@ Built for a racing game on the engine, actors; a scene without one leaves them out, so its keys press nothing more. They are `throttle`, `brake`, `steer`, `handbrake`, `shift_up`, `shift_down`, `reset`, `camera`, `look_back`, `look_round`, `look_over`, and `autopilot`, which hands the car to a driver of its own that follows the - track's centre line at a speed the bends ahead allow. That is for showing a circuit off, + track's centre line at a speed the bends ahead allow, changing gear itself even for a + `manual` car (the player has their own gearbox back when they take over). That is for showing a circuit off, and for trying one headless: `viewer SCENE --play --press autopilot@40 --frames 5000`. - **Building one.** `circuit SIZE` in a scene file builds a whole circuit from the scene's track (`apps/bake/src/circuit`): an island whose height follows the road, with cliffs, the From 4065d8065d2140de22a998b68ed4af973466382c Mon Sep 17 00:00:00 2001 From: SamG-Coder <13449963+SamG-Coder@users.noreply.github.com> Date: Fri, 13 Nov 2026 07:41:39 +1100 Subject: [PATCH 2/3] Game: fmt Co-Authored-By: Claude Opus 5.5 --- apps/viewer/src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/viewer/src/main.rs b/apps/viewer/src/main.rs index c303b67..909cd65 100644 --- a/apps/viewer/src/main.rs +++ b/apps/viewer/src/main.rs @@ -1661,9 +1661,7 @@ mod native { .state .as_ref() .and_then(|s| s.play.as_ref()) - .is_some_and(|(play, _)| { - play.play.has_player() && !play.play.flying() - }); + .is_some_and(|(play, _)| play.play.has_player() && !play.play.flying()); match event.state { ElementState::Pressed => { self.keys.insert(code); From ee259e801a563b308d1bfd4207fc3529396cc6c0 Mon Sep 17 00:00:00 2001 From: SamG-Coder <13449963+SamG-Coder@users.noreply.github.com> Date: Fri, 13 Nov 2026 08:10:45 +1100 Subject: [PATCH 3/3] Game: the autopilot key does nothing without a circuit From review: with no track it took a manual car's gearbox and gave it back only on a second press, while driving nothing. Co-Authored-By: Claude Opus 5.5 --- crates/solstice-game/src/play.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/solstice-game/src/play.rs b/crates/solstice-game/src/play.rs index 876ef82..ea03085 100644 --- a/crates/solstice-game/src/play.rs +++ b/crates/solstice-game/src/play.rs @@ -365,7 +365,8 @@ impl Play { drive::asked(world.input()) }; let reset = !away && world.input().pressed("reset"); - if !away && world.input().pressed("autopilot") { + // With no circuit there is nothing to drive round: the key does nothing. + if !away && circuit.is_some() && world.input().pressed("autopilot") { itself = !itself; last_at = None; // The driver it is handed to changes gear itself, whatever gearbox the