~starkingdoms/starkingdoms

ref: 8c951740367d5a236bfa4115017155da9257cf49 starkingdoms/crates/unified/src/shared_plugins.rs -rw-r--r-- 1.8 KiB
8c951740 — core fix: attachment joint child entities causing `GlobalTransform` to be reset after a frame 5 months 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
use crate::attachment::{Joint, JointOf, SnapOfJoint, PartInShip, Peer, Ship, SnapOf};
use crate::config::planet::Planet;
use crate::ecs::{DragRequestEvent, Part, Particles, Player, ThrustEvent};
use bevy::app::{App, PluginGroup, PluginGroupBuilder};
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
use bevy_replicon::prelude::{AppRuleExt, Channel, ClientEventAppExt};

pub struct SharedPluginGroup;

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

pub fn register_everything(app: &mut App) {
    app.add_client_event::<ThrustEvent>(Channel::Ordered)
        .add_mapped_client_event::<DragRequestEvent>(Channel::Ordered)
        .replicate::<Transform>()
        .replicate::<GlobalTransform>()
        .replicate::<Collider>()
        .replicate::<RigidBody>()
        .replicate::<Planet>()
        .replicate::<Part>()
        .replicate::<Player>()
        .replicate::<Particles>()
        .replicate::<ChildOf>()
        .replicate::<Ship>()
        .replicate::<PartInShip>()
        .replicate::<Joint>()
        .replicate::<Peer>()
        .replicate::<JointOf>()
        .replicate::<SnapOfJoint>()
        .replicate::<SnapOf>();
}

fn physics_setup_plugin(app: &mut App) {
    app.add_systems(Startup, 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;
}