aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/trackers.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2018-04-27 13:22:29 +0200
committerDaniel Schadt <kingdread@gmx.de>2018-04-27 13:22:29 +0200
commit1fe2fde9604db53e57996648d6d8627480391bab (patch)
treecdf77eaa1b45795b00b75ce5b1e1d52b0259be17 /src/statistics/trackers.rs
parent8423b0c401a484314241391f2f78d129eef704c4 (diff)
downloadevtclib-1fe2fde9604db53e57996648d6d8627480391bab.tar.gz
evtclib-1fe2fde9604db53e57996648d6d8627480391bab.tar.bz2
evtclib-1fe2fde9604db53e57996648d6d8627480391bab.zip
speed up boon calculation
This prevents calling BoonQueue::simulate a lot of times. Still needs more profiling to make it even faster.
Diffstat (limited to 'src/statistics/trackers.rs')
-rw-r--r--src/statistics/trackers.rs22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/statistics/trackers.rs b/src/statistics/trackers.rs
index d80c5ee..9b8d633 100644
--- a/src/statistics/trackers.rs
+++ b/src/statistics/trackers.rs
@@ -233,6 +233,7 @@ pub struct BoonTracker {
boon_areas: HashMap<u64, HashMap<u16, u64>>,
boon_queues: HashMap<u64, HashMap<u16, BoonQueue>>,
last_time: u64,
+ next_update: u64,
}
impl BoonTracker {
@@ -279,6 +280,17 @@ impl BoonTracker {
}
}
+ fn update_next_update(&mut self) {
+ let next_update = self.boon_queues
+ .values()
+ .flat_map(HashMap::values)
+ .map(BoonQueue::next_update)
+ .filter(|v| *v != 0)
+ .min()
+ .unwrap_or(0);
+ self.next_update = next_update;
+ }
+
/// Get the boon queue for the given agent and buff_id.
///
/// If the queue does not yet exist, create it.
@@ -302,9 +314,12 @@ impl Tracker for BoonTracker {
fn feed(&mut self, event: &Event) -> Result<(), Self::Error> {
let delta_t = event.time - self.last_time;
- self.update_queues(delta_t);
- self.update_areas(delta_t);
- self.last_time = event.time;
+ if self.next_update != 0 && delta_t > self.next_update {
+ self.update_queues(delta_t);
+ self.update_areas(delta_t);
+ self.update_next_update();
+ self.last_time = event.time;
+ }
match event.kind {
EventKind::BuffApplication {
@@ -315,6 +330,7 @@ impl Tracker for BoonTracker {
} => {
self.get_queue(destination_agent_addr, buff_id)
.add_stack(duration as u64);
+ self.update_next_update();
}
_ => (),