From 046837d9a119fbd3451ee86833c101e1b25ba5ec Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Wed, 27 Sep 2023 03:39:22 +0100 Subject: [PATCH] returning the fade2black with distance --- src/consts/visuals.rs | 6 ++++-- src/main.rs | 14 ++++++++++---- src/map/mod.rs | 8 +++++--- src/map/themes.rs | 25 +++++++++++++++++++++---- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/consts/visuals.rs b/src/consts/visuals.rs index 26fa5ee..982c4f9 100644 --- a/src/consts/visuals.rs +++ b/src/consts/visuals.rs @@ -13,12 +13,14 @@ pub const HP_BAR_LAYER: usize = 4; pub const BRIGHTEN_FG_COLOUR_BY: i32 = 16; pub const GLOBAL_OFFSET_MIN_CLAMP: f32 = -0.5; pub const GLOBAL_OFFSET_MAX_CLAMP: f32 = 1.0; +pub const SPRITE_OFFSET_MIN_CLAMP: f32 = 0.85; +pub const SPRITE_OFFSET_MAX_CLAMP: f32 = 1.0; pub const WITH_SCANLINES_BRIGHTEN_AMOUNT: f32 = 0.1; // 0.0 = no brightening, 1.0 = full brightening. pub const NON_VISIBLE_MULTIPLIER: f32 = 0.3; // 0.0 = black, 1.0 = full colour. pub const NON_VISIBLE_MULTIPLIER_IF_SCANLINES: f32 = 0.8; // as above, but when using scanlines. should be higher. -pub const MAX_DARKENING: f32 = 0.45; // 0.0 = black, 1.0 = full colour - only used if WITH_DARKEN_BY_DISTANCE is true. +pub const MAX_DARKENING: f32 = 0.35; // 0.0 = black, 1.0 = full colour - only used if WITH_DARKEN_BY_DISTANCE is true. pub const MAX_DARKENING_IF_SCANLINES: f32 = 0.9; // as above, but when using scanlines. should be higher. -pub const START_DARKEN_AT_N_TILES: f32 = 8.0; // start darkening at this distance (should always be less than entity::DEFAULT_VIEWSHED_STANDARD). +pub const START_DARKEN_AT_N_TILES: f32 = 7.0; // start darkening at this distance (should always be less than entity::DEFAULT_VIEWSHED_STANDARD). pub const SHORT_PARTICLE_LIFETIME: f32 = 100.0; // in ms pub const DEFAULT_PARTICLE_LIFETIME: f32 = 200.0; diff --git a/src/main.rs b/src/main.rs index b817e4e..5f770fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -181,8 +181,6 @@ fn draw_camera( let positions = ecs.read_storage::(); let renderables = ecs.read_storage::(); let hidden = ecs.read_storage::(); - let props = ecs.read_storage::(); - let items = ecs.read_storage::(); let minds = ecs.read_storage::(); let pools = ecs.read_storage::(); let entities = ecs.entities(); @@ -257,7 +255,14 @@ fn draw_camera( renderable.fg.b ) } else { - Color::WHITE + let mul = themes::darken_by_distance( + Point::new( + entry.0.x + bounds.min_x - bounds.x_offset, + entry.0.y + bounds.min_y - bounds.y_offset + ), + *ecs.fetch::() + ); + Color::from_rgb(mul, mul, mul) } ); if let Some(pool) = pools.get(entry.1.e) { @@ -376,7 +381,8 @@ fn render_map_in_view( if memory.recolour { Color::from_rgb(memory.fg.r, memory.fg.g, memory.fg.b) } else { - Color::from_rgb(0.75, 0.75, 0.75) + let mult = 0.3; + Color::from_rgb(mult, mult, mult) } ); } diff --git a/src/map/mod.rs b/src/map/mod.rs index f07aedd..1f87056 100644 --- a/src/map/mod.rs +++ b/src/map/mod.rs @@ -20,6 +20,8 @@ use super::consts::visuals::{ BRIGHTEN_FG_COLOUR_BY, GLOBAL_OFFSET_MIN_CLAMP, GLOBAL_OFFSET_MAX_CLAMP, + SPRITE_OFFSET_MIN_CLAMP, + SPRITE_OFFSET_MAX_CLAMP, }; // FIXME: If the map size gets too small, entities stop being rendered starting from the right. @@ -110,9 +112,9 @@ impl Map { rng.range(GLOBAL_OFFSET_MIN_CLAMP, GLOBAL_OFFSET_MAX_CLAMP), ); map.colour_offset[idx].1 = ( - rng.range(GLOBAL_OFFSET_MIN_CLAMP, GLOBAL_OFFSET_MAX_CLAMP), - rng.range(GLOBAL_OFFSET_MIN_CLAMP, GLOBAL_OFFSET_MAX_CLAMP), - rng.range(GLOBAL_OFFSET_MIN_CLAMP, GLOBAL_OFFSET_MAX_CLAMP), + rng.range(SPRITE_OFFSET_MIN_CLAMP, SPRITE_OFFSET_MAX_CLAMP), + rng.range(SPRITE_OFFSET_MIN_CLAMP, SPRITE_OFFSET_MAX_CLAMP), + rng.range(SPRITE_OFFSET_MIN_CLAMP, SPRITE_OFFSET_MAX_CLAMP), ); } diff --git a/src/map/themes.rs b/src/map/themes.rs index 2698eda..3ecde0b 100644 --- a/src/map/themes.rs +++ b/src/map/themes.rs @@ -12,13 +12,30 @@ pub fn get_sprite_for_id(idx: usize, map: &Map, other_pos: Option) -> (&s TileType::Wall => map.tiles[idx].sprite(check_if_base(TileType::Wall, idx, map), f), _ => map.tiles[idx].sprite(false, f), }; - let tint = if !map.visible_tiles[idx] { - Color::from_rgb(0.75, 0.75, 0.75) + let base = if !map.visible_tiles[idx] { + NON_VISIBLE_MULTIPLIER } else { - Color::WHITE + if other_pos.is_some() { + darken_by_distance( + Point::new((idx as i32) % map.width, (idx as i32) / map.width), + other_pos.unwrap() + ) + } else { + 1.0 + } }; + let offsets = get_normalised_offsets(idx, map); + let tint = Color::from_rgb(base * offsets.0, base * offsets.1, base * offsets.2); return (sprite, tint); } + +fn get_normalised_offsets(idx: usize, map: &Map) -> (f32, f32, f32) { + let offsets = map.colour_offset[idx].1; + let max = f32::max(f32::max(offsets.0, offsets.1), offsets.2); + let normalised = (offsets.0 / max, offsets.1 / max, offsets.2 / max); + normalised +} + /// Gets the renderables for a tile, with darkening/offset/post-processing/etc. Passing a val for "debug" will ignore viewshed. pub fn get_tile_renderables_for_id( idx: usize, @@ -354,7 +371,7 @@ pub fn multiply_by_float(rgb: RGB, offsets: (f32, f32, f32)) -> RGB { return RGB::from_f32(r, g, b); } -fn darken_by_distance(pos: Point, other_pos: Point) -> f32 { +pub fn darken_by_distance(pos: Point, other_pos: Point) -> f32 { let distance = DistanceAlg::Pythagoras.distance2d(pos, other_pos) as f32; // Get distance in tiles. let interp_factor = (distance - START_DARKEN_AT_N_TILES) /