Fixed suppressed clippy warnings for #587 - useless_conversion

This commit is contained in:
Ben Wallis 2020-07-13 20:57:13 +01:00
parent 2b13b7d952
commit a9be045cb8
15 changed files with 207 additions and 220 deletions

View File

@ -33,7 +33,6 @@ pub struct ServerMetrics {
} }
impl TickMetrics { impl TickMetrics {
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
pub fn new(registry: &Registry, tick: Arc<AtomicU64>) -> Result<Self, Box<dyn Error>> { pub fn new(registry: &Registry, tick: Arc<AtomicU64>) -> Result<Self, Box<dyn Error>> {
let player_online = IntGauge::with_opts(Opts::new( let player_online = IntGauge::with_opts(Opts::new(
"player_online", "player_online",
@ -65,10 +64,10 @@ impl TickMetrics {
"chunks_count", "chunks_count",
"number of all chunks currently active on the server", "number of all chunks currently active on the server",
))?; ))?;
let tick_time = IntGaugeVec::from(IntGaugeVec::new( let tick_time = IntGaugeVec::new(
Opts::new("tick_time", "time in ns requiered for a tick of the server"), Opts::new("tick_time", "time in ns requiered for a tick of the server"),
&["period"], &["period"],
)?); )?;
let since_the_epoch = SystemTime::now() let since_the_epoch = SystemTime::now()
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)

View File

@ -9,7 +9,7 @@ impl Animation for GlideWieldAnimation {
type Dependency = (Option<ToolKind>, Option<ToolKind>, Vec3<f32>, Vec3<f32>, Vec3<f32>, f64); type Dependency = (Option<ToolKind>, Option<ToolKind>, Vec3<f32>, Vec3<f32>, Vec3<f32>, f64);
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(_active_tool_kind, _second_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency, (_active_tool_kind, _second_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency,

View File

@ -21,7 +21,7 @@ impl Animation for ChargeAnimation {
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_charge")] #[cfg_attr(feature = "be-dyn-lib", export_name = "character_charge")]
#[allow(clippy::approx_constant)] // TODO: Pending review in #587 #[allow(clippy::approx_constant)] // TODO: Pending review in #587
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
fn update_skeleton_inner( fn update_skeleton_inner(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(active_tool_kind, second_tool_kind, velocity, orientation, last_ori, _global_time): Self::Dependency, (active_tool_kind, second_tool_kind, velocity, orientation, last_ori, _global_time): Self::Dependency,
@ -60,10 +60,10 @@ impl Animation for ChargeAnimation {
let stop = ((anim_time as f32).powf(0.3 as f32)).min(1.2); let stop = ((anim_time as f32).powf(0.3 as f32)).min(1.2);
let stopa = ((anim_time as f32).powf(0.9 as f32)).min(5.0); let stopa = ((anim_time as f32).powf(0.9 as f32)).min(5.0);
let ori = Vec2::from(orientation); let ori: Vec2<f32> = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori); let last_ori = Vec2::from(last_ori);
let tilt = if Vec2::new(ori, last_ori) let tilt = if Vec2::new(ori, last_ori)
.map(|o| Vec2::<f32>::from(o).magnitude_squared()) .map(|o| o.magnitude_squared())
.map(|m| m > 0.001 && m.is_finite()) .map(|m| m > 0.001 && m.is_finite())
.reduce_and() .reduce_and()
&& ori.angle_between(last_ori).is_finite() && ori.angle_between(last_ori).is_finite()

View File

@ -22,7 +22,7 @@ impl Animation for GlideWieldAnimation {
const UPDATE_FN: &'static [u8] = b"character_glidewield\0"; const UPDATE_FN: &'static [u8] = b"character_glidewield\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_glidewield")] #[cfg_attr(feature = "be-dyn-lib", export_name = "character_glidewield")]
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
fn update_skeleton_inner( fn update_skeleton_inner(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(active_tool_kind, second_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency, (active_tool_kind, second_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency,
@ -94,10 +94,10 @@ impl Animation for GlideWieldAnimation {
* 0.1, * 0.1,
); );
let ori = Vec2::from(orientation); let ori: Vec2<f32> = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori); let last_ori = Vec2::from(last_ori);
let tilt = if Vec2::new(ori, last_ori) let tilt = if Vec2::new(ori, last_ori)
.map(|o| Vec2::<f32>::from(o).magnitude_squared()) .map(|o| o.magnitude_squared())
.map(|m| m > 0.001 && m.is_finite()) .map(|m| m > 0.001 && m.is_finite())
.reduce_and() .reduce_and()
&& ori.angle_between(last_ori).is_finite() && ori.angle_between(last_ori).is_finite()

View File

@ -22,7 +22,7 @@ impl Animation for GlidingAnimation {
const UPDATE_FN: &'static [u8] = b"character_gliding\0"; const UPDATE_FN: &'static [u8] = b"character_gliding\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_gliding")] #[cfg_attr(feature = "be-dyn-lib", export_name = "character_gliding")]
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
fn update_skeleton_inner( fn update_skeleton_inner(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(active_tool_kind, second_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency, (active_tool_kind, second_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency,
@ -54,10 +54,10 @@ impl Animation for GlidingAnimation {
* 0.25, * 0.25,
); );
let ori = Vec2::from(orientation); let ori: Vec2<f32> = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori); let last_ori = Vec2::from(last_ori);
let tilt = if Vec2::new(ori, last_ori) let tilt = if Vec2::new(ori, last_ori)
.map(|o| Vec2::<f32>::from(o).magnitude_squared()) .map(|o| o.magnitude_squared())
.map(|m| m > 0.0001 && m.is_finite()) .map(|m| m > 0.0001 && m.is_finite())
.reduce_and() .reduce_and()
&& ori.angle_between(last_ori).is_finite() && ori.angle_between(last_ori).is_finite()

View File

@ -18,7 +18,7 @@ impl Animation for JumpAnimation {
const UPDATE_FN: &'static [u8] = b"character_jump\0"; const UPDATE_FN: &'static [u8] = b"character_jump\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_jump")] #[cfg_attr(feature = "be-dyn-lib", export_name = "character_jump")]
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
fn update_skeleton_inner( fn update_skeleton_inner(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(active_tool_kind, second_tool_kind, orientation, last_ori, global_time): Self::Dependency, (active_tool_kind, second_tool_kind, orientation, last_ori, global_time): Self::Dependency,
@ -39,10 +39,10 @@ impl Animation for JumpAnimation {
let switch = if random > 0.5 { 1.0 } else { -1.0 }; let switch = if random > 0.5 { 1.0 } else { -1.0 };
let ori = Vec2::from(orientation); let ori: Vec2<f32> = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori); let last_ori = Vec2::from(last_ori);
let tilt = if Vec2::new(ori, last_ori) let tilt = if Vec2::new(ori, last_ori)
.map(|o| Vec2::<f32>::from(o).magnitude_squared()) .map(|o| o.magnitude_squared())
.map(|m| m > 0.001 && m.is_finite()) .map(|m| m > 0.001 && m.is_finite())
.reduce_and() .reduce_and()
&& ori.angle_between(last_ori).is_finite() && ori.angle_between(last_ori).is_finite()

View File

@ -19,7 +19,7 @@ impl Animation for RollAnimation {
const UPDATE_FN: &'static [u8] = b"character_roll\0"; const UPDATE_FN: &'static [u8] = b"character_roll\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_roll")] #[cfg_attr(feature = "be-dyn-lib", export_name = "character_roll")]
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
fn update_skeleton_inner( fn update_skeleton_inner(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(active_tool_kind, second_tool_kind, orientation, last_ori, _global_time): Self::Dependency, (active_tool_kind, second_tool_kind, orientation, last_ori, _global_time): Self::Dependency,
@ -31,10 +31,10 @@ impl Animation for RollAnimation {
let mut next = (*skeleton).clone(); let mut next = (*skeleton).clone();
let spin = anim_time as f32; let spin = anim_time as f32;
let ori = Vec2::from(orientation); let ori: Vec2<f32> = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori); let last_ori = Vec2::from(last_ori);
let tilt = if Vec2::new(ori, last_ori) let tilt = if Vec2::new(ori, last_ori)
.map(|o| Vec2::<f32>::from(o).magnitude_squared()) .map(|o| o.magnitude_squared())
.map(|m| m > 0.0001 && m.is_finite()) .map(|m| m > 0.0001 && m.is_finite())
.reduce_and() .reduce_and()
&& ori.angle_between(last_ori).is_finite() && ori.angle_between(last_ori).is_finite()

View File

@ -23,7 +23,7 @@ impl Animation for RunAnimation {
const UPDATE_FN: &'static [u8] = b"character_run\0"; const UPDATE_FN: &'static [u8] = b"character_run\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_run")] #[cfg_attr(feature = "be-dyn-lib", export_name = "character_run")]
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
fn update_skeleton_inner( fn update_skeleton_inner(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(active_tool_kind, second_tool_kind, velocity, orientation, last_ori, global_time, avg_vel): Self::Dependency, (active_tool_kind, second_tool_kind, velocity, orientation, last_ori, global_time, avg_vel): Self::Dependency,
@ -96,10 +96,10 @@ impl Animation for RunAnimation {
* 0.1, * 0.1,
); );
let ori = Vec2::from(orientation); let ori: Vec2<f32> = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori); let last_ori = Vec2::from(last_ori);
let tilt = if Vec2::new(ori, last_ori) let tilt = if Vec2::new(ori, last_ori)
.map(|o| Vec2::<f32>::from(o).magnitude_squared()) .map(|o| o.magnitude_squared())
.map(|m| m > 0.001 && m.is_finite()) .map(|m| m > 0.001 && m.is_finite())
.reduce_and() .reduce_and()
&& ori.angle_between(last_ori).is_finite() && ori.angle_between(last_ori).is_finite()

View File

@ -22,7 +22,7 @@ impl Animation for SwimAnimation {
const UPDATE_FN: &'static [u8] = b"character_swim\0"; const UPDATE_FN: &'static [u8] = b"character_swim\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_swim")] #[cfg_attr(feature = "be-dyn-lib", export_name = "character_swim")]
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
fn update_skeleton_inner( fn update_skeleton_inner(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(active_tool_kind, second_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency, (active_tool_kind, second_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency,
@ -57,10 +57,10 @@ impl Animation for SwimAnimation {
.sin() .sin()
* 0.1, * 0.1,
); );
let ori = Vec2::from(orientation); let ori: Vec2<f32> = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori); let last_ori = Vec2::from(last_ori);
let tilt = if Vec2::new(ori, last_ori) let tilt = if Vec2::new(ori, last_ori)
.map(|o| Vec2::<f32>::from(o).magnitude_squared()) .map(|o| o.magnitude_squared())
.map(|m| m > 0.001 && m.is_finite()) .map(|m| m > 0.001 && m.is_finite())
.reduce_and() .reduce_and()
&& ori.angle_between(last_ori).is_finite() && ori.angle_between(last_ori).is_finite()

View File

@ -11,7 +11,6 @@ impl Animation for RunAnimation {
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"quadruped_low_run\0"; const UPDATE_FN: &'static [u8] = b"quadruped_low_run\0";
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_low_run")] #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_low_run")]
fn update_skeleton_inner( fn update_skeleton_inner(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
@ -71,10 +70,10 @@ impl Animation for RunAnimation {
* ((anim_time as f32 * 16.0 * lab as f32 + PI * 0.05).sin()); * ((anim_time as f32 * 16.0 * lab as f32 + PI * 0.05).sin());
let footvertrb = (anim_time as f32 * 16.0 * lab as f32 + PI * 0.6).sin(); let footvertrb = (anim_time as f32 * 16.0 * lab as f32 + PI * 0.6).sin();
let ori = Vec2::from(orientation); let ori: Vec2<f32> = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori); let last_ori = Vec2::from(last_ori);
let tilt = if Vec2::new(ori, last_ori) let tilt = if Vec2::new(ori, last_ori)
.map(|o| Vec2::<f32>::from(o).magnitude_squared()) .map(|o| o.magnitude_squared())
.map(|m| m > 0.001 && m.is_finite()) .map(|m| m > 0.001 && m.is_finite())
.reduce_and() .reduce_and()
&& ori.angle_between(last_ori).is_finite() && ori.angle_between(last_ori).is_finite()

View File

@ -11,7 +11,6 @@ impl Animation for RunAnimation {
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"quadruped_medium_run\0"; const UPDATE_FN: &'static [u8] = b"quadruped_medium_run\0";
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_run")] #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_run")]
fn update_skeleton_inner( fn update_skeleton_inner(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
@ -58,10 +57,10 @@ impl Animation for RunAnimation {
let footvertaltfslow = (anim_time as f32 * 16.0 * lab as f32 * speedmult + PI * 1.8).sin(); let footvertaltfslow = (anim_time as f32 * 16.0 * lab as f32 * speedmult + PI * 1.8).sin();
let footverttaltfslow = (anim_time as f32 * 16.0 * lab as f32 * speedmult + PI * 2.2).sin(); let footverttaltfslow = (anim_time as f32 * 16.0 * lab as f32 * speedmult + PI * 2.2).sin();
// //
let ori = Vec2::from(orientation); let ori: Vec2<f32> = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori); let last_ori = Vec2::from(last_ori);
let tilt = if Vec2::new(ori, last_ori) let tilt = if Vec2::new(ori, last_ori)
.map(|o| Vec2::<f32>::from(o).magnitude_squared()) .map(|o| o.magnitude_squared())
.map(|m| m > 0.001 && m.is_finite()) .map(|m| m > 0.001 && m.is_finite())
.reduce_and() .reduce_and()
&& ori.angle_between(last_ori).is_finite() && ori.angle_between(last_ori).is_finite()

View File

@ -17,11 +17,10 @@ impl From<gfx::PipelineStateError<String>> for RenderError {
} }
impl From<gfx::PipelineStateError<&str>> for RenderError { impl From<gfx::PipelineStateError<&str>> for RenderError {
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
fn from(err: gfx::PipelineStateError<&str>) -> Self { fn from(err: gfx::PipelineStateError<&str>) -> Self {
match err { match err {
gfx::PipelineStateError::DescriptorInit(err) => { gfx::PipelineStateError::DescriptorInit(err) => {
gfx::PipelineStateError::DescriptorInit(err.into()) gfx::PipelineStateError::DescriptorInit(err)
}, },
err => err, err => err,
} }

View File

@ -70,7 +70,6 @@ impl<'a, R: Rng> GenCtx<'a, R> {
} }
impl Civs { impl Civs {
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
pub fn generate(seed: u32, sim: &mut WorldSim) -> Self { pub fn generate(seed: u32, sim: &mut WorldSim) -> Self {
let mut this = Self::default(); let mut this = Self::default();
let rng = ChaChaRng::from_seed(seed_expan::rng_state(seed)); let rng = ChaChaRng::from_seed(seed_expan::rng_state(seed));
@ -120,7 +119,7 @@ impl Civs {
for site in this.sites.iter() { for site in this.sites.iter() {
let radius = 48i32; let radius = 48i32;
let wpos = site.center * Vec2::from(TerrainChunkSize::RECT_SIZE).map(|e: u32| e as i32); let wpos = site.center * TerrainChunkSize::RECT_SIZE.map(|e: u32| e as i32);
let flatten_radius = match &site.kind { let flatten_radius = match &site.kind {
SiteKind::Settlement => 10.0, SiteKind::Settlement => 10.0,
@ -164,11 +163,9 @@ impl Civs {
let mut cnt = 0; let mut cnt = 0;
for site in this.sites.iter() { for site in this.sites.iter() {
cnt += 1; cnt += 1;
let wpos = site let wpos = site.center.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| {
.center e * sz as i32 + sz as i32 / 2
.map2(Vec2::from(TerrainChunkSize::RECT_SIZE), |e, sz: u32| { });
e * sz as i32 + sz as i32 / 2
});
let mut rng = ctx.reseed().rng; let mut rng = ctx.reseed().rng;
let world_site = match &site.kind { let world_site = match &site.kind {

View File

@ -64,7 +64,6 @@ impl World {
pub fn sample_blocks(&self) -> BlockGen { BlockGen::new(ColumnGen::new(&self.sim)) } pub fn sample_blocks(&self) -> BlockGen { BlockGen::new(ColumnGen::new(&self.sim)) }
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
#[allow(clippy::or_fun_call)] // TODO: Pending review in #587 #[allow(clippy::or_fun_call)] // TODO: Pending review in #587
pub fn generate_chunk( pub fn generate_chunk(
&self, &self,
@ -74,7 +73,7 @@ impl World {
) -> Result<(TerrainChunk, ChunkSupplement), ()> { ) -> Result<(TerrainChunk, ChunkSupplement), ()> {
let mut sampler = self.sample_blocks(); let mut sampler = self.sample_blocks();
let chunk_wpos2d = Vec2::from(chunk_pos) * TerrainChunkSize::RECT_SIZE.map(|e| e as i32); let chunk_wpos2d = chunk_pos * TerrainChunkSize::RECT_SIZE.map(|e| e as i32);
let grid_border = 4; let grid_border = 4;
let zcache_grid = Grid::populate_from( let zcache_grid = Grid::populate_from(
TerrainChunkSize::RECT_SIZE.map(|e| e as i32) + grid_border * 2, TerrainChunkSize::RECT_SIZE.map(|e| e as i32) + grid_border * 2,

View File

@ -109,7 +109,6 @@ impl MapConfig {
/// to the caller to provide a function that translates this information /// to the caller to provide a function that translates this information
/// into the correct format for a buffer and writes to it. /// into the correct format for a buffer and writes to it.
#[allow(clippy::if_same_then_else)] // TODO: Pending review in #587 #[allow(clippy::if_same_then_else)] // TODO: Pending review in #587
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
#[allow(clippy::unnested_or_patterns)] // TODO: Pending review in #587 #[allow(clippy::unnested_or_patterns)] // TODO: Pending review in #587
#[allow(clippy::many_single_char_names)] #[allow(clippy::many_single_char_names)]
pub fn generate( pub fn generate(
@ -142,190 +141,186 @@ impl MapConfig {
let focus_rect = Vec2::from(focus); let focus_rect = Vec2::from(focus);
let true_sea_level = (CONFIG.sea_level as f64 - focus.z) / gain as f64; let true_sea_level = (CONFIG.sea_level as f64 - focus.z) / gain as f64;
(0..dimensions.y * dimensions.x) (0..dimensions.y * dimensions.x).for_each(|chunk_idx| {
.into_iter() let i = chunk_idx % dimensions.x as usize;
.for_each(|chunk_idx| { let j = chunk_idx / dimensions.x as usize;
let i = chunk_idx % dimensions.x as usize;
let j = chunk_idx / dimensions.x as usize;
let pos = let pos = (focus_rect + Vec2::new(i as f64, j as f64) * scale).map(|e: f64| e as i32);
(focus_rect + Vec2::new(i as f64, j as f64) * scale).map(|e: f64| e as i32);
let ( let (
alt, alt,
basement, basement,
water_alt, water_alt,
humidity, humidity,
temperature, temperature,
downhill, downhill,
river_kind, river_kind,
is_path, is_path,
near_site, near_site,
) = sampler ) = sampler
.get(pos) .get(pos)
.map(|sample| { .map(|sample| {
( (
sample.alt, sample.alt,
sample.basement, sample.basement,
sample.water_alt, sample.water_alt,
sample.humidity, sample.humidity,
sample.temp, sample.temp,
sample.downhill, sample.downhill,
sample.river.river_kind, sample.river.river_kind,
sample.path.is_path(), sample.path.is_path(),
sample.sites.iter().any(|site| { sample.sites.iter().any(|site| {
site.get_origin() site.get_origin()
.distance_squared(pos * TerrainChunkSize::RECT_SIZE.x as i32) .distance_squared(pos * TerrainChunkSize::RECT_SIZE.x as i32)
< 64i32.pow(2) < 64i32.pow(2)
}), }),
) )
}) })
.unwrap_or(( .unwrap_or((
CONFIG.sea_level, CONFIG.sea_level,
CONFIG.sea_level, CONFIG.sea_level,
CONFIG.sea_level, CONFIG.sea_level,
0.0, 0.0,
0.0, 0.0,
None, None,
None, None,
false, false,
false, false,
)); ));
let humidity = humidity.min(1.0).max(0.0); let humidity = humidity.min(1.0).max(0.0);
let temperature = temperature.min(1.0).max(-1.0) * 0.5 + 0.5; let temperature = temperature.min(1.0).max(-1.0) * 0.5 + 0.5;
let pos = pos * TerrainChunkSize::RECT_SIZE.map(|e| e as i32); let pos = pos * TerrainChunkSize::RECT_SIZE.map(|e| e as i32);
let downhill_pos = (downhill let downhill_pos = (downhill
.map(|downhill_pos| downhill_pos) .map(|downhill_pos| downhill_pos)
.unwrap_or(pos + TerrainChunkSize::RECT_SIZE.map(|e| e as i32)) .unwrap_or(pos + TerrainChunkSize::RECT_SIZE.map(|e| e as i32))
- pos) - pos)
+ pos; + pos;
let downhill_alt = sampler let downhill_alt = sampler
.get_wpos(downhill_pos) .get_wpos(downhill_pos)
.map(|s| if is_basement { s.basement } else { s.alt }) .map(|s| if is_basement { s.basement } else { s.alt })
.unwrap_or(CONFIG.sea_level); .unwrap_or(CONFIG.sea_level);
let alt = if is_basement { basement } else { alt }; let alt = if is_basement { basement } else { alt };
let cross_pos = pos let cross_pos = pos
+ ((downhill_pos - pos) + ((downhill_pos - pos)
.map(|e| e as f32) .map(|e| e as f32)
.rotated_z(f32::consts::FRAC_PI_2) .rotated_z(f32::consts::FRAC_PI_2)
.map(|e| e as i32)); .map(|e| e as i32));
let cross_alt = sampler let cross_alt = sampler
.get_wpos(cross_pos) .get_wpos(cross_pos)
.map(|s| if is_basement { s.basement } else { s.alt }) .map(|s| if is_basement { s.basement } else { s.alt })
.unwrap_or(CONFIG.sea_level); .unwrap_or(CONFIG.sea_level);
// Pointing downhill, forward // Pointing downhill, forward
// (index--note that (0,0,1) is backward right-handed) // (index--note that (0,0,1) is backward right-handed)
let forward_vec = Vec3::new( let forward_vec = Vec3::new(
(downhill_pos.x - pos.x) as f64, (downhill_pos.x - pos.x) as f64,
(downhill_alt - alt) as f64 * lgain, (downhill_alt - alt) as f64 * lgain,
(downhill_pos.y - pos.y) as f64, (downhill_pos.y - pos.y) as f64,
); );
// Pointing 90 degrees left (in horizontal xy) of downhill, up // Pointing 90 degrees left (in horizontal xy) of downhill, up
// (middle--note that (1,0,0), 90 degrees CCW backward, is right right-handed) // (middle--note that (1,0,0), 90 degrees CCW backward, is right right-handed)
let up_vec = Vec3::new( let up_vec = Vec3::new(
(cross_pos.x - pos.x) as f64, (cross_pos.x - pos.x) as f64,
(cross_alt - alt) as f64 * lgain, (cross_alt - alt) as f64 * lgain,
(cross_pos.y - pos.y) as f64, (cross_pos.y - pos.y) as f64,
); );
// Then cross points "to the right" (upwards) on a right-handed coordinate // Then cross points "to the right" (upwards) on a right-handed coordinate
// system. (right-handed coordinate system means (0, 0, 1.0) is // system. (right-handed coordinate system means (0, 0, 1.0) is
// "forward" into the screen). // "forward" into the screen).
let surface_normal = forward_vec.cross(up_vec).normalized(); let surface_normal = forward_vec.cross(up_vec).normalized();
let light = (surface_normal.dot(light) + 1.0) / 2.0; let light = (surface_normal.dot(light) + 1.0) / 2.0;
let light = (light * 0.9) + 0.1; let light = (light * 0.9) + 0.1;
let true_water_alt = (alt.max(water_alt) as f64 - focus.z) / gain as f64; let true_water_alt = (alt.max(water_alt) as f64 - focus.z) / gain as f64;
let true_alt = (alt as f64 - focus.z) / gain as f64; let true_alt = (alt as f64 - focus.z) / gain as f64;
let water_depth = (true_water_alt - true_alt).min(1.0).max(0.0); let water_depth = (true_water_alt - true_alt).min(1.0).max(0.0);
let water_alt = true_water_alt.min(1.0).max(0.0); let water_alt = true_water_alt.min(1.0).max(0.0);
let alt = true_alt.min(1.0).max(0.0); let alt = true_alt.min(1.0).max(0.0);
if is_debug { if is_debug {
let quad = |x: f32| { let quad =
((x as f64 * QUADRANTS as f64).floor() as usize).min(QUADRANTS - 1) |x: f32| ((x as f64 * QUADRANTS as f64).floor() as usize).min(QUADRANTS - 1);
}; if river_kind.is_none() || humidity != 0.0 {
if river_kind.is_none() || humidity != 0.0 { quads[quad(humidity)][quad(temperature)] += 1;
quads[quad(humidity)][quad(temperature)] += 1;
}
match river_kind {
Some(RiverKind::River { .. }) => {
rivers += 1;
},
Some(RiverKind::Lake { .. }) => {
lakes += 1;
},
Some(RiverKind::Ocean { .. }) => {
oceans += 1;
},
None => {},
}
} }
match river_kind {
let water_color_factor = 2.0; Some(RiverKind::River { .. }) => {
let g_water = 32.0 * water_color_factor; rivers += 1;
let b_water = 64.0 * water_color_factor;
let rgba = match (river_kind, (is_water, true_alt >= true_sea_level)) {
(_, (false, _)) | (None, (_, true)) => {
let (r, g, b) = (
(if is_shaded { alt } else { alt }
* if is_temperature {
temperature as f64
} else if is_shaded {
alt
} else {
0.0
})
.sqrt(),
if is_shaded { 0.4 + (alt * 0.6) } else { alt },
(if is_shaded { alt } else { alt }
* if is_humidity {
humidity as f64
} else if is_shaded {
alt
} else {
0.0
})
.sqrt(),
);
let light = if is_shaded { light } else { 1.0 };
(
(r * light * 255.0) as u8,
(g * light * 255.0) as u8,
(b * light * 255.0) as u8,
255,
)
}, },
(Some(RiverKind::Ocean), _) => ( Some(RiverKind::Lake { .. }) => {
0, lakes += 1;
((g_water - water_depth * g_water) * 1.0) as u8, },
((b_water - water_depth * b_water) * 1.0) as u8, Some(RiverKind::Ocean { .. }) => {
255, oceans += 1;
), },
(Some(RiverKind::River { .. }), _) => ( None => {},
0, }
g_water as u8 + (alt * (127.0 - g_water)) as u8, }
b_water as u8 + (alt * (255.0 - b_water)) as u8,
255,
),
(None, _) | (Some(RiverKind::Lake { .. }), _) => (
0,
(((g_water + water_alt * (127.0 - 32.0)) + (-water_depth * g_water)) * 1.0)
as u8,
(((b_water + water_alt * (255.0 - b_water)) + (-water_depth * b_water))
* 1.0) as u8,
255,
),
};
let rgba = if near_site { let water_color_factor = 2.0;
(0x57, 0x39, 0x33, 0xFF) let g_water = 32.0 * water_color_factor;
} else if is_path { let b_water = 64.0 * water_color_factor;
(0x37, 0x29, 0x23, 0xFF) let rgba = match (river_kind, (is_water, true_alt >= true_sea_level)) {
} else { (_, (false, _)) | (None, (_, true)) => {
rgba let (r, g, b) = (
}; (if is_shaded { alt } else { alt }
* if is_temperature {
temperature as f64
} else if is_shaded {
alt
} else {
0.0
})
.sqrt(),
if is_shaded { 0.4 + (alt * 0.6) } else { alt },
(if is_shaded { alt } else { alt }
* if is_humidity {
humidity as f64
} else if is_shaded {
alt
} else {
0.0
})
.sqrt(),
);
let light = if is_shaded { light } else { 1.0 };
(
(r * light * 255.0) as u8,
(g * light * 255.0) as u8,
(b * light * 255.0) as u8,
255,
)
},
(Some(RiverKind::Ocean), _) => (
0,
((g_water - water_depth * g_water) * 1.0) as u8,
((b_water - water_depth * b_water) * 1.0) as u8,
255,
),
(Some(RiverKind::River { .. }), _) => (
0,
g_water as u8 + (alt * (127.0 - g_water)) as u8,
b_water as u8 + (alt * (255.0 - b_water)) as u8,
255,
),
(None, _) | (Some(RiverKind::Lake { .. }), _) => (
0,
(((g_water + water_alt * (127.0 - 32.0)) + (-water_depth * g_water)) * 1.0)
as u8,
(((b_water + water_alt * (255.0 - b_water)) + (-water_depth * b_water)) * 1.0)
as u8,
255,
),
};
write_pixel(Vec2::new(i, j), rgba); let rgba = if near_site {
}); (0x57, 0x39, 0x33, 0xFF)
} else if is_path {
(0x37, 0x29, 0x23, 0xFF)
} else {
rgba
};
write_pixel(Vec2::new(i, j), rgba);
});
MapDebug { MapDebug {
quads, quads,