• 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

0.0
/src/engine/EntityComponentSystem/SystemManager.ts
1
import { System, SystemType } from './System';
2
import { Scene } from '../Scene';
3
import { World } from './World';
4
import { removeItemFromArray } from '../Util/Util';
5

6
export interface SystemCtor<T extends System> {
7
  new (...args: any[]): T;
8
}
9

10
/**
11
 *
12
 */
13
export function isSystemConstructor(x: any): x is SystemCtor<System> {
UNCOV
14
  return !!x?.prototype && !!x?.prototype?.constructor?.name;
×
15
}
16

17
/**
18
 * The SystemManager is responsible for keeping track of all systems in a scene.
19
 * Systems are scene specific
20
 */
21
export class SystemManager {
22
  /**
23
   * List of systems, to add a new system call {@apilink SystemManager.addSystem}
24
   */
UNCOV
25
  public systems: System[] = [];
×
UNCOV
26
  public initialized = false;
×
UNCOV
27
  constructor(private _world: World) {}
×
28

29
  /**
30
   * Get a system registered in the manager by type
31
   * @param systemType
32
   */
33
  public get<T extends System>(systemType: SystemCtor<T>): T | null {
UNCOV
34
    return this.systems.find((s) => s instanceof systemType) as unknown as T;
×
35
  }
36

37
  /**
38
   * Adds a system to the manager, it will now be updated every frame
39
   * @param systemOrCtor
40
   */
41
  public addSystem(systemOrCtor: SystemCtor<System> | System): void {
42
    let system: System;
UNCOV
43
    if (systemOrCtor instanceof System) {
×
UNCOV
44
      system = systemOrCtor;
×
45
    } else {
UNCOV
46
      system = new systemOrCtor(this._world);
×
47
    }
48

UNCOV
49
    this.systems.push(system);
×
UNCOV
50
    this.systems.sort((a, b) => (a.constructor as typeof System).priority - (b.constructor as typeof System).priority);
×
51
    // If systems are added and the manager has already been init'd
52
    // then immediately init the system
UNCOV
53
    if (this.initialized && system.initialize) {
×
UNCOV
54
      system.initialize(this._world, this._world.scene);
×
55
    }
56
  }
57

58
  /**
59
   * Removes a system from the manager, it will no longer be updated
60
   * @param system
61
   */
62
  public removeSystem(system: System) {
UNCOV
63
    removeItemFromArray(system, this.systems);
×
64
  }
65

66
  /**
67
   * Initialize all systems in the manager
68
   *
69
   * Systems added after initialize() will be initialized on add
70
   */
71
  public initialize() {
UNCOV
72
    if (!this.initialized) {
×
UNCOV
73
      this.initialized = true;
×
UNCOV
74
      for (const s of this.systems) {
×
UNCOV
75
        if (s.initialize) {
×
UNCOV
76
          s.initialize(this._world, this._world.scene);
×
77
        }
78
      }
79
    }
80
  }
81

82
  /**
83
   * Updates all systems
84
   * @param type whether this is an update or draw system
85
   * @param scene context reference
86
   * @param elapsed time in milliseconds
87
   */
88
  public updateSystems(type: SystemType, scene: Scene, elapsed: number) {
UNCOV
89
    const systems = this.systems.filter((s) => s.systemType === type);
×
UNCOV
90
    for (const s of systems) {
×
UNCOV
91
      if (s.preupdate) {
×
UNCOV
92
        s.preupdate(scene, elapsed);
×
93
      }
94
    }
95

UNCOV
96
    for (const s of systems) {
×
UNCOV
97
      s.update(elapsed);
×
98
    }
99

UNCOV
100
    for (const s of systems) {
×
UNCOV
101
      if (s.postupdate) {
×
UNCOV
102
        s.postupdate(scene, elapsed);
×
103
      }
104
    }
105
  }
106

107
  public clear(): void {
UNCOV
108
    for (let i = this.systems.length - 1; i >= 0; i--) {
×
UNCOV
109
      this.removeSystem(this.systems[i]);
×
110
    }
111
  }
112
}
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