returns the option for scanlines, cleans up config

This commit is contained in:
Llywelwyn 2023-08-23 21:14:07 +01:00
parent e62a081103
commit ff344ccee4
6 changed files with 40 additions and 25 deletions

View file

@ -7,7 +7,6 @@ const SHOW_BOUNDARIES: bool = false;
pub fn get_screen_bounds(ecs: &World, _ctx: &mut Rltk) -> (i32, i32, i32, i32, i32, i32) {
let player_pos = ecs.fetch::<Point>();
//let (x_chars, y_chars) = ctx.get_char_size();
let (x_chars, y_chars, x_offset, y_offset) = (69, 41, 1, 10);
let centre_x = (x_chars / 2) as i32;

View file

@ -4,6 +4,7 @@ pub mod glyphs;
pub mod messages;
pub mod char_create;
pub const SHOW_MAPGEN: bool = false;
pub const LOG_SPAWNING: bool = true;
pub const LOG_TICKS: bool = false;
// DEBUG/LOGGING
pub const SHOW_MAPGEN: bool = false; // Shows the step-by-step map gen process.
pub const LOG_SPAWNING: bool = true; // Logs spawning of entities.
pub const LOG_TICKS: bool = false; // Logs hunger/energy ticks.

View file

@ -1,8 +1,16 @@
pub const NON_VISIBLE_MULTIPLIER: f32 = 0.3;
pub const MAX_DARKENING: f32 = 0.45;
pub const START_DARKEN_AT_N_TILES: f32 = 8.0;
// POST-PROCESSING
pub const WITH_SCANLINES: bool = false; // Adds scanlines to the screen.
pub const WITH_SCREEN_BURN: bool = false; // Requires WITH_SCANLINES.
pub const WITH_DARKEN_BY_DISTANCE: bool = true; // If further away tiles should get darkened, instead of a harsh transition to non-visible.
pub const SHORT_PARTICLE_LIFETIME: f32 = 100.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_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 SHORT_PARTICLE_LIFETIME: f32 = 100.0; // in ms
pub const DEFAULT_PARTICLE_LIFETIME: f32 = 200.0;
pub const LONG_PARTICLE_LIFETIME: f32 = 300.0;

View file

@ -617,14 +617,16 @@ fn main() -> rltk::BError {
//rltk::link_resource!(CURSES14X16, "../resources/curses_14x16.png");
use rltk::RltkBuilder;
let context = RltkBuilder::new()
let mut context = RltkBuilder::new()
.with_title("rust-rl")
.with_dimensions(DISPLAYWIDTH, DISPLAYHEIGHT)
.with_font("curses14x16.png", 14, 16)
.with_tile_dimensions(14, 16)
.with_simple_console(DISPLAYWIDTH, DISPLAYHEIGHT, "curses14x16.png")
//.with_simple_console_no_bg(DISPLAYWIDTH, DISPLAYHEIGHT, "terminal8x8.jpg")
.build()?;
if config::visuals::WITH_SCANLINES {
context.with_post_scanlines(config::visuals::WITH_SCREEN_BURN);
}
let mut gs = State {
ecs: World::new(),

View file

@ -22,7 +22,6 @@ pub struct Map {
pub visible_tiles: Vec<bool>,
pub lit_tiles: Vec<bool>,
pub telepath_tiles: Vec<bool>,
// Combine these offsets into one Vec<(u8, u8, u8)>
pub colour_offset: Vec<(f32, f32, f32)>,
pub additional_fg_offset: rltk::RGB,
pub id: i32,

View file

@ -4,8 +4,6 @@ use crate::config::visuals::*;
use rltk::prelude::*;
use std::ops::{ Add, Mul };
const DARKEN_TILES_BY_DISTANCE: bool = true;
pub fn get_tile_renderables_for_id(idx: usize, map: &Map, other_pos: Option<Point>) -> (rltk::FontCharType, RGB, RGB) {
let (glyph, mut fg, mut bg) = match map.id {
2 => get_forest_theme_renderables(idx, map),
@ -21,18 +19,28 @@ pub fn get_tile_renderables_for_id(idx: usize, map: &Map, other_pos: Option<Poin
fg = fg.add(map.additional_fg_offset);
(fg, bg) = apply_colour_offset(fg, bg, map, idx);
if WITH_SCANLINES && WITH_SCANLINES_BRIGHTEN_AMOUNT > 0.0 {
(fg, bg) = brighten_by(fg, bg, WITH_SCANLINES_BRIGHTEN_AMOUNT);
}
bg = apply_bloodstain_if_necessary(bg, map, idx);
let (mut multiplier, mut nonvisible, mut darken) = (1.0, false, false);
if !map.visible_tiles[idx] {
multiplier = NON_VISIBLE_MULTIPLIER;
multiplier = if WITH_SCANLINES { NON_VISIBLE_MULTIPLIER_IF_SCANLINES } else { NON_VISIBLE_MULTIPLIER };
nonvisible = true;
}
if other_pos.is_some() && DARKEN_TILES_BY_DISTANCE && !nonvisible {
if other_pos.is_some() && WITH_DARKEN_BY_DISTANCE && !nonvisible {
let distance = darken_by_distance(
Point::new((idx as i32) % map.width, (idx as i32) / map.width),
other_pos.unwrap()
);
multiplier = distance.clamp(NON_VISIBLE_MULTIPLIER, 1.0);
multiplier = distance.clamp(
if WITH_SCANLINES {
NON_VISIBLE_MULTIPLIER_IF_SCANLINES
} else {
NON_VISIBLE_MULTIPLIER
},
1.0
);
darken = true;
}
if nonvisible || darken {
@ -237,14 +245,6 @@ fn apply_colour_offset(mut fg: RGB, mut bg: RGB, map: &Map, idx: usize) -> (RGB,
return (fg, bg);
}
fn darken_if_not_visible(mut fg: RGB, mut bg: RGB, map: &Map, idx: usize) -> (RGB, RGB) {
if !map.visible_tiles[idx] {
fg = fg.mul(NON_VISIBLE_MULTIPLIER);
bg = bg.mul(NON_VISIBLE_MULTIPLIER);
}
return (fg, bg);
}
fn apply_bloodstain_if_necessary(mut bg: RGB, map: &Map, idx: usize) -> RGB {
if map.bloodstains.contains(&idx) {
bg = bg.add(RGB::named(BLOODSTAIN_COLOUR));
@ -266,5 +266,11 @@ fn darken_by_distance(pos: Point, other_pos: Point) -> f32 {
(distance - START_DARKEN_AT_N_TILES) /
((crate::config::entity::DEFAULT_VIEWSHED_STANDARD as f32) - START_DARKEN_AT_N_TILES);
let interp_factor = interp_factor.max(0.0).min(1.0); // Clamp [0-1]
return 1.0 - interp_factor * (1.0 - MAX_DARKENING);
return 1.0 - interp_factor * (1.0 - (if WITH_SCANLINES { MAX_DARKENING_IF_SCANLINES } else { MAX_DARKENING }));
}
fn brighten_by(mut fg: RGB, mut bg: RGB, amount: f32) -> (RGB, RGB) {
fg = fg.add(RGB::from_f32(amount, amount, amount));
bg = bg.add(RGB::from_f32(amount, amount, amount));
return (fg, bg);
}