Compare commits

..

2 Commits

Author SHA1 Message Date
dani 8f78bbdca1 map edit shows border around map 2023-08-06 17:25:20 +00:00
dani 42f8174a51 added size to backgrounds 2023-08-06 16:50:36 +00:00
5 changed files with 76 additions and 23 deletions

View File

@ -1,3 +1,6 @@
# 0.3.0
- added size to backgrounds
# 0.2.1 - 2023-07-27 # 0.2.1 - 2023-07-27
- fixed missing dependency in scaffolding - fixed missing dependency in scaffolding
@ -8,4 +11,4 @@
- added gsa scaffolding tool - added gsa scaffolding tool
# 0.1.0 - 2023-07-21 # 0.1.0 - 2023-07-21
initial release - initial release

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -7,6 +7,8 @@ pub struct Background {
pub tiles: Vec<Vec<u16>>, pub tiles: Vec<Vec<u16>>,
/// Camera scroll (negative draw offset) for rendering /// Camera scroll (negative draw offset) for rendering
pub scroll: IVec2, pub scroll: IVec2,
/// Size (used for rendering)
pub size: IVec2,
/// Are tiles indices half-tile indices? /// Are tiles indices half-tile indices?
pub half_tile: bool, pub half_tile: bool,
/// Is this background being displayed? /// Is this background being displayed?
@ -22,6 +24,7 @@ impl Default for Background {
scroll: IVec2::ZERO, scroll: IVec2::ZERO,
half_tile: false, half_tile: false,
active: true, active: true,
size: IVec2 { x: 19, y: 11 },
} }
} }
} }

View File

@ -41,10 +41,14 @@ fn render_map(target: &mut [u8], map: &Background, tileset: &[u8], screen_size:
} as i32; } as i32;
let mut startx = map.scroll.x / tilesize; let mut startx = map.scroll.x / tilesize;
let mut starty = map.scroll.y / tilesize; let mut starty = map.scroll.y / tilesize;
let endx = let endx = map
(BACKGROUND_MAX_SIZE as i32).min(startx + (screen_size.x / TILE_SIZE as i32 + 1) * tcmult); .size
let endy = .x
(BACKGROUND_MAX_SIZE as i32).min(starty + (screen_size.y / TILE_SIZE as i32 + 1) * tcmult); .min(startx + (screen_size.x / TILE_SIZE as i32 + 1) * tcmult);
let endy = map
.size
.y
.min(starty + (screen_size.y / TILE_SIZE as i32 + 1) * tcmult);
startx = 0.max(startx); startx = 0.max(startx);
starty = 0.max(starty); starty = 0.max(starty);
for x in startx..endx { for x in startx..endx {

View File

@ -19,6 +19,26 @@ use winit::{
const SPR_CURSOR: usize = 0x01; const SPR_CURSOR: usize = 0x01;
const TILE_CURSOR: u16 = 0x7308; const TILE_CURSOR: u16 = 0x7308;
const TILE_MARKER: u16 = 0x7309; 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() { pub(crate) fn run_mapedit() {
println!("running map edit"); println!("running map edit");
@ -54,6 +74,9 @@ pub(crate) fn run_mapedit() {
}; };
gsa2.reset_bgs(); gsa2.reset_bgs();
gsa2.reset_sprites(); gsa2.reset_sprites();
for i in 0..2 {
gsa2.bgs[i].scroll = IVec2 { x: -16, y: 0 };
}
for y in 0..TILESET_SIZE { for y in 0..TILESET_SIZE {
for x 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[0].active = false;
gsa2.bgs[1].active = false; gsa2.bgs[1].active = false;
gsa2.bgs[2].active = true; 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 { for y in 0..BACKGROUND_MAX_SIZE {
gsa2.bgs[2].tiles[0][y] = 0x7408; gsa2.bgs[2].tiles[0][y] = 0x7408;
@ -238,24 +262,43 @@ pub(crate) fn run_mapedit() {
let mut screen_buffer = let mut screen_buffer =
vec![TRANSPARENT; size.width as usize * size.height as usize / 4]; vec![TRANSPARENT; size.width as usize * size.height as usize / 4];
let mut window_buffer = surface.buffer_mut().unwrap(); let mut window_buffer = surface.buffer_mut().unwrap();
render_to_screen( let screen_size = IVec2 {
&mut screen_buffer,
&gsa,
&tileset,
IVec2 {
x: size.width as i32 / 2, x: size.width as i32 / 2,
y: size.height as i32 / 2, y: size.height as i32 / 2,
}, };
); render_to_screen(&mut screen_buffer, &gsa, &tileset, screen_size);
render_to_screen( render_to_screen(&mut screen_buffer, &gsa2, &tileset, screen_size);
&mut screen_buffer, let mut screen = Surface {
&gsa2, data: &mut screen_buffer,
&tileset, size: screen_size,
IVec2 { };
x: size.width as i32 / 2, if gsa.bgs[0].active {
y: size.height as i32 / 2, 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( render_to_window(
&mut window_buffer, &mut window_buffer,
&mut screen_buffer, &mut screen_buffer,