From 236dd601a9398f9f15c0203f69127b25e78413d1 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Thu, 16 Jan 2020 19:53:09 +0200 Subject: [PATCH] core: gpu: Use Vec<> instead of fix size arrays Resorting to this since big arrays tend to overflow the stack on windows Former-commit-id: e792a9c844d8f87075ee02323cf0a58d083e9f63 --- src/core/gpu/mod.rs | 48 ++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/core/gpu/mod.rs b/src/core/gpu/mod.rs index 9a80cc0..19d6192 100644 --- a/src/core/gpu/mod.rs +++ b/src/core/gpu/mod.rs @@ -44,8 +44,6 @@ pub mod consts { } pub use self::consts::*; -pub type FrameBuffer = [T; DISPLAY_WIDTH * DISPLAY_HEIGHT]; - #[derive(Debug, Primitive, Copy, Clone)] pub enum PixelFormat { BPP4 = 0, @@ -65,31 +63,35 @@ impl Default for GpuState { } use GpuState::*; -#[derive(Copy, Clone)] -pub struct Scanline([T; DISPLAY_WIDTH]); +#[derive(Serialize, Deserialize, Clone)] +pub struct Scanline { + inner: Vec, +} -impl Default for Scanline { - fn default() -> Scanline { - Scanline([Rgb15::TRANSPARENT; DISPLAY_WIDTH]) +impl Default for Scanline { + fn default() -> Scanline { + Scanline { + inner: vec![Rgb15::TRANSPARENT; DISPLAY_WIDTH], + } } } -impl fmt::Debug for Scanline { +impl fmt::Debug for Scanline { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "...") } } -impl std::ops::Index for Scanline { - type Output = T; +impl std::ops::Index for Scanline { + type Output = Rgb15; fn index(&self, index: usize) -> &Self::Output { - &self.0[index] + &self.inner[index] } } -impl std::ops::IndexMut for Scanline { +impl std::ops::IndexMut for Scanline { fn index_mut(&mut self, index: usize) -> &mut Self::Output { - &mut self.0[index] + &mut self.inner[index] } } @@ -98,10 +100,11 @@ pub struct Background { pub bgcnt: BgControl, pub bgvofs: u16, pub bghofs: u16, - line: Scanline, + + line: Scanline, // for mosaic - mosaic_first_row: Scanline, + mosaic_first_row: Scanline, } #[derive(Debug, Default)] @@ -211,10 +214,10 @@ pub struct Gpu { pub oam: BoxedMemory, #[debug_stub = "Sprite Buffer"] - pub obj_buffer: FrameBuffer, + pub obj_buffer: Vec, #[debug_stub = "Frame Buffer"] - pub(super) frame_buffer: FrameBuffer, + pub(super) frame_buffer: Vec, } impl Gpu { @@ -224,7 +227,12 @@ impl Gpu { dispcnt: DisplayControl(0x80), dispstat: DisplayStatus(0), - bg: [Background::default(); 4], + bg: [ + Background::default(), + Background::default(), + Background::default(), + Background::default(), + ], bg_aff: [BgAffine::default(); 2], win0: Window::default(), win1: Window::default(), @@ -243,8 +251,8 @@ impl Gpu { vram: BoxedMemory::new(vec![0; VIDEO_RAM_SIZE].into_boxed_slice()), oam: BoxedMemory::new(vec![0; OAM_SIZE].into_boxed_slice()), - obj_buffer: [Default::default(); DISPLAY_WIDTH * DISPLAY_HEIGHT], - frame_buffer: [0; DISPLAY_WIDTH * DISPLAY_HEIGHT], + obj_buffer: vec![Default::default(); DISPLAY_WIDTH * DISPLAY_HEIGHT], + frame_buffer: vec![0; DISPLAY_WIDTH * DISPLAY_HEIGHT], } }