Skip to content

Commit

Permalink
Getting lods to be parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyTornetta committed Sep 7, 2023
1 parent caa2d50 commit 6af3f0e
Show file tree
Hide file tree
Showing 16 changed files with 315 additions and 129 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion cosmos_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cosmos_core = { version = "0.0.4", path = "../cosmos_core", features = [ "client" ] }
cosmos_core = { version = "0.0.4", path = "../cosmos_core", features = [
"client",
] }

bevy = { workspace = true }
bevy_renet = { workspace = true }
Expand All @@ -15,6 +17,7 @@ bincode = { workspace = true }
local-ip-address = { workspace = true }
bevy_rapier3d = { workspace = true }
bigdecimal = { workspace = true }
futures-lite = { workspace = true }

serde_json = { workspace = true }
image = { workspace = true }
Expand Down
33 changes: 26 additions & 7 deletions cosmos_client/src/asset/asset_loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
//!
//! This also combines the textures into one big atlas.
use std::fs;
use std::{
fs,
sync::{Arc, Mutex, MutexGuard, RwLock, RwLockReadGuard},
};

use bevy::{
prelude::*,
Expand Down Expand Up @@ -38,7 +41,7 @@ struct AssetsLoadingID(usize);
#[derive(Resource, Debug, Default)]
struct AssetsLoading(Vec<LoadingAsset>);

#[derive(Resource, Reflect, Debug)]
#[derive(Resource, Reflect, Debug, Clone)]
/// This stores the texture atlas for all blocks in the game.
///
/// Eventually this will be redone to allow for multiple atlases, but for now this works fine.
Expand All @@ -56,6 +59,19 @@ pub struct MainAtlas {
padding: u32,
}

#[derive(Resource, Debug, Clone)]
/// This stores the texture atlas for all blocks in the game.
///
/// Eventually this will be redone to allow for multiple atlases, but for now this works fine.
pub struct ReadOnlyMainAtlas(Arc<RwLock<MainAtlas>>);

impl ReadOnlyMainAtlas {
/// Locks the atlas for use on this thread
pub fn atlas<'a>(&'a self) -> RwLockReadGuard<'a, MainAtlas> {
self.0.as_ref().read().expect("Failed to lock atlas")
}
}

impl MainAtlas {
#[inline]
/// Returns the UV coordinates for the texture atlas given the block's index
Expand Down Expand Up @@ -256,12 +272,15 @@ fn check_assets_ready(

let texture = atlas.texture.clone();

commands.insert_resource(MainAtlas {
let main_atlas = MainAtlas {
material: material_handle,
unlit_material: unlit_material_handle,
atlas,
padding: PADDING,
});
};

commands.insert_resource(main_atlas.clone());
commands.insert_resource(ReadOnlyMainAtlas(Arc::new(RwLock::new(main_atlas))));

let illuminated_material_handle = materials.add(StandardMaterial {
base_color_texture: Some(texture),
Expand Down Expand Up @@ -294,7 +313,7 @@ fn check_assets_ready(
}
}

#[derive(Debug)]
#[derive(Debug, Clone)]
/// Contains information that links the block faces to their texture indices.
///
/// This could also link non-face imformation to their texture indices.
Expand All @@ -312,7 +331,7 @@ impl BlockTextureIndicies {
}
}

#[derive(Debug)]
#[derive(Debug, Clone)]
/// Links blocks to their correspoding atlas index.
pub struct BlockTextureIndex {
indices: BlockTextureIndicies,
Expand Down Expand Up @@ -363,7 +382,7 @@ struct ReadBlockInfo {
model: Option<String>,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
/// Every block will have information about how to render it -- even air
pub struct BlockRenderingInfo {
/// This maps textures ids to the various parts of its model.
Expand Down
2 changes: 1 addition & 1 deletion cosmos_client/src/block/lighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct BlockLightProperties {
pub shadows_disabled: bool,
}

#[derive(Debug, Reflect, Default, Serialize, Deserialize)]
#[derive(Debug, Clone, Reflect, Default, Serialize, Deserialize)]
/// This links up a block to its block light properties
pub struct BlockLighting {
/// The properties this block has
Expand Down
1 change: 1 addition & 0 deletions cosmos_client/src/materials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
state::game_state::GameState,
};

#[derive(Debug, Clone)]
/// An identifiable `StandardMaterial`
pub struct CosmosMaterial {
/// The handle to the bevy `StandardMaterial`
Expand Down
Loading

0 comments on commit 6af3f0e

Please sign in to comment.