@@ -386,6 +386,9 @@ fn main() -> Result<(), Box<dyn Error>> {
386386 for tile in schematic. tiles ( ) . iter ( ) . progress ( ) {
387387 builder. add_schematic_tile ( tile) ?;
388388 }
389+
390+ println ! ( "Finalizing VM..." ) ;
391+
389392 let globals = LVar :: create_globals ( ) ;
390393 let vm = builder. build_with_globals ( Cow :: Borrowed ( & globals) ) ?;
391394
@@ -450,11 +453,12 @@ fn main() -> Result<(), Box<dyn Error>> {
450453 let mut frozen = false ;
451454 let mut ticks = 0 ;
452455 let mut start = Instant :: now ( ) ;
453- let mut next_state_update = Duration :: ZERO ;
456+ let mut next_state_update = start ;
454457 let state_update_interval = Duration :: from_secs_f64 ( 1. / 8. ) ;
455458
456459 loop {
457- let time = start. elapsed ( ) ;
460+ let now = Instant :: now ( ) ;
461+ let time = now - start;
458462 if !frozen {
459463 vm. do_tick ( time) ;
460464 ticks += 1 ;
@@ -474,15 +478,15 @@ fn main() -> Result<(), Box<dyn Error>> {
474478 }
475479 }
476480
477- if time >= next_state_update
481+ if now >= next_state_update
478482 && let BuildingData :: Switch ( power) = & mut * power_switch. data . borrow_mut ( )
479483 && let BuildingData :: Switch ( pause) = & mut * pause_switch. data . borrow_mut ( )
480484 && let BuildingData :: Switch ( single_step) = & mut * single_step_switch. data . borrow_mut ( )
481485 && let BuildingData :: Processor ( controller) = & mut * controller. data . borrow_mut ( )
482486 && let BuildingData :: Processor ( config) = & mut * config. data . borrow_mut ( )
483487 && let BuildingData :: Message ( error_output) = & * error_output. data . borrow ( )
484488 {
485- next_state_update = time + state_update_interval;
489+ next_state_update = now + state_update_interval;
486490
487491 // handle commands
488492 for cmd in rx_cmd. try_iter ( ) {
@@ -511,6 +515,7 @@ fn main() -> Result<(), Box<dyn Error>> {
511515 * pause = false ;
512516 * single_step = false ;
513517 start = Instant :: now ( ) ;
518+ next_state_update = start;
514519 }
515520 VMCommand :: SetBreakpoint ( Some ( value) ) => {
516521 config. set_variable ( "BREAKPOINT_ADDRESS" , value. into ( ) ) ?;
0 commit comments