Broadphase2DPlugin

View source

ExtendsPlugin

Installs 2D broadphase resources and candidate generation in an App.

The plugin makes the configured Broadphasable2D implementation available through Broadphase2D and provides CollisionPairs for the current broadphase candidates. Entities with PhysicsHitbox components are indexed, and overlapping hitboxes are reported as potential collision pairs. The pairs are candidates for downstream collision processing, not confirmed collisions.

The app must also register CorePlugin, ReflectPlugin, and MathPlugin. The plugin reports these dependencies through Broadphase2DPlugin#requires; it does not install them automatically.

Examples

import { App } from '@wimaengine/app'
import { Broadphase2DPlugin, NaiveBroadphase2D } from '@wimaengine/broadphase'
import { CorePlugin } from '@wimaengine/core'
import { MathPlugin } from '@wimaengine/math'
import { ReflectPlugin } from '@wimaengine/reflect'

new App()
  .registerPlugin(new ReflectPlugin())
  .registerPlugin(new CorePlugin())
  .registerPlugin(new MathPlugin())
  .registerPlugin(new Broadphase2DPlugin({
    broadphase: new NaiveBroadphase2D()
  }))
  .run()

Constructor


constructor(options: Broadphase2DPluginOptions)

View source

Creates a broadphase plugin using the supplied indexing implementation.

Parameters

NameDescriptionDefault
options

Plugin configuration.

—

Properties


Methods


register(app: App): void

View source

Makes the broadphase resources available and prepares candidate-pair updates.

The app receives a Broadphase2D resource backed by the configured implementation and a fresh CollisionPairs resource. Each update refreshes the broadphase from entities with PhysicsHitbox and rebuilds the pair list from overlapping hitboxes. Pairs are potential collisions, not confirmed narrowphase results.

Parameters

NameDescriptionDefault
app

App to configure.

—