Skip to content

Commit

Permalink
Overhaul chunk pipeline
Browse files Browse the repository at this point in the history
- start caching generated meshes
- reduce by a lot the amount of unneeded chunk requests from the scene
- do more work in the background

Chunks no longer load from nearest to farthest
  • Loading branch information
jameshiew committed Dec 31, 2024
1 parent 536838f commit ddf5392
Show file tree
Hide file tree
Showing 18 changed files with 670 additions and 464 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/common/src/mesh/faces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::world::{BlockPosition, Direction, MappedBlockID};

pub const RHS_FACES: [OrientedBlockFace; 6] = RIGHT_HANDED_Y_UP_CONFIG.faces;

pub trait BlockVisibilityChecker {
pub trait BlockVisibilityChecker: Clone + Send + Sync {
fn get_visibility(&self, mapped_id: &MappedBlockID) -> BlockVisibility;
}

Expand Down Expand Up @@ -339,6 +339,7 @@ mod tests {
ChunkFace, ChunkFaceShape, PADDED_CHUNK_MAX_INDEX, PADDED_CHUNK_SIZE,
};

#[derive(Clone)]
struct AllOpaque;

impl BlockVisibilityChecker for AllOpaque {
Expand Down
7 changes: 7 additions & 0 deletions crates/common/src/world.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt;
use std::num::NonZeroU8;

use linearize::Linearize;
Expand Down Expand Up @@ -61,6 +62,12 @@ pub struct ChunkPosition {
pub z: i32,
}

impl fmt::Display for ChunkPosition {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}, {}, {})", self.x, self.y, self.z)
}
}

/// Absolute position of something within the world (e.g. a camera)
#[derive(Debug, Clone, Copy)]
pub struct WorldPosition {
Expand Down
4 changes: 2 additions & 2 deletions crates/infinigen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use infinigen_plugins::assets::AssetSettings;
use infinigen_plugins::camera::setup::CameraSettings;
use infinigen_plugins::scene::{self, SceneSettings};
use infinigen_plugins::world::{self, WorldSettings};
use infinigen_plugins::{assets, camera, chunks, debug, AppState};
use infinigen_plugins::{assets, camera, debug, mesh, AppState};

pub mod settings;

Expand Down Expand Up @@ -53,7 +53,7 @@ impl Plugin for AppPlugin {
.add_plugins((
assets::AssetsPlugin,
scene::ScenePlugin,
chunks::ChunksPlugin,
mesh::MeshPlugin,
camera::CameraPlugin,
world::WorldPlugin,
debug::DebugPlugin,
Expand Down
1 change: 0 additions & 1 deletion crates/plugins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ bevy_common_assets = { version = "0.12.0", features = ["ron"] }
bevy_egui = { version = "0.31.1" }
bevy_flycam = "0.15.0"
bevy-inspector-egui = { version = "0.28.0" }
indexed_priority_queue = "0.3.0"
31 changes: 30 additions & 1 deletion crates/plugins/src/assets/blocks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::BTreeMap;

use ahash::AHashMap;
use ahash::{AHashMap, AHashSet};
use bevy::asset::{Asset, Handle};
use bevy::pbr::StandardMaterial;
use bevy::prelude::{Resource, TypePath};
Expand Down Expand Up @@ -88,6 +88,35 @@ impl BlockDefinitions {
}
palette
}

pub fn visibility_checker(&self) -> impl BlockVisibilityChecker {
#[derive(Clone)]
struct Checker {
opaque: AHashSet<MappedBlockID>,
}
impl BlockVisibilityChecker for Checker {
fn get_visibility(&self, mapped_id: &MappedBlockID) -> BlockVisibility {
if self.opaque.contains(mapped_id) {
BlockVisibility::Opaque
} else {
BlockVisibility::Translucent
}
}
}
Checker {
opaque: self
.by_mapped_id
.iter()
.filter_map(|(id, def)| {
if def.visibility == BlockVisibility::Opaque {
Some(*id)
} else {
None
}
})
.collect(),
}
}
}

impl BlockVisibilityChecker for BlockDefinitions {
Expand Down
27 changes: 0 additions & 27 deletions crates/plugins/src/chunks/mod.rs

This file was deleted.

157 changes: 0 additions & 157 deletions crates/plugins/src/chunks/registry.rs

This file was deleted.

87 changes: 0 additions & 87 deletions crates/plugins/src/chunks/tasks.rs

This file was deleted.

Loading

0 comments on commit ddf5392

Please sign in to comment.