2021-05-05 13:54:24 +00:00
|
|
|
use crate::comp::Pos;
|
2020-12-01 00:28:00 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-03-13 22:15:19 +00:00
|
|
|
use specs::Entity;
|
2020-12-01 00:28:00 +00:00
|
|
|
|
|
|
|
/// A resource that stores the time of day.
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, Default)]
|
|
|
|
pub struct TimeOfDay(pub f64);
|
|
|
|
|
|
|
|
/// A resource that stores the tick (i.e: physics) time.
|
|
|
|
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
|
|
|
|
pub struct Time(pub f64);
|
|
|
|
|
|
|
|
/// A resource that stores the time since the previous tick.
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct DeltaTime(pub f32);
|
2020-12-13 12:27:48 +00:00
|
|
|
|
2021-05-05 13:54:24 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct EntitiesDiedLastTick(pub Vec<(Entity, Pos)>);
|
|
|
|
|
2020-12-13 12:27:48 +00:00
|
|
|
/// A resource that indicates what mode the local game is being played in.
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
|
|
|
pub enum GameMode {
|
2020-12-13 17:40:15 +00:00
|
|
|
/// The game is being played in server mode (i.e: the code is running
|
|
|
|
/// server-side)
|
2020-12-13 12:27:48 +00:00
|
|
|
Server,
|
2020-12-13 17:40:15 +00:00
|
|
|
/// The game is being played in client mode (i.e: the code is running
|
|
|
|
/// client-side)
|
2020-12-13 12:27:48 +00:00
|
|
|
Client,
|
2020-12-13 17:40:15 +00:00
|
|
|
/// The game is being played in singleplayer mode (i.e: both client and
|
|
|
|
/// server at once)
|
2020-12-13 12:27:48 +00:00
|
|
|
// To be used later when we no longer start up an entirely new server for singleplayer
|
|
|
|
Singleplayer,
|
|
|
|
}
|
2021-03-13 22:15:19 +00:00
|
|
|
|
|
|
|
/// A resource that stores the player's entity (on the client), and None on the
|
|
|
|
/// server
|
|
|
|
#[derive(Copy, Clone, Default, Debug)]
|
|
|
|
pub struct PlayerEntity(pub Option<Entity>);
|
2021-04-14 19:51:03 +00:00
|
|
|
|
2021-04-15 18:24:20 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2021-04-14 19:51:03 +00:00
|
|
|
pub struct PlayerPhysicsSetting {
|
|
|
|
/// true if the client wants server-authoratative physics (e.g. to use
|
|
|
|
/// airships properly)
|
|
|
|
pub client_optin: bool,
|
|
|
|
/// true if the server is forcing server-authoratative physics (e.g. as
|
|
|
|
/// punishment for wallhacking)
|
2021-04-15 18:24:20 +00:00
|
|
|
pub server_force: bool,
|
2021-04-14 19:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for PlayerPhysicsSetting {
|
|
|
|
fn default() -> PlayerPhysicsSetting {
|
|
|
|
PlayerPhysicsSetting {
|
|
|
|
client_optin: false,
|
2021-04-15 18:24:20 +00:00
|
|
|
server_force: false,
|
2021-04-14 19:51:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PlayerPhysicsSetting {
|
2021-04-15 18:24:20 +00:00
|
|
|
pub fn server_authoritative(&self) -> bool { self.client_optin || self.server_force }
|
2021-04-14 19:51:03 +00:00
|
|
|
|
|
|
|
pub fn client_authoritative(&self) -> bool { !self.server_authoritative() }
|
|
|
|
}
|
|
|
|
|
|
|
|
/// List of which players are using client-authoratative vs server-authoratative
|
|
|
|
/// physics, as a stop-gap until we can use server-authoratative physics for
|
|
|
|
/// everyone
|
|
|
|
#[derive(Clone, Default, Debug)]
|
|
|
|
pub struct PlayerPhysicsSettings {
|
|
|
|
pub settings: hashbrown::HashMap<uuid::Uuid, PlayerPhysicsSetting>,
|
|
|
|
}
|