airmash_protocol/types/units.rs
1use crate::types::Vector2;
2
3/// On-map distances.
4///
5/// While this vector can represent any distance or
6/// position that fits within the float, the range
7/// of coordinates on the map is limited to the
8/// ranges `[-16384, 16384]` for `x` coordiantes and
9/// `[-8192, 8192]` for `y` coordinates.
10pub type Distance = f32;
11/// Time unit. (1 unit of time ~= 16.667ms)
12///
13/// Usually you will want [`Duration`][0] instead
14/// of this. This unit is only relevant when doing
15/// physics calculations. An implementation of
16/// [`From`][1] is implemented to convert from
17/// [`Duration`s][0] when needed.
18///
19/// [0]: https://doc.rust-lang.org/std/time/struct.Duration.html
20/// [1]: https://doc.rust-lang.org/std/convert/trait.From.html
21pub type Time = f32;
22/// Health unit.
23///
24/// This is used to represent the health of all players.
25/// While this unit can represent any floating point
26/// value, the only values that are valid when sent to
27/// the client are in the range `[0, 1]`.
28pub type Health = f32;
29/// Energy unit.
30///
31/// Used to represent the energy of all players.
32/// While this unit can represent any floating point
33/// value, only values in the range `[0, 1]` are valid
34/// when sent to the client.
35pub type Energy = f32;
36/// Unit for rotations (in radians).
37///
38/// While this unit can represent any floating point
39/// value, only values in the range `[0, ~10)` will
40/// be sent properly to the client.
41pub type Rotation = f32;
42
43/// Unit of `Health / Time`.
44///
45/// Represents how fast a plane regenerates lost health.
46pub type HealthRegen = f32;
47/// Unit of `Energy / Time`.
48///
49/// Represents how fast a plane regenerates used energy.
50pub type EnergyRegen = f32;
51/// Unit of velocity: `Distance / Time`.
52///
53/// Represents how fast a plane is moving.
54pub type Speed = f32; // self::base::Speed<BaseType>;
55/// Unit of acceleration: `Distance / Time^2`.
56pub type AccelScalar = f32; // self::base::Accel<BaseType>;
57/// Unit of angular velocity: `Rotation / Time`.
58pub type RotationRate = f32;
59
60/// A 2D vector of [`Distance`]s.
61pub type Position = Vector2;
62/// A 2D vector of [`Speed`]s.
63pub type Velocity = Vector2;
64/// A 2D vector of [`AccelScalar`]s.
65pub type Accel = Vector2;