forked from feather-rs/feather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity.rs
More file actions
33 lines (28 loc) · 1.03 KB
/
entity.rs
File metadata and controls
33 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//! Sends entity-related packets to clients.
//! Spawn packets, position updates, equipment, animations, etc.
use base::Position;
use common::Game;
use ecs::{SysResult, SystemExecutor};
use quill_common::components::OnGround;
use crate::{entities::PreviousPosition, NetworkId, Server};
mod spawn_packet;
pub fn register(game: &mut Game, systems: &mut SystemExecutor<Game>) {
spawn_packet::register(game, systems);
systems.group::<Server>().add_system(send_entity_movement);
}
/// Sends entity movement packets.
fn send_entity_movement(game: &mut Game, server: &mut Server) -> SysResult {
for (_, (&position, prev_position, &on_ground, &network_id)) in game
.ecs
.query::<(&Position, &mut PreviousPosition, &OnGround, &NetworkId)>()
.iter()
{
if position != prev_position.0 {
server.broadcast_nearby_with(position, |client| {
client.update_entity_position(network_id, position, on_ground);
});
prev_position.0 = position;
}
}
Ok(())
}