From 72723edaa3325d23e64bdff49088e0eb57cc0e9c Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sun, 19 Mar 2023 19:12:56 +1100 Subject: [PATCH] fix trait bounds + tile window --- lib/src/processor/memory/mmio/gpu.rs | 12 ++++++++++-- .../processor/memory/mmio/gpu/addresses.rs | 6 +++++- .../processor/memory/mmio/gpu/tile_window.rs | 19 ++++++++++++------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/src/processor/memory/mmio/gpu.rs b/lib/src/processor/memory/mmio/gpu.rs index 5734e28..be64f2c 100644 --- a/lib/src/processor/memory/mmio/gpu.rs +++ b/lib/src/processor/memory/mmio/gpu.rs @@ -23,7 +23,11 @@ mod types; const TILE_WINDOW_WIDTH: usize = 16 * 8; const TILE_WINDOW_HEIGHT: usize = 24 * 8; -pub struct Gpu, R: Renderer> { +pub struct Gpu +where + ColourFormat: From + Clone, + R: Renderer, +{ pub buffer: Vec, pub vram: Vram, pub oam: Oam, @@ -48,7 +52,11 @@ pub struct Gpu, R: Renderer> { } #[derive(Serialize, Deserialize)] -pub struct GpuSaveState, R: Renderer> { +pub struct GpuSaveState +where + ColourFormat: From + Clone, + R: Renderer, +{ buffer: Vec, vram: Vram, oam: Oam, diff --git a/lib/src/processor/memory/mmio/gpu/addresses.rs b/lib/src/processor/memory/mmio/gpu/addresses.rs index d38e730..b51a373 100644 --- a/lib/src/processor/memory/mmio/gpu/addresses.rs +++ b/lib/src/processor/memory/mmio/gpu/addresses.rs @@ -8,7 +8,11 @@ use super::{ Colour, Gpu, }; -impl, R: Renderer> Gpu { +impl Gpu +where + ColourFormat: From + Clone, + R: Renderer, +{ pub fn update_lcdc(&mut self, data: u8) { self.lcdc.enable = get_bit(data, 7); self.lcdc.window_tilemap = if get_bit(data, 6) { diff --git a/lib/src/processor/memory/mmio/gpu/tile_window.rs b/lib/src/processor/memory/mmio/gpu/tile_window.rs index 1c6bed0..03cdbdc 100644 --- a/lib/src/processor/memory/mmio/gpu/tile_window.rs +++ b/lib/src/processor/memory/mmio/gpu/tile_window.rs @@ -6,18 +6,23 @@ use crate::{ use super::{types::Vram, Colour}; -pub(super) struct TileWindow, R: Renderer> { - sprite_buffer: Vec, +pub(super) struct TileWindow +where + ColourFormat: From + Clone, + R: Renderer, +{ + sprite_buffer: Vec, sprite_renderer: R, } -impl, R: Renderer> TileWindow { +impl TileWindow +where + ColourFormat: From + Clone, + R: Renderer, +{ pub(super) fn new(window: R) -> Self { - let mut sprite_buffer = Vec::new(); - sprite_buffer.reserve_exact(TILE_WINDOW_WIDTH * TILE_WINDOW_HEIGHT); - Self { - sprite_buffer, + sprite_buffer: vec![Colour::Error.into(); TILE_WINDOW_WIDTH * TILE_WINDOW_HEIGHT], sprite_renderer: window, } }