# Race scene The race screen runs every race of the game: GT Mode and arcade races, licence tests, time trials, 2P battles, online battles, replays and the Replay Theater. On its own (`gt3r --screen race`, "Time trial" in the main menu) it is a time trial: choose a course and a car (names from `data::CarDatabase`), then drive. Code: `src/race/` (engine side) and `src/app/screen_race*.cpp` (the screen; see "Race screen code map" below). | File | What | |---|---| | `race/backend.h/.cpp` | `RaceTrack` (over `track::Track`) and `RaceVehicle` (the player's car of a race on the exact core) interfaces, `car_setup_from_database()` | | `race/controls.h/.cpp` | Pad → `sim::ControlInputs` mapping, rumble model | | `race/interp.h/.cpp` | Fixed-tick accumulator, quaternion helpers, `VehicleState` interpolation | | `race/camera_rig.h/.cpp` | Chase, far chase, bumper, roof and free-orbit cameras | | `race/hood_camera.h/.cpp` | The hood mount's profile: 17 fore/aft eyes above the body's surface, from its mesh | | `race/driver_seat.h/.cpp` | The seat the car's own driver sits in, from its body's mesh (`CarVisual::driver_seat`; VR's Match the car, [VR](VR.md)). Tests `driver_seat_*` | | `race/race_scene.h/.cpp` | GPU scene: course (scenery, backdrop, sky domes) and the car (body LODs + four wheels) | | `race/hud.h/.cpp` | HUD (lap times, tachometer, gear, speed) using the game's own assets | | `race/hud_layout.h/.cpp` | The HUD layout per display mode (the original's layout table) and the mode a run uses | | `race/hud_clocks.h/.cpp` | The start title's and the replay mark's clocks (`TitleClock`, `ReplayMarkTimer`) | | `race/time_text.h/.cpp` | The menus' time format (`menu_time_text`) and the game's "none" placeholders in the font's long dash (no time, no speed, no date) | | `race/machine_test.h/.cpp` | Machine tests: the test from the event, its timing points and goal (`MachineTest`) | | `race/lap_events.h/.cpp` | The event display (the pop-ups' queue and timing), race gaps (`PassingOrder`), time trials' best lap and split times (`BestLapSplits`) | | `race/replay.h/.cpp` | Replay format, recorder, player, save/list in `/replays/` | | `sim/exact/race_record.h/.cpp` | A race on the exact core as a replay keeps it (`RaceRecord`: setup, every car's frames, the game's changes, the end hash), `RacePlayback`, `race_hash` | | `race/exact_demo.h/.cpp` | The disc's demo runs as race records (`demo_record`: the race GT3's replay playback builds from the save) | | `sim/exact/sparks.h/.cpp`, `race/sparks.h/.cpp` | The race's sparks: the particles in GT3's arithmetic, stepped by `ExactRace::step` (`Sparks`); their draw (`SparkDraw`; see "Sparks") | | `race/replay_library.h/.cpp` | The Replay Theater's files: list with headers, delete, rename, info texts | | `race/replay_options.h/.cpp` | REPLAY OPTIONS: replay view mode, target, HUD items, sound; the panel | | `race/analyzer.h/.cpp` | The Analyzer (data logger): the logger's sectors, keys and graph from the race's data logger tables, GRAPH / REPLAY screens | | `race/ghost.h` | `GhostLap`: the Analyzer's logger ghost (a recorded lap as poses); race ghosts are cars of the exact race (see "Ghost") | | `race/replay_cameras.h/.cpp` | GT3's replay camera script (GTRC) and the replay director | | `race/replay_focus.h/.cpp` | The car the replay cameras follow: battles, TOP / AUTO interest scores | | `race/procedural_cameras.h/.cpp`, `race/music_markers.h/.cpp` | View mode 1's procedural cameras; the race music's markers its cuts follow | | `race/clut_animations.h/.cpp` | The course models' palette animations (see "Course animations") | | `race/race_audio.h/.cpp` | Reverb ambience model, race music, opponents' engine notes | | `race/race_playlist.h/.cpp` | The race playlist (the options' music list): next song, list order / shuffle, saved text | | `race/race_sfx.h/.cpp`, `race/car_sfx.h/.cpp` | Named se.inf effects; tyre, kerb, road and collision sounds per car | | `race/field.h/.cpp` | `RaceField`: the race's cars for the screen (player(s), opponents, standings); `RaceField::create` builds an `ExactField` | | `race/exact_field.h/.cpp` | Races on the exact core: `RaceField` over `sim::exact::ExactRace` (see "Races on the exact core") | | `race/exact_car.h/.cpp`, `race/exact_setup.h/.cpp` | A record as the screen reads a car (state, setup, telemetry, facts, condition); the program's tables, the course and each car's equipment for the exact core | | `race/results.h/.cpp` | Results overlay, time-trial overlay, post-race quick menu (game .pmb pages) | | `race/post_run.h/.cpp` | What follows a run per mode (prize / name entry / replay), the quick menu's backdrop, pause EXIT as a finish | | `race/paint.h/.cpp` | carcolor.db and the race-start colour draw | | `tests/test_race.cpp` | Control mapping, stepping, interpolation, rumble, render-state decoding, car setup | | `tests/test_race_presentation.cpp` | Presentation rules without the disc: records and RETRY, HUD layouts, replay view modes, quick menus, what follows a run, the title and mark clocks | | `tests/test_race_lap_events.cpp` | The pop-ups, split points, machine-test timing and the loading picture without the disc | | `tests/test_time_text.cpp` | The time formats; disc (any region): the placeholders against the game program and laid out with the disc's fonts | | `tests/test_exact_game.cpp` | Disc: the pad read's frames; whole races through `RaceField` on the exact core equal to `ExactRace` stepped directly (`exact_game_race_lockstep`); a pad-read run equal to its replay's inputs (`exact_game_pad_replay`) | | `tests/test_sparks.cpp` | The sparks' pool, bursts, update, VU0 sine and cosine, emission gates and colours without the disc; disc: the 24 models with spark points, an F090/S race that sparks and replays to the same race | | `tests/test_exact_replay.cpp`, `tests/test_exact_demos.cpp` | Disc: races on the exact core through a replay file and back, every step (`exact_replay_round_trip`); the whole-run ghost car (`exact_replay_ghost`); the disc's demos through their race records (`exact_demo_records`) | | `tools/gt3tool/cmd_race.cpp` | Diagnostics: `race-texlod`, `race-blend`, `race-sheen`, `race-carprims` | ## Race screen code map The screen is one class, `RaceScreen`, declared in the private header `src/app/screen_race_impl.h` and defined over several files next to the other screens in `src/app/` (a `screen_race_` prefix rather than a subdirectory: the app sources are the flat `src/app/*.cpp` glob, and `src/race/` is already the engine side). The header lists the methods grouped by the file that defines them, then the state. | File | What lives there | |---|---| | `screen_race.h` | Public: `make_menu_race_screen()` (`make_online_race_screen()` is declared in `screen_online.h`) | | `screen_race_impl.h` | Private: `RaceScreen`, `DebugPreset` (GT3R_RACE), `MenuLaunch`, small helpers (`BrakeLamps`, `Perf`, `menu_keys`) | | `screen_race.cpp` | Core: constructors (menu / online / `--screen race`), `update` / `render` dispatch, `init` / `begin` and the loading picture (`render_loading`), the menu request handler, `make_*_race_screen`, the screen registration | | `screen_race_launch.cpp` | GT3R_RACE parsing (`read_preset`), menu requests → course / car / event / options (`resolve_launch`), online launches (`resolve_online`) | | `screen_race_setup.cpp` | Loading and (re)starting a run: `start`, `build_vehicle` (the run's `RaceField` on the exact core; a race that cannot be set up becomes the error page), `restart` / `reset_run_state`, warp, TV cameras, LOAD GHOST | | `screen_race_drive.cpp` | The race loop: `update_drive` (one frame) and `tick` (one race step), the race's AI taking the player's car (autopilot) and scripted inputs, finish detection, gear hint, dirt, pylons, tyre smoke, force feedback | | `screen_race_render.cpp` | `render_drive`: 3D views (1P, 2P split, 4:3 frame), draw items, reflections, mirrors, sun / lamps, `hud_data`, the results / licence / time-trial overlays | | `screen_race_audio.cpp` | Music cues, the song controls (`song_controls`, `skip_song`), course ambience listeners, extra car sound inputs, `silence` | | `screen_race_select.cpp` | The standalone selection page: course / car picker and saved-replay list | | `screen_race_quick_menu.cpp` | Pre-race and result quick menus (layout per mode, item actions, disabled items), free run before a GT race, the run's records and Top 3 (`record_run`, `fill_top3`), options / settings / records panels | | `screen_race_pause.cpp` | The pause window (GT3's PauseMenu, REPLAY OPTIONS, our longer list), the song under it (`draw_song`, L1 / R1) | | `screen_race_results.cpp` | Result rows, the result latched and posted to the menus, `leave`, race display strings | | `screen_race_replay.cpp` | Recording / playback glue, replay view modes and REPLAY OPTIONS, the replay pad and the followed car, the camera manager's 60 Hz frames (music cut requests, view mode 1's handler), the dissolve and the post pass's grade | | `screen_race_post_run.cpp` | After a run: the exit transition, prize / trophy and name entry, the automatic replay, back to the quick menu, its backdrop (play mode 2), pause EXIT (`run_kind`, `after_run`, `return_to_menu`) | | `screen_race_analyzer.cpp` | The Analyzer: the quick menu's data logger and the theater's logger mode | | `screen_race_online.cpp` | Online battle glue (field from the grid, events, synchronised start, prediction, ghosting); its state is `RaceScreen::net_` | | `screen_race_license.cpp` | Licence tests (the race's judging, medals) and the disc's demonstration runs (DEMO, preview box) | | `screen_race_events.cpp` | The pop-ups in the middle of the screen: lap times, split times, gaps, "+N Laps", "Pitting in..." (`lap_events`, `reset_lap_events`) | | `screen_race_camera_editor.cpp` | The camera editor (Settings → Cameras, `app/camera_editor.h`): a race frozen 5 s past its start, drawn through the camera being edited; saving it (`make_camera_editor_screen`); the car and course of the last race for it (`remember_editor_scene`) | | `screen_race_vr.cpp` | VR builds only: the stereo race (`vr_stereo`, `vr_base`, `render_vr_eyes`); see [VR](VR.md) | ## Loop ``` update(dt): FixedStep::advance(dt) -> n ticks of 1/60 s (sim::kDefaultTickHz), at most 8 per frame (online: FixedStep::follow, by the clock since the synchronised start) per tick: prev = state; inputs = ControlMapper(pad) (the race reads the pad itself) field.step(inputs, 1/60) (race::ExactField: one step of GT3's race on the exact core) lap timer, rumble render_state = interpolate(prev, state, FixedStep::alpha()) (the wheels turn by the tick's own turn, WheelState::spin_step: their spin angles wrap) camera, engine audio and rumble use render_state render: View3D::draw(course items + car items) with frustum culling, GT3's far plane, sorted blending, fog HUD over it ``` A race that cannot be set up (the disc's program unreadable, a course or car the race step cannot run) shows "The race cannot start." with the reason; any button (Cross, Circle, Triangle, Start) goes back to the menu. On the standalone selection page the reason shows under the lists instead. ## Controls | Pad | Action | |---|---| | Cross (pressure) | throttle | | Square (pressure) | brake | | Circle | handbrake | | Left stick X / d-pad | steer (d-pad ramps at 2.8 lock/s, returns at 5/s) | | R2 / L2 | shift up / down (manual gearbox; toggle AT/MT with Square on the selection screen or in the pause menu) | | R1 | change view (in-car, in-car without the mirror, chase, far chase; see "Cameras") | | L1 (held) | look back | | Triangle (pressure) | reverse | | Select | no race action (no respawn, as in GT3); in time trials, free runs, machine tests and licence tests the controller's own Select (the menu pad's) shows / hides the ghost | | Start | GT3's pause window (see "Pause"); Select there opens our list: Resume, Restart, Watch replay, Save replay, Camera, Gearbox, Exit | | R3 | performance overlay | | Right stick, L2/R2, mouse | free-orbit camera | Stick: 6 % deadzone, response curve `x^1.25` (fine control near the centre). Pedals: 8/255 bottom deadzone. Buttons held without a pressure report give full travel (keyboards). Rumble (`race::RumbleModel`, `InputManager::set_rumble`): each step computes two outputs and each player's Rumble setting picks one (`InputManager::gt3_rumble`: `[playerN] rumble`; `auto`, the default, is Modern; `race_rumble_mode`). GT3 original (physics §1.2), as GT3 drives a DualShock 2: each race step's vibration level (`VehicleTelemetry::pad_rumble`, 0-127, set in phase 12 from the front tires' drive and brake forces, the dampers and curbs under the front wheels, and a hit's rumble) goes to the large motor as it is, so at most about half strength; the small motor never runs. Modern (ours) runs both motors for everything with a lean (`RumbleModel::rumble`): the body level on the large (low-frequency, left) motor and the tyre level on the small (high-frequency, right) one, each motor also playing 0.35 of the other's level, or 0.7 on a DualSense (`InputManager::dualsense`), whose motors play in separate grips where a split reads as a side; elsewhere the large motor shakes the whole pad. A DualSense also plays its small motor (the right grip) much lighter than the large one, so `set_rumble` sends it 1.75 times stronger (`dualsense_rumble`), whatever the rumble. The body: a wall or car hit (`RaceVehicle::last_impact`, the stronger impulse over the car's mass, over 1.5 m/s) holds speed change / 8 m/s for 0.25 s; off-road (`RaceTrack::is_offroad` under the car, above 3 m/s) 0.18 plus the speed / 150 m/s (up to 0.2 more). The tyres: wheelspin under throttle up to 0.4, a slide (the strongest grounded wheel's slip intensity, physics §8.3, from 0.35 to 1.25) up to 0.4 and locked wheels under braking up to 0.35; a wheel on a curb (`RaceTrack::is_kerb`) pulses 0.63 at 4 Hz plus 0.4 Hz per m/s. Either way a car the pad does not drive (an AI run-up, after the finish; `VehicleTelemetry::pad_output` clear) sends nothing, and its motors stop. Replays and demonstrations send nothing, and the Vibration option (`vib1`, the quick menu's OPTIONS) turns it off. The triggers (ours, `ForceFeedback::apply` from `RaceScreen::feedback`): the brake's follows GT3's ABS at work (`VehicleTelemetry::abs_level`, from `exact_telemetry`: the slip over the tyre's best braking slip times G g, the share of pressure the ABS takes off), the throttle's the edge of grip (`VehicleTelemetry::traction_level`, from `exact_telemetry`: the slip and the slip-angle force as shares of the tyre's best, see docs/INPUT.md), neither while the computer drives; Xbox impulse triggers as levels, a DualSense's as adaptive-trigger vibrations (`ffb::brake_trigger_effect`, `throttle_trigger_effect`), as SDL's trigger rumble does nothing there. ## Rendering - Course: slot 1 scenery (one mesh per GTM1 node; the slot 27 licence course line as its own item, below) with frustum and distance culling (2.5 km), backdrop (slot 22, never distance-culled), sky dome (slot 21 only, as the original's main view; slot 24, a low-resolution dome, is the rear-view mirror's) drawn first as camera-centred background without depth writes. The frame is cleared to black like the original. Scenery packets take the node programs' GS state (`gtm1::Options::gs_state`): depth write (ZMSK), culling, alpha test reference and AFAIL (foliage). See docs/formats/course.md. - Car: `cars/day/` (eve / night models on dusk and night courses, see "Car lamps") with all LODs; body LOD by camera distance (< 30 m, < 80 m, beyond; `race::car_lod`), or LOD 0 at any distance with `[video] full_car_detail = on` (Settings → Display → Always show full car detail; the default except on phones and tablets). LOD 0's wheels are the menus' with `[video] showroom_wheels = on` (Settings → Display → Showroom wheels in races; the default except on phones and tablets): the `menu/cars/` rim and tyre, a fitted wheel's `menu/wheel/