Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Remove unnecessary clone
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubelotix committed Nov 17, 2023
1 parent 5173b94 commit 3956c33
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions minecraft-server/src/entities/tasks/newton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ use crate::CollisionShape;
use super::*;

pub async fn newton_task<T: EntityDescendant>(h: Handler<T>, mut server_msg_rcvr: BroadcastReceiver<ServerMessage>) where AnyEntity: TryAsEntityRef<T> {
let Some(network_entity) = h.observe_any(|any_entity| any_entity.to_network()).await else { return; };

let (width, height) = match network_entity {
Some(network_entity) => (network_entity.width() as f64, network_entity.height() as f64),
None => {
warn!("Entity {} has no network entity", h.eid);
return;
}
};

loop {
let Ok(msg) = server_msg_rcvr.recv().await else {continue};

Expand All @@ -11,20 +21,11 @@ pub async fn newton_task<T: EntityDescendant>(h: Handler<T>, mut server_msg_rcvr
}

// Get data from entity
let Some((mut position, mut velocity, network_entity)) = h.observe_any(|any_entity| {
let Some((mut position, mut velocity)) = h.observe_any(|any_entity| {
let entity = any_entity.as_entity();
let network_entity = any_entity.to_network();
(entity.position.clone(), entity.velocity.clone(), network_entity)
(entity.position.clone(), entity.velocity.clone())
}).await else { return; };

let (width, height) = match network_entity {
Some(network_entity) => (network_entity.width() as f64, network_entity.height() as f64),
None => {
warn!("Entity {} has no network entity", h.eid); // TODO(perf): Make gravity verify that the entity has bounding boxes at the start
return;
}
};

// Apply velocity and collisions
let mut changes = EntityChanges::nothing();
let mut new_velocity = velocity.clone();
Expand Down

0 comments on commit 3956c33

Please sign in to comment.