~starkingdoms/starkingdoms

ref: 7979969ad49f6317692813c1ce338a9e7eac00f5 starkingdoms/crates/unified/src/shared_plugins.rs -rw-r--r-- 2.6 KiB
7979969a — core test 21 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
69
70
71
72
73
74
75
76
77
use crate::attachment::{Joint, JointOf, PartInShip, Peer, Ship, SnapOf, SnapOfJoint};
use crate::config::planet::{Planet, PlanetConfigCollection};
use crate::ecs::{DragRequestEvent, Hi, Part, Particles, Player, PlayerStorage};
use bevy::app::{App, PluginGroup, PluginGroupBuilder};
use bevy_common_assets::toml::TomlAssetPlugin;
use crate::prelude::*;
use bevy_replicon::prelude::{AppRuleExt, Channel, ClientMessageAppExt};
use crate::config::part::PartConfig;
use crate::config::world::GlobalWorldConfig;
use crate::ecs::thruster::{Thruster, ThrusterOfPart};
use crate::physics::register_physics_components_for_replication;
use crate::thrust::ThrustSolution;

pub struct SharedPluginGroup;

impl PluginGroup for SharedPluginGroup {
    fn build(self) -> PluginGroupBuilder {
        PluginGroupBuilder::start::<Self>()
            .add_group(RepliconPlugins)
            //.add(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0))
            .add(physics_setup_plugin)
            .add(register_everything)
            .add(register_physics_components_for_replication)

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

pub fn register_everything(app: &mut App) {
    app.add_mapped_client_message::<ThrustSolution>(Channel::Ordered);
    app.add_mapped_client_message::<DragRequestEvent>(Channel::Ordered);
    app.add_mapped_server_message::<Hi>(Channel::Ordered);
    app.replicate::<Transform>();
    app.replicate::<GlobalTransform>();
    app.replicate::<Planet>();
    app.replicate::<Part>();
    app.replicate::<Player>();
    app.replicate::<Particles>();
    app.replicate::<ChildOf>();
    app.replicate::<Ship>();
    app.replicate::<PartInShip>();
    app.replicate::<Joint>();
    app.replicate::<Peer>();
    app.replicate::<JointOf>();
    app.replicate::<SnapOfJoint>();
    app.replicate::<SnapOf>();
    app.replicate::<PlayerStorage>();
    app.replicate::<Thruster>();
    app.replicate::<ThrusterOfPart>();
}

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

fn setup_physics(

) {

}

/*
fn setup_physics(
    mut rapier_config: Query<&mut RapierConfiguration>,
    mut rapier_context: Query<&mut RapierContextSimulation>,
) {
    let mut cfg = rapier_config.single_mut().unwrap();
    cfg.gravity = Vec2::ZERO;
    let ctx = rapier_context.single_mut().unwrap();
    let mut params = ctx.integration_parameters;
    params.num_internal_stabilization_iterations = 16;
}
*/