Arch-ECS
💬 Join the discord!☕ Buy us a coffee!
  • 🌄Why Arch?
  • 📖Documentation
    • Concepts
    • World
    • Entity
    • Query
    • Archetypes & Chunks
    • Optimizations
      • Query-Techniques
      • Pass on data
      • Batch and Bulk
      • PURE_ECS
      • Multithreading
      • EntityData
    • Utilities
      • Component Registration
      • Non-generic API
      • CommandBuffer
      • Events
      • Dangerous Extensions
  • 🧩Extensions
    • Arch.Extended
      • Arch.System
      • Arch.System.SourceGenerator
      • Arch.EventBus
      • Arch.AOT.SourceGenerator
      • Arch.LowLevel
      • Arch.Persistence
      • Arch.Relationships
  • 💡Examples & Guidelines
    • Arch.Samples
    • Entities in Query
    • Structural changes
  • Unity
  • 🎮Projects using Arch
    • Skylandkingdoms
    • Cubetory
    • SS14
    • EquilibriumEngine-CSharp
    • Rougelite-Survivor
  • ✏️Misc
    • Roadmap
    • FAQ
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Extensions
  2. Arch.Extended

Arch.EventBus

Arch.EventBus, a high-performance way of sending notifications or events.

To decouple code and outsource logic using events, Arch.Extended has the EventBus. The special feature here, it is completely source generated and therefore as fast as native method calls. And it can even be inlined and supports static classes and instances.

Example

public partial class MyInstanceReceiver {

   public MysInstanceReceiver(){ Hook(); } // To start listening.

   [Event]
   public void OnShootEvent(ref ShootEvent @event){
      // Handle
   }
}

public static class SomeEventHandler{

   [Event(order: 2)]
   public static void OnShootFireBullets(ref ShootEvent @event){  // ref, none, in supported and all types as a event. Only one param!
      // Do stuff
   }
   
   [Event(order: 1)]
   public static void OnShootFireBullets(ref ShootEvent @event){  // ref, none, in supported and all types as a event. Only one param!
      // Do stuff
   }
}

var shootEvent = new ShootEvent();
EventBus.Send(ref shootEvent); // Broadcasts the event to all annotated methods wherever they are.

The order is optional and determines the order of the calls. However, this is separate, the static methods are always called first. An order can be specified. And then come the instances that are called, within which an order can also be determined.

The call will forward the events to the receivers directly and without delay. The assignment happens via the parameters, so if we pass the struct, the methods that receive this struct as a parameter are always called. The struct is therefore virtually our event.

PreviousArch.System.SourceGeneratorNextArch.AOT.SourceGenerator

Last updated 2 months ago

Was this helpful?

🧩