Expand description
Plaza, a server-authoritative foundation for real-time shared state.
An application defines three things and Plaza runs the loop around them:
- a state type: whatever data is being shared,
- an op type: the discrete operations that may change it,
- a
StateLogic, the rules mapping ops onto state.
A StateController owns that state and is
the only thing that mutates it, processing inputs one at a time in its own
task. Because it is a single actor, application logic needs no locking. It
reaches clients through a Session and hands joining
clients a snapshot from a SnapshotProvider.
let session = InProcessSession::<MyOp, MyId>::new();
let (tx, controller) = StateControllerBuilder::new(
Arc::new(MyLogic), session.clone(), Arc::new(MySnapshotter), MyState::default(),
).build();
tokio::spawn(controller.run());
tokio::spawn(TickDriver::from_hz(60).run(tx.clone()));For real networking use the transports in plaza_session; for rooms and
matchmaking, plaza_lobby.
§Optional building blocks
Beyond the core loop this crate ships pieces real-time apps tend to need:
schedulers (common::scheduler), finite state machines (common::fsm),
participant tracking (common::participants), turn/round/phase control
and scorekeeping (game_common), client prediction and lag compensation
(game_common::reconciliation) and op payloads for collaborative apps:
locking, presence, ordered collections (app_common). All of them are
optional.
Re-exports§
pub use controller::query_state;pub use controller::query_with;pub use controller::submit_system_ops;pub use controller::Applied;pub use controller::CommandSender;pub use controller::ControllerCommand;pub use controller::StateController;pub use controller::StateControllerBuilder;pub use controller::StateReader;pub use error::PlazaError;pub use op_guard::GuardFn;pub use op_guard::NoGuard;pub use op_guard::OpClearance;pub use op_guard::OpGuard;pub use session::InProcessSession;pub use session::MessageTarget;pub use session::Session;pub use session::SessionMessage;pub use session::TargetedOp;pub use snapshot::NoSnapshots;pub use snapshot::SnapshotFn;pub use snapshot::SnapshotProvider;pub use state_logic::LogicInput;pub use state_logic::StateLogic;pub use tick_driver::TickDriver;
Modules§
- agent
- Agent identity, re-exported from
plaza_wire. - app_
common - common
- controller
- error
- game_
common - op_
guard - Authorization ahead of
StateLogic: whether an agent may submit an op at all. - session
- The transport abstraction: how a controller reaches its clients.
- snapshot
- state_
logic - stats
- Counters only the controller can collect about itself.
- tick_
driver - Drives a controller’s simulation clock.
Enums§
- Agent
- An actor in the system: a person, a bot or the server itself.
Traits§
- AgentId
- What may identify an agent.