Physics · class

IslandSet

Connected components of the contact graph, and the sleeping that rides on them.

Explained in Your first game, Rigid bodies.

class IslandSet
import { IslandSet } from '@driftengine/physics';

In depth

Only dynamic bodies join islands. A static floor touches everything standing on it, so letting it merge would make one island of the whole world and nothing would ever sleep. That is not an optimisation: it is what an island means, and it is why two towers on one floor are two.

A body with no contacts is a singleton island, so every dynamic body belongs to exactly one and the executor can own the whole substep loop for it rather than integration being a separate global pass. That is the shape a worker pool needs.

Islands are ordered by their lowest body index, and bodies within one by index. That comes from the ascending scan below, which numbers an island the first time it meets a member — not from union-find's root choice, which is why swapping the root to the larger index changes no result and no test catches it. Keeping the smaller one is convention and shortens paths a little; nothing depends on it. Nothing here iterates a Map or a Set.

Constructor

new

constructor(capacity?: number)
ParameterTypeDescription
capacity?number

Properties

NameTypeDescription
countnumberHow many islands the last build found.
constraintOrderInt32ArrayConstraint indices grouped by island.
constraintStartInt32ArrayOffsets into constraintOrder, length count + 1.
bodyOrderInt32ArrayDynamic body indices grouped by island.
bodyStartInt32ArrayOffsets into bodyOrder, length count + 1.
islandOfInt32ArrayWhich island a body is in, or −1 for a body that is not dynamic.
jointOrderInt32ArrayJoint indices grouped by island.
jointStartInt32ArrayOffsets into jointOrder, length count + 1.

Methods

build

build(bodies: BodySet, c: ContactConstraints, joints: JointSet): number
ParameterTypeDescription
bodiesBodySet
cContactConstraints
jointsJointSet