Physics · class
IslandSet
Connected components of the contact graph, and the sleeping that rides on them.
Explained in Your first game, Rigid bodies.
class IslandSetimport { 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)| Parameter | Type | Description |
|---|---|---|
capacity? | number |
Properties
| Name | Type | Description |
|---|---|---|
count | number | How many islands the last build found. |
constraintOrder | Int32Array | Constraint indices grouped by island. |
constraintStart | Int32Array | Offsets into constraintOrder, length count + 1. |
bodyOrder | Int32Array | Dynamic body indices grouped by island. |
bodyStart | Int32Array | Offsets into bodyOrder, length count + 1. |
islandOf | Int32Array | Which island a body is in, or −1 for a body that is not dynamic. |
jointOrder | Int32Array | Joint indices grouped by island. |
jointStart | Int32Array | Offsets into jointOrder, length count + 1. |
Methods
build
build(bodies: BodySet, c: ContactConstraints, joints: JointSet): number| Parameter | Type | Description |
|---|---|---|
bodies | BodySet | |
c | ContactConstraints | |
joints | JointSet |