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

expose option for sweepandprune both directions so it can be tested in external games #615

Merged
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: 3 additions & 1 deletion src/kaplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ import {
rgb,
RNG,
shuffle,
SweepAndPruneBoth,
SweepAndPruneHorizontal,
SweepAndPruneVertical,
testCirclePolygon,
testLineCircle,
testLineLine,
Expand Down Expand Up @@ -855,7 +857,7 @@ const kaplay = <
return true;
}

const sap = new SweepAndPruneHorizontal();
const sap = gopt.sapDirection === "both" ? new SweepAndPruneBoth() : gopt.sapDirection === "vertical" ? new SweepAndPruneVertical() : new SweepAndPruneHorizontal();
let sapInit = false;
function broadPhase() {
if (!usesArea()) {
Expand Down
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6025,6 +6025,16 @@ export interface KAPLAYOpt<
* @default 0
*/
spriteAtlasPadding?: number;
/**
* The direction the sweep-and-prune system should run in to speed up collisions.
*
* XXX: Don't set this to "both" right now, the implementation is extremely slow and laggy.
*
* @default "horizontal"
* @since v4000
* @experimental This feature is unstable, it may be removed at any time.
*/
sapDirection?: "horizontal" | "vertical" | "both";
}

/**
Expand Down