mirror of
https://github.com/kirjavascript/trueLMAO.git
synced 2024-06-02 19:47:21 -04:00
moved frame_timer
This commit is contained in:
parent
7d4fffd5a5
commit
b92b282805
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -514,6 +514,7 @@ dependencies = [
|
||||||
name = "emu"
|
name = "emu"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"instant",
|
||||||
"r68k-emu",
|
"r68k-emu",
|
||||||
"r68k-tools",
|
"r68k-tools",
|
||||||
]
|
]
|
||||||
|
@ -652,7 +653,6 @@ dependencies = [
|
||||||
"eframe",
|
"eframe",
|
||||||
"egui",
|
"egui",
|
||||||
"emu",
|
"emu",
|
||||||
"instant",
|
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"tracing-wasm",
|
"tracing-wasm",
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,3 +6,4 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
r68k-emu = { git = "https://github.com/marhel/r68k.git" }
|
r68k-emu = { git = "https://github.com/marhel/r68k.git" }
|
||||||
r68k-tools = { git = "https://github.com/marhel/r68k.git" }
|
r68k-tools = { git = "https://github.com/marhel/r68k.git" }
|
||||||
|
instant = "0.1"
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
use r68k_emu::cpu::{STACK_POINTER_REG, ConfiguredCore};
|
|
||||||
use r68k_emu::interrupts::AutoInterruptController;
|
|
||||||
|
|
||||||
pub mod debug;
|
pub mod debug;
|
||||||
pub mod gfx;
|
pub mod gfx;
|
||||||
pub mod io;
|
pub mod io;
|
||||||
|
@ -9,6 +6,9 @@ pub mod rom;
|
||||||
pub mod vdp;
|
pub mod vdp;
|
||||||
pub mod z80;
|
pub mod z80;
|
||||||
|
|
||||||
|
use r68k_emu::cpu::{STACK_POINTER_REG, ConfiguredCore};
|
||||||
|
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,9 +24,44 @@ 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,
|
||||||
// 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());
|
||||||
|
@ -39,9 +74,24 @@ impl Megadrive {
|
||||||
Megadrive {
|
Megadrive {
|
||||||
core,
|
core,
|
||||||
gfx: Gfx::new(),
|
gfx: Gfx::new(),
|
||||||
|
frame_timer: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// render frame at current instant
|
||||||
|
pub fn render(&mut self) {
|
||||||
|
let frames_to_render = self.frame_timer.frames_to_render();
|
||||||
|
if frames_to_render > 3 { // magic number
|
||||||
|
self.frame(true);
|
||||||
|
} else if frames_to_render > 0 {
|
||||||
|
for _ in 0..frames_to_render - 1 {
|
||||||
|
self.frame(false);
|
||||||
|
}
|
||||||
|
self.frame(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// renders a single frame
|
||||||
pub fn frame(&mut self, draw: bool) {
|
pub fn frame(&mut self, draw: bool) {
|
||||||
/* cycle counts initially taken from drx/kiwi */
|
/* cycle counts initially taken from drx/kiwi */
|
||||||
// TODO: use a counter instead
|
// TODO: use a counter instead
|
||||||
|
|
|
@ -14,7 +14,6 @@ crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
emu = { path = "../emu" }
|
emu = { path = "../emu" }
|
||||||
instant = "0.1"
|
|
||||||
|
|
||||||
# puffin = "0.13.3"
|
# puffin = "0.13.3"
|
||||||
# puffin_egui = "0.15.0"
|
# puffin_egui = "0.15.0"
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
use emu::Megadrive;
|
use emu::Megadrive;
|
||||||
use crate::widgets;
|
use crate::widgets;
|
||||||
use instant::Instant;
|
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
emu: Megadrive,
|
emu: Megadrive,
|
||||||
debug: crate::debug::Debug,
|
debug: crate::debug::Debug,
|
||||||
game_state: FrameCounter,
|
|
||||||
pub fullscreen: bool,
|
pub fullscreen: bool,
|
||||||
pub vsync: bool,
|
pub vsync: bool,
|
||||||
pub running: bool,
|
pub running: bool,
|
||||||
|
@ -19,7 +17,6 @@ impl Default for App {
|
||||||
Self {
|
Self {
|
||||||
emu: Megadrive::new(buf),
|
emu: Megadrive::new(buf),
|
||||||
debug: Default::default(),
|
debug: Default::default(),
|
||||||
game_state: Default::default(),
|
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
vsync: false,
|
vsync: false,
|
||||||
running: true,
|
running: true,
|
||||||
|
@ -28,39 +25,6 @@ impl Default for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move to core
|
|
||||||
pub struct FrameCounter {
|
|
||||||
frames: u64,
|
|
||||||
epoch: Instant,
|
|
||||||
frames_to_render: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for FrameCounter {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
frames: 0,
|
|
||||||
frames_to_render: 0,
|
|
||||||
epoch: Instant::now(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FrameCounter {
|
|
||||||
/// returns frames to render
|
|
||||||
pub fn tick(&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 App {
|
impl App {
|
||||||
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||||
cc.egui_ctx.set_visuals(egui::Visuals {
|
cc.egui_ctx.set_visuals(egui::Visuals {
|
||||||
|
@ -99,16 +63,7 @@ impl eframe::App for App {
|
||||||
|
|
||||||
crate::input::dummy_input(ctx, &mut self.emu);
|
crate::input::dummy_input(ctx, &mut self.emu);
|
||||||
|
|
||||||
let frames_to_render = self.game_state.tick();
|
self.emu.render();
|
||||||
|
|
||||||
if frames_to_render > 3 {
|
|
||||||
self.emu.frame(true);
|
|
||||||
} else if frames_to_render > 0 {
|
|
||||||
for _ in 0..frames_to_render - 1 {
|
|
||||||
self.emu.frame(false);
|
|
||||||
}
|
|
||||||
self.emu.frame(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// layout starts with fullscreen
|
// layout starts with fullscreen
|
||||||
|
@ -150,7 +105,7 @@ impl eframe::App for App {
|
||||||
egui::warn_if_debug_build(ui);
|
egui::warn_if_debug_build(ui);
|
||||||
// ctx.inspection_ui(ui);
|
// ctx.inspection_ui(ui);
|
||||||
|
|
||||||
ui.label(&format!("MD frames this frame: {}", self.game_state.frames_to_render));
|
ui.label(&format!("MD frames this frame: {}", self.emu.frame_timer.frames_to_render));
|
||||||
ui.label(&format!("avg frames {:.1}", self.test_vec.iter().sum::<u64>() as f32 / self.test_vec.len() as f32));
|
ui.label(&format!("avg frames {:.1}", self.test_vec.iter().sum::<u64>() as f32 / self.test_vec.len() as f32));
|
||||||
|
|
||||||
if ui.button(if self.running { "pause" } else { "play" }).clicked() {
|
if ui.button(if self.running { "pause" } else { "play" }).clicked() {
|
||||||
|
@ -159,7 +114,7 @@ impl eframe::App for App {
|
||||||
ui.radio_value(&mut self.vsync, true, "vsync");
|
ui.radio_value(&mut self.vsync, true, "vsync");
|
||||||
ui.radio_value(&mut self.vsync, false, "not vsync");
|
ui.radio_value(&mut self.vsync, false, "not vsync");
|
||||||
|
|
||||||
self.test_vec.push_back(self.game_state.frames_to_render.min(4));
|
self.test_vec.push_back(self.emu.frame_timer.frames_to_render.min(4));
|
||||||
|
|
||||||
if self.test_vec.len() > 60 {
|
if self.test_vec.len() > 60 {
|
||||||
self.test_vec.pop_front();
|
self.test_vec.pop_front();
|
||||||
|
|
Loading…
Reference in a new issue