Emergency 20 Dokumentation  4.2.0
MovableData.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 //[-------------------------------------------------------]
14 
15 #include <qsf/base/WeakPtr.h>
16 
17 #include <glm/gtc/quaternion.hpp>
18 
19 
20 //[-------------------------------------------------------]
21 //[ Forward declarations ]
22 //[-------------------------------------------------------]
23 namespace qsf
24 {
25  class Entity;
26  class MovableComponent;
27  namespace game
28  {
29  class BitStream;
30  }
31 }
32 
33 
34 //[-------------------------------------------------------]
35 //[ Namespace ]
36 //[-------------------------------------------------------]
37 namespace em5
38 {
39  namespace multiplayer
40  {
41 
42 
43  //[-------------------------------------------------------]
44  //[ Classes ]
45  //[-------------------------------------------------------]
50  class MovableData: public DataCacheBase
51  {
52 
53 
54  //[-------------------------------------------------------]
55  //[ Public methods ]
56  //[-------------------------------------------------------]
57  public:
58  MovableData(const qsf::Entity& targetEntity);
59  virtual ~MovableData();
60 
61 
62  //[-------------------------------------------------------]
63  //[ Public virtual em5::multiplayer::DataCacheBase methods ]
64  //[-------------------------------------------------------]
65  public:
66  virtual bool includeForPrepare(const int32 currentTickCount, bool entityIsVisible);
67  virtual bool prepareForUpdate(const qsf::Entity& targetEntity, const qsf::Clock& clock) override;
68  virtual void updateData(qsf::game::BitStream& bitStream, bool force) override;
69  virtual void setData(const qsf::game::BitStream& bitStream, const int32 receivedHostTickCount) override;
70  virtual void interpolate(qsf::Entity& targetEntity, const qsf::Clock& clock, const int32 receivedHostTickCount) override;
71 
72 
73  //[-------------------------------------------------------]
74  //[ Private methods ]
75  //[-------------------------------------------------------]
76  private:
77  // Checks if the entity is linked to a another entity as child
78  bool isEntityLinked(const qsf::Entity& entity) const;
79  bool preparePositionForUpdate(const qsf::MovableComponent& movableComponent, bool includeHeight = false, bool force = false);
80  void writePositionToStream(qsf::game::BitStream& bitStream);
81  bool readPositionFromStream(const qsf::game::BitStream& bitStream, glm::vec3& position);
82 
83  bool prepareRotationForUpdate(const qsf::MovableComponent& movableComponent, bool force = false);
84  void writeRotationToStream(qsf::game::BitStream& bitStream);
85  bool readRotationFromStream(const qsf::game::BitStream& bitStream, float& rotation);
86 
87  bool prepareVelocityForUpdate(const qsf::MovableComponent& movableComponent);
88  void writeVelocityToStream(qsf::game::BitStream& bitStream);
89  bool readVelocityFromStream(const qsf::game::BitStream& bitStream, glm::vec3& velocity);
90 
91  glm::vec3 calculateNewPosition(const glm::vec3& position, const glm::vec3& velocity, float timePassedInSeconds);
92 
93 
94  //[-------------------------------------------------------]
95  //[ Private data ]
96  //[-------------------------------------------------------]
97  private:
99  bool mInitialTransfer;
100  bool mForceTransfer;
101  bool mUnuseable;
102  bool mEntityVisible;
103  bool mIsUnit;
104 
105  bool mVelocityChanged;
106  glm::vec3 mLastVelocity;
107  uint32 mChangedVelocity[2];
108  bool mChangedVelocityChanged[2];
109  bool mPositionChanged;
110  glm::vec3 mLastPosition;
111  uint32 mChangedPosition[3];
112  bool mChangedPositionChanged[3];
113  bool mRotationChanged;
114  glm::quat mLastRotation;
115  int8 mChangedRotation;
116  uint64 mContainerEntityId;
117  bool mContainerEntityChanged;
118  uint8 mContainerCategory;
119  bool mIsMoving;
120 
121  // Only for client side
122  glm::vec3 mCurrentVelocity;
123 
124  // For client side only
125  struct HistoryEntry
126  {
127  int32 tickCount;
128  bool velocityChanged;
129  glm::vec3 velocity;
130  bool positionChanged;
131  glm::vec3 position;
132  bool rotationChanged;
133  float rotationAroundYAxis;
134  uint64 containerEntityId;
135  bool containerEntityChanged;
136  uint8 mContainerCategory;
137  bool mIsMoving;
138  };
139 
140  std::vector<HistoryEntry> mHistoryList;
141 
142 
143  };
144 
145 
146 //[-------------------------------------------------------]
147 //[ Namespace ]
148 //[-------------------------------------------------------]
149  } // multiplayer
150 } // em5
Definition: ActionPriority.h:13
signed char int8
Definition: PlatformTypes.h:174
EMERGENCY 5 multiplayer data cache base class.
Definition: DataCacheBase.h:48
Movable component base class.
Definition: MovableComponent.h:62
Entity class.
Definition: Entity.h:46
unsigned int uint32
Definition: PlatformTypes.h:181
Clock class.
Definition: Clock.h:33
virtual bool prepareForUpdate(const qsf::Entity &targetEntity, const qsf::Clock &clock) override
Prepares for an update.
virtual void updateData(qsf::game::BitStream &bitStream, bool force) override
Updates the cache and writes any changed data to the given bit stream.
uint64_t uint64
Definition: PlatformTypes.h:184
Game bit stream class (just a wrapper for linnet bit stream)
Definition: BitStream.h:40
Definition: PickupPersonByParamedicAction.h:21
MovableData(const qsf::Entity &targetEntity)
EMERGENCY 5 entity with a movable componet data cache for a single entity for multiplayer.
Definition: MovableData.h:50
signed int int32
Definition: PlatformTypes.h:180
virtual void setData(const qsf::game::BitStream &bitStream, const int32 receivedHostTickCount) override
Reads the data from the bit stream.
virtual void interpolate(qsf::Entity &targetEntity, const qsf::Clock &clock, const int32 receivedHostTickCount) override
Does any interpolation steps needed to apply the cached data to the entity.
virtual bool includeForPrepare(const int32 currentTickCount, bool entityIsVisible)
Returns if the data cache item should be generally included into the current update cycle...
unsigned char uint8
Definition: PlatformTypes.h:175