mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-26 17:30:45 +01:00
Generators: a whole-map field's sampled mesh map is a type of its own (clippy type_complexity)
This commit is contained in:
1 parent
5f33d84f1e
commit
eda6f834de
4 files changed
+24
-23
No files matched your search
@@ -6,6 +6,7 @@ use texturecraft_geom::UvGBuffer;
|
||||
|
||||
use crate::eval::Inputs;
|
||||
use crate::field_cache_key::FieldCacheKey;
|
||||
use crate::sampled_map::SampledMap;
|
||||
use crate::working_field::working_block;
|
||||
|
||||
/// Most fields cached, and the bytes they may hold (the newest is kept whatever its size)
|
||||
@@ -47,7 +48,9 @@ impl FieldCache {
|
||||
) -> Arc<Vec<f32>> {
|
||||
let gbuf = inp.gbuf;
|
||||
let block = working_block(inp);
|
||||
let read = maps.iter().filter_map(|map| inp.baked.maps.get(map).map(|data| (Arc::downgrade(data), (inp.baked.resolution, inp.baked.height(*map)))));
|
||||
let read = maps.iter().filter_map(|map| {
|
||||
inp.baked.maps.get(map).map(|data| SampledMap { data: Arc::downgrade(data), baked_size: (inp.baked.resolution, inp.baked.height(*map)) })
|
||||
});
|
||||
let key = FieldCacheKey {
|
||||
layout: gbuf.tri.as_ptr() as usize,
|
||||
size: (gbuf.width, gbuf.height),
|
||||
@@ -63,7 +66,7 @@ impl FieldCache {
|
||||
// A hit moves to the most recently used end
|
||||
let cached = {
|
||||
let mut entries = self.entries.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
|
||||
entries.retain(|(key, _)| key.maps.iter().all(|(map, _)| map.strong_count() > 0));
|
||||
entries.retain(|(key, _)| key.maps.iter().all(|map| map.data.strong_count() > 0));
|
||||
let hit = entries.iter().position(|(cached, _)| *cached == key).map(|index| entries.remove(index));
|
||||
hit.map(|(cached, field)| {
|
||||
entries.push((cached, field.clone()));
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use std::sync::Weak;
|
||||
|
||||
use texturecraft_core::BlockScales;
|
||||
|
||||
use crate::sampled_map::SampledMap;
|
||||
|
||||
/// What a field was built from: the working layout (the g-buffer's address, size, coverage, UV tile block and tile scales), the mesh's positions and UVs, the mesh maps it reads and its settings' bits
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub(crate) struct FieldCacheKey {
|
||||
pub(crate) layout: usize,
|
||||
pub(crate) size: (u32, u32),
|
||||
@@ -14,23 +14,6 @@ pub(crate) struct FieldCacheKey {
|
||||
/// The mesh's positions and UVs, each by address and length: a UV edit changes island fields
|
||||
pub(crate) positions: (usize, usize),
|
||||
pub(crate) uvs: (usize, usize),
|
||||
/// The mesh maps it samples, each with the size it was baked at: one allocation read as another layout reads other texels
|
||||
pub(crate) maps: Vec<(Weak<Vec<f32>>, (u32, u32))>,
|
||||
pub(crate) maps: Vec<SampledMap>,
|
||||
pub(crate) settings: Vec<u32>,
|
||||
}
|
||||
|
||||
impl PartialEq for FieldCacheKey {
|
||||
fn eq(&self, other: &FieldCacheKey) -> bool {
|
||||
let same_maps = self.maps.len() == other.maps.len()
|
||||
&& self.maps.iter().zip(&other.maps).all(|((a, a_size), (b, b_size))| a.strong_count() > 0 && a.ptr_eq(b) && a_size == b_size);
|
||||
same_maps
|
||||
&& self.layout == other.layout
|
||||
&& self.size == other.size
|
||||
&& self.coverage == other.coverage
|
||||
&& self.block == other.block
|
||||
&& self.scales == other.scales
|
||||
&& self.positions == other.positions
|
||||
&& self.uvs == other.uvs
|
||||
&& self.settings == other.settings
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ pub mod projector_cover;
|
||||
pub mod projector_depth;
|
||||
mod projector_depth_cache;
|
||||
pub mod projector_view;
|
||||
mod sampled_map;
|
||||
mod sections;
|
||||
mod shape_distance;
|
||||
mod slope_texel;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
use std::sync::Weak;
|
||||
|
||||
/// A mesh map a whole-map field samples: its allocation and the size it was baked at (one allocation read as another layout reads other texels)
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct SampledMap {
|
||||
pub(crate) data: Weak<Vec<f32>>,
|
||||
pub(crate) baked_size: (u32, u32),
|
||||
}
|
||||
|
||||
impl PartialEq for SampledMap {
|
||||
fn eq(&self, other: &SampledMap) -> bool {
|
||||
self.data.strong_count() > 0 && self.data.ptr_eq(&other.data) && self.baked_size == other.baked_size
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user