Factorio Under the Hood: Deterministic Sim, Transport Lines & UPS Tricks

Factorio Under the Hood: Deterministic Sim, Transport Lines & UPS Tricks

Engine & Tech Stack

  • Engine / language: a custom C++ engine; Lua drives both the data/prototype stage and runtime mod scripting.
  • Map representation: a tile grid partitioned into 32×32 chunks; entities live on the grid and are tracked in per-system update lists.
  • Determinism: the simulation is fully deterministic, enabling lock-step multiplayer where only player inputs are sent over the network.

Core AI & Decision Making

  • Enemies (biters): pollution spreads per-chunk and raises aggression; enemies form unit groups that move and attack together.
  • Dispatch: attack targets and routes come from the pathfinder; groups gather, then path toward the nearest polluting structures.

State Management & Data Architecture

  • Model: custom C++ entities updated from active update lists; entities with nothing to do are removed from those lists ("sleeping") so idle factories cost almost nothing.
  • Transport lines: contiguous belt segments are merged into a single transport line with a compact item representation: items aren't simulated as individual objects, which is the core belt-throughput optimization.
  • Persistence: the entire deterministic world state is serialized to the save.

Tick Scheduling & Performance Tricks

  • Fixed 60 UPS: the simulation runs at a constant 60 updates/second, fully decoupled from render FPS.
  • Multithreading: later versions parallelize belt, fluid, electric-network and entity-preparation work across cores; the electric network and heat/fluid systems update on their own schedules.

Pathfinding & Spatial Systems

  • Algorithm: A* over the collision grid with an abstract, cached base-to-base pathfinder to keep long enemy paths cheap.
  • Spatial partitioning: chunk-based iteration and path caching bound the search space as the factory sprawls.

Follow us on social media for updates