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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*!
Provides integration for [`bevy_replicon`](https://docs.rs/bevy_replicon) for [`bevy_renet`](https://docs.rs/bevy_renet).
# Getting started
This guide assumes that you have already read [quick start guide](https://docs.rs/bevy_replicon#quick-start) from `bevy_replicon`.
All Renet API is re-exported from this plugin, you don't need to include `bevy_renet` or `renet` to your `Cargo.toml`.
Renet by default uses the netcode transport which is re-exported by the `renet_transport` feature. If you want to use other transports, you can disable it.
## Initialization
Add [`RepliconRenetPlugins`] along with [`RepliconPlugins`]:
```
use bevy::prelude::*;
use bevy_replicon::prelude::*;
use bevy_replicon_renet::RepliconRenetPlugins;
let mut app = App::new();
app.add_plugins((MinimalPlugins, RepliconPlugins, RepliconRenetPlugins));
```
If you want to separate the client and server, you can use the `client` and `server` features (both enabled by default),
which control enabled plugins. These features automatically enable corresponding features in `bevy_replicon`.
It's also possible to do it at runtime via [`PluginGroupBuilder::disable()`].
For server disable [`RepliconRenetClientPlugin`].
For client disable [`RepliconRenetServerPlugin`].
Plugins in [`RepliconRenetPlugins`] automatically add `renet` plugins, you don't need to add them.
If the `renet_transport` feature is enabled, netcode plugins will also be automatically added.
## Server and client creation
To connect to the server or create it, you need to initialize the
[`RenetClient`](renet::RenetClient) and [`NetcodeClientTransport`](bevy_renet::netcode::NetcodeClientTransport) **or**
[`RenetServer`](renet::RenetServer) and [`NetcodeServerTransport`](bevy_renet::netcode::NetcodeServerTransport)
resources from Renet.
For steam transport you need to activate the corresponding and use its transport resource instead.
Never insert client and server resources in the same app for single-player, it will cause a replication loop.
This crate provides the [`RenetChannelsExt`] extension trait to conveniently convert channels
from the [`RepliconChannels`] resource into renet channels.
When creating a server or client you need to use a [`ConnectionConfig`](renet::ConnectionConfig)
from [`renet`], which can be initialized like this:
```
use bevy::prelude::*;
use bevy_replicon::prelude::*;
use bevy_replicon_renet::{renet::ConnectionConfig, RenetChannelsExt, RepliconRenetPlugins};
# let mut app = App::new();
# app.add_plugins(RepliconPlugins);
let channels = app.world().resource::<RepliconChannels>();
let connection_config = ConnectionConfig {
server_channels_config: channels.get_server_configs(),
client_channels_config: channels.get_client_configs(),
..Default::default()
};
```
For a full example of how to initialize a server or client see the example in the
repository.
## Replicon conditions
The crate updates the running state of [`RepliconServer`] and connection state of [`RepliconClient`]
based on the states of [`RenetServer`](renet::RenetServer) and [`RenetClient`](renet::RenetServer)
in [`PreUpdate`].
This means that [replicon conditions](bevy_replicon::core::common_conditions) won't work in schedules
like [`Startup`]. As a workaround, you can directly check if renet's resources are present. This may be resolved
in the future once we have [observers for resources](https://github.com/bevyengine/bevy/issues/12231)
to immediately react to changes.
*/
pub use netcode;
pub use renet;
pub use steam;
use ;
use *;
use ;
use RepliconRenetClientPlugin;
use RepliconRenetServerPlugin;
/// Plugin group for all replicon plugins for renet.
///
/// Contains the following:
/// * [`RepliconRenetServerPlugin`] - with feature `server`.
/// * [`RepliconRenetClientPlugin`] - with feature `client`.
;
/// External trait for [`RepliconChannels`] to provide convenient conversion into renet channel configs.
/// Converts replicon channels into renet channel configs.