~starkingdoms/starkingdoms

ref: f08012977a1c1ad3c9195b18318ff811360bbaa7 starkingdoms/server/src/manager.rs -rw-r--r-- 2.8 KiB
f0801297 — c0repwn3r fix updates 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use std::collections::HashMap;
use std::net::SocketAddr;
use std::sync::Arc;
use rapier2d_f64::na::Vector2;
use rapier2d_f64::prelude::{IntegrationParameters, PhysicsPipeline, IslandManager, BroadPhase, NarrowPhase, ImpulseJointSet, MultibodyJointSet, CCDSolver, RigidBodySet, ColliderSet, RigidBodyHandle};
use async_std::sync::RwLock;
use async_std::channel::Sender;
use starkingdoms_protocol::api::APISavedPlayerData;
use starkingdoms_protocol::module::ModuleType;

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

#[derive(Clone)]
pub struct Player {
    pub handle: RigidBodyHandle,
    pub input: PlayerInput,
    pub addr: SocketAddr,
    pub auth_token: Option<String>,
    pub auth_user: Option<String>,
}

impl Player {
    pub fn as_api_data(&self) -> APISavedPlayerData {
        APISavedPlayerData {}
    }

    pub fn load_api_data(&mut self, _data: &APISavedPlayerData) {

    }
}

#[derive(Clone)]
pub struct Module {
    pub handle: RigidBodyHandle,
    pub module_type: ModuleType,
    pub lifetime: f64,
}

#[derive(Default, Clone)]
pub struct PlayerInput {
    pub up: bool,
    pub left: bool,
    pub right: bool,
    pub down: bool
}

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

#[derive(Clone, Default)]
pub struct PhysicsData {
    pub gravity: Vector2<f64>,
    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,
                           &(),
                           &()
                        );
    }
}

#[derive(Debug, Clone)]
pub enum ClientHandlerMessage {
    Tick,
    ChatMessage { from: String, message: String },
    PlayersUpdate { players: Vec<starkingdoms_protocol::player::Player> },
    PlanetData { planets: Vec<starkingdoms_protocol::planet::Planet> },
    ModulesUpdate { modules: Vec<starkingdoms_protocol::module::Module> },
}