# AREA_DEPTH
const AREA_DEPTH = 4WinQuake's AREA_DEPTH=4 tree contains at most 31 nodes. Edicts are linked into exactly one solid or trigger list at the deepest node that fully contains their expanded bounds.
src/miniquake/server_collision.mlminiquake/constants.ml as c → src/miniquake/constants.mlminiquake/mathlib.ml as math → src/miniquake/mathlib.mlminiquake/native.ml as native → src/miniquake/native.mlminiquake/quakec/vm.ml as vm → src/miniquake/quakec/vm.mlminiquake/types.ml as t → src/miniquake/types.mlminiquake/world_bsp.ml as world → src/miniquake/world_bsp.mlminiquake/world_hull.ml as boxhull → src/miniquake/world_hull.mlconst AREA_DEPTH = 4WinQuake's AREA_DEPTH=4 tree contains at most 31 nodes. Edicts are linked into exactly one solid or trigger list at the deepest node that fully contains their expanded bounds.
const AREA_NODE_CAPACITY = 31Defines the area node capacity value used by `miniquake.server_collision`.
areaEntityNextTracks the module-level area entity next state owned by `miniquake.server_collision`.
areaEntityNodeTracks the module-level area entity node state owned by `miniquake.server_collision`.
areaEntityPreviousTracks the module-level area entity previous state owned by `miniquake.server_collision`.
areaEntityTriggerTracks the module-level area entity trigger state owned by `miniquake.server_collision`.
areaMachineTracks the module-level area machine state owned by `miniquake.server_collision`.
areaNodeAxisTracks the module-level area node axis state owned by `miniquake.server_collision`.
areaNodeChild0Tracks the module-level area node child0 state owned by `miniquake.server_collision`.
areaNodeChild1Tracks the module-level area node child1 state owned by `miniquake.server_collision`.
areaNodeCountTracks the module-level area node count state owned by `miniquake.server_collision`.
areaNodeDistTracks the module-level area node dist state owned by `miniquake.server_collision`.
areaSolidHeadTracks the module-level area solid head state owned by `miniquake.server_collision`.
areaTriggerHeadTracks the module-level area trigger head state owned by `miniquake.server_collision`.
function boxesOverlap(minsA, maxsA, minsB, maxsB)Implements the `boxesOverlap` operation for `miniquake.server_collision` (boxes overlap).
| Parameter | Type | Default | Description |
|---|---|---|---|
minsA | dynamic | — | The mins a input consumed by `boxesOverlap`. |
maxsA | dynamic | — | The maxs a input consumed by `boxesOverlap`. |
minsB | dynamic | — | The mins b input consumed by `boxesOverlap`. |
maxsB | dynamic | — | The maxs b input consumed by `boxesOverlap`. |
function checkBottom(server, entityIndex)SV_CheckBottom: first accept the common case where all four lower corners are solid, then trace the midpoint and corners down by two step heights.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
function chooseTrace(best, candidate)Implements the `chooseTrace` operation for `miniquake.server_collision` (choose trace).
| Parameter | Type | Default | Description |
|---|---|---|---|
best | dynamic | — | The best input consumed by `chooseTrace`. |
candidate | dynamic | — | The candidate input consumed by `chooseTrace`. |
function clipAreaEntity(server, index, start, mins, maxs, finish, moveType, passedEntity, passedOwner, passedSizeX, boxMins, boxMaxs, best)Apply the stock SV_ClipToLinks filters to one broadphase candidate.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
index | dynamic | — | Zero-based index of the requested entry. |
start | dynamic | — | The start input consumed by `clipAreaEntity`. |
mins | dynamic | — | The mins input consumed by `clipAreaEntity`. |
maxs | dynamic | — | The maxs input consumed by `clipAreaEntity`. |
finish | dynamic | — | The finish input consumed by `clipAreaEntity`. |
moveType | dynamic | — | The move type input consumed by `clipAreaEntity`. |
passedEntity | dynamic | — | The passed entity input consumed by `clipAreaEntity`. |
passedOwner | dynamic | — | The passed owner input consumed by `clipAreaEntity`. |
passedSizeX | dynamic | — | The passed size x input consumed by `clipAreaEntity`. |
boxMins | dynamic | — | The box mins input consumed by `clipAreaEntity`. |
boxMaxs | dynamic | — | The box maxs input consumed by `clipAreaEntity`. |
best | dynamic | — | The best input consumed by `clipAreaEntity`. |
function clipAreaNode(server, node, start, mins, maxs, finish, moveType, passedEntity, passedOwner, passedSizeX, boxMins, boxMaxs, best)Recursively clip only the area nodes intersected by the swept move bounds.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
node | dynamic | — | The node input consumed by `clipAreaNode`. |
start | dynamic | — | The start input consumed by `clipAreaNode`. |
mins | dynamic | — | The mins input consumed by `clipAreaNode`. |
maxs | dynamic | — | The maxs input consumed by `clipAreaNode`. |
finish | dynamic | — | The finish input consumed by `clipAreaNode`. |
moveType | dynamic | — | The move type input consumed by `clipAreaNode`. |
passedEntity | dynamic | — | The passed entity input consumed by `clipAreaNode`. |
passedOwner | dynamic | — | The passed owner input consumed by `clipAreaNode`. |
passedSizeX | dynamic | — | The passed size x input consumed by `clipAreaNode`. |
boxMins | dynamic | — | The box mins input consumed by `clipAreaNode`. |
boxMaxs | dynamic | — | The box maxs input consumed by `clipAreaNode`. |
best | dynamic | — | The best input consumed by `clipAreaNode`. |
function clipToEntity(server, entityIndex, start, mins, maxs, finish)Trace to entity through the collision world.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
start | dynamic | — | The start input consumed by `clipToEntity`. |
mins | dynamic | — | The mins input consumed by `clipToEntity`. |
maxs | dynamic | — | The maxs input consumed by `clipToEntity`. |
finish | dynamic | — | The finish input consumed by `clipToEntity`. |
const COLLISION_OFFSET_CACHE_SIZE = 64The C engine resolves entvars_t members at compile time. MiniLang must look them up by name, but collision invokes the same small field set millions of times while monsters chase. Keep a module-local direct cache so those hot reads do not repeatedly enter the generic VM definition lookup machinery.
collisionOffsetKeysTracks the module-level collision offset keys state owned by `miniquake.server_collision`.
collisionOffsetMachineTracks the module-level collision offset machine state owned by `miniquake.server_collision`.
collisionOffsetValuesTracks the module-level collision offset values state owned by `miniquake.server_collision`.
function computedEntityBounds(server, entityIndex)Computes d entity bounds for `miniquake.server_collision`.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
function createAreaNode(depth, minX, minY, maxX, maxY)Recursively construct the same horizontal binary partition as SV_CreateAreaNode in world.c.
| Parameter | Type | Default | Description |
|---|---|---|---|
depth | dynamic | — | The depth input consumed by `createAreaNode`. |
minX | dynamic | — | The min x input consumed by `createAreaNode`. |
minY | dynamic | — | The min y input consumed by `createAreaNode`. |
maxX | dynamic | — | The max x input consumed by `createAreaNode`. |
maxY | dynamic | — | The max y input consumed by `createAreaNode`. |
function emptyPlane()Implements the `emptyPlane` operation for `miniquake.server_collision` (empty plane).
function ensureAreaTree(server)Initialize the area tree for a new QuakeC edict table and seed it from the currently linked bounds. Subsequent SV_LinkEdict calls maintain it in O(1).
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
function entityAbsMax(server, entityIndex)Implements the `entityAbsMax` operation for `miniquake.server_collision` (entity abs max).
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
function entityAbsMin(server, entityIndex)Implements the `entityAbsMin` operation for `miniquake.server_collision` (entity abs min).
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
function entityFloat(server, entityIndex, name, fallback)Implements the `entityFloat` operation for `miniquake.server_collision` (entity float).
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
name | dynamic | — | Stable name that identifies the requested object or option. |
fallback | dynamic | — | Value to use when the requested input is unavailable or invalid. |
function entityString(server, entityIndex, name, fallback)Implements the `entityString` operation for `miniquake.server_collision` (entity string).
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
name | dynamic | — | Stable name that identifies the requested object or option. |
fallback | dynamic | — | Value to use when the requested input is unavailable or invalid. |
function entityValid(server, entityIndex)Report whether entity valid holds for the active state.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
function entityVector(server, entityIndex, name, fallback)Implements the `entityVector` operation for `miniquake.server_collision` (entity vector).
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
name | dynamic | — | Stable name that identifies the requested object or option. |
fallback | dynamic | — | Value to use when the requested input is unavailable or invalid. |
function entityVectorZero(server, entityIndex, name)Read a generated QuakeC vector and allocate the zero fallback only for a genuinely missing field. Stock progs.dat contains all collision vectors; passing zeroVector() eagerly at every call site formerly created more than one million dead Vec3 values in a 300-frame e1m2 sample.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
name | dynamic | — | Stable name that identifies the requested object or option. |
function entityWord(server, entityIndex, name, fallback)Implements the `entityWord` operation for `miniquake.server_collision` (entity word).
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
name | dynamic | — | Stable name that identifies the requested object or option. |
fallback | dynamic | — | Value to use when the requested input is unavailable or invalid. |
function executeTouch(server, selfIndex, otherIndex)Execute touch.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
selfIndex | dynamic | — | Zero-based index of the requested entry. |
otherIndex | dynamic | — | Zero-based index of the requested entry. |
function fieldOffset(server, name)Implements the `fieldOffset` operation for `miniquake.server_collision` (field offset).
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
name | dynamic | — | Stable name that identifies the requested object or option. |
function impact(server, firstEntity, secondEntity)Implements the `impact` operation for `miniquake.server_collision` (impact).
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
firstEntity | dynamic | — | The first entity input consumed by `impact`. |
secondEntity | dynamic | — | The second entity input consumed by `impact`. |
function insertAreaEntity(entityIndex, bounds, solid)Insert one linked edict into its deepest non-splitting area node.
| Parameter | Type | Default | Description |
|---|---|---|---|
entityIndex | dynamic | — | Zero-based index of the requested entry. |
bounds | dynamic | — | The bounds input consumed by `insertAreaEntity`. |
solid | dynamic | — | Stable identifier of the requested entry. |
function linkedEntityBounds(server, entityIndex)Return the abs bounds maintained by SV_LinkEdict. Hand-built unit fixtures may omit the link step and leave both generated vectors zeroed, so retain a computed fallback for that non-production case.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
function linkEntity(server, entityIndex, touchTriggerLinks)Linear-scan equivalent of world.c SV_LinkEdict. Area nodes only optimize the candidate set; updated abs bounds, SOLID_NOT suppression and touch ordering are observable parts of the engine contract.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
touchTriggerLinks | dynamic | — | The touch trigger links input consumed by `linkEntity`. |
function modelSubIndex(name)Return model sub index derived from the active module state.
| Parameter | Type | Default | Description |
|---|---|---|---|
name | dynamic | — | Stable name that identifies the requested object or option. |
function move(server, start, mins, maxs, finish, moveType, passedEntity)SV_Move: clip first against the world, then every potentially intersecting solid edict. Area nodes are an optimization only; a linear scan has the same observable Quake semantics and is suitable for the stock MAX_EDICTS limit.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
start | dynamic | — | The start input consumed by `move`. |
mins | dynamic | — | The mins input consumed by `move`. |
maxs | dynamic | — | The maxs input consumed by `move`. |
finish | dynamic | — | The finish input consumed by `move`. |
moveType | dynamic | — | The move type input consumed by `move`. |
passedEntity | dynamic | — | The passed entity input consumed by `move`. |
function moveBounds(start, mins, maxs, finish)Transfer data for move bounds.
| Parameter | Type | Default | Description |
|---|---|---|---|
start | dynamic | — | The start input consumed by `moveBounds`. |
mins | dynamic | — | The mins input consumed by `moveBounds`. |
maxs | dynamic | — | The maxs input consumed by `moveBounds`. |
finish | dynamic | — | The finish input consumed by `moveBounds`. |
function pushEntity(server, entityIndex, push)Add state for push entity.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
push | dynamic | — | The push input consumed by `pushEntity`. |
function relinkAreaEntity(server, entityIndex, bounds, solid)Refresh an edict's area-list membership after its abs bounds change.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
bounds | dynamic | — | The bounds input consumed by `relinkAreaEntity`. |
solid | dynamic | — | Stable identifier of the requested entry. |
function setEntityFloat(server, entityIndex, name, value)Sets entity float for `miniquake.server_collision`.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
name | dynamic | — | Stable name that identifies the requested object or option. |
value | dynamic | — | Value consumed by `setEntityFloat`. |
function setEntityVector(server, entityIndex, name, value)Sets entity vector for `miniquake.server_collision`.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
name | dynamic | — | Stable name that identifies the requested object or option. |
value | dynamic | — | Value consumed by `setEntityVector`. |
function setEntityWord(server, entityIndex, name, value)Update module state for entity word.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
name | dynamic | — | Stable name that identifies the requested object or option. |
value | dynamic | — | Value consumed by `setEntityWord`. |
function testEntityPosition(server, entityIndex)Verify entity position against the expected Quake behavior.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
function touchAreaNode(server, node, entityIndex, absMin, absMax)Visit only trigger-area nodes intersected by one linked edict.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
node | dynamic | — | The node input consumed by `touchAreaNode`. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
absMin | dynamic | — | The abs min input consumed by `touchAreaNode`. |
absMax | dynamic | — | The abs max input consumed by `touchAreaNode`. |
function touchTriggers(server, entityIndex)Implements the `touchTriggers` operation for `miniquake.server_collision` (touch triggers).
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
function touchTriggersWithBounds(server, entityIndex, absMin, absMax)Implements the `touchTriggersWithBounds` operation for `miniquake.server_collision` (touch triggers with bounds).
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
absMin | dynamic | — | The abs min input consumed by `touchTriggersWithBounds`. |
absMax | dynamic | — | The abs max input consumed by `touchTriggersWithBounds`. |
function traceAgainstBox(server, entityIndex, start, mins, maxs, finish)Trace against box through the collision world.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
start | dynamic | — | The start input consumed by `traceAgainstBox`. |
mins | dynamic | — | The mins input consumed by `traceAgainstBox`. |
maxs | dynamic | — | The maxs input consumed by `traceAgainstBox`. |
finish | dynamic | — | The finish input consumed by `traceAgainstBox`. |
function traceAgainstBrush(server, entityIndex, start, mins, maxs, finish)Trace against brush through the collision world.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
start | dynamic | — | The start input consumed by `traceAgainstBrush`. |
mins | dynamic | — | The mins input consumed by `traceAgainstBrush`. |
maxs | dynamic | — | The maxs input consumed by `traceAgainstBrush`. |
finish | dynamic | — | The finish input consumed by `traceAgainstBrush`. |
function unlinkAreaEntity(entityIndex)Remove one edict from its current O(1) area-list position.
| Parameter | Type | Default | Description |
|---|---|---|---|
entityIndex | dynamic | — | Zero-based index of the requested entry. |
function updateEntityBounds(server, entityIndex)Update module state for entity bounds.
| Parameter | Type | Default | Description |
|---|---|---|---|
server | dynamic | — | Server state participating in the operation. |
entityIndex | dynamic | — | Zero-based index of the requested entry. |
function zeroVector()Implements the `zeroVector` operation for `miniquake.server_collision` (zero vector).