Queued inputs are now culled after a period of time if they are not actively held

This commit is contained in:
Sam 2022-11-07 00:36:43 -05:00
parent 7ec9a7677f
commit 5f126bb5c6
4 changed files with 17 additions and 8 deletions

View File

@ -8,6 +8,7 @@ use crate::{
invite::{InviteKind, InviteResponse},
BuffKind,
},
resources::Time,
trade::{TradeAction, TradeId},
uid::Uid,
util::Dir,
@ -247,7 +248,7 @@ pub struct ControllerInputs {
pub struct Controller {
pub inputs: ControllerInputs,
pub held_inputs: BTreeMap<InputKind, InputAttr>,
pub queued_inputs: BTreeMap<InputKind, InputAttr>,
pub queued_inputs: BTreeMap<InputKind, (Time, InputAttr)>,
// TODO: consider SmallVec
pub events: Vec<ControlEvent>,
pub actions: Vec<ControlAction>,
@ -311,6 +312,12 @@ impl Controller {
pub fn push_cancel_input(&mut self, input: InputKind) {
self.push_action(ControlAction::CancelInput(input));
}
pub fn cull_queued_inputs(&mut self, time: Time) {
const QUEUED_CULL_DUR: f64 = 0.5;
self.queued_inputs
.retain(|_, (init_time, _)| init_time.0 + QUEUED_CULL_DUR > time.0);
}
}
impl Component for Controller {

View File

@ -146,6 +146,7 @@ pub struct JoinData<'a> {
pub terrain: &'a TerrainGrid,
pub mount_data: Option<&'a Is<Rider>>,
pub stance: Option<&'a Stance>,
pub time: &'a Time,
}
pub struct JoinStruct<'a> {
@ -173,6 +174,7 @@ pub struct JoinStruct<'a> {
pub terrain: &'a TerrainGrid,
pub mount_data: Option<&'a Is<Rider>>,
pub stance: Option<&'a Stance>,
pub time: &'a Time,
}
impl<'a> JoinData<'a> {
@ -214,6 +216,7 @@ impl<'a> JoinData<'a> {
active_abilities: j.active_abilities,
mount_data: j.mount_data,
stance: j.stance,
time: j.time,
}
}
}

View File

@ -1390,12 +1390,7 @@ impl AbilityInfo {
tool,
hand,
input,
input_attr: data
.controller
.queued_inputs
.get(&input)
.or_else(|| data.controller.held_inputs.get(&input))
.copied(),
input_attr: data.controller.queued_inputs.get(&input).map(|x| x.1).or_else(|| data.controller.held_inputs.get(&input).copied()),
ability_meta,
ability,
}

View File

@ -201,6 +201,7 @@ impl<'a> System<'a> for Sys {
terrain: &read_data.terrain,
mount_data: read_data.is_riders.get(entity),
stance: read_data.stances.get(entity),
time: &read_data.time,
};
for action in actions {
@ -271,7 +272,9 @@ impl Sys {
*join.ori = state_update.ori;
for (input, attr) in state_update.queued_inputs {
join.controller.queued_inputs.insert(input, attr);
join.controller
.queued_inputs
.insert(input, (*join.time, attr));
join.controller.held_inputs.insert(input, attr);
}
for input in state_update.used_inputs {
@ -280,6 +283,7 @@ impl Sys {
for input in state_update.removed_inputs {
join.controller.held_inputs.remove(&input);
}
join.controller.cull_queued_inputs(*join.time);
if state_update.swap_equipped_weapons {
output_events.emit_server(ServerEvent::InventoryManip(
join.entity,