~starkingdoms/starkingdoms

ref: 042d48c0414586735443cef771cb1f227fa16461 starkingdoms/server/src/manager.rs -rw-r--r-- 2.0 KiB
042d48c0 — ghostlyzsh yay broken, player initialization 2 years 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
use std::collections::HashMap;

use std::net::SocketAddr;
use std::sync::Arc;

use rapier2d::na::{Vector3, Vector2};
use rapier2d::prelude::{IntegrationParameters, PhysicsPipeline, IslandManager, BroadPhase, NarrowPhase, ImpulseJointSet, MultibodyJointSet, CCDSolver, EventHandler, PhysicsHooks, RigidBodySet, ColliderSet, RigidBodyHandle};
use tokio::sync::mpsc::Sender;
use tokio::sync::RwLock;

#[derive(Clone)]
pub struct ClientManager {
    pub handlers: Arc<RwLock<HashMap<SocketAddr, ClientHandler>>>,
    pub usernames: Arc<RwLock<HashMap<SocketAddr, String>>>,
    pub players: Arc<RwLock<HashMap<SocketAddr, Player>>>
}

#[derive(Default)]
pub struct Player {
    pub handle: RigidBodyHandle
}

#[derive(Clone)]
pub struct ClientHandler {
    pub tx: Sender<ClientHandlerMessage>
}

#[derive(Clone, Default)]
pub struct PhysicsData {
    pub gravity: Vector2<f32>,
    pub integration_parameters: IntegrationParameters,
    pub island_manager: IslandManager,
    pub broad_phase: BroadPhase,
    pub narrow_phase: NarrowPhase,
    pub rigid_body_set: RigidBodySet,
    pub collider_set: ColliderSet,
    pub impulse_joint_set: ImpulseJointSet,
    pub multibody_joint_set: MultibodyJointSet,
    pub ccd_solver: CCDSolver,
}
impl PhysicsData {
    pub fn tick(&mut self, pipeline: &mut PhysicsPipeline) {
        pipeline.step(&self.gravity,
                           &self.integration_parameters,
                           &mut self.island_manager,
                           &mut self.broad_phase,
                           &mut self.narrow_phase,
                           &mut self.rigid_body_set,
                           &mut self.collider_set,
                           &mut self.impulse_joint_set,
                           &mut self.multibody_joint_set,
                           &mut self.ccd_solver,
                           None,
                           &(),
                           &()
                        );
    }
}

pub enum ClientHandlerMessage {
    Tick,
    ChatMessage { from: String, message: String }
}