diff options
author | Ben Bridle <ben@derelict.engineering> | 2024-07-31 15:30:20 +1200 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2024-07-31 15:30:20 +1200 |
commit | 3ab32debad4fcfc73df7c60ea46df619ca60a579 (patch) | |
tree | 2f9054daffee31a13cc67e742aa34c6db4322119 /src | |
parent | c3ff1b843a486832b739803d113558d7ee7144c1 (diff) | |
download | bedrock-pc-3ab32debad4fcfc73df7c60ea46df619ca60a579.zip |
Improve frame-rate stability
Some frames would sporadically lag between on_process and on_render,
because on_process would bail once one frame had elapsed since the end
of the previous on_process, and the processor would not always reach a
sleep point in this time. This was really an issue to do with with the
time taken between the end of the previous on_process and the start of
the current on_process.
To fix this, the on_process invocation will run the processor for a full
frame, without subtracting the time elapsed between frames. This seems
to have no negative effects. It also allows us to remove end_of_process
from the emulator.
The sleep in the Signal::Sleep handler has also been removed, because
it serves no real purpose and will most likely cause issues in the
future.
Diffstat (limited to 'src')
-rw-r--r-- | src/emulator.rs | 11 |
1 files changed, 1 insertions, 10 deletions
diff --git a/src/emulator.rs b/src/emulator.rs index 195b8c8..b0f2d51 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -21,7 +21,6 @@ pub struct BedrockEmulator { sleeping: bool, pixel_scale: u32, start_of_process: Instant, - end_of_process: Instant, end_of_render: Instant, debug_mark: Instant, cycles_elapsed: usize, @@ -41,7 +40,6 @@ impl BedrockEmulator { sleeping: false, pixel_scale: 3, start_of_process: Instant::now(), - end_of_process: Instant::now(), end_of_render: Instant::now(), debug_mark: Instant::now(), cycles_elapsed: 0, @@ -208,7 +206,6 @@ impl WindowController for BedrockEmulator { // prevents the current frame from being overdrawn before rendering. if self.vm.dev.screen.dirty { sleep(FRAME); - self.end_of_process = Instant::now(); return; } // Ensure a minimum delay of FRAME between the start of consecutive @@ -221,13 +218,11 @@ impl WindowController for BedrockEmulator { None => time_to_frame_start, }; sleep(time_to_sleep); - self.end_of_process = Instant::now(); return; } // Stay asleep if there are no pending wake events. if !self.vm.dev.can_wake() { sleep(FRAME); - self.end_of_process = Instant::now(); return; } } @@ -235,7 +230,7 @@ impl WindowController for BedrockEmulator { // Run the processor for the remainder of the frame. self.start_of_process = Instant::now(); self.sleeping = false; - let frame_end = self.end_of_process + FRAME; + let frame_end = Instant::now() + FRAME; while Instant::now() < frame_end { if let Some(signal) = self.vm.evaluate(1000) { @@ -243,9 +238,6 @@ impl WindowController for BedrockEmulator { Signal::Debug(var) => self.debug(var), Signal::Sleep => { self.sleeping = true; - // Sleep for the remainer of the frame. - sleep(frame_end.duration_since(Instant::now())); - self.end_of_process = Instant::now(); break; }, Signal::Halt => { @@ -258,7 +250,6 @@ impl WindowController for BedrockEmulator { } self.vm.dev.stream.flush_local(); self.vm.dev.file.flush_entry(); - self.end_of_process = Instant::now(); } fn render_request(&mut self) -> RenderRequest { |