mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
replaced CHUNK_SIZE by RECT_SIZE everywhere, and change the use (and remove...
This commit is contained in:
parent
589fddab4e
commit
5ddc55be52
@ -42,8 +42,9 @@ use common::{
|
||||
resources::{GameMode, PlayerEntity, TimeOfDay},
|
||||
spiral::Spiral2d,
|
||||
terrain::{
|
||||
block::Block, map::MapConfig, neighbors, site::DungeonKindMeta, BiomeKind, SiteKindMeta,
|
||||
SpriteKind, TerrainChunk, TerrainChunkSize, TerrainGrid,
|
||||
block::Block, map::MapConfig, neighbors, site::DungeonKindMeta, BiomeKind,
|
||||
CoordinateConversions, SiteKindMeta, SpriteKind, TerrainChunk, TerrainChunkSize,
|
||||
TerrainGrid,
|
||||
},
|
||||
trade::{PendingTrade, SitePrices, TradeAction, TradeId, TradeResult},
|
||||
uid::{Uid, UidAllocator},
|
||||
@ -569,7 +570,7 @@ impl Client {
|
||||
)
|
||||
},
|
||||
|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) {
|
||||
scale_height_big(alt[pos])
|
||||
} else {
|
||||
@ -597,7 +598,7 @@ impl Client {
|
||||
)
|
||||
},
|
||||
|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) {
|
||||
scale_height_big(alt[pos])
|
||||
} else {
|
||||
|
@ -82,17 +82,28 @@ pub trait CoordinateConversions {
|
||||
}
|
||||
|
||||
impl CoordinateConversions for Vec2<i32> {
|
||||
#[inline]
|
||||
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) }
|
||||
}
|
||||
|
||||
impl CoordinateConversions for Vec2<f32> {
|
||||
#[inline]
|
||||
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) }
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
@ -43,9 +43,9 @@ use common::{
|
||||
outcome::Outcome,
|
||||
parse_cmd_args,
|
||||
resources::{BattleMode, PlayerPhysicsSettings, Time, TimeOfDay},
|
||||
terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize},
|
||||
terrain::{Block, BlockKind, CoordinateConversions, SpriteKind, TerrainChunkSize},
|
||||
uid::{Uid, UidAllocator},
|
||||
vol::{ReadVol, RectVolSize},
|
||||
vol::ReadVol,
|
||||
weather, Damage, DamageKind, DamageSource, Explosion, LoadoutBuilder, RadiusEffect,
|
||||
};
|
||||
use common_net::{
|
||||
@ -2793,7 +2793,7 @@ fn handle_debug_column(
|
||||
let rockiness = sim.get_interpolated(wpos, |chunk| chunk.rockiness)?;
|
||||
let tree_density = sim.get_interpolated(wpos, |chunk| chunk.tree_density)?;
|
||||
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 col = sampler.get((wpos, server.index.as_index_ref(), Some(calendar)))?;
|
||||
let gradient = sim.get_gradient_approx(chunk_pos)?;
|
||||
@ -2873,7 +2873,7 @@ fn handle_debug_ways(
|
||||
pos.0.xy().map(|x| x as i32)
|
||||
};
|
||||
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();
|
||||
for delta in LOCALITY {
|
||||
let pos = chunk_pos + delta;
|
||||
@ -3316,9 +3316,7 @@ fn handle_battlemode(
|
||||
// get chunk position
|
||||
let pos = position(server, target, "target")?;
|
||||
let wpos = pos.0.xy().map(|x| x as i32);
|
||||
let chunk_pos = wpos.map2(TerrainChunkSize::RECT_SIZE, |wpos, size: u32| {
|
||||
wpos / size as i32
|
||||
});
|
||||
let chunk_pos = wpos.wpos_to_cpos();
|
||||
server.world.civs().sites().any(|site| {
|
||||
// empirical
|
||||
const RADIUS: f32 = 9.0;
|
||||
|
@ -6,7 +6,7 @@ use common::{
|
||||
comp::Pos,
|
||||
event::{EventBus, ServerEvent},
|
||||
spiral::Spiral2d,
|
||||
terrain::{TerrainChunkSize, TerrainGrid},
|
||||
terrain::{CoordinateConversions, TerrainChunkSize, TerrainGrid},
|
||||
vol::RectVolSize,
|
||||
};
|
||||
use common_ecs::{Job, Origin, ParMode, Phase, System};
|
||||
@ -128,7 +128,8 @@ impl<'a> System<'a> for Sys {
|
||||
let player_chunk = pos
|
||||
.0
|
||||
.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)) {
|
||||
let key = player_chunk + rpos;
|
||||
if terrain.get_key(key).is_none() {
|
||||
|
@ -6,7 +6,7 @@ use crate::{
|
||||
use common::{
|
||||
comp::{Ori, Pos, Vel},
|
||||
region::{region_in_vd, regions_in_vd, Event as RegionEvent, RegionMap},
|
||||
terrain::TerrainChunkSize,
|
||||
terrain::{CoordinateConversions, TerrainChunkSize},
|
||||
uid::Uid,
|
||||
vol::RectVolSize,
|
||||
};
|
||||
@ -81,8 +81,7 @@ impl<'a> System<'a> for Sys {
|
||||
{
|
||||
let vd = presence.entity_view_distance.current();
|
||||
// Calculate current chunk
|
||||
let chunk = (Vec2::<f32>::from(pos.0))
|
||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32);
|
||||
let chunk = (Vec2::<f32>::from(pos.0)).as_::<i32>().wpos_to_cpos();
|
||||
// Only update regions when moving to a new chunk or if view distance has
|
||||
// changed.
|
||||
//
|
||||
@ -104,8 +103,7 @@ impl<'a> System<'a> for Sys {
|
||||
// Update the view distance
|
||||
subscription.last_entity_view_distance = vd;
|
||||
// Update current chunk
|
||||
subscription.fuzzy_chunk = Vec2::<f32>::from(pos.0)
|
||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32);
|
||||
subscription.fuzzy_chunk = Vec2::<f32>::from(pos.0).as_::<i32>().wpos_to_cpos();
|
||||
// Use the largest side length as our chunk size
|
||||
let chunk_size = TerrainChunkSize::RECT_SIZE.reduce_max() as f32;
|
||||
// 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),
|
||||
) {
|
||||
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 regions = regions_in_vd(
|
||||
client_pos.0,
|
||||
|
@ -11,7 +11,13 @@ use crate::{
|
||||
GlobalState,
|
||||
};
|
||||
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 conrod_core::{
|
||||
color,
|
||||
@ -383,9 +389,7 @@ impl<'a> Widget for Map<'a> {
|
||||
},
|
||||
MarkerChange::ClickPos => {
|
||||
let tmp: Vec2<f64> = Vec2::<f64>::from(click.xy) / zoom - drag;
|
||||
let wpos = tmp
|
||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as f32 * sz as f32)
|
||||
+ player_pos;
|
||||
let wpos = tmp.as_::<f32>().cpos_to_wpos() + player_pos;
|
||||
events.push(Event::SetLocationMarker(wpos.as_()));
|
||||
},
|
||||
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
|
||||
let rwpos = wpos - player_pos;
|
||||
// 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
|
||||
+ drag.map(|e| e as f32);
|
||||
// Convert to relative pixel coordinates from the center of the map
|
||||
|
@ -15,7 +15,9 @@ use common::{
|
||||
comp::group::Role,
|
||||
grid::Grid,
|
||||
slowjob::SlowJobPool,
|
||||
terrain::{Block, BlockKind, TerrainChunk, TerrainChunkSize, TerrainGrid},
|
||||
terrain::{
|
||||
Block, BlockKind, CoordinateConversions, TerrainChunk, TerrainChunkSize, TerrainGrid,
|
||||
},
|
||||
vol::{ReadVol, RectVolSize},
|
||||
};
|
||||
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
|
||||
let rwpos = wpos - player_pos;
|
||||
// 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
|
||||
let rfpos = rcpos / max_zoom as f32;
|
||||
// Convert to unrotated pixel coordinates from the player location on the map
|
||||
|
@ -2,7 +2,7 @@
|
||||
use common::{
|
||||
terrain::{
|
||||
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,
|
||||
};
|
||||
@ -286,7 +286,7 @@ fn main() {
|
||||
let chunk_pos = (Vec2::<f64>::from(focus)
|
||||
+ (Vec2::new(mx as f64, my as f64) * scale))
|
||||
.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!(
|
||||
"Block: ({}, {}), Chunk: ({}, {})",
|
||||
block_pos.x, block_pos.y, chunk_pos.x, chunk_pos.y
|
||||
|
@ -16,7 +16,8 @@ use common::{
|
||||
spiral::Spiral2d,
|
||||
store::{Id, Store},
|
||||
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,
|
||||
};
|
||||
@ -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 {
|
||||
for x in (-radius)..radius {
|
||||
for y in (-radius)..radius {
|
||||
let check_loc =
|
||||
loc + Vec2::new(x, y).map2(TerrainChunkSize::RECT_SIZE, |e, sz| e * sz as i32);
|
||||
let check_loc = loc + Vec2::new(x, y).cpos_to_wpos();
|
||||
if sim.get(check_loc).map_or(false, |c| !c.sites.is_empty()) {
|
||||
return false;
|
||||
}
|
||||
@ -1424,10 +1424,9 @@ fn find_site_loc(
|
||||
}
|
||||
|
||||
loc = ctx.sim.get(test_loc).and_then(|c| {
|
||||
site_kind.is_suitable_loc(test_loc, ctx.sim).then_some(
|
||||
c.downhill?
|
||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| e / (sz as i32)),
|
||||
)
|
||||
site_kind
|
||||
.is_suitable_loc(test_loc, ctx.sim)
|
||||
.then_some(c.downhill?.wpos_to_cpos())
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1530,9 +1529,7 @@ impl SiteKind {
|
||||
let mut land_chunks = 0;
|
||||
for x in (-RESOURCE_RADIUS)..RESOURCE_RADIUS {
|
||||
for y in (-RESOURCE_RADIUS)..RESOURCE_RADIUS {
|
||||
let check_loc = loc
|
||||
+ Vec2::new(x, y)
|
||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e * sz as i32);
|
||||
let check_loc = loc + Vec2::new(x, y).cpos_to_wpos();
|
||||
sim.get(check_loc).map(|c| {
|
||||
if num::abs(chunk.alt - c.alt) < 200.0 {
|
||||
if c.river.is_river() {
|
||||
|
@ -9,7 +9,7 @@ use common::{
|
||||
calendar::{Calendar, CalendarEvent},
|
||||
terrain::{
|
||||
quadratic_nearest_point, river_spline_coeffs, uniform_idx_as_vec2, vec2_as_uniform_idx,
|
||||
TerrainChunkSize,
|
||||
CoordinateConversions, TerrainChunkSize,
|
||||
},
|
||||
vol::RectVolSize,
|
||||
};
|
||||
@ -68,7 +68,7 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
|
||||
|
||||
fn get(&self, (wpos, index, calendar): Self::Index) -> Option<ColumnSample<'a>> {
|
||||
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;
|
||||
|
||||
@ -247,8 +247,7 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
|
||||
}
|
||||
let neighbor_pass_wpos =
|
||||
neighbor_pass_pos.map(|e| e as f64) + neighbor_coef * 0.5;
|
||||
let neighbor_pass_pos = neighbor_pass_pos
|
||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| e / sz as i32);
|
||||
let neighbor_pass_pos = neighbor_pass_pos.wpos_to_cpos();
|
||||
let coeffs = river_spline_coeffs(
|
||||
neighbor_wpos,
|
||||
spline_derivative,
|
||||
|
@ -7,10 +7,9 @@ use crate::{
|
||||
use common::{
|
||||
generation::EntityInfo,
|
||||
terrain::{
|
||||
quadratic_nearest_point, river_spline_coeffs, Block, BlockKind, SpriteKind,
|
||||
TerrainChunkSize,
|
||||
quadratic_nearest_point, river_spline_coeffs, Block, BlockKind, CoordinateConversions,
|
||||
SpriteKind,
|
||||
},
|
||||
vol::RectVolSize,
|
||||
};
|
||||
use noise::NoiseFn;
|
||||
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 {
|
||||
let sz_cells = to_cell(
|
||||
land.size()
|
||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| (e * sz) as i32),
|
||||
0,
|
||||
);
|
||||
let sz_cells = to_cell(land.size().as_::<i32>().cpos_to_wpos(), 0);
|
||||
(0..sz_cells.x + 1)
|
||||
.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))
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
use common::{
|
||||
terrain::{
|
||||
map::{Connection, ConnectionKind, MapConfig, MapSample},
|
||||
vec2_as_uniform_idx, TerrainChunkSize, NEIGHBOR_DELTA,
|
||||
vec2_as_uniform_idx, CoordinateConversions, TerrainChunkSize, NEIGHBOR_DELTA,
|
||||
},
|
||||
vol::RectVolSize,
|
||||
};
|
||||
@ -218,7 +218,7 @@ pub fn sample_pos(
|
||||
RiverKind::Lake { .. } | RiverKind::Ocean => TerrainChunkSize::RECT_SIZE.x as f32,
|
||||
});
|
||||
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
|
||||
.iter()
|
||||
.zip(connections.iter_mut())
|
||||
|
@ -46,8 +46,8 @@ use common::{
|
||||
spiral::Spiral2d,
|
||||
store::Id,
|
||||
terrain::{
|
||||
map::MapConfig, uniform_idx_as_vec2, vec2_as_uniform_idx, BiomeKind, MapSizeLg,
|
||||
TerrainChunk, TerrainChunkSize,
|
||||
map::MapConfig, uniform_idx_as_vec2, vec2_as_uniform_idx, BiomeKind, CoordinateConversions,
|
||||
MapSizeLg, TerrainChunk, TerrainChunkSize,
|
||||
},
|
||||
vol::RectVolSize,
|
||||
};
|
||||
@ -1907,8 +1907,7 @@ impl WorldSim {
|
||||
pub fn get_gradient_approx(&self, chunk_pos: Vec2<i32>) -> Option<f32> {
|
||||
let a = self.get(chunk_pos)?;
|
||||
if let Some(downhill) = a.downhill {
|
||||
let b =
|
||||
self.get(downhill.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| e / (sz as i32)))?;
|
||||
let b = self.get(downhill.wpos_to_cpos())?;
|
||||
Some((a.alt - b.alt).abs() / TerrainChunkSize::RECT_SIZE.x as f32)
|
||||
} else {
|
||||
Some(0.0)
|
||||
@ -1968,9 +1967,7 @@ impl WorldSim {
|
||||
T: Copy + Default + Add<Output = T> + Mul<f32, Output = T>,
|
||||
F: FnMut(&SimChunk) -> T,
|
||||
{
|
||||
let pos = pos.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| {
|
||||
e as f64 / sz as f64
|
||||
});
|
||||
let pos = pos.as_::<f64>().wpos_to_cpos();
|
||||
|
||||
let cubic = |a: T, b: T, c: T, d: T, x: f32| -> T {
|
||||
let x2 = x * x;
|
||||
@ -2016,9 +2013,7 @@ impl WorldSim {
|
||||
//
|
||||
// Note that these are only guaranteed monotone in one dimension; fortunately,
|
||||
// that is sufficient for our purposes.
|
||||
let pos = pos.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| {
|
||||
e as f64 / sz as f64
|
||||
});
|
||||
let pos = pos.as_::<f64>().wpos_to_cpos();
|
||||
|
||||
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,
|
||||
// that is sufficient for our purposes.
|
||||
let pos = pos.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| {
|
||||
e as f64 / sz as f64
|
||||
});
|
||||
let pos = pos.as_::<f64>().wpos_to_cpos();
|
||||
|
||||
// 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.
|
||||
|
Loading…
Reference in New Issue
Block a user