Docs / The project / Architecture
Known debt
-
What is already in place. The frame is a declared list of stages run by one runner (
omsi-app/src/frame_stages.rs:app_events::WINDOW_FRAMEfor the window,offscreen::OFFSCREEN_STEPfor the offscreen run, each stage naming the field groups it reads and writes and the values it hands on; tests pin both orders and the three places where the two paths knowingly differ;OMSI_FRAME_ORDER=1logs them);the AI traffic and the people simulate in
omsi-sim, withomsi-app::traffic::Trafficandomsi-app::humans::Humansas thin wrappers (the simulation, with the cars' sounds) that dereference to them; everyOMSI_*switch goes throughomsi_cfg::flags(docs/DEBUG_FLAGS.md);App's state is grouped by subsystem (omsi-app/src/app/groups.rs). -
The stages' declarations are checked.
App::parts(omsi-app/src/app/parts.rs) takesAppapart into one borrow perGroup, naming every field ofAppand ofSessionState(a new field does not build until it has its group).A stage handed a context made by
stage_ctx!(placement, streaming, traffic, view_keys, humans, after_humans, on_foot, player_tick, scripted, lights, wheel_surface, audio, photo, lighting, trace_look) can touch its groups only, and its declaration is that context'sREADS/WRITES, so the compiler holds it to it.A helper such a stage shares with the rest of the game takes a narrower context of its own (
shift_clockaShiftClockCx), which the stage takes out of its own withnarrow!and anAppmethod withXCx::of.The other window stages still take the whole
App: they callAppmethods of many groups, and several write whatCommonlends read-only (the controllers, duty and weather stages the command line'sArgs, the view camera the seat inSettings).For them
frame_stages/access_tests.rsreads the crate's source (omsi-srcscan) and fails when a stage reaches, throughAppmethods and the functions handed theApp, a field of a group it does not declare.What the declarations show: the stages that take the whole
Appreach most of the sixteen groups each, so no two of them are independent, and the converted ones are a fraction of a millisecond: no stage runs in parallel (a stage becomes a candidate once its context is narrow and it costs enough).OMSI_PROFILE's keys are
profile_keys::ProfKey, a slot of an array each (the names in the logs and in OMSI_PROFILE_JSON are unchanged). -
The timetable is
omsi-sim::timetable_run: the trip times, the IBIS, the player's duty, andScheduleSim(timetable_run/sim/) - the day's departures and which are due, queued, waiting for their tiles or awaiting their tour's bus, the tours' vehicles (choose), the routes on the lanes and where on its route a due bus is (place_departure), the routes carried on as tiles load, the tours, the duty taken from one and the departure boards.It reads the map through
TimetableWorld(the world snapshotomsi_sim::world_data::WorldDataimplements it) and the traffic asTrafficSim.omsi-app::schedule::Scheduleholds it (DereftoScheduleSim) as the GPU adapter:fleetreads and uploads the vehicle sets of the next departures,dispatchandspawnput the buses on the road (Traffic::spawn_bus,set_trailers,attach_cars,turn_train), hand a tour's bus its next trip, and take buses off, each tellingScheduleSimwhat became of the departure.Still in the adapter: the bus put on the road itself (its trailers and cars, where it starts, whether it may appear there), which needs the app's
Traffic(trailer_chain,may_appear,blocked) besides the GPU. -
The map world the simulation reads is
omsi-sim::world_data:WorldData, an immutable snapshot of Arc'd parts - the loaded tiles' ground (GroundTiles: terrain and road faces, with the wheel, walking, camera and drawn-ground questions), the lists made from the tiles (TileLists: stops, waiting places, obstacles, parked cars' boxes, petrol stations, echoing places), where the map's objects stand (ObjectPlaces), the map index's stop facts and the map's own facts (MapFacts: the only copy of the AI lists, the date and the chrono folders).omsi-scene::Worldholds it in aWorldCell(arc-swap) and publishes a new one where a tile's ground comes or goes and where the tile lists are rebuilt; readers take it without a lock (peekfor one look,snapshotfor a step), the vehicles' wheels throughLiveGround. It implementspeople::WorldandTimetableWorld.What loading hands the simulation goes through
omsi-sim::handover::Inbox(pushed by the loader's threads, taken whole at the start of a step): the traffic'sTrafficArrivals - the crossings' light programs as they are numbered, a tile's lanes and parked cars.Still in
Worldand locked: the GPU side, the type and file caches of loading, the light programs' numbering by owner object, the scripted objects' view halves and the lamps. -
LAN play (
omsi-lan): the session as the game plays it isomsi_lan::gameand runs on values - aLanConfigthe game fills from its arguments (and takes back where a joining player adopted the host's map, date, time and weather), aLanInputeach frame, our bus as aVehicleInstance- and asks the rest of the game throughLanHost(the world asWorldData, its lanes, another player's vehicle made as the game makes its vehicles, destination displays).A frame is
tick_send, the shared world,tick_receive, thenview_sync::apply_landraws and sounds the others fromLanGame::drawn. The app's side isomsi-app/src/lan_play.rs(name tags, the HUD's line,AppLanHost).Still the app's: the shared world's mirror (
omsi-app/src/lan_world.rs), which drivesTrafficfrom the traffic table (omsi-net::traffic_table, seedocs/TRAFFIC_TABLE.md),Humansand their view directly; it goes to omsi-lan once it is simulation state plus events for the view, as the other players' vehicles are. -
The view sync phase (
omsi-app/src/view_sync/): the code that turns the traffic's and the people's state into renderer instances is in one module -traffic.rs(the AI vehicles' renders, their drivers, the traffic lamps),people.rs(the people's meshes, posing and skinning, the coins and ticket blocks) - with one entry point,view_sync::sync(ViewSync { traffic, people }, sim_view, world, renderer, scene), traffic first.Its state,
view_sync::SimView { traffic: TrafficView, people: PeopleView }(the cars' renders and drivers; the people's meshes, GPU materials, posing and ticket blocks), is held apart from the simulation: by the window inGfxState::sim_view, by the offscreen run in its own struct.Each part starts afresh with the simulation it shows (the
Trafficput in place,Humans::new). It runs where each part was synced before, so that the renderer sees the same calls in the same order:- the window: the traffic at the end of
frame_traffic(after its step and sound, before the player and the people move: the cars that parked leave the traffic's list there, and the people's step reads it), the people at the end offrame_people(after their step and the coins handed out); - the offscreen run: the traffic after each population (and before an
OMSI_POPULATION_SHOTSpicture), the people every step whileOMSI_TRACE_PAXtraces, both before each snapshot (the traffic, the player's pose, then the people from the snapshot's camera) and in the closing reports.
The simulation's calls hand the view data, never renderer calls: what they did that the renders have to follow - a car put on the road with its coupled parts or taken off (now, or at the next sync for the step's retired and parked cars), parts coupled or let go, a train made anew under its id, a parked car driving off or one parking - is written down as
omsi_sim::view_events::TrafficEvents (Traffic::events), somebody appearing, going or renamed and coins on the desk asomsi_sim::people::BodyOps (PeopleSim::bodies).view_sync::apply_trafficandapply_peoplereplay them in order, called right after each call that can make them (population, the timetable's tick - before its vehicle sets go up and at its end -, the LAN mirror, admin and plugin removals, the clock's restart, the people's step, the avatar), where those calls made the renderer calls before: the renderer sees the same calls in the same order (OMSI_SCENE_DIGESTchecks it on an offscreen run).None of those calls takes a renderer, a scene or a part of the view;
Traffic::tickisTrafficSim::advanceplusTraffic::after_step(the step's retired cars to events), so the step can run on another thread.The people hold no renderer handles (
PeopleView::meshes, by person id); the parked cars' world side (World::take_departing_parked,take_returning_parked) is apart from their renderer side (show_parked_instances).The AI cars are drawn from an owned
FrameSnapshot(omsi_sim::view_events: every car's parts, their meshes' transforms, visibility and per-slot values in flat buffers kept from frame to frame), taken at the sync, with their looks (TrafficSim::snapshot_looks,CarLooks: a copy of the variables for the switched materials, the string variables as they change, the interior lamps, the text, script and HTML pictures to upload, cracks, dents and reshaped bellows - the simulation's side of drawing a car is done there) and the timetable buses as their drivers read them (snapshot_drivers,DriverFrame; the figures read a bus throughomsi_scene::driver::DriverCar).The AI cars' sounds play from a
SoundFrame(TrafficSim::snapshot_sounds), the people are posed from aPeopleFrame(PeopleSim::snapshot_into; the pose as drawn is the view's,PeopleView).Still read from the simulation's state while syncing (the sync is therefore a point where the simulation stands still): the snapshots are taken there, not at the end of a step; the traffic's lamps (their scripts run there: the scenery state's
LampScripts, by key);the player's vehicle (materials, lamps, textures, bellows, damage:
view_sync/vehicle.rsreads it in place throughLookVars), the bus the player rides in on foot (its sound); the people's coins and ticket blocks; the sync also hands the AI vehiclesEnvir_Brightnessand swaps their poses between the traffic's last two steps. - the window: the traffic at the end of
-
Global mutable state. The introduction's "no global mutable state" is still not quite true, but what is left no longer carries a session's state into the next one.
The game state that lived in statics (a second drive started from the phone's launcher runs in the same process, and the window, the offscreen run and the launcher's showroom share it) moved into its owners: the physical weather model and the classic sky's cloud type into
weather_setup::SkyState(kept by the session, the offscreen run and the showroom), the duty start's opened world and the real-time start intoArgs, the map lights near the camera, the fading spotlight cookies, the spline-check ends and the season-mix counts intoWorld, the passengers' waiting voice lines, the photo mode's settings and the settings window's flags intoApp's groups, the/adminpassword intoLanGame, the drive's extremes intoOffscreen, and which corona pictures a renderer holds into theRenderer(pictures_taken).Left: in
omsi-app20 module-level statics with interior mutability, 35 more inside functions andthread_local!blocks (9 of those); inomsi-scene14 and 15, nothread_local!(count them withgrep -rnE '^\s*(pub(\([a-z:]+\))? )?static ' crates/omsi-app/src | grep -E 'Mutex|Atomic|OnceLock|RwLock|Cell|Lazy|Once\b'andgrep -rn 'thread_local!').They are install-once hooks, platform handles and process resources (the signal handler, the tilt sensor, the translation worker, thread pools, the LAN gateway and mods root), memos of file contents and environment switches, rate limits of log lines and refreshes, the picture-file numbering that is the same for every renderer.
The settings and the session's weather that were broadcast to loading code through statics are passed down now: the session's look and switches in
Args::session_settings(startup::SessionSettings: Enhanced+, Enhanced, Vanilla, clouds), carried on to theSkyState, the tyres' spray (scene::host::GraphicsKind) and the renderer's options;what the world's loading and sounds read (the scenery's volume, the mirrors' size, the rain's quality, the weather's snow) in each
World(World::settings, ascene::host::SceneSettings); the traffic's volume, the rain's quality and the lamps' cone weather (lights::ConeWeather) as arguments of the calls that use them. -
Very long functions and files.
scripts/size-budget.sh(run on every pull request) keeps them from growing;scripts/size-budget.txtlists those over the limits (1500 lines a file, 300 a function) with their recorded sizes. The baseline only goes down.
Something wrong or missing? Fix it on GitHub or open an issue.