From 291a424b4ed5b068857e95196f0058504837bfa0 Mon Sep 17 00:00:00 2001 From: Imbris Date: Mon, 27 Jun 2022 04:06:26 -0400 Subject: [PATCH] This seems to save at least 30 seconds (out of 90 to 120 secs) when tweaking TILE_SIZE in voxygen/src/mesh/greedy.rs (NOTE: I did some more timing, see associated MR description) --- assets/voxygen/voxel/sprite_manifest.ron | 14 ++++++++++---- voxygen/src/scene/terrain.rs | 16 +++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/assets/voxygen/voxel/sprite_manifest.ron b/assets/voxygen/voxel/sprite_manifest.ron index 32a0688b2b..ea021ba90c 100644 --- a/assets/voxygen/voxel/sprite_manifest.ron +++ b/assets/voxygen/voxel/sprite_manifest.ron @@ -1,5 +1,7 @@ #![enable(unwrap_newtypes)] -( +{ +// Represents the lack of a sprite. +Empty: None, // Windows Window1: Some(( variations: [ @@ -1348,7 +1350,7 @@ Ember: Some(( wind_sway: 0.0, )), // Smoke dummy -Smoke: Some(( +SmokeDummy: Some(( variations: [ ( model: "voxygen.voxel.sprite.ember.dummy", @@ -2902,7 +2904,11 @@ GiantKelp: Some(( ], wind_sway: 0.2, )), -//Seagrass +// Red Algae +RedAlgae: None, +// Underwater Vent +UnderwaterVent: None, +// Seagrass Seagrass: Some(( variations: [ ( @@ -3945,4 +3951,4 @@ Eldwood: Some(( ], wind_sway: 0.0, )), -) +} diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index e6504646a5..6857de389b 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -24,7 +24,7 @@ use common::{ assets::{self, AssetExt, DotVoxAsset}, figure::Segment, spiral::Spiral2d, - terrain::{sprite, Block, SpriteKind, TerrainChunk}, + terrain::{Block, SpriteKind, TerrainChunk}, vol::{BaseVol, ReadVol, RectRasterableVol, SampleVol}, volumes::vol_grid_2d::{VolGrid2d, VolGrid2dError}, }; @@ -157,7 +157,7 @@ struct SpriteConfig { /// NOTE: Model is an asset path to the appropriate sprite .vox model. #[derive(Deserialize)] #[serde(transparent)] -struct SpriteSpec(sprite::sprite_kind::PureCases>>); +struct SpriteSpec(HashMap>>); impl assets::Asset for SpriteSpec { type Loader = assets::RonLoader; @@ -236,7 +236,7 @@ fn mesh_worker + RectRasterableVol + ReadVol + Debug + ' continue; }; - if let Some(cfg) = sprite.elim_case_pure(&sprite_config.0) { + if let Some(cfg) = sprite_config.0.get(&sprite).and_then(Option::as_ref) { let seed = wpos.x as u64 * 3 + wpos.y as u64 * 7 + wpos.x as u64 * wpos.y as u64; // Awful PRNG @@ -394,10 +394,16 @@ impl SpriteRenderContext { let max_size = guillotiere::Size::new(max_texture_size as i32, max_texture_size as i32); let mut greedy = GreedyMesh::new(max_size); let mut sprite_mesh = Mesh::new(); - let sprite_config_ = &sprite_config; // NOTE: Tracks the start vertex of the next model to be meshed. let sprite_data: HashMap<(SpriteKind, usize), _> = SpriteKind::into_enum_iter() - .filter_map(|kind| Some((kind, kind.elim_case_pure(&sprite_config_.0).as_ref()?))) + .filter_map(|kind| { + let config = sprite_config + .0 + .get(&kind) + .unwrap_or_else(|| panic!("{kind:?}")) + .as_ref()?; + Some((kind, config)) + }) .flat_map(|(kind, sprite_config)| { sprite_config.variations.iter().enumerate().map( move |(