add blit_atlas method
for some additional convenience when blitting BitmapAtlas tiles
This commit is contained in:
parent
6a730ed70c
commit
0ccc37420d
|
@ -707,10 +707,10 @@ fn render_system_sprites(context: &mut Core) {
|
||||||
// now render them in the correct order ...
|
// now render them in the correct order ...
|
||||||
for (entity, position, blit_method) in context.sprite_render_list.iter() {
|
for (entity, position, blit_method) in context.sprite_render_list.iter() {
|
||||||
let sprite = sprites.get(entity).unwrap();
|
let sprite = sprites.get(entity).unwrap();
|
||||||
context.system.video.blit_region(
|
context.system.video.blit_atlas(
|
||||||
*blit_method,
|
*blit_method,
|
||||||
sprite.atlas.bitmap(),
|
&sprite.atlas,
|
||||||
&sprite.atlas[sprite.index],
|
sprite.index,
|
||||||
position.x as i32 - camera.x,
|
position.x as i32 - camera.x,
|
||||||
position.y as i32 - camera.y,
|
position.y as i32 - camera.y,
|
||||||
);
|
);
|
||||||
|
|
|
@ -750,11 +750,25 @@ impl Bitmap {
|
||||||
self.blit_region(method, src, &src_region, x, y);
|
self.blit_region(method, src, &src_region, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn blit_atlas(&mut self, method: BlitMethod, src: &BitmapAtlas, index: usize, x: i32, y: i32) {
|
||||||
|
if let Some(src_region) = src.get(index) {
|
||||||
|
self.blit_region(method, src.bitmap(), src_region, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn blit_unchecked(&mut self, method: BlitMethod, src: &Bitmap, x: i32, y: i32) {
|
pub unsafe fn blit_unchecked(&mut self, method: BlitMethod, src: &Bitmap, x: i32, y: i32) {
|
||||||
let src_region = Rect::new(0, 0, src.width, src.height);
|
let src_region = Rect::new(0, 0, src.width, src.height);
|
||||||
self.blit_region_unchecked(method, src, &src_region, x, y);
|
self.blit_region_unchecked(method, src, &src_region, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub unsafe fn blit_atlas_unchecked(&mut self, method: BlitMethod, src: &BitmapAtlas, index: usize, x: i32, y: i32) {
|
||||||
|
if let Some(src_region) = src.get(index) {
|
||||||
|
self.blit_region_unchecked(method, src.bitmap(), &src_region, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -101,6 +101,11 @@ impl BitmapAtlas {
|
||||||
self.tiles.len()
|
self.tiles.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get(&self, index: usize) -> Option<&Rect> {
|
||||||
|
self.tiles.get(index)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn bitmap(&self) -> &Bitmap {
|
pub fn bitmap(&self) -> &Bitmap {
|
||||||
&self.bitmap
|
&self.bitmap
|
||||||
}
|
}
|
||||||
|
@ -110,7 +115,7 @@ impl Index<usize> for BitmapAtlas {
|
||||||
type Output = Rect;
|
type Output = Rect;
|
||||||
|
|
||||||
fn index(&self, index: usize) -> &Self::Output {
|
fn index(&self, index: usize) -> &Self::Output {
|
||||||
&self.tiles[index]
|
self.get(index).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue