mirror of
https://github.com/kirjavascript/trueLMAO.git
synced 2024-06-02 19:47:21 -04:00
eframe web stuff
This commit is contained in:
parent
b92b282805
commit
9d4f9c44cb
32
emu/src/frame_timer.rs
Normal file
32
emu/src/frame_timer.rs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
pub mod debug;
|
pub mod debug;
|
||||||
|
pub mod frame_timer;
|
||||||
pub mod gfx;
|
pub mod gfx;
|
||||||
pub mod io;
|
pub mod io;
|
||||||
pub mod mem;
|
pub mod mem;
|
||||||
|
@ -8,7 +9,6 @@ pub mod z80;
|
||||||
|
|
||||||
use r68k_emu::cpu::{STACK_POINTER_REG, ConfiguredCore};
|
use r68k_emu::cpu::{STACK_POINTER_REG, ConfiguredCore};
|
||||||
use r68k_emu::interrupts::AutoInterruptController;
|
use r68k_emu::interrupts::AutoInterruptController;
|
||||||
use instant::Instant;
|
|
||||||
use gfx::Gfx;
|
use gfx::Gfx;
|
||||||
|
|
||||||
// TODO: composit layers in gfx istead of multiple buffers
|
// TODO: composit layers in gfx istead of multiple buffers
|
||||||
|
@ -24,44 +24,10 @@ use gfx::Gfx;
|
||||||
pub struct Megadrive {
|
pub struct Megadrive {
|
||||||
pub core: ConfiguredCore<AutoInterruptController, mem::Mem>,
|
pub core: ConfiguredCore<AutoInterruptController, mem::Mem>,
|
||||||
pub gfx: Gfx,
|
pub gfx: Gfx,
|
||||||
pub frame_timer: FrameTimer,
|
pub frame_timer: frame_timer::FrameTimer,
|
||||||
// version: NTSC/PAL
|
// 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 {
|
impl Megadrive {
|
||||||
pub fn new(buf: Vec<u8>) -> Self {
|
pub fn new(buf: Vec<u8>) -> Self {
|
||||||
let mem = mem::Mem::new(buf.into());
|
let mem = mem::Mem::new(buf.into());
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#![warn(clippy::all, rust_2018_idioms)]
|
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
mod debug;
|
mod debug;
|
||||||
mod input;
|
mod input;
|
||||||
mod widgets;
|
mod widgets;
|
||||||
pub use app::App;
|
pub use app::App;
|
||||||
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use eframe::wasm_bindgen::{self, prelude::*};
|
use eframe::wasm_bindgen::{self, prelude::*};
|
||||||
|
|
||||||
|
@ -22,5 +21,5 @@ pub fn start(canvas_id: &str) -> Result<(), eframe::wasm_bindgen::JsValue> {
|
||||||
canvas_id,
|
canvas_id,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Box::new(|cc| Box::new(App::new(cc)))
|
Box::new(|cc| Box::new(App::new(cc)))
|
||||||
)
|
).expect("eframe didnt load");
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
impl egui::Widget + 'a
|
||||||
{
|
{
|
||||||
move |ui: &mut egui::Ui| {
|
move |ui: &mut egui::Ui| {
|
||||||
egui::menu::bar(ui, |ui| {
|
egui::menu::bar(ui, |ui| {
|
||||||
ui.menu_button("File", |ui| {
|
ui.menu_button("File", |ui| {
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
if ui.button("Quit").clicked() {
|
if ui.button("Quit").clicked() {
|
||||||
frame.close();
|
_frame.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue