• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

excaliburjs / Excalibur / 14804036802

02 May 2025 09:58PM UTC coverage: 5.927% (-83.4%) from 89.28%
14804036802

Pull #3404

github

web-flow
Merge 5c103d7f8 into 0f2ccaeb2
Pull Request #3404: feat: added Graph module to Math

234 of 8383 branches covered (2.79%)

229 of 246 new or added lines in 1 file covered. (93.09%)

13145 existing lines in 208 files now uncovered.

934 of 15759 relevant lines covered (5.93%)

4.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

3.57
/src/engine/Collision/MotionSystem.ts
1
import { Entity, Query, SystemPriority, World } from '../EntityComponentSystem';
2
import { MotionComponent } from '../EntityComponentSystem/Components/MotionComponent';
3
import { TransformComponent } from '../EntityComponentSystem/Components/TransformComponent';
4
import { System, SystemType } from '../EntityComponentSystem/System';
5
import { BodyComponent } from './BodyComponent';
6
import { CollisionType } from './CollisionType';
7
import { EulerIntegrator } from './Integrator';
8
import { PhysicsWorld } from './PhysicsWorld';
9

10
export class MotionSystem extends System {
11
  static priority = SystemPriority.Higher;
1✔
12

UNCOV
13
  public systemType = SystemType.Update;
×
UNCOV
14
  private _physicsConfigDirty = false;
×
15
  query: Query<typeof TransformComponent | typeof MotionComponent>;
16
  constructor(
UNCOV
17
    public world: World,
×
UNCOV
18
    public physics: PhysicsWorld
×
19
  ) {
UNCOV
20
    super();
×
UNCOV
21
    physics.$configUpdate.subscribe(() => (this._physicsConfigDirty = true));
×
UNCOV
22
    this.query = this.world.query([TransformComponent, MotionComponent]);
×
23
  }
24

25
  update(elapsed: number): void {
26
    let transform: TransformComponent;
27
    let motion: MotionComponent;
UNCOV
28
    const entities = this.query.entities;
×
UNCOV
29
    const substep = this.physics.config.substep;
×
30

UNCOV
31
    for (let i = 0; i < entities.length; i++) {
×
UNCOV
32
      transform = entities[i].get(TransformComponent);
×
UNCOV
33
      motion = entities[i].get(MotionComponent);
×
34

UNCOV
35
      const optionalBody = entities[i].get(BodyComponent);
×
UNCOV
36
      if (this._physicsConfigDirty && optionalBody) {
×
UNCOV
37
        optionalBody.updatePhysicsConfig(this.physics.config.bodies);
×
38
      }
39

UNCOV
40
      if (optionalBody?.isSleeping) {
×
41
        continue;
×
42
      }
43

UNCOV
44
      const totalAcc = motion.acc.clone();
×
UNCOV
45
      if (optionalBody?.collisionType === CollisionType.Active && optionalBody?.useGravity) {
×
UNCOV
46
        totalAcc.addEqual(this.physics.config.gravity);
×
47
      }
48

49
      // capture old transform of this entity and all of its children so that
50
      // any transform properties that derived from their parents are properly captured
UNCOV
51
      if (!entities[i].parent) {
×
UNCOV
52
        this.captureOldTransformWithChildren(entities[i]);
×
53
      }
54

55
      // Update transform and motion based on Euler linear algebra
UNCOV
56
      EulerIntegrator.integrate(transform, motion, totalAcc, elapsed / substep);
×
57
    }
UNCOV
58
    this._physicsConfigDirty = false;
×
59
  }
60

61
  captureOldTransformWithChildren(entity: Entity) {
UNCOV
62
    entity.get(BodyComponent)?.captureOldTransform();
×
63

UNCOV
64
    for (let i = 0; i < entity.children.length; i++) {
×
UNCOV
65
      this.captureOldTransformWithChildren(entity.children[i]);
×
66
    }
67
  }
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc