Skip to content

Commit

Permalink
3.5.26
Browse files Browse the repository at this point in the history
  • Loading branch information
quinton-ashley committed Feb 13, 2023
1 parent 42815d1 commit a7aedbe
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 89 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ p5play is currently led by Quinton Ashley [@quinton-ashley][] and was initiated

## Support p5play

It took thousands of hours (not an exaggeration!) to upgrade and maintain this open source project. p5play will always be available for free, but your support would be greatly appreciated. If you use p5play professionally in your lessons or commercial games, please consider donating!
p5play is an open source project and will always be available for free, but your support would be greatly appreciated. If you use p5play professionally in your lessons or commercial games, please consider donating!

[![Donate](https://img.shields.io/badge/[email protected])](https://paypal.me/qashto) [![Venmo](https://img.shields.io/badge/[email protected])](https://venmo.com/Quinton-Ashley) [![Patreon](https://img.shields.io/badge/[email protected])](https://www.patreon.com/p5play)

Expand Down
85 changes: 42 additions & 43 deletions p5.play.js
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,7 @@ p5.prototype.registerMethod('init', function p5PlayInit() {
}
if (b instanceof this.p.Group) continue;

let cb = _findContactCB.call(this.p, contactType, a, b);
let cb = this.p.world._findContactCB(contactType, a, b);
if (typeof cb == 'function') cb(a, b, f);
}
}
Expand Down Expand Up @@ -4384,8 +4384,6 @@ p5.prototype.registerMethod('init', function p5PlayInit() {
}

/**
* EXPERIMENTAL implementation for beta testing!
*
* Apply a force that is scaled to the sprite's mass.
*
* @method applyForce
Expand Down Expand Up @@ -5020,6 +5018,43 @@ p5.prototype.registerMethod('init', function p5PlayInit() {
}
}

/**
* Used internally to find a contact callback between two sprites.
*
* @private _findContactCB
* @param {String} type "collide" or "overlap"
* @param {Sprite} s0
* @param {Sprite} s1
* @returns contact cb if one can be found between the two sprites
*/
_findContactCB(type, s0, s1) {
let cb = s0[type][s1];
if (cb) return cb;

let s1IsSprite = s1 instanceof this.p.Sprite;

if (s1IsSprite) {
for (let g1 of s1.groups) {
cb = s0[type][g1];
if (cb) return cb;
}
}

if (s0 instanceof this.p.Sprite) {
for (let g0 of s0.groups) {
cb = g0[type][s1];
if (cb) return cb;
if (s1IsSprite) {
for (let g1 of s1.groups) {
cb = g0[type][g1];
if (cb) return cb;
}
}
}
}
return false;
}

get autoCull() {
return this.p.allSprites.autoCull;
}
Expand Down Expand Up @@ -5200,44 +5235,8 @@ p5.prototype.registerMethod('init', function p5PlayInit() {
}; //end camera class

/**
* Used internally to find a contact callback between two sprites.
*
* @private _findContactCB
* @param {String} type "collide" or "overlap"
* @param {Sprite} s0
* @param {Sprite} s1
* @returns contact cb if one can be found between the two sprites
*/
function _findContactCB(type, s0, s1) {
let cb = s0[type][s1];
if (cb) return cb;

let s1IsSprite = s1 instanceof this.Sprite;

if (s1IsSprite) {
for (let g1 of s1.groups) {
cb = s0[type][g1];
if (cb) return cb;
}
}

if (s0 instanceof this.Sprite) {
for (let g0 of s0.groups) {
cb = g0[type][s1];
if (cb) return cb;
if (s1IsSprite) {
for (let g1 of s1.groups) {
cb = g0[type][g1];
if (cb) return cb;
}
}
}
}
return false;
}
/**
* This planck function should've be named "shouldContact", because that's what
* it actually decides.
* This planck function should've been named "shouldContact",
* because that's what it actually decides.
*
* Here we override it to allow for overlap events between sprites.
*/
Expand All @@ -5258,8 +5257,8 @@ p5.prototype.registerMethod('init', function p5PlayInit() {

// if `a` has an overlap enabled with `b` their colliders should not produce a
// contact event, the overlap contact event is between their sensors
let shouldOverlap = _findContactCB.call(pInst, '_overlap', a, b);
if (!shouldOverlap) shouldOverlap = _findContactCB.call(pInst, '_overlap', b, a);
let shouldOverlap = a.p.world._findContactCB('_overlap', a, b);
if (!shouldOverlap) shouldOverlap = a.p.world._findContactCB('_overlap', b, a);
if (shouldOverlap) return false;
return true;
};
Expand Down
85 changes: 42 additions & 43 deletions p5play.js
Original file line number Diff line number Diff line change
Expand Up @@ -2249,7 +2249,7 @@ p5.prototype.registerMethod('init', function p5PlayInit() {
}
if (b instanceof this.p.Group) continue;

let cb = _findContactCB.call(this.p, contactType, a, b);
let cb = this.p.world._findContactCB(contactType, a, b);
if (typeof cb == 'function') cb(a, b, f);
}
}
Expand Down Expand Up @@ -4379,8 +4379,6 @@ p5.prototype.registerMethod('init', function p5PlayInit() {
}

/**
* EXPERIMENTAL implementation for beta testing!
*
* Apply a force that is scaled to the sprite's mass.
*
* @method applyForce
Expand Down Expand Up @@ -5015,6 +5013,43 @@ p5.prototype.registerMethod('init', function p5PlayInit() {
}
}

/**
* Used internally to find a contact callback between two sprites.
*
* @private _findContactCB
* @param {String} type "collide" or "overlap"
* @param {Sprite} s0
* @param {Sprite} s1
* @returns contact cb if one can be found between the two sprites
*/
_findContactCB(type, s0, s1) {
let cb = s0[type][s1];
if (cb) return cb;

let s1IsSprite = s1 instanceof this.p.Sprite;

if (s1IsSprite) {
for (let g1 of s1.groups) {
cb = s0[type][g1];
if (cb) return cb;
}
}

if (s0 instanceof this.p.Sprite) {
for (let g0 of s0.groups) {
cb = g0[type][s1];
if (cb) return cb;
if (s1IsSprite) {
for (let g1 of s1.groups) {
cb = g0[type][g1];
if (cb) return cb;
}
}
}
}
return false;
}

get autoCull() {
return this.p.allSprites.autoCull;
}
Expand Down Expand Up @@ -5195,44 +5230,8 @@ p5.prototype.registerMethod('init', function p5PlayInit() {
}; //end camera class

/**
* Used internally to find a contact callback between two sprites.
*
* @private _findContactCB
* @param {String} type "collide" or "overlap"
* @param {Sprite} s0
* @param {Sprite} s1
* @returns contact cb if one can be found between the two sprites
*/
function _findContactCB(type, s0, s1) {
let cb = s0[type][s1];
if (cb) return cb;

let s1IsSprite = s1 instanceof this.Sprite;

if (s1IsSprite) {
for (let g1 of s1.groups) {
cb = s0[type][g1];
if (cb) return cb;
}
}

if (s0 instanceof this.Sprite) {
for (let g0 of s0.groups) {
cb = g0[type][s1];
if (cb) return cb;
if (s1IsSprite) {
for (let g1 of s1.groups) {
cb = g0[type][g1];
if (cb) return cb;
}
}
}
}
return false;
}
/**
* This planck function should've be named "shouldContact", because that's what
* it actually decides.
* This planck function should've been named "shouldContact",
* because that's what it actually decides.
*
* Here we override it to allow for overlap events between sprites.
*/
Expand All @@ -5253,8 +5252,8 @@ p5.prototype.registerMethod('init', function p5PlayInit() {

// if `a` has an overlap enabled with `b` their colliders should not produce a
// contact event, the overlap contact event is between their sensors
let shouldOverlap = _findContactCB.call(pInst, '_overlap', a, b);
if (!shouldOverlap) shouldOverlap = _findContactCB.call(pInst, '_overlap', b, a);
let shouldOverlap = a.p.world._findContactCB('_overlap', a, b);
if (!shouldOverlap) shouldOverlap = a.p.world._findContactCB('_overlap', b, a);
if (shouldOverlap) return false;
return true;
};
Expand Down
2 changes: 1 addition & 1 deletion p5play.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
"version": "git add -A",
"postversion": "git push"
},
"version": "3.5.25"
"version": "3.5.26"
}

0 comments on commit a7aedbe

Please sign in to comment.