mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'Thegaming_Life/replacing_all_map2_with_RECT_SIZE_with_cpos_to_wpos_and_wpos_to_cpos' into 'master'
replaced CHUNK_SIZE by RECT_SIZE everywhere, and change the use (and remove... See merge request veloren/veloren!3807
This commit is contained in:
@ -42,8 +42,9 @@ use common::{
|
|||||||
resources::{GameMode, PlayerEntity, TimeOfDay},
|
resources::{GameMode, PlayerEntity, TimeOfDay},
|
||||||
spiral::Spiral2d,
|
spiral::Spiral2d,
|
||||||
terrain::{
|
terrain::{
|
||||||
block::Block, map::MapConfig, neighbors, site::DungeonKindMeta, BiomeKind, SiteKindMeta,
|
block::Block, map::MapConfig, neighbors, site::DungeonKindMeta, BiomeKind,
|
||||||
SpriteKind, TerrainChunk, TerrainChunkSize, TerrainGrid,
|
CoordinateConversions, SiteKindMeta, SpriteKind, TerrainChunk, TerrainChunkSize,
|
||||||
|
TerrainGrid,
|
||||||
},
|
},
|
||||||
trade::{PendingTrade, SitePrices, TradeAction, TradeId, TradeResult},
|
trade::{PendingTrade, SitePrices, TradeAction, TradeId, TradeResult},
|
||||||
uid::{Uid, UidAllocator},
|
uid::{Uid, UidAllocator},
|
||||||
@ -569,7 +570,7 @@ impl Client {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
|wpos| {
|
|wpos| {
|
||||||
let pos = wpos.map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as i32);
|
let pos = wpos.wpos_to_cpos();
|
||||||
rescale_height(if bounds_check(pos) {
|
rescale_height(if bounds_check(pos) {
|
||||||
scale_height_big(alt[pos])
|
scale_height_big(alt[pos])
|
||||||
} else {
|
} else {
|
||||||
@ -597,7 +598,7 @@ impl Client {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
|wpos| {
|
|wpos| {
|
||||||
let pos = wpos.map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as i32);
|
let pos = wpos.wpos_to_cpos();
|
||||||
rescale_height(if bounds_check(pos) {
|
rescale_height(if bounds_check(pos) {
|
||||||
scale_height_big(alt[pos])
|
scale_height_big(alt[pos])
|
||||||
} else {
|
} else {
|
||||||
|
@ -83,17 +83,28 @@ pub trait CoordinateConversions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CoordinateConversions for Vec2<i32> {
|
impl CoordinateConversions for Vec2<i32> {
|
||||||
|
#[inline]
|
||||||
fn wpos_to_cpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e / sz as i32) }
|
fn wpos_to_cpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e / sz as i32) }
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn cpos_to_wpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e * sz as i32) }
|
fn cpos_to_wpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e * sz as i32) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CoordinateConversions for Vec2<f32> {
|
impl CoordinateConversions for Vec2<f32> {
|
||||||
|
#[inline]
|
||||||
fn wpos_to_cpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e / sz as f32) }
|
fn wpos_to_cpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e / sz as f32) }
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn cpos_to_wpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e * sz as f32) }
|
fn cpos_to_wpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e * sz as f32) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl CoordinateConversions for Vec2<f64> {
|
||||||
|
#[inline]
|
||||||
|
fn wpos_to_cpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e / sz as f64)}
|
||||||
|
#[inline]
|
||||||
|
fn cpos_to_wpos(&self) -> Self { self.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e * sz as f64)}
|
||||||
|
}
|
||||||
|
|
||||||
// TerrainChunkMeta
|
// TerrainChunkMeta
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
@ -43,9 +43,9 @@ use common::{
|
|||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
parse_cmd_args,
|
parse_cmd_args,
|
||||||
resources::{BattleMode, PlayerPhysicsSettings, Time, TimeOfDay},
|
resources::{BattleMode, PlayerPhysicsSettings, Time, TimeOfDay},
|
||||||
terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize},
|
terrain::{Block, BlockKind, CoordinateConversions, SpriteKind, TerrainChunkSize},
|
||||||
uid::{Uid, UidAllocator},
|
uid::{Uid, UidAllocator},
|
||||||
vol::{ReadVol, RectVolSize},
|
vol::ReadVol,
|
||||||
weather, Damage, DamageKind, DamageSource, Explosion, LoadoutBuilder, RadiusEffect,
|
weather, Damage, DamageKind, DamageSource, Explosion, LoadoutBuilder, RadiusEffect,
|
||||||
};
|
};
|
||||||
use common_net::{
|
use common_net::{
|
||||||
@ -2793,7 +2793,7 @@ fn handle_debug_column(
|
|||||||
let rockiness = sim.get_interpolated(wpos, |chunk| chunk.rockiness)?;
|
let rockiness = sim.get_interpolated(wpos, |chunk| chunk.rockiness)?;
|
||||||
let tree_density = sim.get_interpolated(wpos, |chunk| chunk.tree_density)?;
|
let tree_density = sim.get_interpolated(wpos, |chunk| chunk.tree_density)?;
|
||||||
let spawn_rate = sim.get_interpolated(wpos, |chunk| chunk.spawn_rate)?;
|
let spawn_rate = sim.get_interpolated(wpos, |chunk| chunk.spawn_rate)?;
|
||||||
let chunk_pos = wpos.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| e / sz as i32);
|
let chunk_pos = wpos.wpos_to_cpos();
|
||||||
let chunk = sim.get(chunk_pos)?;
|
let chunk = sim.get(chunk_pos)?;
|
||||||
let col = sampler.get((wpos, server.index.as_index_ref(), Some(calendar)))?;
|
let col = sampler.get((wpos, server.index.as_index_ref(), Some(calendar)))?;
|
||||||
let gradient = sim.get_gradient_approx(chunk_pos)?;
|
let gradient = sim.get_gradient_approx(chunk_pos)?;
|
||||||
@ -2873,7 +2873,7 @@ fn handle_debug_ways(
|
|||||||
pos.0.xy().map(|x| x as i32)
|
pos.0.xy().map(|x| x as i32)
|
||||||
};
|
};
|
||||||
let msg_generator = || {
|
let msg_generator = || {
|
||||||
let chunk_pos = wpos.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| e / sz as i32);
|
let chunk_pos = wpos.wpos_to_cpos();
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
for delta in LOCALITY {
|
for delta in LOCALITY {
|
||||||
let pos = chunk_pos + delta;
|
let pos = chunk_pos + delta;
|
||||||
@ -3316,9 +3316,7 @@ fn handle_battlemode(
|
|||||||
// get chunk position
|
// get chunk position
|
||||||
let pos = position(server, target, "target")?;
|
let pos = position(server, target, "target")?;
|
||||||
let wpos = pos.0.xy().map(|x| x as i32);
|
let wpos = pos.0.xy().map(|x| x as i32);
|
||||||
let chunk_pos = wpos.map2(TerrainChunkSize::RECT_SIZE, |wpos, size: u32| {
|
let chunk_pos = wpos.wpos_to_cpos();
|
||||||
wpos / size as i32
|
|
||||||
});
|
|
||||||
server.world.civs().sites().any(|site| {
|
server.world.civs().sites().any(|site| {
|
||||||
// empirical
|
// empirical
|
||||||
const RADIUS: f32 = 9.0;
|
const RADIUS: f32 = 9.0;
|
||||||
|
@ -6,7 +6,7 @@ use common::{
|
|||||||
comp::Pos,
|
comp::Pos,
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
spiral::Spiral2d,
|
spiral::Spiral2d,
|
||||||
terrain::{TerrainChunkSize, TerrainGrid},
|
terrain::{CoordinateConversions, TerrainChunkSize, TerrainGrid},
|
||||||
vol::RectVolSize,
|
vol::RectVolSize,
|
||||||
};
|
};
|
||||||
use common_ecs::{Job, Origin, ParMode, Phase, System};
|
use common_ecs::{Job, Origin, ParMode, Phase, System};
|
||||||
@ -128,7 +128,8 @@ impl<'a> System<'a> for Sys {
|
|||||||
let player_chunk = pos
|
let player_chunk = pos
|
||||||
.0
|
.0
|
||||||
.xy()
|
.xy()
|
||||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32);
|
.as_::<i32>()
|
||||||
|
.wpos_to_cpos();
|
||||||
for rpos in Spiral2d::new().take((crate::MIN_VD as usize + 1).pow(2)) {
|
for rpos in Spiral2d::new().take((crate::MIN_VD as usize + 1).pow(2)) {
|
||||||
let key = player_chunk + rpos;
|
let key = player_chunk + rpos;
|
||||||
if terrain.get_key(key).is_none() {
|
if terrain.get_key(key).is_none() {
|
||||||
|
@ -6,7 +6,7 @@ use crate::{
|
|||||||
use common::{
|
use common::{
|
||||||
comp::{Ori, Pos, Vel},
|
comp::{Ori, Pos, Vel},
|
||||||
region::{region_in_vd, regions_in_vd, Event as RegionEvent, RegionMap},
|
region::{region_in_vd, regions_in_vd, Event as RegionEvent, RegionMap},
|
||||||
terrain::TerrainChunkSize,
|
terrain::{CoordinateConversions, TerrainChunkSize},
|
||||||
uid::Uid,
|
uid::Uid,
|
||||||
vol::RectVolSize,
|
vol::RectVolSize,
|
||||||
};
|
};
|
||||||
@ -81,8 +81,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
{
|
{
|
||||||
let vd = presence.entity_view_distance.current();
|
let vd = presence.entity_view_distance.current();
|
||||||
// Calculate current chunk
|
// Calculate current chunk
|
||||||
let chunk = (Vec2::<f32>::from(pos.0))
|
let chunk = (Vec2::<f32>::from(pos.0)).as_::<i32>().wpos_to_cpos();
|
||||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32);
|
|
||||||
// Only update regions when moving to a new chunk or if view distance has
|
// Only update regions when moving to a new chunk or if view distance has
|
||||||
// changed.
|
// changed.
|
||||||
//
|
//
|
||||||
@ -104,8 +103,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
// Update the view distance
|
// Update the view distance
|
||||||
subscription.last_entity_view_distance = vd;
|
subscription.last_entity_view_distance = vd;
|
||||||
// Update current chunk
|
// Update current chunk
|
||||||
subscription.fuzzy_chunk = Vec2::<f32>::from(pos.0)
|
subscription.fuzzy_chunk = Vec2::<f32>::from(pos.0).as_::<i32>().wpos_to_cpos();
|
||||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32);
|
|
||||||
// Use the largest side length as our chunk size
|
// Use the largest side length as our chunk size
|
||||||
let chunk_size = TerrainChunkSize::RECT_SIZE.reduce_max() as f32;
|
let chunk_size = TerrainChunkSize::RECT_SIZE.reduce_max() as f32;
|
||||||
// Iterate through currently subscribed regions
|
// Iterate through currently subscribed regions
|
||||||
@ -218,7 +216,8 @@ pub fn initialize_region_subscription(world: &World, entity: specs::Entity) {
|
|||||||
world.write_storage::<Client>().get(entity),
|
world.write_storage::<Client>().get(entity),
|
||||||
) {
|
) {
|
||||||
let fuzzy_chunk = (Vec2::<f32>::from(client_pos.0))
|
let fuzzy_chunk = (Vec2::<f32>::from(client_pos.0))
|
||||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32);
|
.as_::<i32>()
|
||||||
|
.wpos_to_cpos();
|
||||||
let chunk_size = TerrainChunkSize::RECT_SIZE.reduce_max() as f32;
|
let chunk_size = TerrainChunkSize::RECT_SIZE.reduce_max() as f32;
|
||||||
let regions = regions_in_vd(
|
let regions = regions_in_vd(
|
||||||
client_pos.0,
|
client_pos.0,
|
||||||
|
@ -11,7 +11,13 @@ use crate::{
|
|||||||
GlobalState,
|
GlobalState,
|
||||||
};
|
};
|
||||||
use client::{self, Client, SiteInfoRich};
|
use client::{self, Client, SiteInfoRich};
|
||||||
use common::{comp, comp::group::Role, terrain::TerrainChunkSize, trade::Good, vol::RectVolSize};
|
use common::{
|
||||||
|
comp,
|
||||||
|
comp::group::Role,
|
||||||
|
terrain::{CoordinateConversions, TerrainChunkSize},
|
||||||
|
trade::Good,
|
||||||
|
vol::RectVolSize,
|
||||||
|
};
|
||||||
use common_net::msg::world_msg::{PoiKind, SiteId, SiteKind};
|
use common_net::msg::world_msg::{PoiKind, SiteId, SiteKind};
|
||||||
use conrod_core::{
|
use conrod_core::{
|
||||||
color,
|
color,
|
||||||
@ -383,9 +389,7 @@ impl<'a> Widget for Map<'a> {
|
|||||||
},
|
},
|
||||||
MarkerChange::ClickPos => {
|
MarkerChange::ClickPos => {
|
||||||
let tmp: Vec2<f64> = Vec2::<f64>::from(click.xy) / zoom - drag;
|
let tmp: Vec2<f64> = Vec2::<f64>::from(click.xy) / zoom - drag;
|
||||||
let wpos = tmp
|
let wpos = tmp.as_::<f32>().cpos_to_wpos() + player_pos;
|
||||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as f32 * sz as f32)
|
|
||||||
+ player_pos;
|
|
||||||
events.push(Event::SetLocationMarker(wpos.as_()));
|
events.push(Event::SetLocationMarker(wpos.as_()));
|
||||||
},
|
},
|
||||||
MarkerChange::Remove => events.push(Event::RemoveMarker),
|
MarkerChange::Remove => events.push(Event::RemoveMarker),
|
||||||
@ -873,7 +877,7 @@ impl<'a> Widget for Map<'a> {
|
|||||||
// Site pos in world coordinates relative to the player
|
// Site pos in world coordinates relative to the player
|
||||||
let rwpos = wpos - player_pos;
|
let rwpos = wpos - player_pos;
|
||||||
// Convert to chunk coordinates
|
// Convert to chunk coordinates
|
||||||
let rcpos = rwpos.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e / sz as f32)
|
let rcpos = rwpos.wpos_to_cpos()
|
||||||
// Add map dragging
|
// Add map dragging
|
||||||
+ drag.map(|e| e as f32);
|
+ drag.map(|e| e as f32);
|
||||||
// Convert to relative pixel coordinates from the center of the map
|
// Convert to relative pixel coordinates from the center of the map
|
||||||
|
@ -15,7 +15,9 @@ use common::{
|
|||||||
comp::group::Role,
|
comp::group::Role,
|
||||||
grid::Grid,
|
grid::Grid,
|
||||||
slowjob::SlowJobPool,
|
slowjob::SlowJobPool,
|
||||||
terrain::{Block, BlockKind, TerrainChunk, TerrainChunkSize, TerrainGrid},
|
terrain::{
|
||||||
|
Block, BlockKind, CoordinateConversions, TerrainChunk, TerrainChunkSize, TerrainGrid,
|
||||||
|
},
|
||||||
vol::{ReadVol, RectVolSize},
|
vol::{ReadVol, RectVolSize},
|
||||||
};
|
};
|
||||||
use common_net::msg::world_msg::SiteKind;
|
use common_net::msg::world_msg::SiteKind;
|
||||||
@ -660,7 +662,7 @@ impl<'a> Widget for MiniMap<'a> {
|
|||||||
// Site pos in world coordinates relative to the player
|
// Site pos in world coordinates relative to the player
|
||||||
let rwpos = wpos - player_pos;
|
let rwpos = wpos - player_pos;
|
||||||
// Convert to chunk coordinates
|
// Convert to chunk coordinates
|
||||||
let rcpos = rwpos.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e / sz as f32);
|
let rcpos = rwpos.wpos_to_cpos();
|
||||||
// Convert to fractional coordinates relative to the worldsize
|
// Convert to fractional coordinates relative to the worldsize
|
||||||
let rfpos = rcpos / max_zoom as f32;
|
let rfpos = rcpos / max_zoom as f32;
|
||||||
// Convert to unrotated pixel coordinates from the player location on the map
|
// Convert to unrotated pixel coordinates from the player location on the map
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
use common::{
|
use common::{
|
||||||
terrain::{
|
terrain::{
|
||||||
map::{MapConfig, MapDebug, MapSample},
|
map::{MapConfig, MapDebug, MapSample},
|
||||||
uniform_idx_as_vec2, vec2_as_uniform_idx, TerrainChunkSize,
|
uniform_idx_as_vec2, vec2_as_uniform_idx, CoordinateConversions, TerrainChunkSize,
|
||||||
},
|
},
|
||||||
vol::RectVolSize,
|
vol::RectVolSize,
|
||||||
};
|
};
|
||||||
@ -286,7 +286,7 @@ fn main() {
|
|||||||
let chunk_pos = (Vec2::<f64>::from(focus)
|
let chunk_pos = (Vec2::<f64>::from(focus)
|
||||||
+ (Vec2::new(mx as f64, my as f64) * scale))
|
+ (Vec2::new(mx as f64, my as f64) * scale))
|
||||||
.map(|e| e as i32);
|
.map(|e| e as i32);
|
||||||
let block_pos = chunk_pos.map2(TerrainChunkSize::RECT_SIZE, |e, f| e * f as i32);
|
let block_pos = chunk_pos.cpos_to_wpos();
|
||||||
println!(
|
println!(
|
||||||
"Block: ({}, {}), Chunk: ({}, {})",
|
"Block: ({}, {}), Chunk: ({}, {})",
|
||||||
block_pos.x, block_pos.y, chunk_pos.x, chunk_pos.y
|
block_pos.x, block_pos.y, chunk_pos.x, chunk_pos.y
|
||||||
|
@ -16,7 +16,8 @@ use common::{
|
|||||||
spiral::Spiral2d,
|
spiral::Spiral2d,
|
||||||
store::{Id, Store},
|
store::{Id, Store},
|
||||||
terrain::{
|
terrain::{
|
||||||
uniform_idx_as_vec2, BiomeKind, MapSizeLg, TerrainChunkSize, TERRAIN_CHUNK_BLOCKS_LG,
|
uniform_idx_as_vec2, BiomeKind, CoordinateConversions, MapSizeLg, TerrainChunkSize,
|
||||||
|
TERRAIN_CHUNK_BLOCKS_LG,
|
||||||
},
|
},
|
||||||
vol::RectVolSize,
|
vol::RectVolSize,
|
||||||
};
|
};
|
||||||
@ -1389,8 +1390,7 @@ fn loc_suitable_for_site(sim: &WorldSim, loc: Vec2<i32>, site_kind: SiteKind) ->
|
|||||||
fn check_chunk_occupation(sim: &WorldSim, loc: Vec2<i32>, radius: i32) -> bool {
|
fn check_chunk_occupation(sim: &WorldSim, loc: Vec2<i32>, radius: i32) -> bool {
|
||||||
for x in (-radius)..radius {
|
for x in (-radius)..radius {
|
||||||
for y in (-radius)..radius {
|
for y in (-radius)..radius {
|
||||||
let check_loc =
|
let check_loc = loc + Vec2::new(x, y).cpos_to_wpos();
|
||||||
loc + Vec2::new(x, y).map2(TerrainChunkSize::RECT_SIZE, |e, sz| e * sz as i32);
|
|
||||||
if sim.get(check_loc).map_or(false, |c| !c.sites.is_empty()) {
|
if sim.get(check_loc).map_or(false, |c| !c.sites.is_empty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1424,10 +1424,9 @@ fn find_site_loc(
|
|||||||
}
|
}
|
||||||
|
|
||||||
loc = ctx.sim.get(test_loc).and_then(|c| {
|
loc = ctx.sim.get(test_loc).and_then(|c| {
|
||||||
site_kind.is_suitable_loc(test_loc, ctx.sim).then_some(
|
site_kind
|
||||||
c.downhill?
|
.is_suitable_loc(test_loc, ctx.sim)
|
||||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| e / (sz as i32)),
|
.then_some(c.downhill?.wpos_to_cpos())
|
||||||
)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1530,9 +1529,7 @@ impl SiteKind {
|
|||||||
let mut land_chunks = 0;
|
let mut land_chunks = 0;
|
||||||
for x in (-RESOURCE_RADIUS)..RESOURCE_RADIUS {
|
for x in (-RESOURCE_RADIUS)..RESOURCE_RADIUS {
|
||||||
for y in (-RESOURCE_RADIUS)..RESOURCE_RADIUS {
|
for y in (-RESOURCE_RADIUS)..RESOURCE_RADIUS {
|
||||||
let check_loc = loc
|
let check_loc = loc + Vec2::new(x, y).cpos_to_wpos();
|
||||||
+ Vec2::new(x, y)
|
|
||||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e * sz as i32);
|
|
||||||
sim.get(check_loc).map(|c| {
|
sim.get(check_loc).map(|c| {
|
||||||
if num::abs(chunk.alt - c.alt) < 200.0 {
|
if num::abs(chunk.alt - c.alt) < 200.0 {
|
||||||
if c.river.is_river() {
|
if c.river.is_river() {
|
||||||
|
@ -9,7 +9,7 @@ use common::{
|
|||||||
calendar::{Calendar, CalendarEvent},
|
calendar::{Calendar, CalendarEvent},
|
||||||
terrain::{
|
terrain::{
|
||||||
quadratic_nearest_point, river_spline_coeffs, uniform_idx_as_vec2, vec2_as_uniform_idx,
|
quadratic_nearest_point, river_spline_coeffs, uniform_idx_as_vec2, vec2_as_uniform_idx,
|
||||||
TerrainChunkSize,
|
CoordinateConversions, TerrainChunkSize,
|
||||||
},
|
},
|
||||||
vol::RectVolSize,
|
vol::RectVolSize,
|
||||||
};
|
};
|
||||||
@ -68,7 +68,7 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
|
|||||||
|
|
||||||
fn get(&self, (wpos, index, calendar): Self::Index) -> Option<ColumnSample<'a>> {
|
fn get(&self, (wpos, index, calendar): Self::Index) -> Option<ColumnSample<'a>> {
|
||||||
let wposf = wpos.map(|e| e as f64);
|
let wposf = wpos.map(|e| e as f64);
|
||||||
let chunk_pos = wpos.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| e / sz as i32);
|
let chunk_pos = wpos.wpos_to_cpos();
|
||||||
|
|
||||||
let sim = &self.sim;
|
let sim = &self.sim;
|
||||||
|
|
||||||
@ -247,8 +247,7 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
|
|||||||
}
|
}
|
||||||
let neighbor_pass_wpos =
|
let neighbor_pass_wpos =
|
||||||
neighbor_pass_pos.map(|e| e as f64) + neighbor_coef * 0.5;
|
neighbor_pass_pos.map(|e| e as f64) + neighbor_coef * 0.5;
|
||||||
let neighbor_pass_pos = neighbor_pass_pos
|
let neighbor_pass_pos = neighbor_pass_pos.wpos_to_cpos();
|
||||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| e / sz as i32);
|
|
||||||
let coeffs = river_spline_coeffs(
|
let coeffs = river_spline_coeffs(
|
||||||
neighbor_wpos,
|
neighbor_wpos,
|
||||||
spline_derivative,
|
spline_derivative,
|
||||||
|
@ -7,10 +7,9 @@ use crate::{
|
|||||||
use common::{
|
use common::{
|
||||||
generation::EntityInfo,
|
generation::EntityInfo,
|
||||||
terrain::{
|
terrain::{
|
||||||
quadratic_nearest_point, river_spline_coeffs, Block, BlockKind, SpriteKind,
|
quadratic_nearest_point, river_spline_coeffs, Block, BlockKind, CoordinateConversions,
|
||||||
TerrainChunkSize,
|
SpriteKind,
|
||||||
},
|
},
|
||||||
vol::RectVolSize,
|
|
||||||
};
|
};
|
||||||
use noise::NoiseFn;
|
use noise::NoiseFn;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
@ -70,11 +69,7 @@ fn node_at(cell: Vec2<i32>, level: u32, land: &Land) -> Option<Node> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn surface_entrances<'a>(land: &'a Land) -> impl Iterator<Item = Vec2<i32>> + 'a {
|
pub fn surface_entrances<'a>(land: &'a Land) -> impl Iterator<Item = Vec2<i32>> + 'a {
|
||||||
let sz_cells = to_cell(
|
let sz_cells = to_cell(land.size().as_::<i32>().cpos_to_wpos(), 0);
|
||||||
land.size()
|
|
||||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| (e * sz) as i32),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
(0..sz_cells.x + 1)
|
(0..sz_cells.x + 1)
|
||||||
.flat_map(move |x| (0..sz_cells.y + 1).map(move |y| Vec2::new(x, y)))
|
.flat_map(move |x| (0..sz_cells.y + 1).map(move |y| Vec2::new(x, y)))
|
||||||
.filter_map(|cell| Some(tunnel_below_from_cell(cell, 0, land)?.a.wpos))
|
.filter_map(|cell| Some(tunnel_below_from_cell(cell, 0, land)?.a.wpos))
|
||||||
|
@ -7,7 +7,7 @@ use crate::{
|
|||||||
use common::{
|
use common::{
|
||||||
terrain::{
|
terrain::{
|
||||||
map::{Connection, ConnectionKind, MapConfig, MapSample},
|
map::{Connection, ConnectionKind, MapConfig, MapSample},
|
||||||
vec2_as_uniform_idx, TerrainChunkSize, NEIGHBOR_DELTA,
|
vec2_as_uniform_idx, CoordinateConversions, TerrainChunkSize, NEIGHBOR_DELTA,
|
||||||
},
|
},
|
||||||
vol::RectVolSize,
|
vol::RectVolSize,
|
||||||
};
|
};
|
||||||
@ -218,7 +218,7 @@ pub fn sample_pos(
|
|||||||
RiverKind::Lake { .. } | RiverKind::Ocean => TerrainChunkSize::RECT_SIZE.x as f32,
|
RiverKind::Lake { .. } | RiverKind::Ocean => TerrainChunkSize::RECT_SIZE.x as f32,
|
||||||
});
|
});
|
||||||
if let (Some(river_width), true) = (river_width, is_water) {
|
if let (Some(river_width), true) = (river_width, is_water) {
|
||||||
let downhill_pos = downhill_wpos.map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as i32);
|
let downhill_pos = downhill_wpos.wpos_to_cpos();
|
||||||
NEIGHBOR_DELTA
|
NEIGHBOR_DELTA
|
||||||
.iter()
|
.iter()
|
||||||
.zip(connections.iter_mut())
|
.zip(connections.iter_mut())
|
||||||
|
@ -46,8 +46,8 @@ use common::{
|
|||||||
spiral::Spiral2d,
|
spiral::Spiral2d,
|
||||||
store::Id,
|
store::Id,
|
||||||
terrain::{
|
terrain::{
|
||||||
map::MapConfig, uniform_idx_as_vec2, vec2_as_uniform_idx, BiomeKind, MapSizeLg,
|
map::MapConfig, uniform_idx_as_vec2, vec2_as_uniform_idx, BiomeKind, CoordinateConversions,
|
||||||
TerrainChunk, TerrainChunkSize,
|
MapSizeLg, TerrainChunk, TerrainChunkSize,
|
||||||
},
|
},
|
||||||
vol::RectVolSize,
|
vol::RectVolSize,
|
||||||
};
|
};
|
||||||
@ -1907,8 +1907,7 @@ impl WorldSim {
|
|||||||
pub fn get_gradient_approx(&self, chunk_pos: Vec2<i32>) -> Option<f32> {
|
pub fn get_gradient_approx(&self, chunk_pos: Vec2<i32>) -> Option<f32> {
|
||||||
let a = self.get(chunk_pos)?;
|
let a = self.get(chunk_pos)?;
|
||||||
if let Some(downhill) = a.downhill {
|
if let Some(downhill) = a.downhill {
|
||||||
let b =
|
let b = self.get(downhill.wpos_to_cpos())?;
|
||||||
self.get(downhill.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| e / (sz as i32)))?;
|
|
||||||
Some((a.alt - b.alt).abs() / TerrainChunkSize::RECT_SIZE.x as f32)
|
Some((a.alt - b.alt).abs() / TerrainChunkSize::RECT_SIZE.x as f32)
|
||||||
} else {
|
} else {
|
||||||
Some(0.0)
|
Some(0.0)
|
||||||
@ -1968,9 +1967,7 @@ impl WorldSim {
|
|||||||
T: Copy + Default + Add<Output = T> + Mul<f32, Output = T>,
|
T: Copy + Default + Add<Output = T> + Mul<f32, Output = T>,
|
||||||
F: FnMut(&SimChunk) -> T,
|
F: FnMut(&SimChunk) -> T,
|
||||||
{
|
{
|
||||||
let pos = pos.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| {
|
let pos = pos.as_::<f64>().wpos_to_cpos();
|
||||||
e as f64 / sz as f64
|
|
||||||
});
|
|
||||||
|
|
||||||
let cubic = |a: T, b: T, c: T, d: T, x: f32| -> T {
|
let cubic = |a: T, b: T, c: T, d: T, x: f32| -> T {
|
||||||
let x2 = x * x;
|
let x2 = x * x;
|
||||||
@ -2016,9 +2013,7 @@ impl WorldSim {
|
|||||||
//
|
//
|
||||||
// Note that these are only guaranteed monotone in one dimension; fortunately,
|
// Note that these are only guaranteed monotone in one dimension; fortunately,
|
||||||
// that is sufficient for our purposes.
|
// that is sufficient for our purposes.
|
||||||
let pos = pos.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| {
|
let pos = pos.as_::<f64>().wpos_to_cpos();
|
||||||
e as f64 / sz as f64
|
|
||||||
});
|
|
||||||
|
|
||||||
let secant = |b: T, c: T| c - b;
|
let secant = |b: T, c: T| c - b;
|
||||||
|
|
||||||
@ -2088,9 +2083,7 @@ impl WorldSim {
|
|||||||
//
|
//
|
||||||
// Note that these are only guaranteed monotone in one dimension; fortunately,
|
// Note that these are only guaranteed monotone in one dimension; fortunately,
|
||||||
// that is sufficient for our purposes.
|
// that is sufficient for our purposes.
|
||||||
let pos = pos.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| {
|
let pos = pos.as_::<f64>().wpos_to_cpos();
|
||||||
e as f64 / sz as f64
|
|
||||||
});
|
|
||||||
|
|
||||||
// Orient the chunk in the direction of the most downhill point of the four. If
|
// Orient the chunk in the direction of the most downhill point of the four. If
|
||||||
// there is no "most downhill" point, then we don't care.
|
// there is no "most downhill" point, then we don't care.
|
||||||
|
Reference in New Issue
Block a user