openOMSI GitHub Discord
Architecture

Docs / The project / Architecture

Threads

2 min readEdit this pagedocs/ARCHITECTURE.md

Work Where it runs
Tile loading (.map parse, terrain, spline tessellation, object types) rayon pool; GPU upload on the main thread
Tile streaming (omsi_scene::tiles::Streamer) Its own thread: picks the tiles around the camera and the player's bus and stages them on rayon
Texture decoding and BC1/BC3 compression Worker threads through TextureCache
Timetable fleet vehicle sets (meshes, textures) Made on the GPU by the worker; the drawing thread only adds them to the scene
People's posing and skinning Parallel (par_iter_mut) over those due this frame
AI vehicle scripts Parallel, after the sequential lane and obstacle planning
Scenery object scripts Parallel (frame_each)
Publisher pack checks rayon, one asset per task, one 64 KiB chunk at a time (VerifiedPack::verify_all)
Culling, render bundles, command buffer finishing Parallel / helper threads
Enhanced sky A helper thread; taken in when ready
Audio mixing The audio device's callback; the cpal stream on the "audio device" thread
LAN socket Its own thread in omsi-net
Quitting on signals (omsi_platform::quit) Signal handler sets an atomic; a watcher thread wakes the event loop

Details worth knowing:

  • Streaming places and uploads only a little of one tile per frame, and unloads within the frame budget, so streaming never shows as a stutter.
  • Object and spline types are shared through Arc caches guarded by mutexes.
  • Lanes: a 50 m grid (Network::grid) answers nearest-lane queries without scanning the network.
  • Renderer updates: only the per-draw entries of instances that changed are rewritten (Scene::changed). A full rebuild happens only when instances are added or the render origin moves.
  • Audio: AudioEngine is Send + Sync. The game hands the mixer commands (play, parameters, stop, radio effects) through a lock-free single-producer ring (omsi_audio::spsc) and gets ended voices back through another. The callback takes no lock and allocates nothing. The internet radio's frames come through a ring too (stream::StreamBuf).
  • LAN: the game's side is its own stage in OMSI_PROFILE ("lan").

Scenery scripts#

The scripts and variables of the loaded tiles' scripted objects are one owned list in the simulation (omsi_sim::scenery::SceneryState, held by the session). Their view half (render instances, materials, texts, sounds) stays in World (omsi_scene::ScriptedSet) under the same key.

  • The tile loader hands over placed objects, removed tiles and particle emitter owners through a SceneryInbox. The list takes it at the start of its step.
  • Only objects near the camera's 50 m cell are candidates; the exact 800 m cut picks among them.
  • Scripts run side by side on inputs gathered before (light phases, boards, clock).
  • The step ends in commands in object order (SceneryCmd) that carry values. World::apply_scripted applies them without reading the simulation's list.

Something wrong or missing? Fix it on GitHub or open an issue.

↑↓ to move↵ to open