VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gameControlInformation.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2015 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
8 
10 
11 #pragma once
12 
15 
16 #include <vrvUtil/DtUnicode.h>
17 
18 #include <boost/serialization/access.hpp>
19 #include <boost/serialization/nvp.hpp>
20 #include <boost/serialization/list.hpp>
21 #include <boost/serialization/map.hpp>
22 #include <boost/serialization/vector.hpp>
23 #include <boost/serialization/string.hpp>
24 #include <boost/archive/xml_oarchive.hpp>
25 #include <boost/archive/xml_iarchive.hpp>
26 
27 namespace makVrv
28 {
33  {
34  public:
36  {
37  TransitionUp = 0x00000001,
38  TransitionDown = 0x00000002,
39  Repeat = 0x00000004,
40  ResetToZeroOnRelease = 0x00000008,
41  Reverse = 0x00000010,
42  Toggle = 0x00000020,
43  SetTo = 0x00000040,
44  };
45 
47  {
48  GameControlEvent() : controlEvent(0), flags(0), transitionValue(0), deviceIndex(-1) {};
49  virtual ~GameControlEvent() { delete controlEvent; };
50  GameControlEvent(const GameControlEvent& orig) : flags(orig.flags), transitionValue(orig.transitionValue), controlEvent(0),
51  controllerName(orig.controllerName), controllerGuid(orig.controllerGuid), deviceIndex(orig.deviceIndex)
52  {
53  if (orig.controlEvent)
54  {
55  controlEvent = orig.controlEvent->clone();
56  }
57  }
58 
60  {
61  if (this != &rhs)
62  {
63  flags = rhs.flags;
64  transitionValue = rhs.transitionValue;
65  controllerName = rhs.controllerName;
66  controllerGuid = rhs.controllerGuid;
67 
68  delete controlEvent;
69  controlEvent = 0;
70 
71  if (rhs.controlEvent)
72  {
73  controlEvent = rhs.controlEvent->clone();
74  }
75  }
76 
77  return *this;
78  }
79 
80  bool needsTransition() const { return transitionUp() || transitionDown(); };
81  bool transitionUp() const { return ((flags & TransitionUp) != 0); };
82  bool transitionDown() const { return ((flags & TransitionDown) != 0); };
83  bool repeat() const { return ((flags & Repeat) != 0); };
84  bool resetToZeroOnRelease() const { return ((flags & ResetToZeroOnRelease) != 0); };
85  bool reverse() const { return ((flags & Reverse) != 0); };
86  bool toggle() const { return ((flags & Toggle) != 0); };
87  bool setTo() const { return ((flags & SetTo) != 0); };
89  {
90  delete controlEvent;
91  controlEvent = 0;
92 
93  if (e)
94  {
95  controlEvent = e->clone();
96  }
97  }
98 
100  {
101  return (controlEvent && rhs && (*controlEvent == *rhs));
102  }
103 
106  {
107  return (controlEvent && controlEvent->isReleaseEvent(e));
108  }
109 
110  bool isIdle(double value) const
111  {
112  int eventType = GameControllerEventUnknown;
113  if (controlEvent)
114  {
115  eventType = controlEvent->myType;
116  }
117 
118  if (value == 0.)
119  {
120  if (eventType == GameControlEventKeyboard)
121  {
122  return resetToZeroOnRelease();
123  }
124 
125  return true;
126  }
127 
128  return false;
129  }
130 
132  std::string controllerName;
133  std::string controllerGuid;
134  int flags;
137 
138  protected:
139  friend class boost::serialization::access;
140 
144  template<class Archive>
145  void serialize(Archive & ar, const unsigned int version)
146  {
147  int eventType = GameControllerEventUnknown;
148 
149  ar & BOOST_SERIALIZATION_NVP(controllerName);
150  ar & BOOST_SERIALIZATION_NVP(controllerGuid);
151  ar & BOOST_SERIALIZATION_NVP(deviceIndex);
152  ar & BOOST_SERIALIZATION_NVP(flags);
153  ar & BOOST_SERIALIZATION_NVP(transitionValue);
154 
155  if (Archive::is_loading::value)
156  {
157  ar & BOOST_SERIALIZATION_NVP(eventType);
158 
159  if (eventType != GameControllerEventUnknown)
160  {
161  if (eventType == GameControlEventJoystick)
162  {
163  controlEvent = new DtGameControllerJoystickEvent;
164  }
165  else if (eventType == GameControlEventKeyboard)
166  {
167  controlEvent = new DtGameControllerKeyboardEvent;
168  }
169 
170  if (controlEvent)
171  {
172  controlEvent->read(*(boost::archive::xml_iarchive*)&ar,version);
173  }
174  }
175  }
176  else
177  {
178  if (controlEvent)
179  {
180  eventType = controlEvent->myType;
181  }
182 
183  ar & BOOST_SERIALIZATION_NVP(eventType);
184 
185  if (controlEvent)
186  {
187  controlEvent->write(*(boost::archive::xml_oarchive*)&ar,version);
188  }
189  }
190  }
191  };
192  typedef std::vector<GameControlEvent> GameControlEvents;
193 
196 
198  virtual ~DtGameControlInformation();
199 
200  void addControllerEvent(const DtGenericControllerEvent&, int flags, double transitionValue,
201  const std::string& controllerName, const std::string& controllerGuid);
202 
204  void addControllerEvent(int flags, double transitionValue,
205  const std::string& controllerName, const std::string& controllerGuid);
206  void addControllerEvent(const GameControlEvent&);
207  void addControllerEvents(const GameControlEvents&);
208  void removeControllerEvent(const DtGenericControllerEvent&);
209 
211  bool eventMatches(DtGenericControllerEvent* rhs) const;
212 
214  bool isMatchingUpEvent(DtGenericControllerEvent* e) const;
215 
217  {
218  return myControllerEvents;
219  }
220 
221  bool isSpecified() const
222  {
223  return (myControllerEvents.size() != 0);
224  }
225 
226  void clear();
227  DtUnicode controllerName() const;
228  DtUnicode descriptiveString() const;
229 
231 
232  protected:
233  friend class boost::serialization::access;
234 
238  template<class Archive>
239  void serialize(Archive & ar, const unsigned int version)
240  {
241  ar & BOOST_SERIALIZATION_NVP(myControllerEvents);
242  }
243 
244  protected:
246  };
247 }
int deviceIndex
Definition: gameControlInformation.h:136
bool transitionDown() const
Definition: gameControlInformation.h:82
bool setTo() const
Definition: gameControlInformation.h:87
A unicode string. DtUnicode stores a UTF-16 encoded unicode string. Code Point, a Unicode character...
Definition: DtUnicode.h:33
bool toggle() const
Definition: gameControlInformation.h:86
bool isSpecified() const
Definition: gameControlInformation.h:221
virtual void read(boost::archive::xml_iarchive &ar, int version)
int flags
Definition: gameControlInformation.h:134
const GameControlEvents & controllerEvents() const
Definition: gameControlInformation.h:216
Definition: gameControllerEvents.h:30
virtual DtGenericControllerEvent * clone() const =0
Definition: gameControllerEvents.h:33
#define DT_DLL_JOYSTICKCORE
Contains DLL export macros.
Definition: joystickCore.h:25
bool isMatchingUpEvent(DtGenericControllerEvent *e) const
Return true if this is a possible key up or other button/HAT event for the given event.
Definition: gameControlInformation.h:105
bool repeat() const
Definition: gameControlInformation.h:83
DtGameControllerKeyboardEvent class wraps a keyboard event.
Definition: gameControllerEvents.h:60
bool transitionUp() const
Definition: gameControlInformation.h:81
Definition: gameControlInformation.h:46
bool isIdle(double value) const
Definition: gameControlInformation.h:110
GameControlEvent & operator=(const GameControlEvent &rhs)
Definition: gameControlInformation.h:59
bool reverse() const
Definition: gameControlInformation.h:85
std::string controllerName
Definition: gameControlInformation.h:132
DtGameControllerJoystickEvent wraps a joystick event.
Definition: gameControllerEvents.h:91
GameControlEvents myControllerEvents
Definition: gameControlInformation.h:245
void serialize(Archive &ar, const unsigned int version)
When the class Archive corresponds to an output archive, the &amp; operator is defined similar to &lt;&lt;...
Definition: gameControlInformation.h:239
Definition: gameControllerEvents.h:28
double transitionValue
Definition: gameControlInformation.h:135
The DtGameControlInformation class contains information about how a function within a function group ...
Definition: gameControlInformation.h:32
void setControlEvent(DtGenericControllerEvent *e)
Definition: gameControlInformation.h:88
void serialize(Archive &ar, const unsigned int version)
When the class Archive corresponds to an output archive, the &amp; operator is defined similar to &lt;&lt;...
Definition: gameControlInformation.h:145
bool resetToZeroOnRelease() const
Definition: gameControlInformation.h:84
std::string controllerGuid
Definition: gameControlInformation.h:133
bool eventMatches(DtGenericControllerEvent *rhs) const
Definition: gameControlInformation.h:99
GameControlEvent()
Definition: gameControlInformation.h:48
GameControlEvent(const GameControlEvent &orig)
Definition: gameControlInformation.h:50
std::vector< GameControlEvent > GameControlEvents
Definition: gameControlInformation.h:192
bool needsTransition() const
Definition: gameControlInformation.h:80
Definition: gameControllerEvents.h:29
virtual ~GameControlEvent()
Definition: gameControlInformation.h:49
DtGenericControllerEvent * controlEvent
Definition: gameControlInformation.h:131
GameControllerFlags
Definition: gameControlInformation.h:35

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)