Skip to content

Commit

Permalink
Caching update
Browse files Browse the repository at this point in the history
- New invalidator: bomb dropped
- Reduce cache lifetime to 10 seconds (down from 3 minutes)
  • Loading branch information
superyu1337 committed Jan 2, 2024
1 parent dc7ff86 commit fbdec0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion radarflow/src/dma/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions radarflow/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fbdec0f

Please sign in to comment.