mirror of
https://github.com/transistorfet/moa.git
synced 2025-01-23 08:32:36 +00:00
Rearranged minifb frontend to reduce the binary-specific code
This commit is contained in:
parent
1938fcc78c
commit
6cc9e98e35
@ -1,43 +1,9 @@
|
||||
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use moa::machines::genesis::build_genesis;
|
||||
use moa_minifb::MiniFrontendBuilder;
|
||||
use moa_minifb::{run_inline, run_threaded};
|
||||
|
||||
fn main() {
|
||||
/*
|
||||
let mut frontend = Arc::new(Mutex::new(MiniFrontendBuilder::new()));
|
||||
|
||||
{
|
||||
let frontend = frontend.clone();
|
||||
thread::spawn(move || {
|
||||
let mut system = build_genesis(&mut *(frontend.lock().unwrap())).unwrap();
|
||||
frontend.lock().unwrap().finalize();
|
||||
system.run_loop();
|
||||
});
|
||||
}
|
||||
|
||||
wait_until_initialized(frontend.clone());
|
||||
|
||||
frontend
|
||||
.lock().unwrap()
|
||||
.build()
|
||||
.start(None);
|
||||
*/
|
||||
|
||||
let mut frontend = MiniFrontendBuilder::new();
|
||||
let mut system = build_genesis(&mut frontend).unwrap();
|
||||
|
||||
frontend
|
||||
.build()
|
||||
.start(Some(system));
|
||||
}
|
||||
|
||||
fn wait_until_initialized(frontend: Arc<Mutex<MiniFrontendBuilder>>) {
|
||||
while frontend.lock().unwrap().finalized == false {
|
||||
thread::sleep(Duration::from_millis(10));
|
||||
}
|
||||
//run_inline(build_genesis);
|
||||
run_threaded(build_genesis);
|
||||
}
|
||||
|
||||
|
@ -1,43 +1,9 @@
|
||||
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use moa::machines::trs80::build_trs80;
|
||||
use moa_minifb::MiniFrontendBuilder;
|
||||
use moa_minifb::{run_inline, run_threaded};
|
||||
|
||||
fn main() {
|
||||
/*
|
||||
let mut frontend = Arc::new(Mutex::new(MiniFrontendBuilder::new()));
|
||||
|
||||
{
|
||||
let frontend = frontend.clone();
|
||||
thread::spawn(move || {
|
||||
let mut system = build_trs80(&mut *(frontend.lock().unwrap())).unwrap();
|
||||
frontend.lock().unwrap().finalize();
|
||||
system.run_loop();
|
||||
});
|
||||
}
|
||||
|
||||
wait_until_initialized(frontend.clone());
|
||||
|
||||
frontend
|
||||
.lock().unwrap()
|
||||
.build()
|
||||
.start(None);
|
||||
*/
|
||||
|
||||
let mut frontend = MiniFrontendBuilder::new();
|
||||
let mut system = build_trs80(&mut frontend).unwrap();
|
||||
|
||||
frontend
|
||||
.build()
|
||||
.start(Some(system));
|
||||
}
|
||||
|
||||
fn wait_until_initialized(frontend: Arc<Mutex<MiniFrontendBuilder>>) {
|
||||
while frontend.lock().unwrap().finalized == false {
|
||||
thread::sleep(Duration::from_millis(10));
|
||||
}
|
||||
//run_inline(build_trs80);
|
||||
run_threaded(build_trs80);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
mod keys;
|
||||
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
@ -13,8 +14,11 @@ use moa::host::traits::{Host, JoystickDevice, JoystickUpdater, KeyboardUpdater,
|
||||
use crate::keys::map_key;
|
||||
|
||||
|
||||
const WIDTH: usize = 320;
|
||||
const HEIGHT: usize = 224;
|
||||
//const WIDTH: usize = 320;
|
||||
//const HEIGHT: usize = 224;
|
||||
|
||||
const WIDTH: usize = 384;
|
||||
const HEIGHT: usize = 128;
|
||||
|
||||
pub struct MiniFrontendBuilder {
|
||||
pub window: Option<Box<dyn WindowUpdater>>,
|
||||
@ -118,7 +122,7 @@ impl MiniFrontend {
|
||||
if let Some(keys) = window.get_keys_pressed(minifb::KeyRepeat::Yes) {
|
||||
let mut modifiers: u16 = 0;
|
||||
for key in keys {
|
||||
if let Some(mut updater) = self.keyboard.as_mut() {
|
||||
if let Some(updater) = self.keyboard.as_mut() {
|
||||
updater.update_keyboard(map_key(key), true);
|
||||
}
|
||||
match key {
|
||||
@ -127,19 +131,19 @@ impl MiniFrontend {
|
||||
_ => { },
|
||||
}
|
||||
}
|
||||
if let Some(mut updater) = self.joystick.as_mut() {
|
||||
if let Some(updater) = self.joystick.as_mut() {
|
||||
updater.update_joystick(modifiers);
|
||||
}
|
||||
}
|
||||
if let Some(keys) = window.get_keys_released() {
|
||||
for key in keys {
|
||||
if let Some(mut updater) = self.keyboard.as_mut() {
|
||||
if let Some(updater) = self.keyboard.as_mut() {
|
||||
updater.update_keyboard(map_key(key), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(mut updater) = self.window.as_mut() {
|
||||
if let Some(updater) = self.window.as_mut() {
|
||||
updater.update_frame(WIDTH as u32, HEIGHT as u32, &mut self.buffer);
|
||||
window.update_with_buffer(&self.buffer, WIDTH, HEIGHT).unwrap();
|
||||
}
|
||||
@ -147,3 +151,40 @@ impl MiniFrontend {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn run_inline<I>(init: I) where I: FnOnce(&mut MiniFrontendBuilder) -> Result<System, Error> {
|
||||
let mut frontend = MiniFrontendBuilder::new();
|
||||
let system = init(&mut frontend).unwrap();
|
||||
|
||||
frontend
|
||||
.build()
|
||||
.start(Some(system));
|
||||
}
|
||||
|
||||
pub fn run_threaded<I>(init: I) where I: FnOnce(&mut MiniFrontendBuilder) -> Result<System, Error> + Send + 'static {
|
||||
let frontend = Arc::new(Mutex::new(MiniFrontendBuilder::new()));
|
||||
|
||||
{
|
||||
let frontend = frontend.clone();
|
||||
thread::spawn(move || {
|
||||
let mut system = init(&mut *(frontend.lock().unwrap())).unwrap();
|
||||
frontend.lock().unwrap().finalize();
|
||||
system.run_loop();
|
||||
});
|
||||
}
|
||||
|
||||
wait_until_initialized(frontend.clone());
|
||||
|
||||
frontend
|
||||
.lock().unwrap()
|
||||
.build()
|
||||
.start(None);
|
||||
}
|
||||
|
||||
fn wait_until_initialized(frontend: Arc<Mutex<MiniFrontendBuilder>>) {
|
||||
while frontend.lock().unwrap().finalized == false {
|
||||
thread::sleep(Duration::from_millis(10));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user