diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-24 21:24:06 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-24 21:24:06 +0100 |
commit | 1caf7aefcc29602a21fa8a400c897b576be238a8 (patch) | |
tree | 02534fcee0d052ee9fa2750e296672db50381ee3 /client | |
parent | 006ad7ce6d30d764411dcf8c2527f2c80e722491 (diff) | |
download | weareserver-1caf7aefcc29602a21fa8a400c897b576be238a8.tar weareserver-1caf7aefcc29602a21fa8a400c897b576be238a8.tar.bz2 weareserver-1caf7aefcc29602a21fa8a400c897b576be238a8.tar.zst |
move demand map to own file
Diffstat (limited to 'client')
-rw-r--r-- | client/src/render/scene/demand_map.rs | 75 | ||||
-rw-r--r-- | client/src/render/scene/draw.rs | 2 | ||||
-rw-r--r-- | client/src/render/scene/mod.rs | 60 |
3 files changed, 79 insertions, 58 deletions
diff --git a/client/src/render/scene/demand_map.rs b/client/src/render/scene/demand_map.rs new file mode 100644 index 0000000..16fa181 --- /dev/null +++ b/client/src/render/scene/demand_map.rs @@ -0,0 +1,75 @@ +/* + wearechat - generic multiplayer game with voip + Copyright (C) 2025 metamuffin + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, version 3 of the License only. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ +use egui::Widget; +use std::{ + collections::{HashMap, HashSet}, + hash::Hash, + sync::RwLock, +}; + +pub struct DemandMap<K, V> { + inner: RwLock<DemandMapState<K, V>>, +} +struct DemandMapState<K, V> { + values: HashMap<K, V>, + needed: HashSet<K>, + size_metric: usize, +} +impl<K: Hash + Eq + Clone, V: Clone> DemandMap<K, V> { + pub fn new() -> Self { + Self { + inner: DemandMapState { + needed: HashSet::new(), + values: HashMap::new(), + size_metric: 0, + } + .into(), + } + } + pub fn needed(&self) -> Vec<K> { + self.inner.read().unwrap().needed.iter().cloned().collect() + } + pub fn insert(&self, key: K, value: V, size: usize) { + let mut s = self.inner.write().unwrap(); + s.needed.remove(&key); + s.values.insert(key, value); + s.size_metric += size; + } + pub fn try_get(&self, key: K) -> Option<V> { + let mut s = self.inner.write().unwrap(); + if let Some(k) = s.values.get(&key) { + Some(k.to_owned()) + } else { + s.needed.insert(key); + None + } + } +} + +impl<K, V> Widget for &DemandMap<K, V> { + fn ui(self, ui: &mut egui::Ui) -> egui::Response { + let state = self.inner.read().unwrap(); + ui.label(state.needed.len().to_string()); + ui.label(state.values.len().to_string()); + ui.label(humansize::format_size( + state.size_metric, + humansize::DECIMAL, + )); + ui.end_row(); + ui.response() + } +} diff --git a/client/src/render/scene/draw.rs b/client/src/render/scene/draw.rs index 9efa561..d133d3b 100644 --- a/client/src/render/scene/draw.rs +++ b/client/src/render/scene/draw.rs @@ -14,7 +14,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use super::{DemandMap, RPrefab}; +use super::{demand_map::DemandMap, RPrefab}; use glam::{EulerRot, Mat3, Mat4}; use std::sync::Arc; use weareshared::{packets::Resource, resources::Prefab, tree::SceneTree}; diff --git a/client/src/render/scene/mod.rs b/client/src/render/scene/mod.rs index e314649..96c8ba4 100644 --- a/client/src/render/scene/mod.rs +++ b/client/src/render/scene/mod.rs @@ -14,6 +14,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ +pub mod demand_map; pub mod draw; pub mod meshops; pub mod pipelines; @@ -23,18 +24,12 @@ pub mod vertex_buffers; use crate::{armature::RArmature, download::Downloader, shaders::SceneShaders}; use anyhow::Result; use bytemuck::{Pod, Zeroable}; +use demand_map::DemandMap; use egui::{Grid, Widget}; use glam::{UVec3, UVec4, Vec2, Vec3, Vec3A, uvec3, uvec4}; -use humansize::DECIMAL; use log::{debug, trace}; use pipelines::SceneBgLayouts; -use std::{ - collections::{HashMap, HashSet}, - hash::Hash, - marker::PhantomData, - sync::{Arc, RwLock}, - time::Instant, -}; +use std::{hash::Hash, marker::PhantomData, sync::Arc, time::Instant}; use textures::MipGenerationPipeline; use weareshared::{ Affine3A, @@ -47,45 +42,6 @@ use wgpu::{ util::{BufferInitDescriptor, DeviceExt}, }; -pub struct DemandMap<K, V> { - inner: RwLock<DemandMapState<K, V>>, -} -struct DemandMapState<K, V> { - values: HashMap<K, V>, - needed: HashSet<K>, - size_metric: usize, -} -impl<K: Hash + Eq + Clone, V: Clone> DemandMap<K, V> { - pub fn new() -> Self { - Self { - inner: DemandMapState { - needed: HashSet::new(), - values: HashMap::new(), - size_metric: 0, - } - .into(), - } - } - pub fn needed(&self) -> Vec<K> { - self.inner.read().unwrap().needed.iter().cloned().collect() - } - pub fn insert(&self, key: K, value: V, size: usize) { - let mut s = self.inner.write().unwrap(); - s.needed.remove(&key); - s.values.insert(key, value); - s.size_metric += size; - } - pub fn try_get(&self, key: K) -> Option<V> { - let mut s = self.inner.write().unwrap(); - if let Some(k) = s.values.get(&key) { - Some(k.to_owned()) - } else { - s.needed.insert(key); - None - } - } -} - struct GraphicsConfig { max_anisotropy: u16, max_mip_count: u32, @@ -444,16 +400,6 @@ impl ScenePreparer { } } -impl<K, V> Widget for &DemandMap<K, V> { - fn ui(self, ui: &mut egui::Ui) -> egui::Response { - let state = self.inner.read().unwrap(); - ui.label(state.needed.len().to_string()); - ui.label(state.values.len().to_string()); - ui.label(humansize::format_size(state.size_metric, DECIMAL)); - ui.end_row(); - ui.response() - } -} impl ScenePreparer { pub fn print_missing(&self) { fn visit<K, V>(name: &str, m: &DemandMap<K, V>) |