switched bg rendering to iterate over pixels rather than over tiles
This commit is contained in:
parent
a20bb4c921
commit
1c8a6bd391
|
@ -4,22 +4,11 @@ use gsa::{run, Gsa, FACE_DOWN};
|
|||
struct Game {}
|
||||
|
||||
fn init(gsa: &mut Gsa) -> Game {
|
||||
gsa.sprites[0].tile = 0x0300;
|
||||
gsa.sprites[1].tile = 0x0200;
|
||||
gsa.bgs[0].tiles[1][1] = 0x0300;
|
||||
gsa.bgs[1].half_tile = true;
|
||||
gsa.load_map(1337);
|
||||
gsa.write_string(1, IVec2::ONE, "Hello world nyaa~");
|
||||
gsa.bg[0].fill(0x0101);
|
||||
//gsa.write_string(IVec2::ONE, "Hello world nyaa~");
|
||||
Game {}
|
||||
}
|
||||
|
||||
fn update(_game: &mut Game, gsa: &mut Gsa) {
|
||||
gsa.sprites[0].pos.x = (gsa.sprites[0].pos.x + 1) % 300;
|
||||
gsa.sprites[1].pos += gsa.input_dir();
|
||||
//gsa.bgs[1].scroll.x += 1;
|
||||
if gsa.button_pressed(FACE_DOWN) {
|
||||
gsa.sprites[1].tile += 1;
|
||||
}
|
||||
}
|
||||
fn update(_game: &mut Game, gsa: &mut Gsa) {}
|
||||
|
||||
run!(init, update);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::usize;
|
||||
//use rayon::prelude::*;
|
||||
|
||||
use crate::{
|
||||
Background, Gsa, Rgb, EMPTY_TILE, HALF_TILE_SIZE, MAX_BACKGROUNDS, TILESET_SIZE, TILE_SIZE,
|
||||
|
@ -32,7 +33,7 @@ fn draw_tile(
|
|||
}
|
||||
}
|
||||
|
||||
fn render_map(target: &mut [u8], map: &Background, tileset: &[u8], screen_size: IVec2) {
|
||||
fn render_bg(target: &mut [u8], map: &Background, tileset: &[u8], screen_size: IVec2) {
|
||||
let tcmult = if map.half_tile { 2 } else { 1 };
|
||||
let tilesize = if map.half_tile {
|
||||
HALF_TILE_SIZE
|
||||
|
@ -71,12 +72,44 @@ fn render_map(target: &mut [u8], map: &Background, tileset: &[u8], screen_size:
|
|||
}
|
||||
}
|
||||
|
||||
fn render_bg2(target: &mut [u8], map: &Background, tileset: &[u8], screen_size: IVec2) {
|
||||
let tilesize = if map.half_tile {
|
||||
HALF_TILE_SIZE
|
||||
} else {
|
||||
TILE_SIZE
|
||||
} as i32;
|
||||
//target.par_chunks_exact_mut(screen_size.x as usize).enumerate().for_each({|(screeny, row)|
|
||||
target.chunks_exact_mut(screen_size.x as usize).enumerate().for_each({|(screeny, row)|
|
||||
for screenx in 0..screen_size.x {
|
||||
let x = screenx + map.scroll.x;
|
||||
let y = screeny as i32 + map.scroll.y;
|
||||
let tilex = x / tilesize;
|
||||
let tiley = y / tilesize;
|
||||
let pixx = x % tilesize;
|
||||
let pixy = y % tilesize;
|
||||
let tile = if tilex >= 0 && tiley >= 0 && tilex < map.size.x && tiley < map.size.y {
|
||||
map.tiles[tilex as usize][tiley as usize]
|
||||
} else {
|
||||
EMPTY_TILE
|
||||
};
|
||||
if tile != EMPTY_TILE {
|
||||
let tilesetx = tile as usize % 0x100 * tilesize as usize + pixx as usize;
|
||||
let tilesety = tile as usize / 0x100 * tilesize as usize + pixy as usize;
|
||||
let p = tileset[tilesetx + tilesety * (TILESET_SIZE * TILE_SIZE)];
|
||||
if p != TRANSPARENT {
|
||||
row[x as usize] = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn render_to_screen(target: &mut [u8], gsa: &Gsa, tileset: &[u8], screen_size: IVec2) {
|
||||
for i in 0..MAX_BACKGROUNDS {
|
||||
if gsa.bgs[i].active {
|
||||
render_map(target, &gsa.bgs[i], tileset, screen_size);
|
||||
if gsa.bg[i].active {
|
||||
render_bg2(target, &gsa.bg[i], tileset, screen_size);
|
||||
}
|
||||
for sprite in &gsa.sprites {
|
||||
for sprite in &gsa.sprite {
|
||||
if sprite.tile != EMPTY_TILE && sprite.priority == i as u8 {
|
||||
draw_tile(target, sprite.pos, sprite.tile, tileset, false, screen_size);
|
||||
}
|
||||
|
|
|
@ -47,15 +47,18 @@ pub fn run<TGame: 'static>(
|
|||
) {
|
||||
let (tileset, palette) = load_tileset(image_data);
|
||||
|
||||
//rayon::ThreadPoolBuilder::new().num_threads(32).build_global().unwrap();
|
||||
|
||||
let mut gsa = Gsa {
|
||||
sprites: [Sprite::default(); MAX_SPRITES],
|
||||
bgs: Default::default(),
|
||||
sprite: [Sprite::default(); MAX_SPRITES],
|
||||
bg: Default::default(),
|
||||
palette,
|
||||
font: FONT_BOLD,
|
||||
pressed: 0,
|
||||
released: 0,
|
||||
down: 0,
|
||||
maps: postcard::from_bytes(maps_data).unwrap(),
|
||||
str_bg: 3,
|
||||
};
|
||||
|
||||
gsa.reset_bgs();
|
||||
|
@ -97,7 +100,7 @@ pub fn run<TGame: 'static>(
|
|||
let mut last_second = Instant::now();
|
||||
|
||||
let mut last_frame = last_second;
|
||||
let target_frame_duration = Duration::from_secs(1).div_f64(60.0);
|
||||
let target_frame_duration = Duration::from_secs(1).div_f64(60000.0);
|
||||
|
||||
let mut scale = 1usize;
|
||||
let mut off_x = 0usize;
|
||||
|
|
Loading…
Reference in New Issue