@@ -61,12 +61,11 @@ impl LogicVM {
6161 /// Run the simulation until all processors halt, or until a number of ticks are finished.
6262 /// Returns true if all processors halted, or false if the tick limit was reached.
6363 pub fn run ( & self , max_ticks : Option < usize > ) -> bool {
64- let mut now = Instant :: now ( ) ;
64+ let start = Instant :: now ( ) ;
6565 let mut tick = 0 ;
6666
6767 loop {
68- self . do_tick ( now. elapsed ( ) ) ;
69- now = Instant :: now ( ) ;
68+ self . do_tick ( start. elapsed ( ) ) ;
7069
7170 if self . running_processors . get ( ) == 0 {
7271 // all processors finished, return true
@@ -85,10 +84,10 @@ impl LogicVM {
8584
8685 /// Execute one tick of the simulation.
8786 ///
88- /// Note: negative delta values will be ignored .
89- pub fn do_tick ( & self , delta : Duration ) {
87+ /// Note: `time` is the time elapsed since the *start* of the simulation .
88+ pub fn do_tick ( & self , time : Duration ) {
9089 // never move time backwards
91- let time = self . time . get ( ) + duration_millis_f64 ( delta ) . max ( 0. ) ;
90+ let time = duration_millis_f64 ( time ) ;
9291 self . time . set ( time) ;
9392
9493 for processor in self . iter_processors ( ) {
@@ -1839,25 +1838,29 @@ mod tests {
18391838 " ,
18401839 ) ;
18411840
1842- vm. do_tick ( Duration :: ZERO ) ;
1841+ let mut time = Duration :: ZERO ;
1842+ vm. do_tick ( time) ;
18431843
18441844 with_processor ( & mut vm, ( 0 , 0 ) , |p| {
18451845 assert_eq ! ( p. state. decode_printbuffer( ) , "123" ) ;
18461846 } ) ;
18471847
1848- vm. do_tick ( Duration :: from_secs_f64 ( 1. / 60. ) ) ;
1848+ time += Duration :: from_secs_f64 ( 1. / 60. ) ;
1849+ vm. do_tick ( time) ;
18491850
18501851 with_processor ( & mut vm, ( 0 , 0 ) , |p| {
18511852 assert_eq ! ( p. state. decode_printbuffer( ) , "1234" ) ;
18521853 } ) ;
18531854
1854- vm. do_tick ( Duration :: from_millis ( 500 ) ) ;
1855+ time += Duration :: from_millis ( 500 ) ;
1856+ vm. do_tick ( time) ;
18551857
18561858 with_processor ( & mut vm, ( 0 , 0 ) , |p| {
18571859 assert_eq ! ( p. state. decode_printbuffer( ) , "1234" ) ;
18581860 } ) ;
18591861
1860- vm. do_tick ( Duration :: from_millis ( 500 ) ) ;
1862+ time += Duration :: from_millis ( 500 ) ;
1863+ vm. do_tick ( time) ;
18611864
18621865 with_processor ( & mut vm, ( 0 , 0 ) , |p| {
18631866 assert_eq ! ( p. state. decode_printbuffer( ) , "12345" ) ;
@@ -2584,17 +2587,22 @@ mod tests {
25842587 " ,
25852588 ) ;
25862589
2587- vm. do_tick ( Duration :: ZERO ) ;
2588- vm. do_tick ( Duration :: ZERO ) ;
2590+ let mut time = Duration :: ZERO ;
25892591
2590- vm. do_tick ( Duration :: from_secs ( 1 ) ) ;
2591- vm. do_tick ( Duration :: ZERO ) ;
2592+ vm. do_tick ( time ) ;
2593+ vm. do_tick ( time ) ;
25922594
2593- vm. do_tick ( Duration :: from_millis ( 1 ) ) ;
2594- vm. do_tick ( Duration :: ZERO ) ;
2595+ time += Duration :: from_secs ( 1 ) ;
2596+ vm. do_tick ( time) ;
2597+ vm. do_tick ( time) ;
25952598
2596- vm. do_tick ( Duration :: from_secs ( 60 ) ) ;
2597- vm. do_tick ( Duration :: ZERO ) ;
2599+ time += Duration :: from_millis ( 1 ) ;
2600+ vm. do_tick ( time) ;
2601+ vm. do_tick ( time) ;
2602+
2603+ time += Duration :: from_secs ( 60 ) ;
2604+ vm. do_tick ( time) ;
2605+ vm. do_tick ( time) ;
25982606
25992607 let processor = take_processor ( & mut vm, ( 0 , 0 ) ) ;
26002608 assert_variables_epsilon (
0 commit comments