• 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/World.ts
1
import { Scene } from '../Scene';
2
import { Logger } from '../Util/Log';
3
import { Component, ComponentCtor } from './Component';
4
import { Entity } from './Entity';
5
import { EntityManager } from './EntityManager';
6
import { Query } from './Query';
7
import { QueryManager } from './QueryManager';
8
import { System, SystemType } from './System';
9
import { SystemCtor, SystemManager, isSystemConstructor } from './SystemManager';
10
import { TagQuery } from './TagQuery';
11

12
/**
13
 * The World is a self-contained entity component system for a particular context.
14
 */
15
export class World {
UNCOV
16
  private _logger = Logger.getInstance();
×
UNCOV
17
  public queryManager: QueryManager = new QueryManager(this);
×
UNCOV
18
  public entityManager: EntityManager = new EntityManager(this);
×
UNCOV
19
  public systemManager: SystemManager = new SystemManager(this);
×
20

21
  /**
22
   * The context type is passed to the system updates
23
   * @param scene
24
   */
UNCOV
25
  constructor(public scene: Scene) {}
×
26

27
  /**
28
   * Query the ECS world for entities that match your components
29
   * @param requiredTypes
30
   */
31
  query<TKnownComponentCtors extends ComponentCtor<Component>>(requiredTypes: TKnownComponentCtors[]): Query<TKnownComponentCtors> {
UNCOV
32
    return this.queryManager.createQuery(requiredTypes);
×
33
  }
34

35
  queryTags<TKnownTags extends string>(requiredTags: TKnownTags[]): TagQuery<TKnownTags> {
UNCOV
36
    return this.queryManager.createTagQuery(requiredTags);
×
37
  }
38

39
  /**
40
   * Update systems by type and time elapsed in milliseconds
41
   */
42
  update(type: SystemType, elapsed: number) {
UNCOV
43
    if (type === SystemType.Update) {
×
UNCOV
44
      this.entityManager.updateEntities(this.scene, elapsed);
×
45
    }
UNCOV
46
    this.systemManager.updateSystems(type, this.scene, elapsed);
×
UNCOV
47
    this.entityManager.findEntitiesForRemoval();
×
UNCOV
48
    this.entityManager.processComponentRemovals();
×
UNCOV
49
    this.entityManager.processEntityRemovals();
×
50
  }
51

52
  /**
53
   * Add an entity to the ECS world
54
   * @param entity
55
   */
56
  add(entity: Entity): void;
57
  /**
58
   * Add a system to the ECS world
59
   * @param system
60
   */
61
  add(system: System): void;
62
  add(system: SystemCtor<System>): void;
63
  add(entityOrSystem: Entity | System | SystemCtor<System>): void {
UNCOV
64
    if (entityOrSystem instanceof Entity) {
×
UNCOV
65
      this.entityManager.addEntity(entityOrSystem);
×
UNCOV
66
      return;
×
67
    }
68

UNCOV
69
    if (entityOrSystem instanceof System || isSystemConstructor(entityOrSystem)) {
×
UNCOV
70
      this.systemManager.addSystem(entityOrSystem);
×
UNCOV
71
      return;
×
72
    }
73

74
    this._logger.warn(
×
75
      `Could not add entity/system ${(entityOrSystem as any).constructor.name} to Excalibur!\n\n` +
76
        `If this looks like an Excalibur type, this can be caused by 2 versions of excalibur being included on the page.\n\n` +
77
        `Check your bundler settings to make sure this is not the case! Excalibur has ESM & UMD bundles be sure one 1 is loaded.`
78
    );
79
  }
80

81
  /**
82
   * Get a system out of the ECS world
83
   */
84
  get(system: SystemCtor<System>) {
UNCOV
85
    return this.systemManager.get(system);
×
86
  }
87

88
  /**
89
   * Remove an entity from the ECS world
90
   * @param entity
91
   */
92
  remove(entity: Entity, deferred?: boolean): void;
93
  /**
94
   * Remove a system from the ECS world
95
   * @param system
96
   */
97
  remove(system: System): void;
98
  remove(entityOrSystem: Entity | System, deferred = true): void {
×
UNCOV
99
    if (entityOrSystem instanceof Entity) {
×
UNCOV
100
      this.entityManager.removeEntity(entityOrSystem, deferred);
×
UNCOV
101
      return;
×
102
    }
103

UNCOV
104
    if (entityOrSystem instanceof System) {
×
UNCOV
105
      this.systemManager.removeSystem(entityOrSystem);
×
UNCOV
106
      return;
×
107
    }
108

109
    this._logger.warn(
×
110
      `Could not remove entity/system ${(entityOrSystem as any).constructor.name} to Excalibur!\n\n` +
111
        `If this looks like an Excalibur type, this can be caused by 2 versions of excalibur being included on the page.\n\n` +
112
        `Check your bundler settings to make sure this is not the case! Excalibur has ESM & UMD bundles be sure one 1 is loaded.`
113
    );
114
  }
115

116
  get entities() {
UNCOV
117
    return this.entityManager.entities;
×
118
  }
119

120
  clearEntities(): void {
UNCOV
121
    this.entityManager.clear();
×
122
  }
123

124
  clearSystems(): void {
UNCOV
125
    this.systemManager.clear();
×
126
  }
127
}
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