Skip to content

Commit

Permalink
added history
Browse files Browse the repository at this point in the history
  • Loading branch information
Spooky-Firefox committed Sep 11, 2024
1 parent 616bfef commit 0b624ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ pub struct Simulator {
pub(crate) halt_on_warning: bool,
// says if simulation is running, halted, stopped or stepping to a specific cycle
pub running_state: RunningState,
pub running_state_history: Vec<RunningState>,
// stores if components return a condition
// TODO add component condition history
pub component_condition: Vec<(Id, Condition)>,
pub component_condition_history: Vec<Vec<(Id, Condition)>>,

// Used to determine active components
pub sinks: Vec<Id>,
Expand Down
14 changes: 14 additions & 0 deletions src/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ impl Simulator {
sinks,
inputs_read: HashMap::new(),
active: HashSet::new(),
running_state_history: vec![],
component_condition_history: vec![],
};

trace!("sim_state {:?}", simulator.sim_state);
Expand Down Expand Up @@ -293,6 +295,9 @@ impl Simulator {
.push((self.sim_state.clone(), self.active.clone()));
trace!("cycle:{}", self.cycle);

self.component_condition_history
.push(self.component_condition.clone());
self.running_state_history.push(self.running_state.clone());
self.clean_active();

// clear component condition data for this new cycle
Expand Down Expand Up @@ -439,6 +444,13 @@ impl Simulator {
self.cycle = self.history.len();
// TODO add component_condition history pop

self.component_condition = self.component_condition_history.pop().unwrap();
match self.running_state_history.pop().unwrap() {
RunningState::Halt => self.running_state = RunningState::Halt,
RunningState::Err => self.running_state = RunningState::Err,
_ => self.running_state = RunningState::Stopped,
};

for component in self.ordered_components.clone() {
component.un_clock();
}
Expand All @@ -452,6 +464,8 @@ impl Simulator {
self.history = vec![];
self.cycle = 0;
self.running_state = RunningState::Stopped;
self.component_condition_history = vec![];
self.running_state_history = vec![];
let _ = self.stop();

self.sim_state.iter_mut().for_each(|val| *val = 0.into());
Expand Down

0 comments on commit 0b624ec

Please sign in to comment.