rust/hwphysics/src/common.rs
changeset 15296 66c987015f2d
parent 15295 42b710b0f883
child 15302 8095853811a6
--- a/rust/hwphysics/src/common.rs	Thu Jul 25 22:31:24 2019 +0300
+++ b/rust/hwphysics/src/common.rs	Thu Jul 25 23:02:02 2019 +0300
@@ -1,8 +1,37 @@
-use std::{collections::BinaryHeap, num::NonZeroU16};
+use fpnum::{fp, FPNum};
+use std::{collections::BinaryHeap, num::NonZeroU16, ops::Add};
 
 pub type GearId = NonZeroU16;
 pub trait GearData {}
 
+#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)]
+pub struct Millis(u32);
+
+impl Millis {
+    #[inline]
+    pub fn new(value: u32) -> Self {
+        Self(value)
+    }
+
+    #[inline]
+    pub fn get(self) -> u32 {
+        self.0
+    }
+
+    #[inline]
+    pub fn to_fixed(self) -> FPNum {
+        FPNum::new(self.0 as i32, 1000)
+    }
+}
+
+impl Add for Millis {
+    type Output = Self;
+
+    fn add(self, rhs: Self) -> Self::Output {
+        Self(self.0 + rhs.0)
+    }
+}
+
 pub trait GearDataProcessor<T: GearData> {
     fn add(&mut self, gear_id: GearId, gear_data: T);
     fn remove(&mut self, gear_id: GearId);