veloren_common/
resources.rs1use crate::{comp::Pos, shared_server_config::ServerConstants};
2use serde::{Deserialize, Serialize};
3use specs::Entity;
4use std::ops::{Mul, MulAssign};
5use vek::Vec3;
6
7#[derive(Copy, Clone, Debug, Serialize, Deserialize, Default)]
9pub struct TimeOfDay(pub f64);
10impl TimeOfDay {
11 pub fn new(t: f64) -> Self { TimeOfDay(t) }
12
13 fn get_angle_rad(self) -> f32 {
14 const TIME_FACTOR: f64 = (std::f64::consts::PI * 2.0) / (3600.0 * 24.0);
15 ((self.0 * TIME_FACTOR) % (std::f64::consts::PI * 2.0)) as f32
16 }
17
18 pub fn get_sun_dir(self) -> Vec3<f32> {
20 let angle_rad = self.get_angle_rad();
21 Vec3::new(-angle_rad.sin(), 0.0, angle_rad.cos())
22 }
23
24 pub fn get_moon_dir(self) -> Vec3<f32> {
26 let angle_rad = self.get_angle_rad();
27 -Vec3::new(-angle_rad.sin(), 0.0, angle_rad.cos() - 0.5).normalized()
28 }
29}
30
31impl TimeOfDay {
32 pub fn day(&self) -> f64 { self.0.rem_euclid(24.0 * 3600.0) }
33}
34
35#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, PartialOrd)]
37pub struct Time(pub f64);
38
39impl Time {
40 pub fn add_seconds(self, seconds: f64) -> Self { Self(self.0 + seconds) }
41
42 pub fn add_minutes(self, minutes: f64) -> Self { Self(self.0 + minutes * 60.0) }
43
44 pub fn add_days(self, days: f64, server_constants: &ServerConstants) -> Self {
47 self.add_seconds(days * 3600.0 * 24.0 / server_constants.day_cycle_coefficient)
48 }
49}
50
51#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
53pub struct ProgramTime(pub f64);
54
55#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
56pub struct TimeScale(pub f64);
57
58impl Default for TimeScale {
59 fn default() -> Self { Self(1.0) }
60}
61
62#[derive(Default)]
64pub struct DeltaTime(pub f32);
65
66#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
68#[serde(transparent)]
69pub struct Secs(pub f64);
70
71impl Mul<f64> for Secs {
72 type Output = Self;
73
74 fn mul(self, mult: f64) -> Self { Self(self.0 * mult) }
75}
76impl MulAssign<f64> for Secs {
77 fn mul_assign(&mut self, mult: f64) { *self = *self * mult; }
78}
79
80#[derive(Default)]
81pub struct EntitiesDiedLastTick(pub Vec<(Entity, Pos)>);
82
83#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
85pub enum GameMode {
86 Server,
89 Client,
92 Singleplayer,
96}
97
98#[derive(Copy, Clone, Default, Debug)]
101pub struct PlayerEntity(pub Option<Entity>);
102
103#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
104pub struct PlayerPhysicsSetting {
105 pub client_optin: bool,
108}
109
110impl PlayerPhysicsSetting {
111 pub fn server_authoritative_physics_optin(&self) -> bool { self.client_optin }
117}
118
119#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, enum_map::Enum)]
121pub enum MapKind {
122 Square,
124 Circle,
126}
127
128impl std::fmt::Display for MapKind {
129 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
130 match self {
131 MapKind::Square => f.write_str("Square"),
132 MapKind::Circle => f.write_str("Circle"),
133 }
134 }
135}
136
137#[derive(Clone, Default, Debug)]
141pub struct PlayerPhysicsSettings {
142 pub settings: hashbrown::HashMap<uuid::Uuid, PlayerPhysicsSetting>,
143}
144
145#[derive(PartialEq, Eq, Copy, Clone, Debug, Deserialize, Serialize)]
150pub enum BattleMode {
151 PvP,
152 PvE,
153}