Skip to content

Commit

Permalink
Remove command throttle
Browse files Browse the repository at this point in the history
Shifts are now super cheap do not need it anymore.
  • Loading branch information
PetrGlad committed Nov 30, 2023
1 parent 9df67ae commit 0818896
Showing 1 changed file with 0 additions and 50 deletions.
50 changes: 0 additions & 50 deletions src/track_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@ use crate::track::{import_smf, Track};
use crate::util;
use crate::util::IdSeq;

#[derive(Debug)]
struct ActionThrottle {
timestamp: Instant,
// FIXME action_id: ActionId,
changeset: Changeset,
}

impl ActionThrottle {
pub fn is_waiting(&self, now: Instant) -> bool {
now - self.timestamp < Duration::from_millis(400)
}
}

// Undo/redo history and snapshots.
#[derive(Debug)]
pub struct TrackHistory {
Expand All @@ -35,7 +22,6 @@ pub struct TrackHistory {
pub version: VersionId,
pub max_version: VersionId, // May be higher than self.version after an undo.
pub directory: PathBuf,
throttle: Option<ActionThrottle>,
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -72,44 +58,9 @@ impl TrackHistory {
applied_command
};

// TODO (tokio, throttle, diff history) Reimplement throttling (batch sequences of repeatable
// heavy operations). Applying immediately for now.

self.update(applied_command);

// let now = Instant::now();
// if let Some(throttle) = &mut self.throttle {
// if action_id.is_some() && throttle.action_id == action_id && throttle.is_waiting(now) {
// throttle.changeset.merge(changeset);
// return;
// }
// let throttle = mem::replace(&mut self.throttle, None).unwrap();
// self.update(throttle.changeset);
// self.throttle = None;
// } else {
// self.throttle = Some(ActionThrottle {
// timestamp: now,
// action_id,
// changeset,
// });
// }
}

// TODO (tokio, throttle, diff history) Update throttle implementation.
// pub fn do_pending(&mut self) {
// // TODO (tokio) This is ugly (depending on rendering cycles is unpredictable),
// // just making it work for now. History may need some scheduled events.
// // To do this asynchronously one would need to put id behind an Arc<RwLock<>> or
// // use Tokio here (and in the engine).
// if let Some(throttle) = &self.throttle {
// if !throttle.is_waiting(Instant::now()) {
// let throttle = mem::replace(&mut self.throttle, None).unwrap();
// self.update(throttle.changeset);
// self.throttle = None;
// }
// }
// }

fn update(&mut self, applied_command: (EditCommandId, Vec<CommandDiff>)) {
let (command_id, diff) = applied_command;
if diff.is_empty() {
Expand Down Expand Up @@ -247,7 +198,6 @@ impl TrackHistory {
version: 0,
max_version: 0,
track: Default::default(),
throttle: None,
}
}

Expand Down

0 comments on commit 0818896

Please sign in to comment.