From 1caf7aefcc29602a21fa8a400c897b576be238a8 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 24 Jan 2025 21:24:06 +0100 Subject: move demand map to own file --- client/src/render/scene/demand_map.rs | 75 +++++++++++++++++++++++++++++++++++ client/src/render/scene/draw.rs | 2 +- client/src/render/scene/mod.rs | 60 ++-------------------------- 3 files changed, 79 insertions(+), 58 deletions(-) create mode 100644 client/src/render/scene/demand_map.rs (limited to 'client/src') 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 . +*/ +use egui::Widget; +use std::{ + collections::{HashMap, HashSet}, + hash::Hash, + sync::RwLock, +}; + +pub struct DemandMap { + inner: RwLock>, +} +struct DemandMapState { + values: HashMap, + needed: HashSet, + size_metric: usize, +} +impl DemandMap { + pub fn new() -> Self { + Self { + inner: DemandMapState { + needed: HashSet::new(), + values: HashMap::new(), + size_metric: 0, + } + .into(), + } + } + pub fn needed(&self) -> Vec { + 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 { + 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 Widget for &DemandMap { + 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 . */ -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 . */ +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 { - inner: RwLock>, -} -struct DemandMapState { - values: HashMap, - needed: HashSet, - size_metric: usize, -} -impl DemandMap { - pub fn new() -> Self { - Self { - inner: DemandMapState { - needed: HashSet::new(), - values: HashMap::new(), - size_metric: 0, - } - .into(), - } - } - pub fn needed(&self) -> Vec { - 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 { - 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 Widget for &DemandMap { - 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(name: &str, m: &DemandMap) -- cgit v1.2.3-70-g09d2