1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Module to handle client inputs
//!
//! Client inputs are generated by the user and sent to the server.
//! They have to be handled separately from other messages, for several reasons:
//! - the history of inputs might need to be saved on the client to perform rollback and client-prediction
//! - we not only send the input for tick T, but we also include the inputs for the last N ticks before T. This redundancy helps ensure
//! that the server isn't missing any client inputs even if a packet gets lost
//! - we must provide [`SystemSet`](bevy_ecs::prelude::SystemSet)s so that the user can order their systems before and after the input handling
//!
//! ### Adding a new input type
//!
//! An input type must be serializable, `Reflect`, `MapEntities`, `Clone`, `PartialEq`, and `Debug`.
//!
//! You can then add the input type by adding the [`InputPlugin<InputType>`](prelude::InputPlugin) to your app.
//!
//! ```rust
//! # use bevy_app::App;
//! # use bevy_ecs::entity::{MapEntities, EntityMapper};
//! # use serde::{Serialize, Deserialize};
//! # use bevy_reflect::Reflect;
//! use lightyear_inputs_native::prelude::*;
//!
//! #[derive(Serialize, Deserialize, Clone, PartialEq, Reflect, Debug, Default)]
//! pub enum MyInput {
//! Move { x: f32, y: f32 },
//! Jump,
//! // we need a variant for "no input", to differentiate between "no input" and "missing input packet"
//! #[default]
//! None,
//! }
//!
//! // every input must implement MapEntities
//! impl MapEntities for MyInput {
//! fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {
//! }
//! }
//!
//! let mut app = App::new();
//! app.add_plugins(InputPlugin::<MyInput>::default());
//! ```
//!
//! ### Sending inputs
//!
//! There are several steps to use the `InputPlugin`:
//! - (optional) read the inputs from an external signal (mouse click or keyboard press, for instance)
//! - to buffer inputs for each tick. This is done by setting the input value in the [`ActionState`](action_state::ActionState) component.
//! That system must run in the [`WriteClientInputs`](lightyear_inputs::prelude::client::InputSystems::WriteClientInputs) system set, in the `FixedPreUpdate` stage.
//! - handle inputs in your game logic in systems that run in the `FixedUpdate` schedule. These systems
//! will read the inputs using the `ActionState` component
//!
//! [`FixedUpdate`]: bevy_app::prelude::FixedUpdate
extern crate alloc;
extern crate core;
extern crate std;
pub
pub