From 511199443a419f549aeb500d7b013baef10152de Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 16 Jul 2024 18:05:29 +0200 Subject: refactor renderer again --- light-client/src/tilemap.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'light-client/src/tilemap.rs') diff --git a/light-client/src/tilemap.rs b/light-client/src/tilemap.rs index e84db8b1..cf8c5eef 100644 --- a/light-client/src/tilemap.rs +++ b/light-client/src/tilemap.rs @@ -15,15 +15,19 @@ along with this program. If not, see . */ -use crate::sprite_renderer::SpriteRenderer; use hurrycurry_protocol::{glam::IVec2, TileIndex}; -use sdl2::rect::{FRect, Rect}; +use sdl2::rect::Rect; use std::collections::HashMap; +use crate::render::{ + sprite::{Sprite, SpriteDraw}, + SpriteRenderer, +}; + #[derive(Default)] pub struct Tilemap { tile_srcs: Vec<[Rect; 16]>, - tiles: HashMap, + tiles: HashMap, } impl Tilemap { @@ -72,23 +76,13 @@ impl Tilemap { idx |= 0b0010 * (Some(tile) == neighbors[3]) as usize; let src = self.tile_srcs[tile.0][idx]; - self.tiles.insert( - pos, - ( - src, - FRect::new( - pos.x as f32, - pos.y as f32 + 1. - src.height() as f32 / 24., - src.width() as f32 / 32., - src.height() as f32 / 24., - ), - ), - ); + self.tiles + .insert(pos, Sprite::new_tile(src).at(pos.as_vec2() + 0.5)); } pub fn draw(&self, ctx: &mut SpriteRenderer) { - for &(src, dst) in self.tiles.values() { - ctx.draw(dst.y + dst.h, src, dst); + for &sprite in self.tiles.values() { + ctx.draw_world(sprite); } } } -- cgit v1.2.3-70-g09d2 From 4064c56783bd78b96b0e79d5a7b15b1fb0d8edad Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 16 Jul 2024 18:32:14 +0200 Subject: fix z-order problems partially --- light-client/src/render/sprite.rs | 6 +++--- light-client/src/tilemap.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'light-client/src/tilemap.rs') diff --git a/light-client/src/render/sprite.rs b/light-client/src/render/sprite.rs index 13ede525..c19f8392 100644 --- a/light-client/src/render/sprite.rs +++ b/light-client/src/render/sprite.rs @@ -10,13 +10,13 @@ pub struct Sprite { impl Sprite { pub fn new(src: Rect, anchor: Vec2, elevation: f32) -> Self { let relative_dst = FRect::new( - -anchor.x - (src.w as f32) / 32. / 2., - -anchor.y - (src.h as f32) / 24., + anchor.x - (src.w as f32) / 32. / 2., + anchor.y - (src.h as f32) / 24., (src.w as f32) / 32., (src.h as f32) / 24., ); Self { - z_offset: -relative_dst.h + anchor.y - elevation, + z_offset: elevation, src, relative_dst, } diff --git a/light-client/src/tilemap.rs b/light-client/src/tilemap.rs index cf8c5eef..e7341efa 100644 --- a/light-client/src/tilemap.rs +++ b/light-client/src/tilemap.rs @@ -77,7 +77,7 @@ impl Tilemap { let src = self.tile_srcs[tile.0][idx]; self.tiles - .insert(pos, Sprite::new_tile(src).at(pos.as_vec2() + 0.5)); + .insert(pos, Sprite::new_tile(src).at(pos.as_vec2())); } pub fn draw(&self, ctx: &mut SpriteRenderer) { -- cgit v1.2.3-70-g09d2