summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/src/audio.rs10
-rw-r--r--client/src/camera.rs6
-rw-r--r--client/src/download.rs17
-rw-r--r--client/src/interfaces/profiler.rs2
-rw-r--r--client/src/main.rs1
-rw-r--r--client/src/render/scene/demand_map.rs6
-rw-r--r--client/src/render/scene/draw.rs2
-rw-r--r--client/src/render/scene/mod.rs24
-rw-r--r--client/src/render/scene/textures.rs10
-rw-r--r--client/src/render/ui.rs48
-rw-r--r--client/src/state.rs18
-rw-r--r--client/src/window.rs32
-rw-r--r--server/src/network.rs8
-rw-r--r--shared/src/helper.rs14
-rw-r--r--shared/src/lib.rs1
-rw-r--r--shared/src/packets.rs8
-rw-r--r--shared/src/resources.rs4
-rw-r--r--shared/src/store.rs4
-rw-r--r--shared/src/tree.rs45
-rw-r--r--world/src/main.rs20
-rw-r--r--world/src/mesh.rs59
-rw-r--r--world/src/physics.rs6
22 files changed, 170 insertions, 175 deletions
diff --git a/client/src/audio.rs b/client/src/audio.rs
index e61f333..dca9cb4 100644
--- a/client/src/audio.rs
+++ b/client/src/audio.rs
@@ -155,8 +155,8 @@ impl AEncoder {
let mut out = [0u8; AE_FRAME_SIZE];
let mut denoise = [0f32; AE_FRAME_SIZE];
let mut raw = [0f32; AE_FRAME_SIZE];
- for i in 0..AE_FRAME_SIZE {
- raw[i] = self.buffer.pop_front().unwrap() * 32768.0;
+ for sample in raw.iter_mut().take(AE_FRAME_SIZE) {
+ *sample = self.buffer.pop_front().unwrap() * 32768.0;
}
self.noise_rnn.process_frame(&mut denoise, &raw);
for e in &mut denoise {
@@ -241,11 +241,11 @@ impl ADecoder {
(self.playback + JITTER_COMP) % BUFFER_SIZE
});
let free_space = *channel_cursor - self.playback;
- for i in 0..size.min(free_space) {
+ for sample in output.iter().take(size.min(free_space)) {
// TODO positional audio
let _ = p.pos;
- self.buffer[*channel_cursor][0] += output[i];
- self.buffer[*channel_cursor][1] += output[i];
+ self.buffer[*channel_cursor][0] += sample;
+ self.buffer[*channel_cursor][1] += sample;
*channel_cursor += 1;
*channel_cursor %= BUFFER_SIZE
}
diff --git a/client/src/camera.rs b/client/src/camera.rs
index bd86e79..ea984b3 100644
--- a/client/src/camera.rs
+++ b/client/src/camera.rs
@@ -23,6 +23,12 @@ pub struct Camera {
pub aspect: f32,
}
+impl Default for Camera {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Camera {
pub fn new() -> Self {
Self {
diff --git a/client/src/download.rs b/client/src/download.rs
index 4e2f0aa..44d613b 100644
--- a/client/src/download.rs
+++ b/client/src/download.rs
@@ -68,17 +68,14 @@ impl Downloader {
}
pub fn packet(&self, p: &Packet) -> Result<()> {
let mut state = self.inner.write().unwrap();
- match p {
- Packet::RespondResource(_, d) => {
- let key = Resource(resource_hash(&d.0), PhantomData);
- state.store.set_raw(&d.0)?;
- state.need.remove(&key);
- state.pending.remove(&key);
- if state.have.insert(key) {
- debug!("have {key}");
- }
+ if let Packet::RespondResource(_, d) = p {
+ let key = Resource(resource_hash(&d.0), PhantomData);
+ state.store.set_raw(&d.0)?;
+ state.need.remove(&key);
+ state.pending.remove(&key);
+ if state.have.insert(key) {
+ debug!("have {key}");
}
- _ => (),
}
Ok(())
}
diff --git a/client/src/interfaces/profiler.rs b/client/src/interfaces/profiler.rs
index b6c4698..541b5c5 100644
--- a/client/src/interfaces/profiler.rs
+++ b/client/src/interfaces/profiler.rs
@@ -38,7 +38,7 @@ impl Widget for &mut Profiler {
.num_columns(2)
.show(ui, |ui| {
ui.label("Backend");
- ui.label(&self.idata.adapter_info.backend.to_string());
+ ui.label(self.idata.adapter_info.backend.to_string());
ui.end_row();
ui.label("Name");
ui.label(&self.idata.adapter_info.name);
diff --git a/client/src/main.rs b/client/src/main.rs
index 804ab44..5fa790a 100644
--- a/client/src/main.rs
+++ b/client/src/main.rs
@@ -15,6 +15,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#![feature(iter_array_chunks, mpmc_channel, array_chunks, new_zeroed_alloc)]
+#![allow(clippy::too_many_arguments, clippy::type_complexity)]
pub mod armature;
pub mod audio;
pub mod camera;
diff --git a/client/src/render/scene/demand_map.rs b/client/src/render/scene/demand_map.rs
index c27eaac..dc73142 100644
--- a/client/src/render/scene/demand_map.rs
+++ b/client/src/render/scene/demand_map.rs
@@ -29,6 +29,12 @@ struct DemandMapState<K, V> {
needed: HashSet<K>,
size_metric: usize,
}
+impl<K: Hash + Eq + Clone, V: Clone> Default for DemandMap<K, V> {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl<K: Hash + Eq + Clone, V: Clone> DemandMap<K, V> {
pub fn new() -> Self {
Self {
diff --git a/client/src/render/scene/draw.rs b/client/src/render/scene/draw.rs
index 1109401..b2bf19e 100644
--- a/client/src/render/scene/draw.rs
+++ b/client/src/render/scene/draw.rs
@@ -53,7 +53,7 @@ impl ScenePipeline {
},
})],
depth_stencil_attachment: Some(RenderPassDepthStencilAttachment {
- view: &depth,
+ view: depth,
depth_ops: Some(Operations {
load: LoadOp::Clear(1.),
store: StoreOp::Store,
diff --git a/client/src/render/scene/mod.rs b/client/src/render/scene/mod.rs
index 16eecfc..7743409 100644
--- a/client/src/render/scene/mod.rs
+++ b/client/src/render/scene/mod.rs
@@ -293,13 +293,11 @@ impl ScenePreparer {
}) {
tex_albedo = Some(bg)
}
- } else {
- if let Some((_tex, bg)) = self
- .placeholder_textures
- .try_get(TextureIdentityKind::Multiply)
- {
- tex_albedo = Some(bg)
- }
+ } else if let Some((_tex, bg)) = self
+ .placeholder_textures
+ .try_get(TextureIdentityKind::Multiply)
+ {
+ tex_albedo = Some(bg)
}
let mut tex_normal = None;
if let Some(normalres) = part.tex_normal {
@@ -309,13 +307,11 @@ impl ScenePreparer {
}) {
tex_normal = Some(bg)
}
- } else {
- if let Some((_tex, bg)) = self
- .placeholder_textures
- .try_get(TextureIdentityKind::Normal)
- {
- tex_normal = Some(bg)
- }
+ } else if let Some((_tex, bg)) = self
+ .placeholder_textures
+ .try_get(TextureIdentityKind::Normal)
+ {
+ tex_normal = Some(bg)
}
let material = self.materials.try_get({
diff --git a/client/src/render/scene/textures.rs b/client/src/render/scene/textures.rs
index 4f2b01c..462cb53 100644
--- a/client/src/render/scene/textures.rs
+++ b/client/src/render/scene/textures.rs
@@ -27,8 +27,8 @@ use std::{
use wgpu::{
AddressMode, BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindingResource,
Color, ColorTargetState, ColorWrites, CommandEncoderDescriptor, Device, Extent3d, FilterMode,
- ImageDataLayout, LoadOp, Operations, Queue, RenderPassColorAttachment, RenderPassDescriptor,
- RenderPipeline, SamplerDescriptor, StoreOp, Texture, TextureAspect, TextureDescriptor,
+ LoadOp, Operations, Queue, RenderPassColorAttachment, RenderPassDescriptor, RenderPipeline,
+ SamplerDescriptor, StoreOp, TexelCopyBufferLayout, Texture, TextureAspect, TextureDescriptor,
TextureDimension, TextureFormat, TextureUsages, TextureViewDescriptor, include_wgsl,
};
@@ -193,7 +193,7 @@ fn create_texture(
});
let bind_group = device.create_bind_group(&BindGroupDescriptor {
label: None,
- layout: &bgl,
+ layout: bgl,
entries: &[
BindGroupEntry {
binding: 0,
@@ -246,7 +246,7 @@ fn create_texture(
queue.write_texture(
texture.as_image_copy(),
data,
- ImageDataLayout {
+ TexelCopyBufferLayout {
bytes_per_row: Some(width * 4),
rows_per_image: None,
offset: 0,
@@ -287,7 +287,7 @@ fn create_texture(
occlusion_query_set: None,
});
- rpass.set_pipeline(&mip_pipeline);
+ rpass.set_pipeline(mip_pipeline);
rpass.set_bind_group(0, &mip_bind_group, &[]);
rpass.draw(0..3, 0..1);
}
diff --git a/client/src/render/ui.rs b/client/src/render/ui.rs
index 4de2633..29e9461 100644
--- a/client/src/render/ui.rs
+++ b/client/src/render/ui.rs
@@ -33,12 +33,12 @@ use wgpu::{
BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingResource, BindingType, BlendState,
Buffer, BufferDescriptor, BufferUsages, ColorTargetState, ColorWrites, CommandEncoder,
CompareFunction, DepthStencilState, Device, Extent3d, FilterMode, FragmentState, FrontFace,
- ImageCopyTexture, ImageDataLayout, IndexFormat, LoadOp, MultisampleState, Operations, Origin3d,
- PipelineCompilationOptions, PipelineLayout, PipelineLayoutDescriptor, PolygonMode,
- PrimitiveState, PrimitiveTopology, PushConstantRange, Queue, RenderPassColorAttachment,
- RenderPassDepthStencilAttachment, RenderPassDescriptor, RenderPipeline,
- RenderPipelineDescriptor, SamplerBindingType, SamplerDescriptor, ShaderStages, StoreOp,
- SurfaceConfiguration, Texture, TextureAspect, TextureDescriptor, TextureDimension,
+ IndexFormat, LoadOp, MultisampleState, Operations, Origin3d, PipelineCompilationOptions,
+ PipelineLayout, PipelineLayoutDescriptor, PolygonMode, PrimitiveState, PrimitiveTopology,
+ PushConstantRange, Queue, RenderPassColorAttachment, RenderPassDepthStencilAttachment,
+ RenderPassDescriptor, RenderPipeline, RenderPipelineDescriptor, SamplerBindingType,
+ SamplerDescriptor, ShaderStages, StoreOp, SurfaceConfiguration, TexelCopyBufferLayout,
+ TexelCopyTextureInfo, Texture, TextureAspect, TextureDescriptor, TextureDimension,
TextureFormat, TextureSampleType, TextureUsages, TextureView, TextureViewDescriptor,
TextureViewDimension, VertexBufferLayout, VertexState, VertexStepMode, include_wgsl,
util::{DeviceExt, TextureDataOrder},
@@ -133,7 +133,7 @@ impl UiRenderer {
fn create_pipeline(
device: &Device,
- pipeline_layout: &PipelineLayout,
+ layout: &PipelineLayout,
format: TextureFormat,
sample_count: u32,
) -> RenderPipeline {
@@ -141,7 +141,7 @@ impl UiRenderer {
let vert_shader = device.create_shader_module(include_wgsl!("shaders/vertex_ui.wgsl"));
device.create_render_pipeline(&RenderPipelineDescriptor {
label: Some("ui pipeline"),
- layout: Some(&pipeline_layout),
+ layout: Some(layout),
fragment: Some(FragmentState {
module: &frag_shader,
entry_point: Some("main"),
@@ -241,12 +241,12 @@ impl UiRenderer {
ImageData::Font(font_image) => font_image.srgba_pixels(None).collect(),
};
- if let Some((_texbg, tex, texsize)) = textures.get_mut(&texid) {
+ if let Some((_texbg, texture, texsize)) = textures.get_mut(&texid) {
let pos = delta.pos.unwrap_or([0, 0]);
debug!("updating UI texture at {pos:?}");
self.queue.write_texture(
- ImageCopyTexture {
- texture: &tex,
+ TexelCopyTextureInfo {
+ texture,
mip_level: 0,
origin: Origin3d {
x: pos[0] as u32,
@@ -256,7 +256,7 @@ impl UiRenderer {
aspect: TextureAspect::All,
},
bytemuck::cast_slice::<_, u8>(&pixels),
- ImageDataLayout {
+ TexelCopyBufferLayout {
offset: 0,
bytes_per_row: Some(texsize[0] * 4),
rows_per_image: None,
@@ -344,7 +344,7 @@ impl UiRenderer {
},
})],
depth_stencil_attachment: Some(RenderPassDepthStencilAttachment {
- view: &depth,
+ view: depth,
depth_ops: Some(Operations {
load: LoadOp::Load,
store: StoreOp::Store,
@@ -356,17 +356,19 @@ impl UiRenderer {
rpass.set_pipeline(&self.pipeline);
- let mut raw_input = egui::RawInput::default();
- raw_input.viewport_id = surfaces.keys().next().copied().unwrap();
- raw_input.viewports = surfaces
- .keys()
- .map(|k| {
- (*k, ViewportInfo {
- native_pixels_per_point: Some(2.),
- ..Default::default()
+ let raw_input = egui::RawInput {
+ viewport_id: surfaces.keys().next().copied().unwrap(),
+ viewports: surfaces
+ .keys()
+ .map(|k| {
+ (*k, ViewportInfo {
+ native_pixels_per_point: Some(2.),
+ ..Default::default()
+ })
})
- })
- .collect();
+ .collect(),
+ ..Default::default()
+ };
let mut surfaces_closed = Vec::new();
for (viewport_id, surf) in surfaces.iter_mut() {
diff --git a/client/src/state.rs b/client/src/state.rs
index b260c9e..c39e13a 100644
--- a/client/src/state.rs
+++ b/client/src/state.rs
@@ -166,16 +166,14 @@ impl<'a> State<'a> {
while let Some(p) = self.audio.pop_output() {
self.network.packet_send.send(Packet::Sound(ob, Data(p)))?;
}
- } else {
- if let Some(res) = self.prefab_index.0.get("avatar_test") {
- info!("found avatar resource {res}");
- let ob = Object::new();
- self.network
- .packet_send
- .send(Packet::Add(ob, res.to_owned()))
- .unwrap();
- self.avatar_ob = Some(ob)
- }
+ } else if let Some(res) = self.prefab_index.0.get("avatar_test") {
+ info!("found avatar resource {res}");
+ let ob = Object::new();
+ self.network
+ .packet_send
+ .send(Packet::Add(ob, res.to_owned()))
+ .unwrap();
+ self.avatar_ob = Some(ob)
}
Ok(())
diff --git a/client/src/window.rs b/client/src/window.rs
index dcfb1e8..665aa01 100644
--- a/client/src/window.rs
+++ b/client/src/window.rs
@@ -96,18 +96,15 @@ impl ApplicationHandler for WindowState {
return;
}
if event.state == ElementState::Pressed {
- match event.physical_key {
- PhysicalKey::Code(KeyCode::Escape) => {
- win.set_cursor_grab(if self.lock {
- CursorGrabMode::None
- } else {
- CursorGrabMode::Locked
- })
- .unwrap();
- self.lock = !self.lock;
- win.set_cursor(CursorIcon::Default);
- }
- _ => (),
+ if let PhysicalKey::Code(KeyCode::Escape) = event.physical_key {
+ win.set_cursor_grab(if self.lock {
+ CursorGrabMode::None
+ } else {
+ CursorGrabMode::Locked
+ })
+ .unwrap();
+ self.lock = !self.lock;
+ win.set_cursor(CursorIcon::Default);
}
}
sta.input_state.move_dir += match event.physical_key {
@@ -141,14 +138,11 @@ impl ApplicationHandler for WindowState {
event: winit::event::DeviceEvent,
) {
if let Some((_win, sta)) = &mut self.window {
- match event {
- DeviceEvent::MouseMotion { delta } => {
- if self.lock {
- sta.input_state.mouse_acc.x += delta.0 as f32;
- sta.input_state.mouse_acc.y += delta.1 as f32;
- }
+ if let DeviceEvent::MouseMotion { delta } = event {
+ if self.lock {
+ sta.input_state.mouse_acc.x += delta.0 as f32;
+ sta.input_state.mouse_acc.y += delta.1 as f32;
}
- _ => (),
}
}
}
diff --git a/server/src/network.rs b/server/src/network.rs
index c59b54b..ec65218 100644
--- a/server/src/network.rs
+++ b/server/src/network.rs
@@ -66,7 +66,7 @@ impl ServerNetwork {
continue;
}
}
- if let Err(_) = tcp.send(ser.clone()) {
+ if tcp.send(ser.clone()).is_err() {
warn!("{cid}: queue full, packet dropped")
}
}
@@ -82,7 +82,7 @@ impl ServerNetwork {
}
}
debug!("{conn} -> {packet:?}");
- if let Err(_) = tcp.send(ser.clone()) {
+ if tcp.send(ser.clone()).is_err() {
warn!("{conn}: queue full, packet dropped")
}
}
@@ -220,12 +220,12 @@ fn handle_conn_write(sock: TcpStream, rx: Receiver<Arc<Vec<u8>>>) -> Result<()>
}
impl ServerNetwork {
- pub fn br<'a>(&'a self) -> Broadcaster<'a> {
+ pub fn br(&self) -> Broadcaster<'_> {
Broadcaster(self)
}
}
pub struct Broadcaster<'a>(&'a ServerNetwork);
-impl<'a> PacketSink for Broadcaster<'a> {
+impl PacketSink for Broadcaster<'_> {
fn push(&mut self, p: Packet) {
self.0.broadcast(p, true);
}
diff --git a/shared/src/helper.rs b/shared/src/helper.rs
index 3ae7c37..366ea52 100644
--- a/shared/src/helper.rs
+++ b/shared/src/helper.rs
@@ -27,7 +27,7 @@ pub trait ReadWrite: Sized {
fn write(&self, w: &mut dyn Write) -> Result<()>;
fn read(r: &mut dyn Read) -> Result<Self>;
- fn write_alloc<'a>(&'a self) -> Cow<'a, [u8]> {
+ fn write_alloc(&self) -> Cow<'_, [u8]> {
let mut buf = Vec::new();
self.write(&mut buf).unwrap();
Cow::Owned(buf)
@@ -58,7 +58,7 @@ impl ReadWrite for u32 {
}
impl ReadWrite for Vec<u8> {
fn write(&self, w: &mut dyn Write) -> Result<()> {
- w.write_all(&self)?;
+ w.write_all(self)?;
Ok(())
}
fn read(r: &mut dyn Read) -> Result<Self> {
@@ -67,9 +67,9 @@ impl ReadWrite for Vec<u8> {
Ok(buf)
}
}
-impl<'a> ReadWrite for Cow<'a, [u8]> {
+impl ReadWrite for Cow<'_, [u8]> {
fn write(&self, w: &mut dyn Write) -> Result<()> {
- w.write_all(&self)?;
+ w.write_all(self)?;
Ok(())
}
fn read(r: &mut dyn Read) -> Result<Self> {
@@ -77,10 +77,10 @@ impl<'a> ReadWrite for Cow<'a, [u8]> {
r.read_to_end(&mut buf)?;
Ok(Cow::Owned(buf))
}
- fn write_alloc<'b>(&'b self) -> Cow<'b, [u8]> {
+ fn write_alloc(&self) -> Cow<'_, [u8]> {
match self {
Cow::Borrowed(x) => Cow::Borrowed(x),
- Cow::Owned(x) => Cow::Borrowed(&x),
+ Cow::Owned(x) => Cow::Borrowed(x),
}
}
}
@@ -307,7 +307,7 @@ impl ReadWrite for Data {
impl ReadWrite for Message {
fn write(&self, w: &mut dyn Write) -> Result<()> {
w.write_all(&(self.0.len() as u32).to_be_bytes())?;
- w.write_all(&self.0.as_bytes())?;
+ w.write_all(self.0.as_bytes())?;
Ok(())
}
fn read(r: &mut dyn Read) -> Result<Self> {
diff --git a/shared/src/lib.rs b/shared/src/lib.rs
index e5cf666..e6b296e 100644
--- a/shared/src/lib.rs
+++ b/shared/src/lib.rs
@@ -20,6 +20,7 @@
debug_closure_helpers,
string_from_utf8_lossy_owned
)]
+#![allow(clippy::unit_arg, clippy::type_complexity)]
pub mod helper;
pub mod packets;
diff --git a/shared/src/packets.rs b/shared/src/packets.rs
index a5c017d..dad09ce 100644
--- a/shared/src/packets.rs
+++ b/shared/src/packets.rs
@@ -72,6 +72,11 @@ impl Object {
Self(rand::random())
}
}
+impl Default for Object {
+ fn default() -> Self {
+ Self::new()
+ }
+}
impl Packet {
fn serialize_inner(&self, w: &mut impl Write) -> Result<()> {
match self {
@@ -222,3 +227,6 @@ impl Display for Object {
.finish()
}
}
+impl Object {
+ pub const ROOT: Object = Object(0);
+}
diff --git a/shared/src/resources.rs b/shared/src/resources.rs
index 6c71adc..2c94d05 100644
--- a/shared/src/resources.rs
+++ b/shared/src/resources.rs
@@ -382,14 +382,14 @@ fn write_kv(w: &mut dyn Write, key: &[u8], value: &[u8]) -> Result<()> {
Ok(())
}
-impl<'a> ReadWrite for Image<'a> {
+impl ReadWrite for Image<'_> {
fn write(&self, w: &mut dyn Write) -> Result<()> {
self.0.write(w)
}
fn read(r: &mut dyn Read) -> Result<Self> {
Ok(Self(<Vec<u8> as ReadWrite>::read(r)?.into()))
}
- fn write_alloc<'b>(&'b self) -> Cow<'b, [u8]> {
+ fn write_alloc(&self) -> Cow<'_, [u8]> {
self.0.write_alloc()
}
}
diff --git a/shared/src/store.rs b/shared/src/store.rs
index ddcee2c..b0dbe45 100644
--- a/shared/src/store.rs
+++ b/shared/src/store.rs
@@ -88,7 +88,7 @@ impl ResourceStore {
}
ResourceStore::Memory(map) => Ok(map.lock().unwrap().get(&key).map(|x| x.to_vec())),
ResourceStore::Filesystem(root) => {
- let path = fs_cache_path(&root, key);
+ let path = fs_cache_path(root, key);
if path.exists() {
let mut buf = Vec::new();
File::open(path)?.read_to_end(&mut buf)?;
@@ -113,7 +113,7 @@ impl ResourceStore {
map.lock().unwrap().insert(key, value.to_vec());
}
ResourceStore::Filesystem(root) => {
- let path = fs_cache_path(&root, key);
+ let path = fs_cache_path(root, key);
if !path.exists() {
let path_temp = path.with_extension("part");
File::create(&path_temp)?.write_all(value)?;
diff --git a/shared/src/tree.rs b/shared/src/tree.rs
index a0bbf43..72e4c24 100644
--- a/shared/src/tree.rs
+++ b/shared/src/tree.rs
@@ -22,9 +22,11 @@ use glam::Vec3A;
use log::warn;
use std::collections::{BTreeSet, HashMap};
+#[derive(Default)]
pub struct SceneTree {
pub objects: HashMap<Object, ObjectData>,
}
+
pub struct ObjectData {
pub pos: Vec3A,
pub rot: Vec3A,
@@ -33,13 +35,7 @@ pub struct ObjectData {
pub pose: Vec<f32>,
pub res: Resource<Prefab>,
}
-impl Default for SceneTree {
- fn default() -> Self {
- Self {
- objects: Default::default(),
- }
- }
-}
+
impl SceneTree {
pub fn packet(&mut self, p: &Packet) {
match p {
@@ -50,13 +46,13 @@ impl SceneTree {
self.remove_reparent(*object, &mut ());
}
Packet::Position(object, pos, rot) => {
- if let Some(o) = self.objects.get_mut(&object) {
+ if let Some(o) = self.objects.get_mut(object) {
o.pos = *pos;
o.rot = *rot;
}
}
Packet::Pose(object, pose) => {
- if let Some(o) = self.objects.get_mut(&object) {
+ if let Some(o) = self.objects.get_mut(object) {
o.pose = pose.to_vec();
}
}
@@ -84,7 +80,7 @@ impl SceneTree {
true
} else {
let parent = tree.objects[&o].parent;
- if parent == o {
+ if parent == Object::ROOT {
false
} else {
check_parent_loop(tree, parent, test)
@@ -95,7 +91,7 @@ impl SceneTree {
warn!("reparent of missing objects");
return;
}
- if check_parent_loop(&self, parent, child) {
+ if check_parent_loop(self, parent, child) {
warn!("cyclic parenting prevented");
return;
}
@@ -131,22 +127,19 @@ impl SceneTree {
}
pub fn prime_client(&self) -> impl Iterator<Item = Packet> {
- self.objects
- .iter()
- .map(|(object, data)| {
- [
- Packet::Add(*object, data.res.clone()),
- Packet::Parent(*object, data.parent),
- Packet::Position(*object, data.pos, data.rot),
- ]
- .into_iter()
- .chain(if data.pose.is_empty() {
- None
- } else {
- Some(Packet::Pose(*object, data.pose.clone()))
- })
+ self.objects.iter().flat_map(|(object, data)| {
+ [
+ Packet::Add(*object, data.res.clone()),
+ Packet::Parent(*object, data.parent),
+ Packet::Position(*object, data.pos, data.rot),
+ ]
+ .into_iter()
+ .chain(if data.pose.is_empty() {
+ None
+ } else {
+ Some(Packet::Pose(*object, data.pose.clone()))
})
- .flatten()
+ })
}
}
diff --git a/world/src/main.rs b/world/src/main.rs
index d46f4d1..c65342f 100644
--- a/world/src/main.rs
+++ b/world/src/main.rs
@@ -15,6 +15,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#![feature(iter_array_chunks)]
+#![allow(clippy::too_many_arguments, clippy::type_complexity)]
pub mod mesh;
pub mod physics;
@@ -181,7 +182,7 @@ fn main() -> Result<()> {
&buffers,
&store,
path_base,
- &node,
+ node,
&mut prefab,
&args,
&texture_cache,
@@ -209,7 +210,7 @@ fn main() -> Result<()> {
})?,
));
}
- import_physics(&gltf, *trans, &node, &mut prefab, &store, &buffers)?;
+ import_physics(&gltf, *trans, node, &mut prefab, &store, &buffers)?;
Ok::<_, anyhow::Error>(prefab)
})
.reduce(
@@ -237,8 +238,7 @@ fn main() -> Result<()> {
prefab.name = args.name.clone().or(gltf
.default_scene()
- .map(|n| n.name())
- .flatten()
+ .and_then(|n| n.name())
.map(|n| n.to_owned()));
if args.debug_light {
@@ -285,7 +285,7 @@ fn main() -> Result<()> {
}
if args.spin {
- let ob = obs[0].clone();
+ let ob = obs[0];
let mut sock2 = sock.try_clone().unwrap();
thread::spawn(move || {
let mut x = 0.;
@@ -321,12 +321,10 @@ fn main() -> Result<()> {
}
}
Packet::Add(ob_a, _) => {
- if args.clear {
- if !obs.contains(&ob_a) {
- info!("removing object {ob_a}");
- Packet::Remove(ob_a).write(&mut sock)?;
- sock.flush()?;
- }
+ if args.clear && !obs.contains(&ob_a) {
+ info!("removing object {ob_a}");
+ Packet::Remove(ob_a).write(&mut sock)?;
+ sock.flush()?;
}
}
_ => (),
diff --git a/world/src/mesh.rs b/world/src/mesh.rs
index b8dc0c3..4e6317d 100644
--- a/world/src/mesh.rs
+++ b/world/src/mesh.rs
@@ -38,7 +38,7 @@ pub fn import_mesh(
texture_cache: &TextureCache,
armatures: &[Option<Armature>],
) -> Result<()> {
- Ok(for p in mesh.primitives() {
+ for p in mesh.primitives() {
let name = mesh.name().or(node.name()).map(|e| e.to_owned());
if let Some(name) = &name {
info!("adding mesh {name:?}");
@@ -52,7 +52,7 @@ pub fn import_mesh(
.map(|iter| {
let a = iter.map(|[x, y, z]| vec3a(x, y, z)).collect::<Vec<_>>();
debug!("{} vertex positions", a.len());
- Ok::<_, anyhow::Error>(store.set(&a)?)
+ store.set(&a)
})
.transpose()?;
@@ -61,7 +61,7 @@ pub fn import_mesh(
.map(|iter| {
let a = iter.map(|[x, y, z]| vec3a(x, y, z)).collect::<Vec<_>>();
debug!("{} vertex normals", a.len());
- Ok::<_, anyhow::Error>(store.set(&a)?)
+ store.set(&a)
})
.transpose()?;
@@ -71,7 +71,7 @@ pub fn import_mesh(
// TODO dont ignore handedness
let a = iter.map(|[x, y, z, _h]| vec3a(x, y, z)).collect::<Vec<_>>();
debug!("{} vertex tangents", a.len());
- Ok::<_, anyhow::Error>(store.set(&a)?)
+ store.set(&a)
})
.transpose()?;
@@ -80,7 +80,7 @@ pub fn import_mesh(
.map(|iter| {
let a = iter.into_u16().collect::<Vec<_>>();
debug!("{} vertex joint indecies", a.len());
- Ok::<_, anyhow::Error>(store.set(&a)?)
+ store.set(&a)
})
.transpose()?;
@@ -89,7 +89,7 @@ pub fn import_mesh(
.map(|iter| {
let a = iter.into_f32().collect::<Vec<_>>();
debug!("{} vertex joint weights", a.len());
- Ok::<_, anyhow::Error>(store.set(&a)?)
+ store.set(&a)
})
.transpose()?;
@@ -98,7 +98,7 @@ pub fn import_mesh(
.map(|iter| {
let a = iter.into_f32().map(|[x, y]| vec2(x, y)).collect::<Vec<_>>();
debug!("{} vertex texture coordinates", a.len());
- Ok::<_, anyhow::Error>(store.set(&a)?)
+ store.set(&a)
})
.transpose()?;
@@ -110,7 +110,7 @@ pub fn import_mesh(
.map(|[x, y, z]| vec3a(x, y, z))
.collect::<Vec<_>>();
debug!("{} vertex colors", a.len());
- Ok::<_, anyhow::Error>(store.set(&a)?)
+ store.set(&a)
})
.transpose()?;
@@ -147,9 +147,9 @@ pub fn import_mesh(
if let Some(tex) = p.material().pbr_metallic_roughness().base_color_texture() {
let r = load_texture(
"albedo",
- &store,
+ store,
path_base,
- &buffers,
+ buffers,
&tex.texture().source().source(),
args.webp,
texture_cache,
@@ -161,9 +161,9 @@ pub fn import_mesh(
if let Some(tex) = p.material().normal_texture() {
tex_normal = Some(load_texture(
"normal",
- &store,
+ store,
path_base,
- &buffers,
+ buffers,
&tex.texture().source().source(),
args.webp,
texture_cache,
@@ -173,9 +173,9 @@ pub fn import_mesh(
if let Some(tex) = p.material().emissive_texture() {
tex_emission = Some(load_texture(
"emission",
- &store,
+ store,
path_base,
- &buffers,
+ buffers,
&tex.texture().source().source(),
args.webp,
texture_cache,
@@ -185,14 +185,13 @@ pub fn import_mesh(
if let Some(tex) = p
.material()
.transmission()
- .map(|t| t.transmission_texture())
- .flatten()
+ .and_then(|t| t.transmission_texture())
{
tex_transmission = Some(load_texture(
"transmission",
- &store,
+ store,
path_base,
- &buffers,
+ buffers,
&tex.texture().source().source(),
args.webp,
texture_cache,
@@ -202,14 +201,13 @@ pub fn import_mesh(
if let Some(tex) = p
.material()
.volume()
- .map(|t| t.thickness_texture())
- .flatten()
+ .and_then(|t| t.thickness_texture())
{
tex_thickness = Some(load_texture(
"thickness",
- &store,
+ store,
path_base,
- &buffers,
+ buffers,
&tex.texture().source().source(),
args.webp,
texture_cache,
@@ -219,9 +217,9 @@ pub fn import_mesh(
if let Some(tex) = p.material().occlusion_texture() {
tex_occlusion = Some(load_texture(
"occlusion",
- &store,
+ store,
path_base,
- &buffers,
+ buffers,
&tex.texture().source().source(),
args.webp,
texture_cache,
@@ -236,9 +234,9 @@ pub fn import_mesh(
{
let r = load_texture(
"metallic+roughness",
- &store,
+ store,
path_base,
- &buffers,
+ buffers,
&tex.texture().source().source(),
args.webp,
texture_cache,
@@ -299,10 +297,8 @@ pub fn import_mesh(
let g_dispersion = p
.material()
.extension_value("KHR_materials_dispersion")
- .map(|e| e.get("dispersion"))
- .flatten()
- .map(|e| e.as_f64())
- .flatten()
+ .and_then(|e| e.get("dispersion"))
+ .and_then(|e| e.as_f64())
.map(|e| e as f32);
if let Some(d) = g_dispersion {
debug!("dispersion is {d}");
@@ -391,5 +387,6 @@ pub fn import_mesh(
})?;
prefab.mesh.push((trans, mesh))
- })
+ };
+ Ok(())
}
diff --git a/world/src/physics.rs b/world/src/physics.rs
index 37201af..84f1095 100644
--- a/world/src/physics.rs
+++ b/world/src/physics.rs
@@ -34,8 +34,7 @@ pub fn import_physics(
) -> Result<()> {
if let Some(physics) = node
.extensions()
- .map(|e| e.get("KHR_physics_rigid_bodies"))
- .flatten()
+ .and_then(|e| e.get("KHR_physics_rigid_bodies"))
{
info!("--- COLLISION ---");
if let Some(collider) = physics.get("collider") {
@@ -43,8 +42,7 @@ pub fn import_physics(
if geometry.get("convexHull") == Some(&Value::Bool(true)) {
let node = geometry
.get("node")
- .map(|n| n.as_u64())
- .flatten()
+ .and_then(|n| n.as_u64())
.ok_or(anyhow!("convexHull node missing"))?;
let node = gltf
.nodes()