Vixen
02b45cc4
csharp
public sealed class PlatformEventBuffer

The buffer between whoever produces platform events and the frame that consumes them. Double-buffered, so a drain is a pointer swap rather than a copy and the consumer reads without holding a lock.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Every platform implementation shares this rather than writing its own: the concurrency is the same problem everywhere, and it is not a problem worth solving five times. SDL delivers on the thread that pumps, but Android's lifecycle callbacks arrive on the UI thread and a browser's on the JS thread, so Post has to be safe from any thread even where today's backend only uses one.

Drain is for the owner — the thread running the frame loop — and calling it from two threads at once is a bug the type does not try to make safe, because two threads consuming input is not a thing an engine should be able to do by accident.

Fields and properties (3)

  • public const int Capacity

    How many events may pile up before the oldest are dropped.

  • public int PendingCount

    How many events are waiting for the next Drain.

  • public long DroppedCount

    How many events have been dropped because the queue was full, over the lifetime of the queue.

Methods (3)

  • public bool Post(in PlatformEvent platformEvent)

    Adds an event. Safe from any thread.

  • public ReadOnlySpan<PlatformEvent> Drain()

    Takes everything enqueued since the last call, in the order it arrived.

  • public void Clear()

    Throws away everything pending and everything from the last drain.

Used by (8)

  • DesktopLifecycleVixen.Platform.Desktop
  • DesktopPlatformVixen.Platform.Desktop
  • HeadlessLifecycleVixen.Platform.Headless
  • HeadlessPlatformVixen.Platform.Headless
  • HeadlessWindowVixen.Platform.Headless
  • MobileLifecycleVixen.Platform
  • MobileLifecycleTestsVixen.Platform.Tests
  • PlatformEventBufferTestsVixen.Platform.Tests