[???] Lots of work
Cleanup un-needed elements, simplify memory management
This commit is contained in:
@@ -1,18 +1,53 @@
|
||||
use std::cell::Ref;
|
||||
use std::fmt::Debug;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use sdl2::render::{Canvas, WindowCanvas};
|
||||
use crate::emu::graphics::{DEVICE_FRAMEBUFFER_SIZE, GraphicsProcessor};
|
||||
use crate::graphics::color::Color;
|
||||
use crate::misc::emulator_error::EmulatorError;
|
||||
use crate::misc::result::EmulatorResult;
|
||||
|
||||
pub trait GraphicsAdapter: Debug {
|
||||
fn draw(&self, frame_buf: Ref<Box<[u8; 65536]>>) -> EmulatorResult<()>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SDLGraphicsAdapter<'a> {
|
||||
pub graphics_processor: &'a GraphicsProcessor<'a>
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SDLGraphicsAdapter {
|
||||
}
|
||||
|
||||
impl GraphicsAdapter for SDLGraphicsAdapter {
|
||||
fn draw(&self, frame_buffer: Ref<Box<[u8; 65536]>>) -> EmulatorResult<()> {
|
||||
todo!()
|
||||
impl <'a> Debug for SDLGraphicsAdapter<'a> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str("SDL2 adapter")
|
||||
}
|
||||
}
|
||||
|
||||
impl <'a> SDLGraphicsAdapter<'a> {
|
||||
pub fn new(graphics_processor: &'a GraphicsProcessor)->SDLGraphicsAdapter<'a>{
|
||||
SDLGraphicsAdapter{
|
||||
graphics_processor
|
||||
}
|
||||
}
|
||||
pub fn draw(&self, canvas:&mut WindowCanvas) -> EmulatorResult<()> {
|
||||
let mut canvas_ref = &canvas;
|
||||
let fb = self.graphics_processor.get_framebuffer();
|
||||
for i in 0..fb.len() {
|
||||
let i = i as u32;
|
||||
let y_coord = i&0xff00;
|
||||
let x_coord = i&0x00ff;
|
||||
|
||||
}
|
||||
let xyc = fb.iter().enumerate().map(|(i,e)| {
|
||||
let i = i as u32;
|
||||
let y_coord = i&0xff00;
|
||||
let x_coord = i&0x00ff;
|
||||
let color = Color::new(*e);
|
||||
(x_coord,y_coord,color)
|
||||
});
|
||||
for (x,y,c) in xyc{
|
||||
canvas.set_draw_color(c.get_rgb());
|
||||
let coordinates = (x as i32,y as i32);
|
||||
let draw_result = canvas.draw_point(coordinates).map_err(|str|EmulatorError::OtherError(str));
|
||||
|
||||
draw_result?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user