optic_online/lib.rs
1//! UDP networking for the Optic engine.
2//!
3//! Runs a tokio runtime on a dedicated background thread, communicating
4//! with the main thread via mpsc channels. All I/O is non-blocking from
5//! the game loop's perspective.
6//!
7//! # Architecture
8//!
9//! ```text
10//! Game loop (main thread) Network thread
11//! ┌────────────────────┐ ┌─────────────────────┐
12//! │ NetworkHandle │─tx cmd──▶│ tokio runtime │
13//! │ .send_to() │ │ UdpSocket │
14//! │ .send_all() │◀─data────│ heartbeat keepalive│
15//! │ .poll() │◀─events──│ peer lifecycle │
16//! └────────────────────┘ └─────────────────────┘
17//! ```
18//!
19//! # Feature flag
20//!
21//! This crate is optional. Enable it with the `online` feature:
22//!
23//! ```toml
24//! optic = { git = "..", features = ["online"] }
25//! ```
26//!
27//! Then configure in your [`GameBuilder`](optic_loop::GameBuilder):
28//!
29//! ```ignore
30//! use optic_engine::*;
31//!
32//! let game = GameBuilder::new()
33//! .with_network(NetworkConfig::host(7777))
34//! .build(App)?
35//! .enable_networking();
36//! ```
37
38pub mod channels;
39pub mod config;
40pub mod handle;
41pub mod peer;
42pub mod transport;
43
44pub use handle::NetworkHandle;
45pub use config::*;
46pub use peer::*;