Emergency 20 Dokumentation  4.2.0
Client.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 //[-------------------------------------------------------]
17 
18 #include <qsf/job/JobProxy.h>
20 
21 #include <memory> // for std::unique_ptr
22 
23 
24 //[-------------------------------------------------------]
25 //[ Forward declarations ]
26 //[-------------------------------------------------------]
27 namespace em5
28 {
29  class CommandContext;
30  class MapIdentifier;
31  namespace multiplayer
32  {
33  namespace client
34  {
35  class HostBase;
36  }
37  }
38 }
39 namespace qsf
40 {
41  class Map;
42  namespace game
43  {
44  class BitStream;
45  class Command;
46  class CommandContext;
47  }
48 }
49 
50 
51 //[-------------------------------------------------------]
52 //[ Namespace ]
53 //[-------------------------------------------------------]
54 namespace em5
55 {
56  namespace multiplayer
57  {
58  namespace client
59  {
60 
61 
62  //[-------------------------------------------------------]
63  //[ Classes ]
64  //[-------------------------------------------------------]
70  {
71 
72 
73  //[-------------------------------------------------------]
74  //[ Public boost signals ]
75  //[-------------------------------------------------------]
76  public:
85  boost::signals2::signal<void()> disconnected;
86 
87 
88  //[-------------------------------------------------------]
89  //[ Public methods ]
90  //[-------------------------------------------------------]
91  public:
96  Client();
97 
102  virtual ~Client();
103 
104  bool joinSession(const multiplayer::HostEntry& hostEntry, const std::string& playerName, const std::string& sessionPassword);
105 
113  void joinLocalSession(const std::string& dataPath, const MapIdentifier& mapIdentifier, const std::string& playerName, const std::string& sessionPassword);
114 
119  void closeSession();
120 
121  bool getReadyState() const;
122  void setReadyState(bool isReady);
123  void changeUserData(uint32 newUserData);
124 
125  JoinResponse getJoinResponse() const;
126 
131  void sendOperationMessageToHost(const OperationMessage operationMessageId, const qsf::game::BitStream& operationMessageData);
132 
133  void onCommandExecuted(const qsf::game::Command& command, const std::vector<qsf::Entity*>& callers, qsf::game::CommandContext& context);
134 
135  void onSendHighscoreSubmitInitiated();
136 
137  void onSendHighscoreSubmitDeclined();
138 
139  void onSendHighscoreSubmitAccept();
140 
141 
142  //[-------------------------------------------------------]
143  //[ Public virtual em5::multiplayer::SessionBase methods ]
144  //[-------------------------------------------------------]
145  public:
150  virtual bool startup(qsf::Map& map) override;
151 
156  virtual void loadingFinished() override;
157 
158 
159  //[-------------------------------------------------------]
160  //[ Protected virtual em5::multiplayer::SessionBase methods ]
161  //[-------------------------------------------------------]
162  protected:
163  virtual void onSendChatMessage(const ChatMessage& chatMessage) override;
164 
165 
166  //[-------------------------------------------------------]
167  //[ Private methods ]
168  //[-------------------------------------------------------]
169  private:
170  bool connectToHost();
171  void shutdownConnection();
172 
173  void onConnectedToHost();
174  void onDisconnectedFromHost();
175  void onUnexpectedDisconnectFromHost();
176  void onReceivedOperationMessage(const OperationMessage operationMessageId, uint64 dataSize, const qsf::game::BitStream& bitStream);
177  void onInterpolation(const qsf::JobArguments& jobArguments);
178 
179  // Message handlers
180  void onPreOrderUnitCommandExecute(const qsf::MessageParameters& parameters);
181 
182  void handleCreateEntityFromPrefabData(uint64 dataSize, const qsf::game::BitStream& bitStream);
183  void handleDestroyEntityData(uint64 dataSize, const qsf::game::BitStream& bitStream);
184  void handleUnitSpawnedData(uint64 dataSize, const qsf::game::BitStream& bitStream);
185  void handleUnitSpawnedPlayerUpdateSelectionData(uint64 dataSize, const qsf::game::BitStream& bitStream);
186  void handleFreeplayEventUpdatedData(uint64 dataSize, const qsf::game::BitStream& bitStream);
187  void handlePlayerScoreChangedData(uint64 dataSize, const qsf::game::BitStream& bitStream);
188  void handleGameModeUpdateData(uint64 dataSize, const qsf::game::BitStream& bitStream);
189  void handleMinimapRelatedMessageData(uint64 dataSize, const qsf::game::BitStream& bitStream);
190  void handleMinimapIconMessageData(uint64 dataSize, const qsf::game::BitStream& bitStream);
191  void handleCommandResponseData(uint64 dataSize, const qsf::game::BitStream& bitStream);
192  void handleLayerChangedData(uint64 dataSize, const qsf::game::BitStream& bitStream);
193  void handleHighscoreSubmitInitiated();
194  void handleHighscoreSubmitDeclined();
195  void handleHighscoreSubmitSucceeded(uint64 dataSize, const qsf::game::BitStream& bitStream);
196  void handleServerPing(uint64 dataSize, const qsf::game::BitStream& bitStream);
197  void handleFireHoseUpdateData(uint64 dataSize, const qsf::game::BitStream& bitStream);
198  void handleSpawnParticleData(uint64 dataSize, const qsf::game::BitStream& bitStream);
199 
200  void disableJob(uint32 jobId);
201 
202  void applyLayerChanges(int32 currentTick);
203  void applyDestroyEntityChanges(int32 currentTick);
204 
205  // Proxy part
206  bool connectToProxy();
207  void onProxyClientConnected();
208  void onProxyClientDisconnected();
209  void onProxyClientConnectFailed();
210  void closeProxyConnection();
211 
212 
213  //[-------------------------------------------------------]
214  //[ Private data ]
215  //[-------------------------------------------------------]
216  private:
217  multiplayer::HostEntry mHostEntry;
218  std::string mDataPath;
219  qsf::Map* mCurrentMap;
220  std::unique_ptr<HostBase> mHost;
221  MapCache mMapCache;
222 
223  std::string mPlayerName;
224  bool mIsReady;
225  bool mFirstDataUpdateHandled;
226  JoinResponse mJoinResponse;
227 
228  glm::vec3 mLastViewPosition;
229 
230  qsf::JobProxy mInterpolateJobProxy;
231  qsf::MessageProxy mOrderUnitMessageProxy;
232  qsf::JobProxy mReconnectOneShotJobProxy;
233 
234  boost::container::flat_map<uint32, bool> mJobStatus;
235 
236  std::vector<std::pair<int32, std::vector<EntityCreatedFromPrefabData>>> mCreateEntityHistory;
237  std::vector<std::pair<int32, std::vector<uint64>>> mDestroyEntityHistory;
238  std::vector<std::pair<int32, std::vector<UnitSpawnedData>>> mUnitSpawnedHistory;
239  std::vector<std::pair<int32, std::vector<UnitSpawnedPlayerUpdateSelectionData>>> mUnitSpawnedPlayerUpdateSelectionHistory;
240  std::vector<std::pair<int32, std::vector<FreeplayEventData>>> mChangedEventList;
241  std::vector<std::pair<int32, boost::container::flat_map<uint32, uint32>>> mChangedPlayerScoreHistory;
242  std::vector<std::pair<int32, GameModeUpdateData>> mGameModeUpdateHistory;
243  std::vector<std::pair<int32, std::vector<NewHintData>>> mNewHintHistory;
244  std::vector<std::pair<int32, std::vector<MinimapMessageData>>> mMinimapMessagesHistory;
245  std::vector<std::pair<int32, std::vector<MinimapIconMessageData>>> mMinimapIconMessagesHistory;
246  std::vector<std::pair<int32, std::vector<LayerChangedData>>> mLayerChangedHistory;
247  std::vector<std::pair<int32, std::vector<CreateFireHoseData>>> mCreateFireHoseHistory;
248  std::vector<std::pair<int32, std::vector<SpawnParticleData>>> mSpawnParticleHistory;
249 
250  AudioManager mAudioManager;
251 
252  std::vector<boost::signals2::connection> mMultiplayerProxyClientSignalConnections;
253 
254 
255  };
256 
257 
258 //[-------------------------------------------------------]
259 //[ Namespace ]
260 //[-------------------------------------------------------]
261  } // client
262  } // multiplayer
263 } // em5
Definition: ActionPriority.h:13
Job proxy class.
Definition: JobProxy.h:51
Client side audio manager which handles audio update messages.
Definition: AudioManager.h:56
Message parameters class.
Definition: MessageParameters.h:34
Map class.
Definition: Map.h:93
unsigned int uint32
Definition: PlatformTypes.h:181
#define EM5_API_EXPORT
Definition: Export.h:28
Definition: SessionBase.h:139
Message listener proxy class.
Definition: MessageProxy.h:47
OperationMessage
EMERGENCY 5 multiplayer operation message types.
Definition: OperationMessages.h:51
uint64_t uint64
Definition: PlatformTypes.h:184
Job arguments class: holds data to be passed to the called job method by the job manager.
Definition: JobArguments.h:40
Game bit stream class (just a wrapper for linnet bit stream)
Definition: BitStream.h:40
Definition: PickupPersonByParamedicAction.h:21
EMERGENCY 5 multiplayer session base class.
Definition: SessionBase.h:55
EMERGENCY 5 map identifier class.
Definition: MapIdentifier.h:34
signed int int32
Definition: PlatformTypes.h:180
JoinResponse
Definition: OperationMessages.h:117
boost::signals2::signal< void()> disconnected
Called when the client is disconnected.
Definition: Client.h:85
EMERGENCY 5 multiplayer map cache.
Definition: MapCache.h:63
EMERGENCY 5 multiplayer client class.
Definition: Client.h:69
Abstract command base class.
Definition: Command.h:50
Definition: MatchmakingTypes.h:47
Command context base class.
Definition: CommandContext.h:48