gameConnection.h
Engine/source/T3D/gameBase/gameConnection.h
Classes:
Public Enumerations
enum
GameConnectionConstants { MaxClients = 126 DataBlockQueueCount = 16 }
Public Variables
max camera FOV
min camera FOV
Detailed Description
Public Enumerations
GameConnectionConstants
Enumerator
- MaxClients = 126
- DataBlockQueueCount = 16
Public Variables
const F32 MaxCameraFov
max camera FOV
const F32 MinCameraFov
min camera FOV
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _GAMECONNECTION_H_ 25#define _GAMECONNECTION_H_ 26 27#ifndef _SIMBASE_H_ 28#include "console/simBase.h" 29#endif 30#ifndef _GAMEBASE_H_ 31#include "T3D/gameBase/gameBase.h" 32#endif 33#ifndef _NETCONNECTION_H_ 34#include "sim/netConnection.h" 35#endif 36#ifndef _MOVEMANAGER_H_ 37#include "T3D/gameBase/moveManager.h" 38#endif 39#ifndef _BITVECTOR_H_ 40#include "core/bitVector.h" 41#endif 42 43enum GameConnectionConstants 44{ 45 MaxClients = 126, 46 DataBlockQueueCount = 16 47}; 48 49class IDisplayDevice; 50class SFXProfile; 51class MatrixF; 52class MatrixF; 53class Point3F; 54class MoveManager; 55class MoveList; 56struct Move; 57struct AuthInfo; 58 59const F32 MinCameraFov = 1.f; ///< min camera FOV 60const F32 MaxCameraFov = 179.f; ///< max camera FOV 61 62class GameConnection : public NetConnection 63{ 64private: 65 typedef NetConnection Parent; 66 67 SimObjectPtr<GameBase> mControlObject; 68 SimObjectPtr<GameBase> mCameraObject; 69 U32 mDataBlockSequence; 70 char mDisconnectReason[256]; 71 72 U32 mMissionCRC; // crc of the current mission file from the server 73 74 F32 mVisibleGhostDistance; 75 76private: 77 U32 mLastControlRequestTime; 78 S32 mDataBlockModifiedKey; 79 S32 mMaxDataBlockModifiedKey; 80 81 /// @name Client side first/third person 82 /// @{ 83 84 /// 85 bool mFirstPerson; ///< Are we currently first person or not. 86 bool mUpdateFirstPerson; ///< Set to notify client or server of first person change. 87 bool mUpdateCameraFov; ///< Set to notify server of camera FOV change. 88 F32 mCameraFov; ///< Current camera fov (in degrees). 89 F32 mCameraPos; ///< Current camera pos (0-1). 90 F32 mCameraSpeed; ///< Camera in/out speed. 91 92 IDisplayDevice* mDisplayDevice; ///< Optional client display device that imposes rendering properties. 93 /// @} 94 95 /// @name Client side control scheme that may be referenced by control objects 96 /// @{ 97 bool mUpdateControlScheme; ///< Set to notify client or server of control scheme change 98 bool mAbsoluteRotation; ///< Use absolute rotation values from client, likely through ExtendedMove 99 bool mAddYawToAbsRot; ///< Add relative yaw control to the absolute rotation calculation. Only useful with mAbsoluteRotation. 100 bool mAddPitchToAbsRot; ///< Add relative pitch control to the absolute rotation calculation. Only useful with mAbsoluteRotation. 101 /// @} 102 103public: 104 105 /// @name Protocol Versions 106 /// 107 /// Protocol versions are used to indicated changes in network traffic. 108 /// These could be changes in how any object transmits or processes 109 /// network information. You can specify backwards compatibility by 110 /// specifying a MinRequireProtocolVersion. If the client 111 /// protocol is >= this min value, the connection is accepted. 112 /// 113 /// Torque (V12) SDK 1.0 uses protocol = 1 114 /// 115 /// Torque SDK 1.1 uses protocol = 2 116 /// Torque SDK 1.4 uses protocol = 12 117 /// @{ 118 static const U32 CurrentProtocolVersion; 119 static const U32 MinRequiredProtocolVersion; 120 /// @} 121 122 /// Configuration 123 enum Constants { 124 BlockTypeMove = NetConnectionBlockTypeCount, 125 GameConnectionBlockTypeCount, 126 MaxConnectArgs = 16, 127 DataBlocksDone = NumConnectionMessages, 128 DataBlocksDownloadDone, 129 }; 130 131 /// Set connection arguments; these are passed to the server when we connect. 132 void setConnectArgs(U32 argc, const char **argv); 133 134 /// Set the server password to use when we join. 135 void setJoinPassword(const char *password); 136 137 /// @name Event Handling 138 /// @{ 139 140 virtual void onTimedOut(); 141 virtual void onConnectTimedOut(); 142 virtual void onDisconnect(const char *reason); 143 virtual void onConnectionRejected(const char *reason); 144 virtual void onConnectionEstablished(bool isInitiator); 145 virtual void handleStartupError(const char *errorString); 146 /// @} 147 148 /// @name Packet I/O 149 /// @{ 150 151 virtual void writeConnectRequest(BitStream *stream); 152 virtual bool readConnectRequest(BitStream *stream, const char **errorString); 153 virtual void writeConnectAccept(BitStream *stream); 154 virtual bool readConnectAccept(BitStream *stream, const char **errorString); 155 /// @} 156 157 bool canRemoteCreate(); 158 159 void setVisibleGhostDistance(F32 dist); 160 F32 getVisibleGhostDistance(); 161 162private: 163 /// @name Connection State 164 /// This data is set with setConnectArgs() and setJoinPassword(), and 165 /// sent across the wire when we connect. 166 /// @{ 167 168 U32 mConnectArgc; 169 char *mConnectArgv[MaxConnectArgs]; 170 char *mJoinPassword; 171 /// @} 172 173protected: 174 struct GamePacketNotify : public NetConnection::PacketNotify 175 { 176 S32 cameraFov; 177 GamePacketNotify(); 178 }; 179 PacketNotify *allocNotify(); 180 181 bool mControlForceMismatch; 182 183 Vector<SimDataBlock*> mDataBlockLoadList; 184 185public: 186 187 MoveList *mMoveList; 188 189protected: 190 bool mAIControlled; 191 AuthInfo * mAuthInfo; 192 193 static S32 mLagThresholdMS; 194 S32 mLastPacketTime; 195 bool mLagging; 196 197 /// @name Flashing 198 //// 199 /// Note, these variables are not networked, they are for the local connection only. 200 /// @{ 201 F32 mDamageFlash; 202 F32 mWhiteOut; 203 204 F32 mBlackOut; 205 S32 mBlackOutTimeMS; 206 S32 mBlackOutStartTimeMS; 207 bool mFadeToBlack; 208 209 /// @} 210 211 /// @name Packet I/O 212 /// @{ 213 214 void readPacket (BitStream *bstream); 215 void writePacket (BitStream *bstream, PacketNotify *note); 216 void packetReceived (PacketNotify *note); 217 void packetDropped (PacketNotify *note); 218 void connectionError (const char *errorString); 219 220 void writeDemoStartBlock (ResizeBitStream *stream); 221 bool readDemoStartBlock (BitStream *stream); 222 void handleRecordedBlock (U32 type, U32 size, void *data); 223 /// @} 224 void ghostWriteExtra(NetObject *,BitStream *); 225 void ghostReadExtra(NetObject *,BitStream *, bool newGhost); 226 void ghostPreRead(NetObject *, bool newGhost); 227 228 virtual void onEndGhosting(); 229 230public: 231 232 DECLARE_CONOBJECT(GameConnection); 233 void handleConnectionMessage(U32 message, U32 sequence, U32 ghostCount); 234 void preloadDataBlock(SimDataBlock *block); 235 void fileDownloadSegmentComplete(); 236 void preloadNextDataBlock(bool hadNew); 237 238 static void consoleInit(); 239 240 void setDisconnectReason(const char *reason); 241 GameConnection(); 242 ~GameConnection(); 243 244 bool onAdd(); 245 void onRemove(); 246 247 static GameConnection *getConnectionToServer() 248 { 249 return dynamic_cast<GameConnection*>((NetConnection *) mServerConnection); 250 } 251 252 static GameConnection *getLocalClientConnection() 253 { 254 return dynamic_cast<GameConnection*>((NetConnection *) mLocalClientConnection); 255 } 256 257 /// @name Control object 258 /// @{ 259 260 /// 261 void setControlObject(GameBase *); 262 GameBase* getControlObject() { return mControlObject; } 263 const GameBase* getControlObject() const { return mControlObject; } 264 265 void setCameraObject(GameBase *); 266 GameBase* getCameraObject(); 267 268 bool getControlCameraTransform(F32 dt,MatrixF* mat); 269 bool getControlCameraVelocity(Point3F *vel); 270 271 /// Returns the head transform for the control object, using supplemental information 272 /// from the provided IDisplayDevice 273 bool getControlCameraHeadTransform(IDisplayDevice *display, MatrixF *transform); 274 275 /// Returns the eye transforms for the control object, using supplemental information 276 /// from the provided IDisplayDevice. 277 bool getControlCameraEyeTransforms(IDisplayDevice *display, MatrixF *transforms); 278 279 bool getControlCameraDefaultFov(F32 *fov); 280 bool getControlCameraFov(F32 *fov); 281 bool setControlCameraFov(F32 fov); 282 bool isValidControlCameraFov(F32 fov); 283 284 // Used by editor 285 bool isControlObjectRotDampedCamera(); 286 287 void setFirstPerson(bool firstPerson); 288 289 bool hasDisplayDevice() const { return mDisplayDevice != NULL; } 290 IDisplayDevice* getDisplayDevice() const { return mDisplayDevice; } 291 void setDisplayDevice(IDisplayDevice* display) { if (mDisplayDevice) mDisplayDevice->setDrawCanvas(NULL); mDisplayDevice = display; } 292 void clearDisplayDevice() { mDisplayDevice = NULL; } 293 294 void setControlSchemeParameters(bool absoluteRotation, bool addYawToAbsRot, bool addPitchToAbsRot); 295 bool getControlSchemeAbsoluteRotation() {return mAbsoluteRotation;} 296 bool getControlSchemeAddYawToAbsRot() {return mAddYawToAbsRot;} 297 bool getControlSchemeAddPitchToAbsRot() {return mAddPitchToAbsRot;} 298 299 /// @} 300 301 void detectLag(); 302 303 /// @name Datablock management 304 /// @{ 305 306 S32 getDataBlockModifiedKey () { return mDataBlockModifiedKey; } 307 void setDataBlockModifiedKey (S32 key) { mDataBlockModifiedKey = key; } 308 S32 getMaxDataBlockModifiedKey () { return mMaxDataBlockModifiedKey; } 309 void setMaxDataBlockModifiedKey (S32 key) { mMaxDataBlockModifiedKey = key; } 310 311 /// Return the datablock sequence number that this game connection is on. 312 /// The datablock sequence number is synchronized to the mission sequence number 313 /// on each datablock transmission. 314 U32 getDataBlockSequence() { return mDataBlockSequence; } 315 316 /// Set the datablock sequence number. 317 void setDataBlockSequence(U32 seq) { mDataBlockSequence = seq; } 318 319 /// @} 320 321 /// @name Fade control 322 /// @{ 323 324 F32 getDamageFlash() const { return mDamageFlash; } 325 F32 getWhiteOut() const { return mWhiteOut; } 326 327 void setBlackOut(bool fadeToBlack, S32 timeMS); 328 F32 getBlackOut(); 329 /// @} 330 331 /// @name Authentication 332 /// 333 /// This is remnant code from Tribes 2. 334 /// @{ 335 336 void setAuthInfo(const AuthInfo *info); 337 const AuthInfo *getAuthInfo(); 338 /// @} 339 340 /// @name Sound 341 /// @{ 342 343 void play2D(SFXProfile *profile); 344 void play3D(SFXProfile *profile, const MatrixF *transform); 345 /// @} 346 347 /// @name Misc. 348 /// @{ 349 350 bool isFirstPerson() const { return mCameraPos == 0; } 351 bool isAIControlled() { return mAIControlled; } 352 353 void doneScopingScene(); 354 void demoPlaybackComplete(); 355 356 void setMissionCRC(U32 crc) { mMissionCRC = crc; } 357 U32 getMissionCRC() { return(mMissionCRC); } 358 /// @} 359 360 static Signal<void(F32)> smFovUpdate; 361 static Signal<void()> smPlayingDemo; 362 363protected: 364 DECLARE_CALLBACK( void, onConnectionTimedOut, () ); 365 DECLARE_CALLBACK( void, onConnectionAccepted, () ); 366 DECLARE_CALLBACK( void, onConnectRequestTimedOut, () ); 367 DECLARE_CALLBACK( void, onConnectionDropped, (const char* reason) ); 368 DECLARE_CALLBACK( void, onConnectRequestRejected, (const char* reason) ); 369 DECLARE_CALLBACK( void, onConnectionError, (const char* errorString) ); 370 DECLARE_CALLBACK( void, onDrop, (const char* disconnectReason) ); 371 DECLARE_CALLBACK( void, initialControlSet, () ); 372 DECLARE_CALLBACK( void, onControlObjectChange, () ); 373 DECLARE_CALLBACK( void, setLagIcon, (bool state) ); 374 DECLARE_CALLBACK( void, onDataBlocksDone, (U32 sequence) ); 375 DECLARE_CALLBACK( void, onFlash, (bool state) ); 376}; 377 378#endif 379
