diff --git a/CHANGLOG.md b/CHANGLOG.md index 9f4e05b..0eeb789 100644 --- a/CHANGLOG.md +++ b/CHANGLOG.md @@ -1,3 +1,6 @@ +# 0.3.0 +- added size to backgrounds + # 0.2.1 - 2023-07-27 - fixed missing dependency in scaffolding @@ -8,4 +11,4 @@ - added gsa scaffolding tool # 0.1.0 - 2023-07-21 -initial release \ No newline at end of file +- initial release diff --git a/examples/basic/gfx.gif b/examples/basic/gfx.gif index d3561d1..3bb85d3 100644 Binary files a/examples/basic/gfx.gif and b/examples/basic/gfx.gif differ diff --git a/src/mapedit.rs b/src/mapedit.rs index cd17007..bf28220 100644 --- a/src/mapedit.rs +++ b/src/mapedit.rs @@ -19,6 +19,26 @@ use winit::{ const SPR_CURSOR: usize = 0x01; const TILE_CURSOR: u16 = 0x7308; const TILE_MARKER: u16 = 0x7309; +const TILE_BG: u16 = 0x730a; + +struct Surface<'a> { + pub data: &'a mut [u8], + pub size: IVec2, +} + +impl<'a> Surface<'a> { + fn draw_vline(&mut self, pos: IVec2, len: i32, color: u8) { + for i in 0..len { + self.data[(pos.x + (pos.y + i) * self.size.x) as usize] = color; + } + } + + fn draw_hline(&mut self, pos: IVec2, len: i32, color: u8) { + for i in 0..len { + self.data[(pos.x + i + pos.y * self.size.x) as usize] = color; + } + } +} pub(crate) fn run_mapedit() { println!("running map edit"); @@ -54,6 +74,9 @@ pub(crate) fn run_mapedit() { }; gsa2.reset_bgs(); gsa2.reset_sprites(); + for i in 0..2 { + gsa2.bgs[i].scroll = IVec2 { x: -16, y: 0 }; + } for y in 0..TILESET_SIZE { for x in 0..TILESET_SIZE { @@ -63,6 +86,7 @@ pub(crate) fn run_mapedit() { gsa2.bgs[0].active = false; gsa2.bgs[1].active = false; gsa2.bgs[2].active = true; + gsa2.bgs[2].size = IVec2 { x: 120, y: 68 }; //enough to cover 4k monitors? <_< for y in 0..BACKGROUND_MAX_SIZE { gsa2.bgs[2].tiles[0][y] = 0x7408; @@ -238,24 +262,43 @@ pub(crate) fn run_mapedit() { let mut screen_buffer = vec![TRANSPARENT; size.width as usize * size.height as usize / 4]; let mut window_buffer = surface.buffer_mut().unwrap(); - render_to_screen( - &mut screen_buffer, - &gsa, - &tileset, - IVec2 { - x: size.width as i32 / 2, - y: size.height as i32 / 2, - }, - ); - render_to_screen( - &mut screen_buffer, - &gsa2, - &tileset, - IVec2 { - x: size.width as i32 / 2, - y: size.height as i32 / 2, - }, - ); + let screen_size = IVec2 { + x: size.width as i32 / 2, + y: size.height as i32 / 2, + }; + render_to_screen(&mut screen_buffer, &gsa, &tileset, screen_size); + render_to_screen(&mut screen_buffer, &gsa2, &tileset, screen_size); + let mut screen = Surface { + data: &mut screen_buffer, + size: screen_size, + }; + if gsa.bgs[0].active { + let xs = -gsa.bgs[0].scroll.x - 1; + let ys = -gsa.bgs[0].scroll.y - 1; + let xe = xs + gsa.bgs[0].size.x * TILE_SIZE as i32 + 1; + let ye = ys + gsa.bgs[0].size.y * TILE_SIZE as i32 + 1; + if xs >= 16 && xs < screen_size.x { + let starty = (ys + 1).max(0); + let len = ye.min(screen_size.y) - starty; + screen.draw_vline(IVec2 { x: xs, y: starty }, len, 0xfc); + } + if xe >= 16 && xe < screen_size.x { + let starty = (ys + 1).max(0); + let len = ye.min(screen_size.y) - starty; + screen.draw_vline(IVec2 { x: xe, y: starty }, len, 0xfc); + } + if ys >= 0 && ys < screen_size.y { + let startx = (xs + 1).max(16); + let len = xe.min(screen_size.x) - startx; + screen.draw_hline(IVec2 { x: startx, y: ys }, len, 0xfc); + } + if ye >= 0 && ye < screen_size.y { + let startx = (xs + 1).max(16); + let len = xe.min(screen_size.x) - startx; + screen.draw_hline(IVec2 { x: startx, y: ye }, len, 0xfc); + } + } + render_to_window( &mut window_buffer, &mut screen_buffer,