Skip to content

Commit

Permalink
Merge pull request #131 from steamroller-airmash/missing-health-indic…
Browse files Browse the repository at this point in the history
…ator

Fix missing health and energy indicators
  • Loading branch information
steamroller-airmash committed Aug 14, 2019
2 parents a07a089 + 0df1e95 commit 24a138c
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 114 deletions.
223 changes: 136 additions & 87 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ctf/src/main.rs
Expand Up @@ -56,7 +56,7 @@ fn init_sentry() {

fn main() {
env::set_var("RUST_BACKTRACE", "1");
env::set_var("RUST_LOG", "airmash_server=info");
env::set_var("RUST_LOG", "info");

let matches = clap::App::new("airmash-server-ctf")
.version(env!("CARGO_PKG_VERSION"))
Expand Down
2 changes: 1 addition & 1 deletion server/src/bin/dump-config.rs
@@ -1,5 +1,5 @@
use std::error::Error;
use airmash_server::types::Config;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
let config = Config::default();
Expand Down
4 changes: 2 additions & 2 deletions server/src/systems/handlers/command/spectate.rs
Expand Up @@ -12,8 +12,8 @@ use crate::component::time::{LastKeyTime, ThisFrame};

use crate::protocol::server::Error;
use crate::protocol::ErrorType;
use crate::utils::{EventHandler, EventHandlerTypeProvider};
use crate::systems::PacketHandler;
use crate::utils::{EventHandler, EventHandlerTypeProvider};

const SPEED_THRESHOLD: f32 = 0.01;
const SPEED_THRESHOLD_SQUARED: f32 = SPEED_THRESHOLD * SPEED_THRESHOLD;
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<'a> EventHandler<'a> for Spectate {

let vel = *try_get!(player, velocity);
let spd2 = vel.length2().inner();

if !config.allow_spectate_while_moving && spd2 >= SPEED_THRESHOLD_SQUARED {
allowed = false;
}
Expand Down
@@ -1,7 +1,6 @@
use specs::*;

use crate::component::event::PlayerRespawn as EvtPlayerRespawn;
use crate::component::flag::*;
use crate::types::systemdata::SendToVisible;
use crate::types::*;
use crate::SystemInfo;
Expand All @@ -26,7 +25,6 @@ pub struct SendPlayerRespawnData<'a> {
entities: Entities<'a>,
conns: SendToVisible<'a>,

is_spec: ReadStorage<'a, IsSpectating>,
pos: ReadStorage<'a, Position>,
rot: ReadStorage<'a, Rotation>,
}
Expand All @@ -43,23 +41,28 @@ impl<'a> EventHandler<'a> for SendPlayerRespawn {
return;
}

if data.is_spec.get(evt.player).is_some() {
return;
}

let player = evt.player;
let pos = *try_get!(player, data.pos);
let rot = *try_get!(player, data.rot);

data.conns.send_to_visible(
pos,
PlayerRespawn {
id: player.into(),
pos: pos,
rot: rot,
upgrades: ProtocolUpgrades::default(),
},
);
let packet = PlayerRespawn {
id: player.into(),
pos: pos,
rot: rot,
upgrades: ProtocolUpgrades::default(),
};

// FIXME: Bake setting traits into a respawn task
// so that there's a 1-frame gap between
// setting the position and respawning. This
// would ensure that the collision mask is
// properly updated before.
//
// Alternative: Allow reinserting players into the
// collision grid mid-frame. This one might
// actually be better.
data.conns.send_to_others_visible(pos, player, packet);

data.conns.send_to_player(player, packet);
}
}

Expand Down
2 changes: 0 additions & 2 deletions server/src/task/death_cooldown.rs
Expand Up @@ -12,8 +12,6 @@ use std::time::Duration;
pub async fn death_cooldown(mut task: TaskData, player: Entity) {
task.sleep_for(Duration::from_secs(2)).await;

info!("Clearing dead flag for {:?}", player);

task.write_storage::<IsDead, _, _>(|mut storage: specs::WriteStorage<IsDead>| {
storage.remove(player)
});
Expand Down
14 changes: 9 additions & 5 deletions server/src/types/connection.rs
Expand Up @@ -110,11 +110,15 @@ impl Connections {
}
pub fn send_to_ref(&self, id: ConnectionId, msg: &ServerPacket) {
// FIXME: Send errors back up to the caller
trace!(
target: "server",
"Sent message to {:?}: {:?}",
id, msg
);
match msg {
ServerPacket::Ack | ServerPacket::PlayerUpdate(_) => (),
ServerPacket::PingResult(_) => (),
_ => trace!(
target: "server",
"Sent message to {:?}: {:?}",
id, msg
),
}

let mut conn = match self.conns.get(&id).map(|ref x| x.sink.clone()) {
Some(conn) => conn,
Expand Down
25 changes: 25 additions & 0 deletions server/src/types/systemdata/send_to_visible.rs
Expand Up @@ -113,4 +113,29 @@ impl<'a> SendToVisible<'a> {
self.send_to_ref(associated.0, &msg);
});
}

/// Send to all players that could be visible with
/// the exception of one entity.
///
/// Use this when you need to guarantee that a player
/// is sent a message even when others might not.
pub fn send_to_others_visible<I>(&self, pos: Position, player: Entity, msg: I)
where
I: Into<ServerPacket>,
{
let msg = msg.into();

self.grid
.0
.rough_collide(HitCircle {
pos: pos,
rad: self.config.view_radius,
layer: 0,
ent: player,
})
.into_iter()
.filter(|x| *x != player)
.filter_map(|x| self.associated.get(x))
.for_each(|associated| self.send_to_ref(associated.0, &msg));
}
}

0 comments on commit 24a138c

Please sign in to comment.