~starkingdoms/starkingdoms

ref: 5ccd4fb282fe3858f302b284a4d985d590ac79a4 starkingdoms/crates/unified/src/shared/plugins.rs -rw-r--r-- 2.5 KiB
5ccd4fb2ghostly_zsh feat: removed replicon + clientbound messages implemented, but untested 9 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use aeronet_transport::AeronetTransportPlugin;
use crate::shared::ecs::{CraftPartRequest, DragRequestEvent, TimeOffset, ToggleDrillEvent};
use crate::shared::net::register_net;
use crate::shared::thrust::ThrustSolution;
use bevy::app::{App, PluginGroup, PluginGroupBuilder};
use bevy::diagnostic::DiagnosticsPlugin;
use bevy::state::app::StatesPlugin;
use bevy_common_assets::toml::TomlAssetPlugin;
use crate::prelude::*;
use crate::shared::config::part::PartConfig;
use crate::shared::config::planet::PlanetConfigCollection;
use crate::shared::config::recipe::RecipesConfig;
use crate::shared::config::world::GlobalWorldConfig;
//use crate::shared::net::register_replication;
use crate::shared::world_config::world_config_plugin;

pub const TICK_RATE: f64 = 20.0;
const PHYSICS_LENGTH_UNIT: f64 = 100.0;

pub struct SharedPluginGroup;

impl PluginGroup for SharedPluginGroup {
    fn build(self) -> PluginGroupBuilder {
        PluginGroupBuilder::start::<Self>()
            .add(AssetPlugin::default())
            .add(StatesPlugin)
            .add(TransformPlugin)
            .add(DiagnosticsPlugin)
            .add(AeronetTransportPlugin)
            .add(|app: &mut App| {
                app.insert_resource(Time::from_hz(TICK_RATE));
                app.insert_resource(Time::<Physics>::default().with_relative_speed(1.0));
                app.insert_resource(TimeOffset::default());
            })
            .add_group(
                PhysicsPlugins::default()
                    .with_length_unit(PHYSICS_LENGTH_UNIT)
                    .set(PhysicsInterpolationPlugin::interpolate_all())
                    .build()
                    .disable::<IslandPlugin>()
            )
            .add(physics_setup_plugin)
            //.add(register_replication)
            .add(register_everything)
            .add(register_net)
            .add(world_config_plugin)

            /* Assets */
            .add(TomlAssetPlugin::<GlobalWorldConfig>::new(&["wc.toml"]))
            .add(TomlAssetPlugin::<PlanetConfigCollection>::new(&["pc.toml"]))
            .add(TomlAssetPlugin::<PartConfig>::new(&["part.toml"]))
            .add(TomlAssetPlugin::<RecipesConfig>::new(&["rc.toml"]))
    }
}

pub fn register_everything(app: &mut App) {
    app.add_message::<DragRequestEvent>();
    app.add_message::<ToggleDrillEvent>();
    app.add_message::<CraftPartRequest>();
    app.add_message::<ThrustSolution>();
}

fn physics_setup_plugin(app: &mut App) {
    app.insert_resource(Gravity::ZERO);
    app.add_systems(Startup, setup_physics);
}

fn setup_physics() {}