diff options
author | Daniel Schadt <kingdread@gmx.de> | 2018-07-07 03:23:25 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2018-07-07 03:23:25 +0200 |
commit | 22051473844bddb60c8c062f511fd4b1f90d48bd (patch) | |
tree | 8001a9ff97ae7d065c2e6c56cf5fe5a98d44e6b4 /src/statistics/mechanics.rs | |
parent | 4ea1d4f3e5082925874a271d14cc143ebf80912f (diff) | |
download | evtclib-22051473844bddb60c8c062f511fd4b1f90d48bd.tar.gz evtclib-22051473844bddb60c8c062f511fd4b1f90d48bd.tar.bz2 evtclib-22051473844bddb60c8c062f511fd4b1f90d48bd.zip |
base for mechanic tracking
Diffstat (limited to 'src/statistics/mechanics.rs')
-rw-r--r-- | src/statistics/mechanics.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/statistics/mechanics.rs b/src/statistics/mechanics.rs new file mode 100644 index 0000000..5a16204 --- /dev/null +++ b/src/statistics/mechanics.rs @@ -0,0 +1,42 @@ +use super::gamedata::Mechanic; +use super::math::{Monoid, RecordFunc, Semigroup}; + +use std::fmt; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct Counter(u32); + +impl Semigroup for Counter { + #[inline] + fn combine(&self, other: &Counter) -> Counter { + Counter(self.0 + other.0) + } +} + +impl Monoid for Counter { + #[inline] + fn mempty() -> Counter { + Counter(0) + } +} + +#[derive(Clone, Default)] +pub struct MechanicLog { + inner: RecordFunc<u64, (&'static Mechanic, u64), Counter>, +} + +impl MechanicLog { + pub fn increase(&mut self, time: u64, mechanic: &'static Mechanic, agent: u64) { + self.inner.insert(time, (mechanic, agent), Counter(1)); + } + + pub fn count<F: FnMut(&'static Mechanic, u64) -> bool>(&self, mut filter: F) -> u32 { + self.inner.tally_only(|(a, b)| filter(a, *b)).0 + } +} + +impl fmt::Debug for MechanicLog { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "MechanicLog {{ ... }}") + } +} |