bf2-rs developer wiki
How the engine behind Battlefield 2, 2142 and Heroes works, how our Rust reimplementation is organised, and how to mod it: the Python game-script API, the CON object system, vehicles, weapons, levels and assets.
Where do you come from?#
I play
You came from the game's site and want to know what changed, or why something is not as you remember it.
- The port's status, in two minutes
- Today: Battlefield 2, 2142, Heroes
- What's new: the changelog, in a player's words
- Questions players ask about Heroes
- How to report a bug that gets fixed
- Feature checklists: what is checked, what is open
- Short answers
I host a server
You have a copy of a game and want a server of your own, for friends or for the public.
- Build and run a server and a client
- Start-up and the main loop: what the server reads and when
- Rounds, tickets, flags and game modes
- Bots
- The Python layer: scripts that change the rules
I want to read or change the code
You want to understand the engine, port a function, or mod the game.
- Your first hour: build, play, test, read one port
- How the codebase is organised
- How a port is made, from an address to a proof
- Parity: how much is proven, and what is still open
- The CON system, for modders
Build the server and the client and run them against your own install of a game.
every page of this area (11)Objects and templates, the frame, networking, the console, and how the crates fit together.
- Engine overview
- Objects and templates
- Client render pipeline
- Frame and tick order
- Physics
- Collision queries
Packets bit by bit, the three streams, ghosts, the control block and prediction, demos.
every page of this area (7)Engine, gearbox, wheels and springs with their formulas, and what float precision does to a lap.
- Engine, gearbox, wheels
- Float precision
- Boats and aircraft
- Seats and cameras
- Spawners and wrecks
- Every page of this area
The soldier on foot and his weapons: a tick of input, sprint, whole-tick timers, deviation.
- Input and sprint
- Stances and states
- Animation
- Kits and supplies
- Weapons: components and a shot
- Weapons: ticks and deviation
Sound templates, the gain over the distance, engine sounds, music and voice-over.
every page of this area (5)The Flash layer behind the menus: the player, the native API, text in the engine's fonts.
every page of this area (5)What a server decides: rounds, tickets, a control point's flag, spawning, the map list and votes.
- Rounds, tickets, flags
- Start-up and main loop
- Players and teams
- Kills and scoring
- Bots
- Squads and commander
Abilities, the three classes' values, the HUD variable by variable, the item bar's widgets.
every page of this area (63)The game-script layer: lifecycle, every host function, host.Object method and event per game.
every page of this area (14)The CON language, templates and components, and every property a .con or .tweak file can set.
every page of this area (114)The level folder: heightmaps, static objects, spawns, game modes, and the editor's format matrix.
every page of this area (5)Archives, meshes, textures, animations, sounds and Flash menus: the file formats and their readers.
every page of this area (13)What Battlefield 2, 2142 and Heroes share, and where each one differs.
every page of this area (10)The web modding editor: the engine in the page, the JS / wasm contract, the stages.
every page of this area (4)How the port is checked against the original programs: the parity count and its kinds of proof, the function oracle, the differentials, scenarios and sweeps.
every page of this area (7)How much of each game bf2-rs covers, checked function by function against the original programs.
What is bf2-rs?#
bf2-rs is a clean reimplementation, in Rust, of the engine the three games shipped with. It reads the games' own data (your install's archives and scripts), speaks their network protocol, and runs the same Python 2.3 game scripts through an embedded CPython. Behaviour is checked against the original programs function by function: the parity dashboard shows how much of each game is covered.
This wiki is written for two kinds of reader: modders who want to add a vehicle, change a weapon or script a game mode, and engine developers who want to understand a system before they touch the Rust. Every page cites where its facts come from (a file in the repository or an address in the original binaries), and the reference sections are generated from the code on every build, so they say what the engine really does today.
How this wiki is built#
The site is a single-page app generated by tools/devwiki/build.py from Markdown in docs/dev/ plus reference pages generated from the Rust sources (tools/devwiki/refs_*.py). Search is a prebuilt index, so it works offline and instantly: press / for the sidebar search or Ctrl K for the search dialog. The diagrams are drawn by a script (tools/devwiki/diagrams.py), and the pieces you can play with (a drivetrain bench, a packet explorer, a control point simulator, a 3D collision mesh viewer and more) are plain JavaScript of our own (tools/devwiki/theme/ix.js) that runs the port's formulas in the page. New here? Start here, or take your first hour as one guided path; the words are in the glossary. Pages marked in progress are being written right now; the wiki is updated as the project moves. Its colours come from web/tokens/bf2.css, the design tokens it shares with the web editor.
How it is tested#
This page explains; it holds no code of its own. The wiki's test checks that every link and anchor on it leads to a page of the build and that its diagrams are the ones the script draws. The interactive pieces are held twice: a test names the Rust statements each piece copies, so a change in the port fails the wiki's test, and a tour in a headless browser moves each piece's controls and reads its answers.
In the code#
This page names no crate of its own. How the codebase is organised maps the crates by area, and docs/release/LAYOUT.md in the tree has one line for every folder and crate.
docs/dev/index.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.