Skip to content

Collision

Kevin Bonnoron edited this page Nov 21, 2026 · 1 revision

Collision (idcoli)

How the game detects what touches what: the idcoli library (broad-phase tree, object kinds, queries, character movement) and the framework layer that wraps it (fw::ColiManager, fw::ColiObject, contact events). Files: src/libs/idcoli/source/ (I/), include/idcoli/idcoli.h (H), src/application/BF2/framework/coli/ (C/). Reading guide: Home. Snapshot: main at commit a313ecb66. Roles from unknownXX members and constants like COLI_TBL_GRID are inferred where marked.

Coverage. 407 of 461 idcoli functions are matched, and the framework layer is matched except four functions. The not-yet-decompiled ones are mostly the deep shape-versus-shape tests and the character movement core (listed at the end).

Library layers

IDColiManager (I/idcoli_manager.cpp) owns everything. Below it:

  • a spatial grid, IDColiTreeTop;
  • collision objects, IDColiObj subclasses;
  • query front-ends: IDColiDef, IDColiPhantom, IDColiCheckObj;
  • a character mover, IDColiMove;
  • static ground meshes: IDColiGrandObj, IDColiGrandTree, IDColiGrandMesh.

Object kinds (IDColiObj::unknown24, inferred names): 1 character (moving bodies; IDColiObjChar), 2 phantom (trigger volumes; IDColiObjPhantom), 3 grand (static ground and world mesh; IDColiObjGrand), and a fourth, ground character (IDColiObjGrdChar: ground collision attached to a character, for example a moving platform). createColiGrand, createColiCharacter, createColiPhantom and createColiGrdChar put new objects in a pending list indexed 0 to 3 (grand, character, phantom, ground character).

Shapes. Sphere, box, capsule, a "character" shape (capsule-like), a rotated box and a rotated capsule, plus polygon meshes for grands. A character shape with a degenerate length (at most 0.01) collapses to a sphere, and so does a bone capsule whose squared axis length is below 0.001. Characters can also be built from a binary description (a bone table plus primitives, with separate check lists for three check types).

Broad phase

  • Two IDColiTreeTops, one for characters and one for phantoms. Default bounds are ±64 on every axis, then re-set each frame from the registered objects' bounds.
  • 5 quadtree levels (0 to 4), the cell size halving each level, giving 341 cell lists (1 + 4 + 16 + 64 + 256). The grid tables (COLI_TBL_GRID, COLI_TBL_INDEX) are not defined in the source, so the 1, 2, 4, 8, 16 grids are inferred from the count and the level scaling. A cell is initialised lazily and widened by a 20% margin. An object goes into the deepest level whose cell fully contains it, and levels where the cell size is 1 or less are disabled.
  • A sweep-and-prune pass on 2 axes follows, up to 4 iterations per list per frame (IDColiTreeTop::updateTree, initCehckTree, setupTreeList; IDColiManager::updateConsistentList).

Frame flow

IDColiManager::update runs addDelUpdate (not decompiled), then update() on all 4 lists. consistentUpdate rebuilds the trees from lists 1 and 2 (characters and phantoms). tail() flips a double-buffered index (s_nDebIdx, s_nStkIdx): creation and deletion are double-buffered so that deleting during an update is safe.

Memory. The manager creates its own pool named Collision (0x80000 = 512 KB, passed in by the framework) and a 0x400-byte table of global ids (8192 bits). The global-id table switches grand-mesh parts on and off (isGblId, setGblId).

Queries

IDColiDef, IDColiPhantom and IDColiCheckObj answer: line, ray (length plus back length), sphere, capsule, and AABB (the AABB test can also gather polygon AABBs). Flags select which object classes to test (characters, ground, ground characters). A result keeps up to a caller-chosen number of hits (position and normal arrays), filtered by material bits (hit-material mask against material bit).

Character movement (IDColiMove)

I/idcoli_move.cpp.

  • A capsule or sphere sweep. Defaults: radius 1.0, height 2.0, slope angle 45°, floor tolerance 0.4, down tolerance 0.05. The move is subdivided into length / radius steps, with up to 32 hits per query.
  • Angle constants: s_fBaseWallDot = 0.17364822 (cos 80°: a surface steeper than this counts as a wall), s_fLandingAngle = 0.49999997 (cos 60°: landing), s_fLandingVecChk = -0.8660254 (cos 150°).
  • Results include the moved distance and flags for wall hit, ground hit, landing, ceiling hit and "stuck in wall". An optional "accuracy" mode slows the move against the previous direction.
  • The engine wrapper fw::ColiCharactorProxy::integrate just calls IDColiMove with floor tolerance 0.4 and accuracy on.
  • Not decompiled: moveDataColi (0x71008cc24c, 2,840 bytes), moveDefColi (1,768), calcColiBaseParms (2,048), testWallObject, testVecYObject, testVecYCheck.

The framework layer (fw::ColiManager)

  • It owns the IDColiManager, an intrusive list of fw::ColiObjects, a handle PointerMap (handles up to 0x7fffffff, tagged with bit 31) and a contact table of up to 512 character objects, each with a list reserved for 8 contacts. framework.cpp creates it with capacity 0x1000 (see Engine-Overview).
  • fw::ColiObject has three types (createColiCharacter, createColiPhantom, createColiGrand). Characters and phantoms have a shape (sphere, capsule, box, character, from-binary), a priority, state bits, hit-material and material masks, a scale, an offset matrix, user data and an optional IColiEventListener.
  • Per frame ColiManager::Impl::update runs IDColiManager::update, increments a frame counter, then updateContact: for each character object that is not merely referenced by the manager, it runs ColiCheck::testObjectChara and testObjectPhantom (up to 256 hits, tolerance 0.1) and builds enter, contact and leave records. Contact flags are 5 bits (enter, contact, leave, contacted, entered). sendContactEvent calls enter, contact and leave on the object and, unless the other object is a character, on the other object too; contacts whose other object no longer exists are dropped. The attribute mask for contacts is all bits except bit 20. postUpdate releases objects whose only reference is the manager, then runs consistentUpdate. This is the mechanism behind phantom volumes such as the gimmick triggers of Field-Gimmicks.
  • Checks. fw::ColiCheck::testLine/Ray/Sphere/Capsule/Object (each with Chara, Phantom and Coli variants) drive the library queries with a ColiCheckConfig (flags 0, 1, 2, 3 pick character, ground, phantom, ground character; result type 0, 1 or 2). Type-2 results fill position and normal arrays of 256 entries and drop hits past 256.
  • Not decompiled: ColiManager::Impl::makeContactList (0x710015ae34, 952 bytes), addContactList, ColiCheck::getSnapPos, ColiCheckCallback::coli_param_callback.

Not decompiled yet (notable)

IDColiManager::addDelUpdate (808 bytes), delList, IDColiTreeTop::end (500), IDColiDef::testCharColiObj (4,028), IDColiPhantom::testCharColiObj (2,048), IDColiObjData::calcNodeMatrix (3,628), the IDColiGrandMesh mesh tests (meshCapsule 2,384 bytes, meshSphere 1,696, meshLine, meshAaBb, meshOBB), the IDColiUtilColiResult shape tests and IDColiUtilMath::getNearLineToLine / isTriangleBoxHitCheck (2,240).

See also

Engine-Overview, Field-Gimmicks

Clone this wiki locally