Skip to content

Commit

Permalink
fix warnings for main crate
Browse files Browse the repository at this point in the history
Signed-off-by: Schmarni <[email protected]>
  • Loading branch information
Schmarni-Dev committed Sep 29, 2024
1 parent 7051500 commit f1f5e05
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 61 deletions.
26 changes: 10 additions & 16 deletions src/file_import.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::MainWindow;
use bevy::log::info;
use bevy::math::EulerRot::XYZ;
use bevy::prelude::*;
use bevy_egui::{egui, EguiContext};
use bevy_spatial_egui::SpawnSpatialEguiWindowCommand;
use egui_aesthetix::Aesthetix;
use std::ops::{Add, Sub};
use std::path::Path;
use std::ops::Add;
use std::sync::Arc;

pub struct FileImportPlugin;
Expand All @@ -16,6 +14,7 @@ impl Plugin for FileImportPlugin {
}
}

#[allow(dead_code)]
#[derive(Copy, Clone, Component, Debug)]
pub enum FileType {
Vrm,
Expand All @@ -37,21 +36,16 @@ fn draw_ui(
ctx.get_mut().set_style(
Arc::new(egui_aesthetix::themes::TokyoNightStorm).custom_style(),
);
#[allow(clippy::needless_if)]
egui::panel::CentralPanel::default().show(ctx.get_mut(), |ui| {
ui.heading(format!("Path: {}", file_import_window.path));
if ui.button("png").clicked() {

}
if ui.button("worldspace model").clicked() {

}
if ui.button("switch avatar").clicked() {

}
ui.add_space(10.0);
if ui.button("cancel").clicked() {
commands.entity(entity).despawn_recursive();
}
if ui.button("png").clicked() {}
if ui.button("worldspace model").clicked() {}
if ui.button("switch avatar").clicked() {}
ui.add_space(10.0);
if ui.button("cancel").clicked() {
commands.entity(entity).despawn_recursive();
}
});
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/file_sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::networking::{Connection, ConnectionTrait, ReliableMessage};
use bevy::prelude::*;
use bevy_matchbox::prelude::MultipleChannels;
use bevy_matchbox::MatchboxSocket;
use futures_channel::mpsc::{channel, Receiver, SendError, Sender};
use futures_channel::mpsc::{channel, Receiver, Sender};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use uuid::Uuid;
Expand All @@ -24,6 +24,7 @@ impl FilePart {
}
}

#[allow(dead_code)]
#[derive(Component)]
pub struct InProgressFile {
len: usize,
Expand Down Expand Up @@ -56,6 +57,7 @@ impl Plugin for FileSharingPlugin {
#[derive(Resource)]
struct P2pFileRx(Receiver<(Uuid, Vec<u8>)>);

#[allow(dead_code)]
#[derive(Resource)]
pub struct P2pFileSender(Sender<(Uuid, Vec<u8>)>);

Expand All @@ -70,7 +72,7 @@ fn send_parts_of_file(
for chunk in bytes.chunks(256) {
chunks.push(chunk.to_vec());
}
local.insert(uuid.clone(), chunks);
local.insert(uuid, chunks);
while let Err(e) = connection
.send_all(&ReliableMessage::FilePart(FilePart::Start { uuid, len }))
{
Expand All @@ -82,17 +84,16 @@ fn send_parts_of_file(

let mut list_of_empty = vec![];

for (uuid, mut chunks) in local.iter_mut() {
for (uuid, chunks) in local.iter_mut() {
if let Some(chunk) = chunks.pop() {
let message =
ReliableMessage::FilePart(FilePart::Part(uuid.clone(), chunk));
let message = ReliableMessage::FilePart(FilePart::Part(*uuid, chunk));
while let Err(e) = connection.send_all(&message) {
if e.first().unwrap().1.is_disconnected() {
return;
}
}
} else {
list_of_empty.push(uuid.clone());
list_of_empty.push(*uuid);
}
}

Expand Down
11 changes: 4 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::file_import::FileImportPlugin;
use crate::file_sharing::FileSharingPlugin;
use crate::networking::{ConnectToRoom, LocalPlayer, NetworkingPlugin, SpawnPlayer};
use crate::networking::{ConnectToRoom, LocalPlayer, NetworkingPlugin};
use crate::physics_sync::PhysicsSyncNetworkingPlugin;
use crate::player_networking::PlayerNetworking;
use avian3d::prelude::{
Collider, CollisionLayers, GravityScale, LockedAxes, RigidBody,
};
use avian3d::prelude::{Collider, GravityScale, LockedAxes, RigidBody};
use avian3d::PhysicsPlugins;
use bevy::app::App;
use bevy::asset::{AssetMetaCheck, AssetServer, Assets, Handle};
Expand All @@ -23,10 +21,8 @@ use bevy_suis::debug::SuisDebugGizmosPlugin;
use bevy_suis::window_pointers::SuisWindowPointerPlugin;
use bevy_suis::SuisCorePlugin;
use bevy_vr_controller::animation::defaults::default_character_animations;
use bevy_vr_controller::movement::PlayerInputState;
use bevy_vr_controller::player::{
PlayerAvatar, PlayerBody, PlayerHeight, PlayerJumpHeight, PlayerSettings,
PlayerSpawn, PlayerSpeed, SpawnedPlayer, VoidTeleport,
PlayerAvatar, PlayerBody, PlayerSettings, PlayerSpawn, VoidTeleport,
};
use bevy_vr_controller::velocity::AverageVelocity;
use bevy_vr_controller::VrControllerPlugin;
Expand Down Expand Up @@ -118,6 +114,7 @@ fn setup_main_window(mut cmds: Commands) {
});
}

#[allow(dead_code)]
#[derive(Resource)]
pub struct FloorMaterial((Handle<StandardMaterial>, Handle<Mesh>));

Expand Down
6 changes: 3 additions & 3 deletions src/networking.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::file_sharing::FileParts;
use avian3d::prelude::{AngularVelocity, LinearVelocity, Position};
use bevy::app::App;
use bevy::ecs::system::{EntityCommand, SystemParam};
use bevy::ecs::world::Command;
use bevy::ecs::system::SystemParam;
use bevy::prelude::*;
use bevy_derive::{Deref, DerefMut};
use bevy_matchbox::prelude::{
Expand All @@ -19,6 +17,8 @@ pub enum ReliableMessage {
FilePart(crate::file_sharing::FilePart),
}

// should this used Boxed values for a smaller base size?
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum UnreliableMessage {
UpdatePhysicsPosition(UpdatePhysicsPosition),
Expand Down
18 changes: 9 additions & 9 deletions src/physics_sync.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::networking::{RemotePlayer, UpdatePhysicsPosition};
use avian3d::math::AsF32;
use avian3d::prelude::{AngularVelocity, LinearVelocity, Position, Rotation};
use bevy::prelude::*;

Expand All @@ -22,19 +21,20 @@ fn sync_positions(
)>,
) {
for update in event_reader.read() {
for (uuid, mut pos, mut rot, mut lin, mut ang) in players.iter_mut() {
for (uuid, mut pos, mut rot, mut lin, _) in players.iter_mut() {
if uuid.0 != update.uuid {
continue;
}
if pos.distance(*update.position) <= 0.01 {
if rot.0.angle_between(update.rotation.0).abs() <= 0.01 {
continue;
}
// This position check is one centimeter?! that's a little big no?
if pos.distance(*update.position) <= 0.01
&& rot.0.angle_between(update.rotation.0).abs() <= 0.01
{
continue;
}

*pos = update.position.clone();
*rot = update.rotation.clone();
*lin = update.linear_velocity.clone();
*pos = update.position;
*rot = update.rotation;
*lin = update.linear_velocity;
//*ang = update.angular_velocity.clone();
}
}
Expand Down
39 changes: 19 additions & 20 deletions src/player_networking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ fn when_spawn_player(
},
&mut commands,
);
commands.entity(id).insert(RemotePlayer(
player.uuid.clone(),
player.peer_id.as_ref().unwrap().clone(),
));
commands
.entity(id)
.insert(RemotePlayer(player.uuid, player.peer_id.unwrap()));
}
}

Expand Down Expand Up @@ -82,7 +81,7 @@ fn send_players_when_connected(
let _ = connection.send(
new_player.0,
&ReliableMessage::SpawnPlayer(SpawnPlayer {
uuid: local_player.0.clone(),
uuid: local_player.0,
peer_id: None,
}),
);
Expand Down Expand Up @@ -120,10 +119,10 @@ fn update_player_position(
let message = UnreliableMessage::UpdatePhysicsPosition(UpdatePhysicsPosition {
authority: 0,
uuid: local_player.0,
position: position.clone(),
rotation: rotation.clone(),
linear_velocity: lin_vel.clone(),
angular_velocity: ang_vel.clone(),
position: *position,
rotation: *rotation,
linear_velocity: *lin_vel,
angular_velocity: *ang_vel,
});

let _ = connection.send_all(&message);
Expand All @@ -133,7 +132,7 @@ fn update_player_position(
}*/

let mut player_position_update = PlayerPositionUpdate {
uuid: local_player.0.clone(),
uuid: local_player.0,
head: Default::default(),
left_shoulder: Default::default(),
right_shoulder: Default::default(),
Expand All @@ -145,32 +144,32 @@ fn update_player_position(
right_hand: Default::default(),
};
for children in children.iter_descendants(entity) {
for (bone_name, transform) in transforms.get(children) {
if let Ok((bone_name, transform)) = transforms.get(children) {
match bone_name {
BoneName::Head => player_position_update.head = transform.clone(),
BoneName::Head => player_position_update.head = *transform,
BoneName::LeftShoulder => {
player_position_update.left_shoulder = transform.clone()
player_position_update.left_shoulder = *transform;
}
BoneName::RightShoulder => {
player_position_update.right_shoulder = transform.clone()
player_position_update.right_shoulder = *transform;
}
BoneName::LeftUpperArm => {
player_position_update.left_upper_arm = transform.clone()
player_position_update.left_upper_arm = *transform;
}
BoneName::RightUpperArm => {
player_position_update.right_upper_arm = transform.clone()
player_position_update.right_upper_arm = *transform;
}
BoneName::LeftLowerArm => {
player_position_update.left_lower_arm = transform.clone()
player_position_update.left_lower_arm = *transform;
}
BoneName::RightLowerArm => {
player_position_update.right_lower_arm = transform.clone()
player_position_update.right_lower_arm = *transform;
}
BoneName::LeftHand => {
player_position_update.left_hand = transform.clone()
player_position_update.left_hand = *transform;
}
BoneName::RightHand => {
player_position_update.right_hand = transform.clone()
player_position_update.right_hand = *transform;
}
_ => {}
}
Expand Down

0 comments on commit f1f5e05

Please sign in to comment.