+
+ pub mov: Stick,
+ pub aim: Stick,
+ pub jump: Button,
+ pub start: Button,
+ pub shoot: Button,
+}
+
+impl Controller {
+ pub fn new(device: GameController, haptic: Option<Rc<RefCell<Haptic>>>) -> Self {
+ let map = get_action_mapping();
+ let mut ctrl = Controller {
+ device,
+ haptic,
+ mov: Stick::new(*map.axes.get(&MovementX).unwrap(), *map.axes.get(&MovementY).unwrap()),
+ aim: Stick::new(*map.axes.get(&AimX).unwrap(), *map.axes.get(&AimY).unwrap()),
+ jump: Button::new(*map.buttons.get(&Jump).unwrap()),
+ start: Button::new(*map.buttons.get(&Start).unwrap()),
+ shoot: Button::new(*map.buttons.get(&Shoot).unwrap()),
+ };
+ ctrl.set_mapping(&map);
+ ctrl
+ }
+
+ fn set_mapping(&mut self, map: &ActionMapping) {
+ self.mov.id.0 = *map.axes.get(&MovementX).unwrap();
+ self.mov.id.1 = *map.axes.get(&MovementY).unwrap();
+ self.aim.id.0 = *map.axes.get(&AimX).unwrap();
+ self.aim.id.1 = *map.axes.get(&AimY).unwrap();
+ self.jump.id = *map.buttons.get(&Jump).unwrap();
+ self.shoot.id = *map.buttons.get(&Shoot).unwrap();
+ self.start.id = *map.buttons.get(&Start).unwrap();
+ }
+
+ pub fn update(&mut self, dt: Duration) {
+ self.mov.update(&self.device, dt);
+ self.aim.update(&self.device, dt);
+ self.jump.update(&self.device, dt);
+ self.shoot.update(&self.device, dt);
+ self.start.update(&self.device, dt);
+ }
+
+ /// strength [0 - 1]
+ pub fn rumble(&self, strength: f32, duration: Duration) {
+ if let Some(h) = &self.haptic {
+ h.borrow_mut().rumble_play(strength, duration.whole_milliseconds() as u32);
+ }
+ }
+}
+
+struct ActionMapping {
+ axes: HashMap<ActionControls, SDLAxis>,
+ buttons: HashMap<ActionControls, SDLButton>,
+}
+
+fn get_action_mapping() -> ActionMapping {
+ ActionMapping {
+ axes: hashmap!(
+ MovementX => SDLAxis::LeftX,
+ MovementY => SDLAxis::LeftY,
+ AimX => SDLAxis::RightX,
+ AimY => SDLAxis::RightY
+ ),
+ buttons: hashmap!(
+ Jump => SDLButton::A,
+ Shoot => SDLButton::RightShoulder,
+ Start => SDLButton::Start
+ )
+ }
+}
+
+//#[derive(Debug)]
+pub struct ControllerManager {
+ pub subsystem: GameControllerSubsystem,
+ haptic: Rc<HapticSubsystem>,
+ pub controllers: HashMap<u32, Rc<RefCell<Controller>>>,