event_bridge module
Event Bridge - Connects EventBus to Network State Sync
Subscribes to game events and broadcasts state deltas to connected players. Provides the real-time sync between DM actions and player views.
- class network.event_bridge.EventBridge(session_host: SessionHost, gamemaster, throttle_ms: int = 100)
Bases:
objectBridges
EventBusevents to network state broadcasts.Subscribes to every event type listed in
SYNC_EVENTS, batches rapid changes via a configurable throttle window, computes state deltas usingcompute_delta(), and broadcasts them through theSessionHost.- Parameters:
session_host (SessionHost) – The host instance used for broadcasting.
gamemaster – The Gamemaster whose world provides the authoritative state.
throttle_ms (int) – Minimum milliseconds between consecutive broadcasts.
Example:
bridge = EventBridge(session_host, gamemaster) bridge.start() # ... game runs, events auto-broadcast ... bridge.stop()
- async force_full_sync()
Force a
FULL_STATEbroadcast.Serializes the entire world, entity list, and turn data and sends it to every connected player. Resets the internal snapshot afterwards.
- start()
Start listening to
EventBusevents.Captures an initial world snapshot and subscribes to all
SYNC_EVENTS. Safe to call multiple times (subsequent calls are no-ops).
- stop()
Stop listening and unsubscribe from all events.
- class network.event_bridge.TurnBridge(session_host: SessionHost, gamemaster)
Bases:
objectSpecialized bridge for turn-related events.
Subscribes to
"turn_started"and"round_started"EventBus events and broadcastsTURN_CHANGEmessages to all connected players.- Parameters:
session_host (SessionHost) – The host instance used for broadcasting.
gamemaster – The Gamemaster whose turn system provides state.
- start()
Start listening for turn events on the EventBus.
- stop()
Stop listening and unsubscribe from turn events.