mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'imbris/voxygen-compile-time' into 'master'
Improve voxygen compile time with small tweak See merge request veloren/veloren!3449
This commit is contained in:
commit
6c8970f6fd
@ -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,
|
||||
)),
|
||||
)
|
||||
}
|
||||
|
@ -24,11 +24,11 @@ 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},
|
||||
};
|
||||
use common_base::span;
|
||||
use common_base::{prof_span, span};
|
||||
use core::{f32, fmt::Debug, i32, marker::PhantomData, time::Duration};
|
||||
use crossbeam_channel as channel;
|
||||
use enum_iterator::IntoEnumIterator;
|
||||
@ -156,8 +156,58 @@ struct SpriteConfig<Model> {
|
||||
///
|
||||
/// NOTE: Model is an asset path to the appropriate sprite .vox model.
|
||||
#[derive(Deserialize)]
|
||||
#[serde(transparent)]
|
||||
struct SpriteSpec(sprite::sprite_kind::PureCases<Option<SpriteConfig<String>>>);
|
||||
#[serde(try_from = "HashMap<SpriteKind, Option<SpriteConfig<String>>>")]
|
||||
struct SpriteSpec([Option<SpriteConfig<String>>; 256]);
|
||||
|
||||
impl SpriteSpec {
|
||||
fn get(&self, kind: SpriteKind) -> Option<&SpriteConfig<String>> {
|
||||
const _: () = assert!(core::mem::size_of::<SpriteKind>() == 1);
|
||||
// NOTE: This will never be out of bounds since `SpriteKind` is `repr(u8)`
|
||||
self.0[kind as usize].as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// Conversion of SpriteSpec from a hashmap failed because some sprites were
|
||||
/// missing.
|
||||
struct SpritesMissing(Vec<SpriteKind>);
|
||||
|
||||
use core::fmt;
|
||||
|
||||
impl fmt::Display for SpritesMissing {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
writeln!(
|
||||
f,
|
||||
"Missing entries in the sprite manifest for these sprites: {:?}",
|
||||
&self.0,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Here we ensure all variants have an entry in the config.
|
||||
impl TryFrom<HashMap<SpriteKind, Option<SpriteConfig<String>>>> for SpriteSpec {
|
||||
type Error = SpritesMissing;
|
||||
|
||||
fn try_from(
|
||||
mut map: HashMap<SpriteKind, Option<SpriteConfig<String>>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
let mut array = [(); 256].map(|()| None);
|
||||
let sprites_missing = SpriteKind::into_enum_iter()
|
||||
.filter(|kind| match map.remove(kind) {
|
||||
Some(config) => {
|
||||
array[*kind as usize] = config;
|
||||
false
|
||||
},
|
||||
None => true,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if sprites_missing.is_empty() {
|
||||
Ok(Self(array))
|
||||
} else {
|
||||
Err(SpritesMissing(sprites_missing))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl assets::Asset for SpriteSpec {
|
||||
type Loader = assets::RonLoader;
|
||||
@ -216,7 +266,7 @@ fn mesh_worker<V: BaseVol<Vox = Block> + RectRasterableVol + ReadVol + Debug + '
|
||||
pos,
|
||||
// Extract sprite locations from volume
|
||||
sprite_instances: {
|
||||
span!(_guard, "extract sprite_instances");
|
||||
prof_span!("extract sprite_instances");
|
||||
let mut instances = [(); SPRITE_LOD_LEVELS].map(|()| Vec::new());
|
||||
|
||||
for x in 0..V::RECT_SIZE.x as i32 {
|
||||
@ -236,7 +286,7 @@ fn mesh_worker<V: BaseVol<Vox = Block> + RectRasterableVol + ReadVol + Debug + '
|
||||
continue;
|
||||
};
|
||||
|
||||
if let Some(cfg) = sprite.elim_case_pure(&sprite_config.0) {
|
||||
if let Some(cfg) = sprite_config.get(sprite) {
|
||||
let seed = wpos.x as u64 * 3
|
||||
+ wpos.y as u64 * 7
|
||||
+ wpos.x as u64 * wpos.y as u64; // Awful PRNG
|
||||
@ -394,10 +444,9 @@ 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| Some((kind, sprite_config.get(kind)?)))
|
||||
.flat_map(|(kind, sprite_config)| {
|
||||
sprite_config.variations.iter().enumerate().map(
|
||||
move |(
|
||||
|
Loading…
Reference in New Issue
Block a user