Struct veloren_voxygen::scene::terrain::Terrain
source · pub struct Terrain<V: RectRasterableVol = TerrainChunk> {
atlas: AtlasAllocator,
chunks: HashMap<Vec2<i32>, TerrainChunkData>,
shadow_chunks: Vec<(Vec2<i32>, TerrainChunkData)>,
mesh_send_tmp: Sender<MeshWorkerResponse>,
mesh_recv: Receiver<MeshWorkerResponse>,
mesh_todo: HashMap<Vec2<i32>, ChunkMeshState>,
mesh_todos_active: Arc<AtomicU64>,
mesh_recv_overflow: f32,
pub(super) sprite_render_state: Arc<SpriteRenderState>,
pub(super) sprite_globals: SpriteGlobalsBindGroup,
atlas_textures: Arc<AtlasTextures<Locals, TerrainAtlasData>>,
phantom: PhantomData<V>,
}
Fields§
§atlas: AtlasAllocator
This is always the current atlas into which data is being allocated. Once an atlas is too full to allocate the next texture, we always allocate a fresh texture and start allocating into that. Trying to keep more than one texture available for allocation doesn’t seem worth it, because our allocation patterns are heavily spatial (so all data allocated around the same time should have a very similar lifetime, even in pathological cases). As a result, fragmentation effects should be minimal.
TODO: Consider “moving GC” style allocation to deal with spatial fragmentation effects due to odd texture sizes, which in some cases might significantly reduce the number of textures we need for particularly difficult locations.
chunks: HashMap<Vec2<i32>, TerrainChunkData>
§shadow_chunks: Vec<(Vec2<i32>, TerrainChunkData)>
Temporary storage for dead chunks that might still be shadowing chunks in view. We wait until either the chunk definitely cannot be shadowing anything the player can see, the chunk comes back into view, or for daylight to end, before removing it (whichever comes first).
Note that these chunks are not complete; for example, they are missing texture data (they still currently hold onto a reference to their backing texture, but it generally can’t be trusted for rendering purposes).
mesh_send_tmp: Sender<MeshWorkerResponse>
§mesh_recv: Receiver<MeshWorkerResponse>
§mesh_todo: HashMap<Vec2<i32>, ChunkMeshState>
§mesh_todos_active: Arc<AtomicU64>
§mesh_recv_overflow: f32
§sprite_render_state: Arc<SpriteRenderState>
§sprite_globals: SpriteGlobalsBindGroup
§atlas_textures: Arc<AtlasTextures<Locals, TerrainAtlasData>>
As stated previously, this is always the very latest texture into which
we allocate. Code cannot assume that this is the assigned texture
for any particular chunk; look at the texture
field in
TerrainChunkData
for that.
phantom: PhantomData<V>
Implementations§
source§impl<V: RectRasterableVol> Terrain<V>
impl<V: RectRasterableVol> Terrain<V>
pub fn new( renderer: &mut Renderer, global_model: &GlobalModel, lod_data: &LodData, sprite_render_context: SpriteRenderContext, ) -> Self
fn make_atlas( renderer: &mut Renderer, ) -> Result<(AtlasAllocator, AtlasTextures<Locals, TerrainAtlasData>), RenderError>
fn remove_chunk_meta(&mut self, _pos: Vec2<i32>, chunk: &TerrainChunkData)
fn insert_chunk(&mut self, pos: Vec2<i32>, chunk: TerrainChunkData)
fn remove_chunk(&mut self, pos: Vec2<i32>)
sourcepub fn light_at_wpos(&self, wpos: Vec3<i32>) -> f32
pub fn light_at_wpos(&self, wpos: Vec3<i32>) -> f32
Find the light level (sunlight) at the given world position.
sourcefn skip_remesh(old_block: Block, new_block: Block) -> (bool, bool)
fn skip_remesh(old_block: Block, new_block: Block) -> (bool, bool)
Determine whether a given block change actually require remeshing.
Returns (skip_color, skip_lights) where
skip_color means no textures were recolored (i.e. this was a sprite only change).
skip_lights means no remeshing or relighting was required (i.e. the block opacity / lighting info / block kind didn’t change).
sourcepub fn glow_at_wpos(&self, wpos: Vec3<i32>) -> f32
pub fn glow_at_wpos(&self, wpos: Vec3<i32>) -> f32
Find the glow level (light from lamps) at the given world position.
pub fn glow_normal_at_wpos(&self, wpos: Vec3<f32>) -> (Vec3<f32>, f32)
sourcepub fn maintain(
&mut self,
renderer: &mut Renderer,
scene_data: &SceneData<'_>,
focus_pos: Vec3<f32>,
loaded_distance: f32,
camera: &Camera,
) -> (Aabb<f32>, Vec<Vec3<f32>>, Aabr<f32>, Vec<Vec3<f32>>, Aabr<f32>)
pub fn maintain( &mut self, renderer: &mut Renderer, scene_data: &SceneData<'_>, focus_pos: Vec3<f32>, loaded_distance: f32, camera: &Camera, ) -> (Aabb<f32>, Vec<Vec3<f32>>, Aabr<f32>, Vec<Vec3<f32>>, Aabr<f32>)
Maintain terrain data. To be called once per tick.
The returned visible bounding volumes take into account the current camera position (i.e: when underground, surface structures will be culled from the volume).
pub fn get(&self, chunk_key: Vec2<i32>) -> Option<&TerrainChunkData>
pub fn chunk_count(&self) -> usize
pub fn visible_chunk_count(&self) -> usize
pub fn shadow_chunk_count(&self) -> usize
pub fn render_shadows<'a>( &'a self, drawer: &mut TerrainShadowDrawer<'_, 'a>, focus_pos: Vec3<f32>, culling_mode: CullingMode, )
pub fn render_rain_occlusion<'a>( &'a self, drawer: &mut TerrainShadowDrawer<'_, 'a>, focus_pos: Vec3<f32>, )
pub fn chunks_for_point_shadows( &self, focus_pos: Vec3<f32>, ) -> impl Clone + Iterator<Item = (&Model<Vertex>, &BoundLocals)>
pub fn render<'a>( &'a self, drawer: &mut FirstPassDrawer<'a>, focus_pos: Vec3<f32>, culling_mode: CullingMode, )
pub fn render_sprites<'a>( &'a self, sprite_drawer: &mut SpriteDrawer<'_, 'a>, focus_pos: Vec3<f32>, cam_pos: Vec3<f32>, sprite_render_distance: f32, culling_mode: CullingMode, )
pub fn render_translucent<'a>( &'a self, drawer: &mut FirstPassDrawer<'a>, focus_pos: Vec3<f32>, )
Auto Trait Implementations§
impl<V> Freeze for Terrain<V>
impl<V = Chonk<Block, TerrainChunkSize, TerrainChunkMeta>> !RefUnwindSafe for Terrain<V>
impl<V> Send for Terrain<V>where
V: Send,
impl<V> Sync for Terrain<V>where
V: Sync,
impl<V> Unpin for Terrain<V>where
V: Unpin,
impl<V = Chonk<Block, TerrainChunkSize, TerrainChunkMeta>> !UnwindSafe for Terrain<V>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Chain<T> for T
impl<T> Chain<T> for T
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self
file descriptor.§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
source§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Pointee for T
impl<T> Pointee for T
source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
source§impl<Context> SubContext<Context> for Context
impl<Context> SubContext<Context> for Context
fn sub_context(self) -> Context
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.