Skip to content

Commit

Permalink
fix: flakey tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Dec 6, 2024
1 parent a96da8f commit 6c0b939
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 55 deletions.
10 changes: 5 additions & 5 deletions src/engine/Collision/BodyComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { clamp } from '../Math/util';
import { ColliderComponent } from './ColliderComponent';
import { Transform } from '../Math/transform';
import { EventEmitter } from '../EventEmitter';
import { DefaultPhysicsConfig, PhysicsConfig } from './PhysicsConfig';
import { getDefaultPhysicsConfig, PhysicsConfig } from './PhysicsConfig';
import { DeepRequired } from '../Util/Required';
import { Entity } from '../EntityComponentSystem';

Expand Down Expand Up @@ -52,7 +52,7 @@ export class BodyComponent extends Component implements Clonable<BodyComponent>

private _bodyConfig: DeepRequired<Pick<PhysicsConfig, 'bodies'>['bodies']>;
private static _DEFAULT_CONFIG: DeepRequired<Pick<PhysicsConfig, 'bodies'>['bodies']> = {
...DefaultPhysicsConfig.bodies
...getDefaultPhysicsConfig().bodies
};
public wakeThreshold: number;

Expand All @@ -63,12 +63,12 @@ export class BodyComponent extends Component implements Clonable<BodyComponent>
this.group = options.group ?? this.group;
this.useGravity = options.useGravity ?? this.useGravity;
this._bodyConfig = {
...DefaultPhysicsConfig.bodies,
...getDefaultPhysicsConfig().bodies,
...options.config
};
} else {
this._bodyConfig = {
...DefaultPhysicsConfig.bodies
...getDefaultPhysicsConfig().bodies
};
}
this.updatePhysicsConfig(this._bodyConfig);
Expand All @@ -85,7 +85,7 @@ export class BodyComponent extends Component implements Clonable<BodyComponent>
*/
public updatePhysicsConfig(config: DeepRequired<Pick<PhysicsConfig, 'bodies'>['bodies']>) {
this._bodyConfig = {
...DefaultPhysicsConfig.bodies,
...getDefaultPhysicsConfig().bodies,
...config
};
this.canSleep = this._bodyConfig.canSleepByDefault;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/Collision/Colliders/CompositeCollider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import { DynamicTreeCollisionProcessor } from '../Detection/DynamicTreeCollision
import { RayCastHit } from '../Detection/RayCastHit';
import { Collider } from './Collider';
import { Transform } from '../../Math/transform';
import { DefaultPhysicsConfig } from '../PhysicsConfig';
import { getDefaultPhysicsConfig } from '../PhysicsConfig';

export class CompositeCollider extends Collider {
private _transform: Transform;
private _collisionProcessor = new DynamicTreeCollisionProcessor({
...DefaultPhysicsConfig
...getDefaultPhysicsConfig()
});
private _dynamicAABBTree = new DynamicTree({
boundsPadding: 5,
Expand Down
6 changes: 3 additions & 3 deletions src/engine/Collision/PhysicsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ export interface PhysicsConfig {
};
}

export const DefaultPhysicsConfig: DeepRequired<PhysicsConfig> = {
export const getDefaultPhysicsConfig: () => DeepRequired<PhysicsConfig> = () => ({
enabled: true,
gravity: vec(0, 0),
gravity: vec(0, 0).clone(),
solver: SolverStrategy.Arcade,
substep: 1,
colliders: {
Expand Down Expand Up @@ -254,4 +254,4 @@ export const DefaultPhysicsConfig: DeepRequired<PhysicsConfig> = {
steeringFactor: 0.2,
warmStart: true
}
};
});
6 changes: 3 additions & 3 deletions src/engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { Toaster } from './Util/Toaster';
import { InputMapper } from './Input/InputMapper';
import { GoToOptions, SceneMap, Director, StartOptions, SceneWithOptions, WithRoot } from './Director/Director';
import { InputHost } from './Input/InputHost';
import { DefaultPhysicsConfig, PhysicsConfig } from './Collision/PhysicsConfig';
import { getDefaultPhysicsConfig, PhysicsConfig } from './Collision/PhysicsConfig';
import { DeepRequired } from './Util/Required';
import { Context, createContext, useContext } from './Context';
import { DefaultGarbageCollectionOptions, GarbageCollectionOptions, GarbageCollector } from './GarbageCollector';
Expand Down Expand Up @@ -1039,12 +1039,12 @@ O|===|* >________________>\n\

if (typeof options.physics === 'boolean') {
this.physics = {
...DefaultPhysicsConfig,
...getDefaultPhysicsConfig(),
enabled: options.physics
};
} else {
this.physics = {
...DefaultPhysicsConfig
...getDefaultPhysicsConfig()
};
mergeDeep(this.physics, options.physics);
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Graphics/TiledAnimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class TiledAnimation extends Animation {
promises.push(tiledSprite.ready);
}
}
Promise.allSettled(promises).then(() => this._ready.resolve());
Promise.all(promises).then(() => this._ready.resolve());
}

public static fromAnimation(animation: Animation, options?: Omit<TiledAnimationOptions, 'animation'>): TiledAnimation {
Expand Down
4 changes: 2 additions & 2 deletions src/engine/Particles/GpuParticleEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Actor, clamp, Engine, ExcaliburGraphicsContextWebGL, GraphicsComponent, Random, vec, Vector } from '../';
import { Actor, clamp, Engine, ExcaliburGraphicsContextWebGL, GraphicsComponent, ParticleRenderer, Random, vec, Vector } from '../';
import { EmitterType } from './EmitterType';
import { ParticleEmitterArgs, ParticleTransform } from './Particles';
import { GpuParticleConfig, GpuParticleRenderer } from './GpuParticleRenderer';
Expand Down Expand Up @@ -96,6 +96,6 @@ export class GpuParticleEmitter extends Actor {
}

draw(ctx: ExcaliburGraphicsContextWebGL, elapsed: number) {
ctx.draw<ex.ParticleRenderer>('ex.particle', this.renderer, elapsed);
ctx.draw<ParticleRenderer>('ex.particle', this.renderer, elapsed);
}
}
4 changes: 2 additions & 2 deletions src/engine/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { DefaultLoader } from './Director/DefaultLoader';
import { Transition } from './Director';
import { InputHost } from './Input/InputHost';
import { PointerScope } from './Input/PointerScope';
import { DefaultPhysicsConfig } from './Collision/PhysicsConfig';
import { getDefaultPhysicsConfig } from './Collision/PhysicsConfig';

export class PreLoadEvent {
loader: DefaultLoader;
Expand Down Expand Up @@ -110,7 +110,7 @@ export class Scene<TActivationData = unknown> implements CanInitialize, CanActiv
*
* Can be used to perform scene ray casts, track colliders, broadphase, and narrowphase.
*/
public physics = new PhysicsWorld(DefaultPhysicsConfig);
public physics = new PhysicsWorld(getDefaultPhysicsConfig());

/**
* The actors in the current scene
Expand Down
14 changes: 7 additions & 7 deletions src/spec/ArcadeSolverSpec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ex from '@excalibur';
import { ExcaliburMatchers } from 'excalibur-jasmine';
import { TestUtils } from './util/TestUtils';
import { DefaultPhysicsConfig } from '../engine/Collision/PhysicsConfig';
import { getDefaultPhysicsConfig } from '../engine/Collision/PhysicsConfig';

describe('An ArcadeSolver', () => {
beforeAll(() => {
Expand All @@ -24,7 +24,7 @@ describe('An ArcadeSolver', () => {
const contacts = [...pair1.collide(), ...pair2.collide()];
expect(contacts.length).toBe(2);

const sut = new ex.ArcadeSolver(DefaultPhysicsConfig.arcade);
const sut = new ex.ArcadeSolver(getDefaultPhysicsConfig().arcade);

for (const contact of contacts) {
sut.solvePosition(contact);
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('An ArcadeSolver', () => {
});

it('should cancel collision contacts where there is no more overlap', () => {
const arcadeSolver = new ex.ArcadeSolver(DefaultPhysicsConfig.arcade);
const arcadeSolver = new ex.ArcadeSolver(getDefaultPhysicsConfig().arcade);

const player = new ex.Actor({
x: 0,
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('An ArcadeSolver', () => {
});

it('should NOT cancel collisions where the bodies are moving away from the contact', () => {
const arcadeSolver = new ex.ArcadeSolver(DefaultPhysicsConfig.arcade);
const arcadeSolver = new ex.ArcadeSolver(getDefaultPhysicsConfig().arcade);

const player = new ex.Actor({
x: 0,
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('An ArcadeSolver', () => {
});

it('should cancel near zero mtv collisions', () => {
const arcadeSolver = new ex.ArcadeSolver(DefaultPhysicsConfig.arcade);
const arcadeSolver = new ex.ArcadeSolver(getDefaultPhysicsConfig().arcade);

const player = new ex.Actor({
x: 0,
Expand Down Expand Up @@ -235,7 +235,7 @@ describe('An ArcadeSolver', () => {
});

it('should cancel near zero overlap collisions', () => {
const arcadeSolver = new ex.ArcadeSolver(DefaultPhysicsConfig.arcade);
const arcadeSolver = new ex.ArcadeSolver(getDefaultPhysicsConfig().arcade);

const player = new ex.Actor({
x: 0,
Expand Down Expand Up @@ -272,7 +272,7 @@ describe('An ArcadeSolver', () => {
});

it('should cancel zero overlap collisions during presolve', () => {
const arcadeSolver = new ex.ArcadeSolver(DefaultPhysicsConfig.arcade);
const arcadeSolver = new ex.ArcadeSolver(getDefaultPhysicsConfig().arcade);

const player = new ex.Actor({
x: 0,
Expand Down
18 changes: 9 additions & 9 deletions src/spec/CollisionContactSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as ex from '@excalibur';
import { TransformComponent } from '@excalibur';
import { EulerIntegrator } from '../engine/Collision/Integrator';
import { MotionComponent } from '../engine/EntityComponentSystem/Components/MotionComponent';
import { DefaultPhysicsConfig } from '../engine/Collision/PhysicsConfig';
import { getDefaultPhysicsConfig } from '../engine/Collision/PhysicsConfig';
import { ExcaliburMatchers } from 'excalibur-jasmine';

describe('A CollisionContact', () => {
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('A CollisionContact', () => {
new ex.SeparationInfo()
);

const solver = new ex.ArcadeSolver(DefaultPhysicsConfig.arcade);
const solver = new ex.ArcadeSolver(getDefaultPhysicsConfig().arcade);
solver.solve([cc]);

expect(actorA.pos.x).toBe(-0.5);
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('A CollisionContact', () => {
new ex.SeparationInfo()
);

const solver = new ex.ArcadeSolver(DefaultPhysicsConfig.arcade);
const solver = new ex.ArcadeSolver(getDefaultPhysicsConfig().arcade);
solver.solve([cc]);

expect(actorAPreCollide).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('A CollisionContact', () => {
null
);
// slop is normally 1 pixel, we are testing at a pixel scale here
const solver = new ex.RealisticSolver({ ...DefaultPhysicsConfig.realistic, slop: 0 });
const solver = new ex.RealisticSolver({ ...getDefaultPhysicsConfig().realistic, slop: 0 });
// Realistic solver converges over time
for (let i = 0; i < 4; i++) {
solver.solve([cc]);
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('A CollisionContact', () => {
null
);
// slop is normally 1 pixel, we are testing at a pixel scale here
const solver = new ex.RealisticSolver({ ...DefaultPhysicsConfig.realistic, slop: 0 });
const solver = new ex.RealisticSolver({ ...getDefaultPhysicsConfig().realistic, slop: 0 });

solver.solve([cc]);
// Realistic solver uses velocity impulses to correct overlap
Expand Down Expand Up @@ -209,7 +209,7 @@ describe('A CollisionContact', () => {
[new ex.Vector(10, 0), new ex.Vector(10, 10)],
null
);
const solver = new ex.RealisticSolver(DefaultPhysicsConfig.realistic);
const solver = new ex.RealisticSolver({ ...getDefaultPhysicsConfig().realistic });
solver.solve([cc]);
// Realistic solver uses velocity impulses to correct overlap
EulerIntegrator.integrate(actorA.get(TransformComponent), actorA.get(MotionComponent), ex.Vector.Zero, 30);
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('A CollisionContact', () => {
null
);
const solver = new ex.RealisticSolver({
...DefaultPhysicsConfig.realistic,
...getDefaultPhysicsConfig().realistic,
slop: 0
});
solver.solve([cc]);
Expand Down Expand Up @@ -288,7 +288,7 @@ describe('A CollisionContact', () => {

// slop is normally 1 pixel, we are testing at a pixel scale here
const solver = new ex.RealisticSolver({
...DefaultPhysicsConfig.realistic,
...getDefaultPhysicsConfig().realistic,
slop: 0
});
solver.solve([cc]);
Expand Down Expand Up @@ -325,7 +325,7 @@ describe('A CollisionContact', () => {
null
);

const solver = new ex.RealisticSolver(DefaultPhysicsConfig.realistic);
const solver = new ex.RealisticSolver({ ...getDefaultPhysicsConfig().realistic });
solver.solve([cc]);

expect(emittedA).toBe(true);
Expand Down
6 changes: 3 additions & 3 deletions src/spec/CollisionSpec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ex from '@excalibur';
import { TestUtils } from './util/TestUtils';
import { DefaultPhysicsConfig } from '../engine/Collision/PhysicsConfig';
import { getDefaultPhysicsConfig } from '../engine/Collision/PhysicsConfig';

describe('A Collision', () => {
let actor1: ex.Actor = null;
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('A Collision', () => {

it('order of actors collision should not matter when an Active and Active Collision', () => {
const collisionTree = new ex.DynamicTreeCollisionProcessor({
...DefaultPhysicsConfig
...getDefaultPhysicsConfig()
});

actor1.body.collisionType = ex.CollisionType.Active;
Expand All @@ -75,7 +75,7 @@ describe('A Collision', () => {

it('order of actors collision should not matter when an Active and Passive Collision', () => {
const collisionTree = new ex.DynamicTreeCollisionProcessor({
...DefaultPhysicsConfig
...getDefaultPhysicsConfig()
});

actor1.body.collisionType = ex.CollisionType.Active;
Expand Down
6 changes: 3 additions & 3 deletions src/spec/CompositeColliderSpec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ex from '@excalibur';
import { BoundingBox, GameEvent, LineSegment, Projection, Ray, vec, Vector } from '@excalibur';
import { ExcaliburAsyncMatchers, ExcaliburMatchers } from 'excalibur-jasmine';
import { DefaultPhysicsConfig } from '../engine/Collision/PhysicsConfig';
import { getDefaultPhysicsConfig } from '../engine/Collision/PhysicsConfig';
describe('A CompositeCollider', () => {
beforeAll(() => {
jasmine.addAsyncMatchers(ExcaliburAsyncMatchers);
Expand Down Expand Up @@ -281,7 +281,7 @@ describe('A CompositeCollider', () => {
const compCollider = new ex.CompositeCollider([ex.Shape.Circle(50), ex.Shape.Box(200, 10, Vector.Half)]);

const dynamicTreeProcessor = new ex.DynamicTreeCollisionProcessor({
...DefaultPhysicsConfig
...getDefaultPhysicsConfig()
});
dynamicTreeProcessor.track(compCollider);

Expand All @@ -294,7 +294,7 @@ describe('A CompositeCollider', () => {
const compCollider = new ex.CompositeCollider([ex.Shape.Circle(50), ex.Shape.Box(200, 10, Vector.Half)]);

const dynamicTreeProcessor = new ex.DynamicTreeCollisionProcessor({
...DefaultPhysicsConfig
...getDefaultPhysicsConfig()
});
dynamicTreeProcessor.track(compCollider);

Expand Down
Loading

0 comments on commit 6c0b939

Please sign in to comment.