Emergency 20 Dokumentation  4.2.0
DoorComponent.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Promotion Software GmbH
2 
3 
4 //[-------------------------------------------------------]
5 //[ Header guard ]
6 //[-------------------------------------------------------]
7 #pragma once
8 
9 
10 //[-------------------------------------------------------]
11 //[ Includes ]
12 //[-------------------------------------------------------]
13 #include "em5/audio/AudioProxy.h"
14 
16 #include <qsf/math/Transform.h>
20 #include <qsf/job/JobProxy.h>
25 
26 
27 //[-------------------------------------------------------]
28 //[ Namespace ]
29 //[-------------------------------------------------------]
30 namespace em5
31 {
32 
33 
34  //[-------------------------------------------------------]
35  //[ Classes ]
36  //[-------------------------------------------------------]
42  {
43 
44 
45  //[-------------------------------------------------------]
46  //[ Public definitions ]
47  //[-------------------------------------------------------]
48  public:
49  static const uint32 COMPONENT_ID;
50  static const uint32 DOOR_OFFSET;
51  static const uint32 DOOR_ROTATION;
52 
54  enum DoorState
55  {
59  DOOR_OPENING
60  };
61 
63  enum DoorType
64  {
65  DOORTYPE_UNDEFINED = 0,
72  DOORTYPE_EQUIPMENTRIGHT
73  };
74 
75 
76  //[-------------------------------------------------------]
77  //[ Public methods ]
78  //[-------------------------------------------------------]
79  public:
87  inline explicit DoorComponent(qsf::Prototype* prototype);
88 
93  inline virtual ~DoorComponent();
94 
102  inline DoorState getDoorState() const;
103 
108  float getDoorStateInPercent() const;
109 
114  float getDoorAnimationPosition() const;
115 
120  void openDoor();
121 
126  void closeDoor();
127 
132  void cutDoor();
133 
134  inline const qsf::AssetProxy& getOpeningAnimation() const;
135  inline void setOpeningAnimation(const qsf::AssetProxy& animation);
136 
137  inline const qsf::AssetProxy& getClosingAnimation() const;
138  inline void setClosingAnimation(const qsf::AssetProxy& animation);
139 
140  inline const qsf::AssetProxy& getCuttingAnimation() const;
141  inline void setCuttingAnimation(const qsf::AssetProxy& animation);
142 
143  // Define getters and setters for CAMP exported properties
144  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(RotationAxis, const glm::vec3&, mLocalRotationAxis)
145  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(RotationAngle, float, mMaximumRotationAngle)
146  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(DoorType, DoorType, mDoorType)
147  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(SlideOffset, const glm::vec3&, mSlideOffset)
148  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(OpeningAnimationLength, qsf::Time, mOpeningAnimationLength)
149  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(ClosingAnimationLength, qsf::Time, mClosingAnimationLength)
150 
151  inline const glm::vec3& getDoorOffset() const;
152  void setDoorOffset(const glm::vec3& value);
153 
154  inline const glm::quat& getDoorRotation() const;
155  void setDoorRotation(const glm::quat& value);
156 
157  //[-------------------------------------------------------]
158  //[ Derived data ]
159  //[-------------------------------------------------------]
164  void getDoorWorldSpaceTransform(qsf::Transform& result, const qsf::Transform* vehicleWorldTransform = nullptr) const;
165  void getLocalToWorldTransform(qsf::Transform& transform) const;
166 
167  glm::vec3 getDoorOffsetWorldSpacePosition() const;
168  glm::quat getDoorRotationWorldSpaceRotation() const;
169 
170  // Get a position in front of the door (at the outside) for the given distance
171  void getWorldPositionInFrontOfDoor(float distance, glm::vec3& position, glm::quat& rotation) const;
172 
173 
174  //[-------------------------------------------------------]
175  //[ Public virtual qsf::Component methods ]
176  //[-------------------------------------------------------]
177  public:
178  virtual void serialize(qsf::BinarySerializer& serializer) override;
179 
180 
181  //[-------------------------------------------------------]
182  //[ Protected virtual qsf::Component methods ]
183  //[-------------------------------------------------------]
184  protected:
185  virtual bool onStartup() override;
186  virtual void onShutdown() override;
187  virtual void onSetDebug(bool debug) override;
188 
189 
190  //[-------------------------------------------------------]
191  //[ Private methods ]
192  //[-------------------------------------------------------]
193  private:
194  void activateJob();
195  void updateJob(const qsf::JobArguments& jobArguments);
196  void applyTransformationByAnimation(qsf::Transform& transform) const;
197  bool hasAnimation() const;
198  void updateWithAnimation();
199  void updateWithoutAnimation(const qsf::JobArguments& jobArguments);
200  void updateAudio();
201  void startOpeningAnimation(float animationPosition = 0.0f);
202  void startClosingAnimation(float animationPosition = 1.0f);
203  void updateDoorDebugDraw(bool enabled);
204 
205 
206  //[-------------------------------------------------------]
207  //[ Private data ]
208  //[-------------------------------------------------------]
209  private:
210  // Connected to CAMP
211  glm::vec3 mLocalRotationAxis;
212  float mMaximumRotationAngle;
213  glm::vec3 mSlideOffset;
214  glm::vec3 mDoorOffset;
215  glm::quat mDoorRotation;
216  DoorType mDoorType;
217  qsf::Time mOpeningAnimationLength;
218  qsf::Time mClosingAnimationLength;
219  qsf::AssetProxy mOpeningAnimation;
220  qsf::AssetProxy mClosingAnimation;
221  qsf::AssetProxy mCuttingAnimation;
222 
223  // Internal
224  DoorState mState;
225  float mAnimationPosition;
226  qsf::Transform mOriginalLocalTransform;
227  qsf::DebugDrawProxy mDebugDrawProxy;
228  qsf::JobProxy mUpdateJobProxy;
229  qsf::WeakPtr<qsf::MeshAnimationChannel> mAnimationChannel;
230  AudioProxy mAudioProxy;
231  bool mIsPlayingAudioStarted;
232 
233 
234  //[-------------------------------------------------------]
235  //[ CAMP reflection system ]
236  //[-------------------------------------------------------]
237  QSF_CAMP_RTTI() // Only adds the virtual method "campClassId()", nothing more
238 
239 
240  };
241 
242 
243 //[-------------------------------------------------------]
244 //[ Namespace ]
245 //[-------------------------------------------------------]
246 } // em5
247 
248 
249 //[-------------------------------------------------------]
250 //[ Implementation ]
251 //[-------------------------------------------------------]
252 #include "em5/component/door/DoorComponent-inl.h"
253 
254 
255 //[-------------------------------------------------------]
256 //[ CAMP reflection system ]
257 //[-------------------------------------------------------]
Definition: ActionPriority.h:13
Abstract component class.
Definition: Component.h:105
Vehicle: Driver door.
Definition: DoorComponent.h:67
DoorState
Definition: DoorComponent.h:54
unsigned int uint32
Definition: PlatformTypes.h:181
Door is currently closing.
Definition: DoorComponent.h:57
#define EM5_API_EXPORT
Definition: Export.h:28
Building: Main entrance.
Definition: DoorComponent.h:66
void serialize(BinarySerializer &serializer, BitFlagSet< STORAGE, ENUM > &bitFlagSet)
Definition: BitFlagSet.h:359
Definition: PickupPersonByParamedicAction.h:21
Asset proxy class.
Definition: AssetProxy.h:57
#define QSF_CAMP_RTTI()
Only adds the virtual method "campClassId()", nothing more.
Definition: CampClass.h:75
Vehicle: Co-driver door.
Definition: DoorComponent.h:68
Extended audio proxy for easier multiplay usage.
Definition: AudioProxy.h:47
DoorType
Definition: DoorComponent.h:63
Door is open.
Definition: DoorComponent.h:58
#define QSF_CAMP_TYPE_NONCOPYABLE(type)
See "CAMP_TYPE_NONCOPYABLE" for details.
Definition: CampClass.h:112
Vehicle: Trunk door.
Definition: DoorComponent.h:70
Door is closed.
Definition: DoorComponent.h:56
static const uint32 DOOR_OFFSET
"DoorOffset" unique class property ID inside the class
Definition: DoorComponent.h:50
static const uint32 DOOR_ROTATION
"DoorRotation" unique class property ID inside the class
Definition: DoorComponent.h:51
Vehicle: Passenger door.
Definition: DoorComponent.h:69
static const uint32 COMPONENT_ID
"em5::DoorComponent" unique component ID
Definition: DoorComponent.h:49
#define QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(name, type, variable)
Definition: PropertyHelper.h:16
EMERGENCY 5 door component class.
Definition: DoorComponent.h:41
Prototype class.
Definition: Prototype.h:100
Vehicle: Left equipment door.
Definition: DoorComponent.h:71