mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Inputs now remain queued even when the input is released, until the input is used.
This commit is contained in:
parent
c8d0b337bb
commit
d0a46ed82b
@ -1723,6 +1723,7 @@ impl Client {
|
||||
entry
|
||||
.or_insert_with(|| Controller {
|
||||
inputs: inputs.clone(),
|
||||
held_inputs: BTreeMap::new(),
|
||||
queued_inputs: BTreeMap::new(),
|
||||
events: Vec::new(),
|
||||
actions: Vec::new(),
|
||||
|
@ -27,6 +27,7 @@ pub struct StateUpdate {
|
||||
pub swap_equipped_weapons: bool,
|
||||
pub should_strafe: bool,
|
||||
pub queued_inputs: BTreeMap<InputKind, InputAttr>,
|
||||
pub used_inputs: Vec<InputKind>,
|
||||
pub removed_inputs: Vec<InputKind>,
|
||||
}
|
||||
|
||||
@ -57,6 +58,7 @@ impl From<&JoinData<'_>> for StateUpdate {
|
||||
should_strafe: data.inputs.strafing,
|
||||
character: data.character.clone(),
|
||||
queued_inputs: BTreeMap::new(),
|
||||
used_inputs: Vec::new(),
|
||||
removed_inputs: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
@ -246,6 +246,7 @@ pub struct ControllerInputs {
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Controller {
|
||||
pub inputs: ControllerInputs,
|
||||
pub held_inputs: BTreeMap<InputKind, InputAttr>,
|
||||
pub queued_inputs: BTreeMap<InputKind, InputAttr>,
|
||||
// TODO: consider SmallVec
|
||||
pub events: Vec<ControlEvent>,
|
||||
@ -282,6 +283,7 @@ impl Controller {
|
||||
pub fn reset(&mut self) {
|
||||
self.inputs = Default::default();
|
||||
self.queued_inputs = Default::default();
|
||||
self.held_inputs = Default::default();
|
||||
}
|
||||
|
||||
pub fn clear_events(&mut self) { self.events.clear(); }
|
||||
|
@ -1017,8 +1017,7 @@ pub fn attempt_glide_wield(
|
||||
pub fn handle_jump(
|
||||
data: &JoinData<'_>,
|
||||
output_events: &mut OutputEvents,
|
||||
// TODO: remove?
|
||||
_update: &mut StateUpdate,
|
||||
update: &mut StateUpdate,
|
||||
strength: f32,
|
||||
) -> bool {
|
||||
(input_is_pressed(data, InputKind::Jump) && data.physics.on_ground.is_some())
|
||||
@ -1029,6 +1028,7 @@ pub fn handle_jump(
|
||||
data.entity,
|
||||
strength * impulse / data.mass.0 * data.stats.move_speed_modifier,
|
||||
));
|
||||
update.used_inputs.push(InputKind::Jump);
|
||||
})
|
||||
.is_some()
|
||||
}
|
||||
@ -1054,6 +1054,7 @@ fn handle_ability(data: &JoinData<'_>, update: &mut StateUpdate, input: InputKin
|
||||
AbilityInfo::from_input(data, from_offhand, input, ability.ability_meta()),
|
||||
data,
|
||||
));
|
||||
update.used_inputs.push(input);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1109,6 +1110,7 @@ pub fn handle_block_input(data: &JoinData<'_>, update: &mut StateUpdate) -> bool
|
||||
AbilityInfo::from_input(data, false, InputKind::Block, Default::default()),
|
||||
data,
|
||||
));
|
||||
update.used_inputs.push(InputKind::Block);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@ -1129,6 +1131,7 @@ pub fn handle_dodge_input(data: &JoinData<'_>, update: &mut StateUpdate) -> bool
|
||||
AbilityInfo::from_input(data, false, InputKind::Roll, Default::default()),
|
||||
data,
|
||||
));
|
||||
update.used_inputs.push(InputKind::Roll);
|
||||
if let CharacterState::Roll(roll) = &mut update.character {
|
||||
if let CharacterState::ComboMelee(c) = data.character {
|
||||
roll.was_combo = c
|
||||
@ -1276,11 +1279,7 @@ pub fn get_buff_strength(data: &JoinData<'_>, ai: AbilityInfo) -> f32 {
|
||||
}
|
||||
|
||||
pub fn input_is_pressed(data: &JoinData<'_>, input: InputKind) -> bool {
|
||||
data.controller.queued_inputs.contains_key(&input)
|
||||
}
|
||||
|
||||
pub fn input_just_pressed(update: &StateUpdate, input: InputKind) -> bool {
|
||||
update.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
|
||||
|
@ -244,7 +244,7 @@ impl<'a> System<'a> for Sys {
|
||||
impl Sys {
|
||||
fn publish_state_update(
|
||||
join: &mut JoinStruct,
|
||||
mut state_update: StateUpdate,
|
||||
state_update: StateUpdate,
|
||||
output_events: &mut OutputEvents,
|
||||
) {
|
||||
// Here we check for equality with the previous value of these components before
|
||||
@ -269,12 +269,16 @@ impl Sys {
|
||||
*join.vel = state_update.vel;
|
||||
*join.ori = state_update.ori;
|
||||
|
||||
join.controller
|
||||
.queued_inputs
|
||||
.append(&mut state_update.queued_inputs);
|
||||
for input in state_update.removed_inputs {
|
||||
for (input, attr) in state_update.queued_inputs {
|
||||
join.controller.queued_inputs.insert(input, 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 {
|
||||
join.controller.held_inputs.remove(&input);
|
||||
}
|
||||
if state_update.swap_equipped_weapons {
|
||||
output_events.emit_server(ServerEvent::InventoryManip(
|
||||
join.entity,
|
||||
|
Loading…
Reference in New Issue
Block a user