Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated body.preStep and body.postStep #133

Merged
merged 1 commit into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/callbacks.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
const planet = new CANNON.Body({ mass: 0 })
planet.addShape(planetShape)

moon.preStep = () => {
world.addEventListener('preStep', () => {
const moon_to_planet = new CANNON.Vec3()
moon.position.negate(moon_to_planet)

const distance = moon_to_planet.length()

moon_to_planet.normalize()
moon_to_planet.scale(1500 / Math.pow(distance, 2), moon.force)
}
})

world.addBody(moon)
world.addBody(planet)
Expand Down
14 changes: 0 additions & 14 deletions src/objects/Body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,6 @@ export class Body extends EventTarget {
*/
world: World | null

/**
* Callback function that is used BEFORE stepping the system. Use it to apply forces, for example. Inside the function, "this" will refer to this Body object. Deprecated - use World events instead.
* @deprecated Use World events instead
*/
preStep: (() => void) | null

/**
* Callback function that is used AFTER stepping the system. Inside the function, "this" will refer to this Body object. Deprecated - use World events instead.
* @deprecated Use World events instead
*/
postStep: (() => void) | null

vlambda: Vec3

/**
Expand Down Expand Up @@ -444,8 +432,6 @@ export class Body extends EventTarget {
this.id = Body.idCounter++
this.index = -1
this.world = null
this.preStep = null
this.postStep = null
this.vlambda = new Vec3()

this.collisionFilterGroup = typeof options.collisionFilterGroup === 'number' ? options.collisionFilterGroup : 1
Expand Down
17 changes: 0 additions & 17 deletions src/world/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,6 @@ export class World extends EventTarget {

this.dispatchEvent(World_step_preStepEvent)

// Invoke pre-step callbacks
for (i = 0; i !== N; i++) {
const bi = bodies[i]
if (bi.preStep) {
bi.preStep.call(bi)
}
}

// Leap frog
// vnew = v + h*f/m
// xnew = x + h*vnew
Expand All @@ -855,15 +847,6 @@ export class World extends EventTarget {

this.dispatchEvent(World_step_postStepEvent)

// Invoke post-step callbacks
for (i = 0; i !== N; i++) {
const bi = bodies[i]
const postStep = bi.postStep
if (postStep) {
postStep.call(bi)
}
}

// Sleeping update
let hasActiveBodies = true
if (this.allowSleep) {
Expand Down