mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Removed buffered inputs
This commit is contained in:
@ -1727,7 +1727,6 @@ impl Client {
|
|||||||
entry
|
entry
|
||||||
.or_insert_with(|| Controller {
|
.or_insert_with(|| Controller {
|
||||||
inputs: inputs.clone(),
|
inputs: inputs.clone(),
|
||||||
held_inputs: BTreeMap::new(),
|
|
||||||
queued_inputs: BTreeMap::new(),
|
queued_inputs: BTreeMap::new(),
|
||||||
events: Vec::new(),
|
events: Vec::new(),
|
||||||
actions: Vec::new(),
|
actions: Vec::new(),
|
||||||
|
@ -29,7 +29,6 @@ pub struct StateUpdate {
|
|||||||
pub swap_equipped_weapons: bool,
|
pub swap_equipped_weapons: bool,
|
||||||
pub should_strafe: bool,
|
pub should_strafe: bool,
|
||||||
pub queued_inputs: BTreeMap<InputKind, InputAttr>,
|
pub queued_inputs: BTreeMap<InputKind, InputAttr>,
|
||||||
pub used_inputs: Vec<InputKind>,
|
|
||||||
pub removed_inputs: Vec<InputKind>,
|
pub removed_inputs: Vec<InputKind>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +59,6 @@ impl From<&JoinData<'_>> for StateUpdate {
|
|||||||
should_strafe: data.inputs.strafing,
|
should_strafe: data.inputs.strafing,
|
||||||
character: data.character.clone(),
|
character: data.character.clone(),
|
||||||
queued_inputs: BTreeMap::new(),
|
queued_inputs: BTreeMap::new(),
|
||||||
used_inputs: Vec::new(),
|
|
||||||
removed_inputs: Vec::new(),
|
removed_inputs: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ use crate::{
|
|||||||
invite::{InviteKind, InviteResponse},
|
invite::{InviteKind, InviteResponse},
|
||||||
BuffKind,
|
BuffKind,
|
||||||
},
|
},
|
||||||
resources::Time,
|
|
||||||
trade::{TradeAction, TradeId},
|
trade::{TradeAction, TradeId},
|
||||||
uid::Uid,
|
uid::Uid,
|
||||||
util::Dir,
|
util::Dir,
|
||||||
@ -248,8 +247,7 @@ pub struct ControllerInputs {
|
|||||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Controller {
|
pub struct Controller {
|
||||||
pub inputs: ControllerInputs,
|
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
|
// TODO: consider SmallVec
|
||||||
pub events: Vec<ControlEvent>,
|
pub events: Vec<ControlEvent>,
|
||||||
pub actions: Vec<ControlAction>,
|
pub actions: Vec<ControlAction>,
|
||||||
@ -285,7 +283,6 @@ impl Controller {
|
|||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
self.inputs = Default::default();
|
self.inputs = Default::default();
|
||||||
self.queued_inputs = Default::default();
|
self.queued_inputs = Default::default();
|
||||||
self.held_inputs = Default::default();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_events(&mut self) { self.events.clear(); }
|
pub fn clear_events(&mut self) { self.events.clear(); }
|
||||||
@ -313,12 +310,6 @@ impl Controller {
|
|||||||
pub fn push_cancel_input(&mut self, input: InputKind) {
|
pub fn push_cancel_input(&mut self, input: InputKind) {
|
||||||
self.push_action(ControlAction::CancelInput(input));
|
self.push_action(ControlAction::CancelInput(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cull_queued_inputs(&mut self, time: Time) {
|
|
||||||
const QUEUED_CULL_DUR: f64 = 0.35;
|
|
||||||
self.queued_inputs
|
|
||||||
.retain(|_, (init_time, _)| init_time.0 + QUEUED_CULL_DUR > time.0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for Controller {
|
impl Component for Controller {
|
||||||
|
@ -702,9 +702,7 @@ pub fn fly_move(data: &JoinData<'_>, update: &mut StateUpdate, efficiency: f32)
|
|||||||
/// Checks if an input related to an attack is held. If one is, moves entity
|
/// Checks if an input related to an attack is held. If one is, moves entity
|
||||||
/// into wielding state
|
/// into wielding state
|
||||||
pub fn handle_wield(data: &JoinData<'_>, update: &mut StateUpdate) {
|
pub fn handle_wield(data: &JoinData<'_>, update: &mut StateUpdate) {
|
||||||
if data.controller.queued_inputs.keys().any(|i| i.is_ability())
|
if data.controller.queued_inputs.keys().any(|i| i.is_ability()) {
|
||||||
|| data.controller.held_inputs.keys().any(|i| i.is_ability())
|
|
||||||
{
|
|
||||||
attempt_wield(data, update);
|
attempt_wield(data, update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1051,7 +1049,7 @@ pub fn attempt_glide_wield(
|
|||||||
pub fn handle_jump(
|
pub fn handle_jump(
|
||||||
data: &JoinData<'_>,
|
data: &JoinData<'_>,
|
||||||
output_events: &mut OutputEvents,
|
output_events: &mut OutputEvents,
|
||||||
update: &mut StateUpdate,
|
_update: &mut StateUpdate,
|
||||||
strength: f32,
|
strength: f32,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
(input_is_pressed(data, InputKind::Jump) && data.physics.on_ground.is_some())
|
(input_is_pressed(data, InputKind::Jump) && data.physics.on_ground.is_some())
|
||||||
@ -1062,7 +1060,6 @@ pub fn handle_jump(
|
|||||||
data.entity,
|
data.entity,
|
||||||
strength * impulse / data.mass.0 * data.stats.move_speed_modifier,
|
strength * impulse / data.mass.0 * data.stats.move_speed_modifier,
|
||||||
));
|
));
|
||||||
update.used_inputs.push(InputKind::Jump);
|
|
||||||
})
|
})
|
||||||
.is_some()
|
.is_some()
|
||||||
}
|
}
|
||||||
@ -1104,7 +1101,6 @@ fn handle_ability(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update.used_inputs.push(input);
|
|
||||||
if let CharacterState::Roll(roll) = &mut update.character {
|
if let CharacterState::Roll(roll) = &mut update.character {
|
||||||
if let CharacterState::ComboMelee(c) = data.character {
|
if let CharacterState::ComboMelee(c) = data.character {
|
||||||
roll.was_combo = Some((c.static_data.ability_info.input, c.stage));
|
roll.was_combo = Some((c.static_data.ability_info.input, c.stage));
|
||||||
@ -1150,13 +1146,7 @@ pub fn attempt_input(
|
|||||||
update: &mut StateUpdate,
|
update: &mut StateUpdate,
|
||||||
) {
|
) {
|
||||||
// TODO: look into using first() when it becomes stable
|
// TODO: look into using first() when it becomes stable
|
||||||
if let Some(input) = data
|
if let Some(input) = data.controller.queued_inputs.keys().next() {
|
||||||
.controller
|
|
||||||
.queued_inputs
|
|
||||||
.keys()
|
|
||||||
.next()
|
|
||||||
.or_else(|| data.controller.held_inputs.keys().next())
|
|
||||||
{
|
|
||||||
handle_input(data, output_events, update, *input);
|
handle_input(data, output_events, update, *input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1176,7 +1166,6 @@ pub fn handle_block_input(data: &JoinData<'_>, update: &mut StateUpdate) -> bool
|
|||||||
AbilityInfo::from_input(data, false, InputKind::Block, Default::default()),
|
AbilityInfo::from_input(data, false, InputKind::Block, Default::default()),
|
||||||
data,
|
data,
|
||||||
));
|
));
|
||||||
update.used_inputs.push(InputKind::Block);
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
@ -1300,7 +1289,6 @@ pub fn get_buff_strength(data: &JoinData<'_>, ai: AbilityInfo) -> f32 {
|
|||||||
|
|
||||||
pub fn input_is_pressed(data: &JoinData<'_>, input: InputKind) -> bool {
|
pub fn input_is_pressed(data: &JoinData<'_>, input: InputKind) -> bool {
|
||||||
data.controller.queued_inputs.contains_key(&input)
|
data.controller.queued_inputs.contains_key(&input)
|
||||||
|| data.controller.held_inputs.contains_key(&input)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checked `Duration` addition. Computes `timer` + `dt`, applying relevant stat
|
/// Checked `Duration` addition. Computes `timer` + `dt`, applying relevant stat
|
||||||
@ -1439,12 +1427,7 @@ impl AbilityInfo {
|
|||||||
tool,
|
tool,
|
||||||
hand,
|
hand,
|
||||||
input,
|
input,
|
||||||
input_attr: data
|
input_attr: data.controller.queued_inputs.get(&input).copied(),
|
||||||
.controller
|
|
||||||
.queued_inputs
|
|
||||||
.get(&input)
|
|
||||||
.map(|x| x.1)
|
|
||||||
.or_else(|| data.controller.held_inputs.get(&input).copied()),
|
|
||||||
ability_meta,
|
ability_meta,
|
||||||
ability,
|
ability,
|
||||||
}
|
}
|
||||||
|
@ -271,18 +271,11 @@ impl Sys {
|
|||||||
*join.ori = state_update.ori;
|
*join.ori = state_update.ori;
|
||||||
|
|
||||||
for (input, attr) in state_update.queued_inputs {
|
for (input, attr) in state_update.queued_inputs {
|
||||||
join.controller
|
join.controller.queued_inputs.insert(input, attr);
|
||||||
.queued_inputs
|
|
||||||
.insert(input, (Time(0.0), attr));
|
|
||||||
join.controller.held_inputs.insert(input, attr);
|
|
||||||
}
|
|
||||||
for input in state_update.used_inputs {
|
|
||||||
join.controller.queued_inputs.remove(&input);
|
|
||||||
}
|
}
|
||||||
for input in state_update.removed_inputs {
|
for input in state_update.removed_inputs {
|
||||||
join.controller.held_inputs.remove(&input);
|
join.controller.queued_inputs.remove(&input);
|
||||||
}
|
}
|
||||||
join.controller.cull_queued_inputs(Time(0.0));
|
|
||||||
if state_update.swap_equipped_weapons {
|
if state_update.swap_equipped_weapons {
|
||||||
output_events.emit_server(ServerEvent::InventoryManip(
|
output_events.emit_server(ServerEvent::InventoryManip(
|
||||||
join.entity,
|
join.entity,
|
||||||
|
Reference in New Issue
Block a user