~starkingdoms/starkingdoms

ref: 71ade52ef032a59f7fc96e236eefa00dbc6285d7 starkingdoms/crates/unified/src/server_plugins.rs -rw-r--r-- 1.9 KiB
71ade52eghostly_zsh even better animation 28 days ago
                                                                                
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
use crate::config::part::PartConfig;
use crate::config::planet::PlanetConfigCollection;
use crate::config::world::GlobalWorldConfig;
use aeronet_replicon::server::AeronetRepliconServerPlugin;
use aeronet_websocket::server::WebSocketServerPlugin;
use avian2d::prelude::PhysicsInterpolationPlugin;
use bevy::app::{PluginGroup, PluginGroupBuilder, ScheduleRunnerPlugin, TaskPoolPlugin};
use bevy::asset::AssetPlugin;
use bevy::diagnostic::FrameCountPlugin;
use bevy::time::TimePlugin;
use bevy_common_assets::toml::TomlAssetPlugin;
use bevy_replicon::RepliconPlugins;
use std::net::SocketAddr;
use std::time::Duration;
use avian2d::PhysicsPlugins;
use bevy::state::app::StatesPlugin;

pub struct ServerPluginGroup {
    pub bind: SocketAddr,
    pub tick_rate: f32,
    pub max_clients: usize,
}
impl PluginGroup for ServerPluginGroup {
    fn build(self) -> PluginGroupBuilder {
        PluginGroupBuilder::start::<Self>()
            .add_group(
                PhysicsPlugins::default()
                    .with_length_unit(100.0)
                    .set(PhysicsInterpolationPlugin::interpolate_all())
            )
            .add(StatesPlugin)
            .add(TaskPoolPlugin::default())
            .add(FrameCountPlugin)
            .add(TimePlugin)
            .add(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f32(
                1.0 / self.tick_rate,
            )))
            .add_group(RepliconPlugins)
            .add(WebSocketServerPlugin)
            .add(AeronetRepliconServerPlugin)
            /* Assets */
            .add(AssetPlugin::default())
            .add(TomlAssetPlugin::<GlobalWorldConfig>::new(&["wc.toml"]))
            .add(TomlAssetPlugin::<PlanetConfigCollection>::new(&["pc.toml"]))
            .add(TomlAssetPlugin::<PartConfig>::new(&["part.toml"]))
            .add(crate::server::ServerPlugin {
                bind: self.bind,
                max_clients: self.max_clients,
            })
    }
}