mirror of
https://github.com/lobomfz/VIctory-xmem.git
synced 2026-12-06 05:48:38 +00:00
Merge pull request #592 from tommiehansen/fix/gameinput-synthetic-tests-357
test(hle): isolate GameInput fixtures from host input settings
This commit is contained in:
@ -441,10 +441,6 @@ trait Source: Send {
|
||||
}
|
||||
}
|
||||
|
||||
fn fallback(keys: &[KeyState]) -> PadState {
|
||||
fallback_for(keys, pc_kbm())
|
||||
}
|
||||
|
||||
fn fallback_for(keys: &[KeyState], pc_style: bool) -> PadState {
|
||||
let on = |vk: u8| {
|
||||
if keys.iter().any(|k| k.virtual_key == vk) {
|
||||
@ -759,6 +755,8 @@ impl Steer {
|
||||
}
|
||||
|
||||
struct State {
|
||||
/// Whether to read host input and host input settings rather than injected pad samples.
|
||||
read_host_input: bool,
|
||||
slots: [Slot; DEVICES],
|
||||
callbacks: Vec<Registration>,
|
||||
/// Asynchronous enumerations, delivered by the next poll.
|
||||
@ -812,7 +810,7 @@ fn now() -> u64 {
|
||||
}
|
||||
|
||||
impl Hub {
|
||||
fn new(source: Box<dyn Source>, one_pad: bool) -> &'static Hub {
|
||||
fn new(source: Box<dyn Source>, one_pad: bool, read_host_input: bool) -> &'static Hub {
|
||||
let hub = Box::into_raw(Box::new(Hub {
|
||||
object: Object {
|
||||
vtable: &INPUT,
|
||||
@ -822,6 +820,7 @@ impl Hub {
|
||||
source: Mutex::new(source),
|
||||
one_pad,
|
||||
state: Mutex::new(State {
|
||||
read_host_input,
|
||||
slots: Default::default(),
|
||||
callbacks: Vec::new(),
|
||||
pending: Vec::new(),
|
||||
@ -850,7 +849,7 @@ impl Hub {
|
||||
|
||||
/// A hub over the host's input, polled from now on.
|
||||
fn start(source: Box<dyn Source>) -> &'static Hub {
|
||||
let hub = Hub::new(source, one_pad());
|
||||
let hub = Hub::new(source, one_pad(), true);
|
||||
hub.poll();
|
||||
std::thread::spawn(move || {
|
||||
loop {
|
||||
@ -930,7 +929,7 @@ impl State {
|
||||
#[allow(unused_mut)]
|
||||
let mut keys = keys;
|
||||
#[cfg(windows)]
|
||||
let stand_in = if mouse::native_input() {
|
||||
let stand_in = if self.read_host_input && mouse::native_input() {
|
||||
const WHEEL_HOLD_US: u64 = 55_000;
|
||||
let nm = mouse::read_native();
|
||||
let in_menu = victory_loader::keyboard_events::IN_MENU.load(Ordering::Relaxed);
|
||||
@ -1030,16 +1029,21 @@ impl State {
|
||||
}
|
||||
}
|
||||
with_held_axes(pad, victory_loader::keyboard_events::held_axes())
|
||||
} else if mouse::enabled() {
|
||||
} else if self.read_host_input && mouse::enabled() {
|
||||
self.steer.smooth(mouse::read(&keys), now, key_steer_ms())
|
||||
} else {
|
||||
self.steer
|
||||
.smooth(merged(fallback(&keys), mouse), now, key_steer_ms())
|
||||
self.steer.smooth(
|
||||
merged(fallback_for(&keys, self.read_host_input && pc_kbm()), mouse),
|
||||
now,
|
||||
key_steer_ms(),
|
||||
)
|
||||
};
|
||||
#[cfg(not(windows))]
|
||||
let stand_in = self
|
||||
.steer
|
||||
.smooth(merged(fallback(&keys), mouse), now, key_steer_ms());
|
||||
let stand_in = self.steer.smooth(
|
||||
merged(fallback_for(&keys, self.read_host_input && pc_kbm()), mouse),
|
||||
now,
|
||||
key_steer_ms(),
|
||||
);
|
||||
if one_pad {
|
||||
let pad = pads.into_iter().flatten().fold(stand_in, merged);
|
||||
self.update(devices, FALLBACK, Some(Value::Pad(pad)), now, &mut events);
|
||||
@ -2281,7 +2285,7 @@ mod tests {
|
||||
|
||||
fn fake_with(one_pad: bool) -> (&'static Hub, Arc<Mutex<FakeHost>>) {
|
||||
let host = Arc::new(Mutex::new(FakeHost::default()));
|
||||
let hub = Hub::new(Box::new(Fake(Arc::clone(&host))), one_pad);
|
||||
let hub = Hub::new(Box::new(Fake(Arc::clone(&host))), one_pad, false);
|
||||
hub.poll();
|
||||
(hub, host)
|
||||
}
|
||||
@ -2465,6 +2469,25 @@ mod tests {
|
||||
release(rest);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fake_source_does_not_read_the_host_input_mode() {
|
||||
let (hub, host) = fake_with(true);
|
||||
assert!(!hub.state().read_host_input);
|
||||
{
|
||||
let mut host = host.lock().unwrap();
|
||||
host.keys = vec![key(b'W')];
|
||||
host.mouse = PadState {
|
||||
right_x: 0.5,
|
||||
..Default::default()
|
||||
};
|
||||
}
|
||||
hub.poll();
|
||||
let reading = current(hub, GAMEPAD_KIND, FALLBACK).unwrap();
|
||||
let got = pad(reading);
|
||||
assert_eq!((got.left_y, got.right_x), (1.0, 0.5));
|
||||
release(reading);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keys_feed_the_keyboard_and_the_stand_in_pad() {
|
||||
let (hub, host) = fake();
|
||||
|
||||
Reference in New Issue
Block a user