Skip to content

Commit

Permalink
fix: trigger system getcomponentgroup in update (#17)
Browse files Browse the repository at this point in the history
* mini refactor to cache trigger system component group when constructed instead of fetching on update
  • Loading branch information
pravusjif authored Nov 6, 2020
1 parent 90f8500 commit 98429e1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/triggers/triggerSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ export class TriggerSystem implements ISystem {

private _triggers: Record<string, TriggerWrapper> = {}
private _cameraTriggerWrapper: CameraTrigger
private _componentGroup: ComponentGroup

private constructor() {
TriggerSystem._instance = this
this._cameraTriggerWrapper = new CameraTrigger(
new TriggerBoxShape(new Vector3(0.5, 1.8, 0.5), new Vector3(0, 0.91, 0))
)

this._componentGroup = engine.getComponentGroup(TriggerComponent)
}

static createAndAddToEngine(): TriggerSystem {
Expand All @@ -31,9 +34,7 @@ export class TriggerSystem implements ISystem {
}

update() {
//get entities with trigger component
let entitiesWithTriggers = engine.getComponentGroup(TriggerComponent)
.entities
let entitiesWithTriggers = this._componentGroup.entities

//iterate through all entities with triggers and wrap entities that weren't wrapped yet
entitiesWithTriggers.forEach(entity => {
Expand Down

0 comments on commit 98429e1

Please sign in to comment.