eframe web stuff

This commit is contained in:
kirjavascript 2022-10-05 00:19:18 +01:00
parent b92b282805
commit 9d4f9c44cb
4 changed files with 39 additions and 41 deletions

32
emu/src/frame_timer.rs Normal file
View file

@ -0,0 +1,32 @@
use instant::Instant;
pub struct FrameTimer {
pub frames_to_render: u64,
pub frames: u64,
pub epoch: Instant,
}
impl Default for FrameTimer {
fn default() -> Self {
Self {
frames: 0,
frames_to_render: 0,
epoch: Instant::now(),
}
}
}
impl FrameTimer {
pub fn frames_to_render(&mut self) -> u64 {
let diff = Instant::now().duration_since(self.epoch);
let frames = (diff.as_millis() as f64 * 0.05992274) as u64; // TODO: PAL
// self.emu.gfx.framerate()
self.frames_to_render = frames - self.frames;
self.frames = frames;
self.frames_to_render
}
/// use when unpausing
pub fn reset_epoch(&mut self) {
self.epoch = Instant::now();
}
}

View file

@ -1,4 +1,5 @@
pub mod debug;
pub mod frame_timer;
pub mod gfx;
pub mod io;
pub mod mem;
@ -8,7 +9,6 @@ pub mod z80;
use r68k_emu::cpu::{STACK_POINTER_REG, ConfiguredCore};
use r68k_emu::interrupts::AutoInterruptController;
use instant::Instant;
use gfx::Gfx;
// TODO: composit layers in gfx istead of multiple buffers
@ -24,44 +24,10 @@ use gfx::Gfx;
pub struct Megadrive {
pub core: ConfiguredCore<AutoInterruptController, mem::Mem>,
pub gfx: Gfx,
pub frame_timer: FrameTimer,
pub frame_timer: frame_timer::FrameTimer,
// version: NTSC/PAL
}
pub struct FrameTimer {
pub frames_to_render: u64,
pub frames: u64,
pub epoch: Instant,
}
impl Default for FrameTimer {
fn default() -> Self {
Self {
frames: 0,
frames_to_render: 0,
epoch: Instant::now(),
}
}
}
impl FrameTimer {
/// returns frames to render
pub fn frames_to_render(&mut self) -> u64 {
let diff = Instant::now().duration_since(self.epoch);
let frames = (diff.as_millis() as f64 * 0.05992274) as u64; // TODO: PAL
// self.emu.gfx.framerate()
self.frames_to_render = frames - self.frames;
self.frames = frames;
self.frames_to_render
}
/// for unpausing
pub fn reset_epoch(&mut self) {
self.epoch = Instant::now();
}
}
// impl default for gfx
impl Megadrive {
pub fn new(buf: Vec<u8>) -> Self {
let mem = mem::Mem::new(buf.into());

View file

@ -1,11 +1,10 @@
#![warn(clippy::all, rust_2018_idioms)]
mod app;
mod debug;
mod input;
mod widgets;
pub use app::App;
#[cfg(target_arch = "wasm32")]
use eframe::wasm_bindgen::{self, prelude::*};
@ -22,5 +21,5 @@ pub fn start(canvas_id: &str) -> Result<(), eframe::wasm_bindgen::JsValue> {
canvas_id,
Default::default(),
Box::new(|cc| Box::new(App::new(cc)))
)
).expect("eframe didnt load");
}

View file

@ -1,11 +1,12 @@
pub fn menu<'a>(fullscreen: &'a mut bool, frame: &'a mut eframe::Frame) ->
pub fn menu<'a>(fullscreen: &'a mut bool, _frame: &'a mut eframe::Frame) ->
impl egui::Widget + 'a
{
move |ui: &mut egui::Ui| {
egui::menu::bar(ui, |ui| {
ui.menu_button("File", |ui| {
#[cfg(not(target_arch = "wasm32"))]
if ui.button("Quit").clicked() {
frame.close();
_frame.close();
}
});