Event System

Passive Check

class CollisionSystem {
  void Update(){
      //.../
      if(collisionHappened) {
        eventBus->EmitEvent<CollisionEvent>();
      }
  }
}

class DamageSystem {
  void Update() {
    for (auto e: eventBus->GetEvents<CollisionEvent>() {
      //......
    }
  }
}

Blocking

 class CollisionSystem {
   void Update(){
       //.../
       if(collisionHappened) {
         eventBus->EmitEvent<CollisionEvent>(a, b);
       }
   }
 }

 class DamageSystem {
   eventBus->SubscribeToEvent<CollisionEvent>(onCollision);

   void onCollision(Entity a, Entity b) {
      //....
   }
}

Date: 2024-01-11 Thu 00:00

Author: Terry Fung

Created: 2024-11-10 Sun 14:09

Emacs 29.4 (Org mode 9.6.15)

Validate