VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
VirtualController.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef VIRTUALCONTROLLER_H
18 #define VIRTUALCONTROLLER_H
19 
20 #include <map>
21 #include <vector>
22 #include "ControllerEvent.h"
23 #include "InputScheme.h"
24 #include "JoystickAxisScheme.h"
25 #include "KeyScheme.h"
26 #include "TriggerAxisScheme.h"
27 
37 public:
45  NO_SUPPORT = 0x00,
46 
50  BINARY_ACTION = 0x01,
51 
56 
61  };
62 
67  VirtualController(int deviceId);
68 
69  virtual ~VirtualController();
70 
75  void setJoystickAxisScheme(const JoystickAxisScheme& joystickAxisScheme);
80  void setKeyScheme(const KeyScheme& keyScheme);
85  void setTriggerAxisScheme(const TriggerAxisScheme& triggerAxisScheme);
86 
90  int getDeviceId() const { return mDeviceId; }
96  bool isSourceOfEvent(ControllerEvent* event) const;
97 
103  virtual bool onControllerEvent(ControllerEvent* event);
104 
109  virtual int getActionSupport(const InputScheme<>::Action& action) const;
110 
115  virtual bool isActionActivated(const InputScheme<>::Action& action) const;
120  virtual float getActionUnitIntervalValue(const InputScheme<>::Action& action) const;
125  virtual float getActionSymmetricUnitIntervalValue(const InputScheme<>::Action& action) const;
126 
127 private:
128  int mDeviceId = -1;
129 
130  JoystickAxisScheme mJoystickAxisScheme;
131  // Reverse maps Actions to joystick axes that trigger that action
132  std::map<InputScheme<>::Action, std::vector<JoystickAxisCode> > mActionJoystickAxes;
133 
134  KeyScheme mKeyScheme;
135  // Reverse maps Actions to keys that trigger that action
136  std::map<InputScheme<>::Action, std::vector<KeyCode> > mActionKeys;
137 
138  TriggerAxisScheme mTriggerAxisScheme;
139  // Reverse maps Actions to trigger axes that trigger that action
140  std::map<InputScheme<>::Action, std::vector<TriggerAxisCode> > mActionTriggerAxes;
141 
142  // Since VirtualController can represent the state of a any controller whose input capabilities
143  // can be specified in a ControllerEvent, it makes most sense to store state as a
144  // ControllerEvent
145  ControllerEvent mState;
146 };
147 
148 #endif // VIRTUALCONTROLLER_H
Action has a normalized [0.0f, 1.0f] real value.
Definition: VirtualController.h:55
Represents a scheme mapping input trigger axes to output actions.
Definition: TriggerAxisScheme.h:28
Software represention and state capable of describing almost all physical controllers.
Definition: VirtualController.h:36
Action is binary (i.e. can be "on/off").
Definition: VirtualController.h:50
void setTriggerAxisScheme(const TriggerAxisScheme &triggerAxisScheme)
Sets the VirtualController's TriggerAxisScheme.
virtual float getActionUnitIntervalValue(const InputScheme<>::Action &action) const
Returns the [0.0f, 1.0f] unit interval value for action.
int getDeviceId() const
Returns the VirtualController's device identifier.
Definition: VirtualController.h:90
A platform independent event generated by controller device.
Definition: ControllerEvent.h:34
Represents a scheme mapping input joystick axes to output actions.
Definition: JoystickAxisScheme.h:28
virtual bool onControllerEvent(ControllerEvent *event)
Notifies the VirtualController of the event.
virtual int getActionSupport(const InputScheme<>::Action &action) const
Returns the VirtualController's type of support for action (as a set of flags).
void setJoystickAxisScheme(const JoystickAxisScheme &joystickAxisScheme)
Sets the VirtualController's JoystickAxisScheme.
virtual bool isActionActivated(const InputScheme<>::Action &action) const
Returns whether or not action is "activated" (i.e. the binary value of the action).
Action has a bipolar [-1.0f, 1.0f] real value.
Definition: VirtualController.h:60
SupportedAsFlag
Flags to specify how an action is supported (i.e. what data can be retrieved for it).
Definition: VirtualController.h:41
bool isSourceOfEvent(ControllerEvent *event) const
Returns whether or not this VirtualController, and the device it abstracts, is the source of event...
Represents a scheme mapping keyboard input to output actions.
Definition: KeyScheme.h:28
VirtualController(int deviceId)
Constructs a VirtualController with the specified deviceId.
void setKeyScheme(const KeyScheme &keyScheme)
Sets the VirtualController's KeyScheme.
int Action
Output type.
Definition: InputScheme.h:33
virtual float getActionSymmetricUnitIntervalValue(const InputScheme<>::Action &action) const
Returns the [-1.0f, 1.0f] symmetric unit interval value for action.
Action is unsupported.
Definition: VirtualController.h:45