Caching update

- New invalidator: bomb dropped
- Reduce cache lifetime to 10 seconds (down from 3 minutes)
This commit is contained in:
Janek 2024-01-02 01:08:25 +01:00
parent dc7ff86c38
commit fbdec0f946
2 changed files with 11 additions and 1 deletions
radarflow/src/dma

@ -18,7 +18,7 @@ pub struct Cache {
impl Cache {
pub fn is_valid(&self) -> bool {
if self.valid {
if self.timestamp.elapsed() > std::time::Duration::from_secs(60 * 3) {
if self.timestamp.elapsed() > std::time::Duration::from_secs(10) {
log::info!("Invalidated cache! Reason: time");
return false
}

@ -19,6 +19,7 @@ pub async fn run(connector: Connector, pcileech_device: String, data_lock: Arc<R
let mut last_tickcount = -1;
let mut last_round = -1;
let mut last_gamephase = -1;
let mut last_bomb_dropped = false;
// Duration for a single tick on 128 ticks. I'm assuming 128 ticks because I don't fucking know how to read the current tickrate off cs2 memory lol
let target_interval = Duration::from_nanos(SECOND_AS_NANO / 128);
@ -128,6 +129,15 @@ pub async fn run(connector: Connector, pcileech_device: String, data_lock: Arc<R
continue;
}
let cur_bomb_dropped = cache.gamerules().bomb_dropped(&mut ctx)?;
if cur_bomb_dropped != last_bomb_dropped {
last_bomb_dropped = cur_bomb_dropped;
cache.invalidate();
log::info!("Invalidated cache! Reason: bomb drop status changed");
continue;
}
let cur_tickcount = cache.globals().tick_count(&mut ctx)?;
// New tick, now we want to fetch our data