Make icon smoothing a render pass

This commit is contained in:
Tad Hardesty 2019-11-17 17:40:41 -08:00
parent 4971697711
commit 091cd96671
3 changed files with 35 additions and 12 deletions

View file

@ -7,7 +7,7 @@ use dm::objtree::*;
use dm::constants::Constant;
use dmm::{Map, ZLevel, Prefab};
use dmi::{Dir, Image};
use render_passes::{RenderPass, icon_smoothing};
use render_passes::RenderPass;
use icon_cache::IconCache;
const TILE_SIZE: u32 = 32;
@ -76,13 +76,6 @@ pub fn generate(ctx: Context, icon_cache: &IconCache) -> Result<Image, ()> {
}
atom.sprite = sprite;
// icons which differ from their map states
let p = &atom.type_.path;
if subpath(p, "/turf/closed/mineral/") {
atom.sprite.ofs_x -= 4;
atom.sprite.ofs_y -= 4;
}
for pass in render_passes {
pass.overlays(&mut atom, objtree, &mut underlays, &mut overlays, bump);
}
@ -112,9 +105,16 @@ pub fn generate(ctx: Context, icon_cache: &IconCache) -> Result<Image, ()> {
let adjacency2 = adjacency.iter().map(|v| &v[..]).collect::<Vec<_>>();
let neighborhood = Neighborhood::new(adjacency2[..].try_into().unwrap());
if icon_smoothing::IconSmoothing::default().handle_smooth(&atom, objtree, &neighborhood, &mut underlays, bump) {
let mut normal_appearance = true;
for pass in render_passes {
if !pass.neighborhood_appearance(&atom, objtree, &neighborhood, &mut underlays, bump) {
normal_appearance = false;
}
}
if normal_appearance {
underlays.push(atom.sprite);
}
sprites.extend(underlays.drain(..).map(|o| (loc, o)));
sprites.extend(overlays.drain(..).map(|o| (loc, o)));
}

View file

@ -5,6 +5,8 @@ use dm::constants::Constant;
use dmi::Dir;
use minimap::{Sprite, Atom, GetVar, Neighborhood};
use super::RenderPass;
// (1 << N) where N is the usual value
const N_NORTH: i32 = 2;
const N_SOUTH: i32 = 4;
@ -30,8 +32,20 @@ impl Default for IconSmoothing {
}
}
impl IconSmoothing {
pub fn handle_smooth<'a>(&self,
impl RenderPass for IconSmoothing {
fn adjust_sprite<'a>(&self,
atom: &Atom<'a>,
sprite: &mut Sprite<'a>,
_objtree: &'a ObjectTree,
_bump: &'a bumpalo::Bump,
) {
if atom.istype("/turf/closed/mineral/") {
sprite.ofs_x -= 4;
sprite.ofs_y -= 4;
}
}
fn neighborhood_appearance<'a>(&self,
atom: &Atom<'a>,
objtree: &'a ObjectTree,
neighborhood: &Neighborhood<'a, '_>,

View file

@ -1,6 +1,6 @@
use dm::objtree::*;
use dm::constants::Constant;
use minimap::{Atom, GetVar, Sprite, Layer};
use minimap::{Atom, GetVar, Sprite, Layer, Neighborhood};
pub mod transit_tube;
pub mod random;
@ -51,6 +51,14 @@ pub trait RenderPass: Sync {
bump: &'a bumpalo::Bump, // TODO: kind of a hacky way to pass this
) {}
fn neighborhood_appearance<'a>(&self,
atom: &Atom<'a>,
objtree: &'a ObjectTree,
neighborhood: &Neighborhood<'a, '_>,
output: &mut Vec<Sprite<'a>>,
bump: &'a bumpalo::Bump, // TODO: kind of a hacky way to pass this
) -> bool { true }
/// Filter atoms at the end of the process, after they have been taken into
/// account by their neighbors.
fn late_filter(&self,
@ -88,6 +96,7 @@ pub const RENDER_PASSES: &[RenderPassInfo] = &[
pass!(Wires, "only-powernet", "Render only power cables.", false),
pass!(Pipes, "only-pipenet", "Render only atmospheric pipes.", false),
pass!(FancyLayers, "fancy-layers", "Layer atoms according to in-game rules.", true),
pass!(icon_smoothing::IconSmoothing, "icon-smoothing", "Emulate the icon smoothing subsystem.", true),
];
pub fn configure(include: &str, exclude: &str) -> Vec<Box<dyn RenderPass>> {