Torque3D Documentation / _generateds / gameConnection.h

gameConnection.h

Engine/source/T3D/gameBase/gameConnection.h

More...

Classes:

Public Defines

Public Enumerations

enum
GameConnectionConstants {
  MaxClients = 126
  DataBlockQueueCount = 16
}

Public Variables

max camera FOV

min camera FOV

Detailed Description

Public Defines

AFX_CAP_DATABLOCK_CACHE() 

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//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
 26// Copyright (C) 2015 Faust Logic, Inc.
 27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 28
 29#ifndef _GAMECONNECTION_H_
 30#define _GAMECONNECTION_H_
 31
 32#ifndef _SIMBASE_H_
 33#include "console/simBase.h"
 34#endif
 35#ifndef _GAMEBASE_H_
 36#include "T3D/gameBase/gameBase.h"
 37#endif
 38#ifndef _NETCONNECTION_H_
 39#include "sim/netConnection.h"
 40#endif
 41#ifndef _MOVEMANAGER_H_
 42#include "T3D/gameBase/moveManager.h"
 43#endif
 44#ifndef _BITVECTOR_H_
 45#include "core/bitVector.h"
 46#endif
 47
 48enum GameConnectionConstants
 49{
 50   MaxClients = 126,
 51   DataBlockQueueCount = 16
 52};
 53
 54class IDisplayDevice;
 55class SFXProfile;
 56class MatrixF;
 57class MatrixF;
 58class Point3F;
 59class MoveManager;
 60class MoveList;
 61struct Move;
 62struct AuthInfo;
 63
 64// To disable datablock caching, remove or comment out the AFX_CAP_DATABLOCK_CACHE define below.
 65// Also, at a minimum, the following script preferences should be set to false:
 66//   $pref::Client::EnableDatablockCache = false; (in arcane.fx/client/defaults.tscript)
 67//   $Pref::Server::EnableDatablockCache = false; (in arcane.fx/server/defaults.tscript)
 68// Alternatively, all script code marked with "DATABLOCK CACHE CODE" can be removed or
 69// commented out.
 70//
 71#define AFX_CAP_DATABLOCK_CACHE
 72const F32 MinCameraFov              = 1.f;      ///< min camera FOV
 73const F32 MaxCameraFov              = 179.f;    ///< max camera FOV
 74
 75class GameConnection : public NetConnection
 76{
 77private:
 78   typedef NetConnection Parent;
 79
 80   SimObjectPtr<GameBase> mControlObject;
 81   SimObjectPtr<GameBase> mCameraObject;
 82   U32 mDataBlockSequence;
 83   char mDisconnectReason[256];
 84
 85   U32  mMissionCRC;             // crc of the current mission file from the server
 86
 87   F32 mVisibleGhostDistance;
 88
 89private:
 90   U32 mLastControlRequestTime;
 91   S32 mDataBlockModifiedKey;
 92   S32 mMaxDataBlockModifiedKey;
 93
 94   /// @name Client side first/third person
 95   /// @{
 96
 97   ///
 98   bool  mFirstPerson;     ///< Are we currently first person or not.
 99   bool  mUpdateFirstPerson; ///< Set to notify client or server of first person change.
100   bool  mUpdateCameraFov; ///< Set to notify server of camera FOV change.
101   F32   mCameraFov;       ///< Current camera fov (in degrees).
102   F32   mCameraPos;       ///< Current camera pos (0-1).
103   F32   mCameraSpeed;     ///< Camera in/out speed.
104
105   IDisplayDevice* mDisplayDevice;  ///< Optional client display device that imposes rendering properties.
106   /// @}
107
108   /// @name Client side control scheme that may be referenced by control objects
109   /// @{
110   bool  mUpdateControlScheme;   ///< Set to notify client or server of control scheme change
111   bool  mAbsoluteRotation;      ///< Use absolute rotation values from client, likely through ExtendedMove
112   bool  mAddYawToAbsRot;        ///< Add relative yaw control to the absolute rotation calculation.  Only useful with mAbsoluteRotation.
113   bool  mAddPitchToAbsRot;      ///< Add relative pitch control to the absolute rotation calculation.  Only useful with mAbsoluteRotation.
114   /// @}
115
116public:
117
118   /// @name Protocol Versions
119   ///
120   /// Protocol versions are used to indicated changes in network traffic.
121   /// These could be changes in how any object transmits or processes
122   /// network information. You can specify backwards compatibility by
123   /// specifying a MinRequireProtocolVersion.  If the client
124   /// protocol is >= this min value, the connection is accepted.
125   ///
126   /// Torque (V12) SDK 1.0 uses protocol  =  1
127   ///
128   /// Torque SDK 1.1 uses protocol = 2
129   /// Torque SDK 1.4 uses protocol = 12
130   /// @{
131   static const U32 CurrentProtocolVersion;
132   static const U32 MinRequiredProtocolVersion;
133   /// @}
134
135   /// Configuration
136   enum Constants {
137      BlockTypeMove = NetConnectionBlockTypeCount,
138      GameConnectionBlockTypeCount,
139      MaxConnectArgs = 16,
140      DataBlocksDone = NumConnectionMessages,
141      DataBlocksDownloadDone,
142   };
143
144   /// Set connection arguments; these are passed to the server when we connect.
145   void setConnectArgs(U32 argc, const char **argv);
146
147   /// Set the server password to use when we join.
148   void setJoinPassword(const char *password);
149
150   /// @name Event Handling
151   /// @{
152
153   virtual void onTimedOut();
154   virtual void onConnectTimedOut();
155   virtual void onDisconnect(const char *reason);
156   virtual void onConnectionRejected(const char *reason);
157   virtual void onConnectionEstablished(bool isInitiator);
158   virtual void handleStartupError(const char *errorString);
159   /// @}
160
161   /// @name Packet I/O
162   /// @{
163
164   virtual void writeConnectRequest(BitStream *stream);
165   virtual bool readConnectRequest(BitStream *stream, const char **errorString);
166   virtual void writeConnectAccept(BitStream *stream);
167   virtual bool readConnectAccept(BitStream *stream, const char **errorString);
168   /// @}
169
170   bool canRemoteCreate();
171
172   void setVisibleGhostDistance(F32 dist);
173   F32 getVisibleGhostDistance();
174
175private:
176   /// @name Connection State
177   /// This data is set with setConnectArgs() and setJoinPassword(), and
178   /// sent across the wire when we connect.
179   /// @{
180
181   U32      mConnectArgc;
182   char *mConnectArgv[MaxConnectArgs];
183   char *mJoinPassword;
184   /// @}
185
186protected:
187   struct GamePacketNotify : public NetConnection::PacketNotify
188   {
189      S32 cameraFov;
190      GamePacketNotify();
191   };
192   PacketNotify *allocNotify();
193
194   bool mControlForceMismatch;
195
196   Vector<SimDataBlock*> mDataBlockLoadList;
197
198public:
199
200   MoveList *mMoveList;
201
202protected:
203   bool        mAIControlled;
204   AuthInfo *  mAuthInfo;
205
206   static S32  mLagThresholdMS;
207   S32         mLastPacketTime;
208   bool        mLagging;
209
210   /// @name Flashing
211   ////
212   /// Note, these variables are not networked, they are for the local connection only.
213   /// @{
214   F32 mDamageFlash;
215   F32 mWhiteOut;
216
217   F32   mBlackOut;
218   S32   mBlackOutTimeMS;
219   S32   mBlackOutStartTimeMS;
220   bool  mFadeToBlack;
221
222   /// @}
223
224   /// @name Packet I/O
225   /// @{
226
227   void readPacket      (BitStream *bstream);
228   void writePacket     (BitStream *bstream, PacketNotify *note);
229   void packetReceived  (PacketNotify *note);
230   void packetDropped   (PacketNotify *note);
231   void connectionError (const char *errorString);
232
233   void writeDemoStartBlock   (ResizeBitStream *stream);
234   bool readDemoStartBlock    (BitStream *stream);
235   void handleRecordedBlock   (U32 type, U32 size, void *data);
236   /// @}
237   void ghostWriteExtra(NetObject *,BitStream *);
238   void ghostReadExtra(NetObject *,BitStream *, bool newGhost);
239   void ghostPreRead(NetObject *, bool newGhost);
240   
241   virtual void onEndGhosting();
242
243public:
244
245   DECLARE_CONOBJECT(GameConnection);
246   void handleConnectionMessage(U32 message, U32 sequence, U32 ghostCount);
247   void preloadDataBlock(SimDataBlock *block);
248   void fileDownloadSegmentComplete();
249   void preloadNextDataBlock(bool hadNew);
250   
251   static void consoleInit();
252
253   void setDisconnectReason(const char *reason);
254   GameConnection();
255   ~GameConnection();
256
257   bool onAdd();
258   void onRemove();
259
260   static GameConnection *getConnectionToServer() 
261   { 
262      return dynamic_cast<GameConnection*>((NetConnection *) mServerConnection); 
263   }
264   
265   static GameConnection *getLocalClientConnection() 
266   { 
267      return dynamic_cast<GameConnection*>((NetConnection *) mLocalClientConnection); 
268   }
269
270   /// @name Control object
271   /// @{
272
273   ///
274   void setControlObject(GameBase *);
275   GameBase* getControlObject() {  return  mControlObject; }
276   const GameBase* getControlObject() const {  return  mControlObject; }
277   
278   void setCameraObject(GameBase *);
279   GameBase* getCameraObject();
280   
281   bool getControlCameraTransform(F32 dt,MatrixF* mat);
282   bool getControlCameraVelocity(Point3F *vel);
283
284   /// Returns the head transform for the control object, using supplemental information
285   /// from the provided IDisplayDevice
286   bool getControlCameraHeadTransform(IDisplayDevice *display, MatrixF *transform);
287
288   /// Returns the eye transforms for the control object, using supplemental information 
289   /// from the provided IDisplayDevice.
290   bool getControlCameraEyeTransforms(IDisplayDevice *display, MatrixF *transforms);
291   
292   bool getControlCameraDefaultFov(F32 *fov);
293   bool getControlCameraFov(F32 *fov);
294   bool setControlCameraFov(F32 fov);
295   bool isValidControlCameraFov(F32 fov);
296   
297   // Used by editor
298   bool isControlObjectRotDampedCamera();
299
300   void setFirstPerson(bool firstPerson);
301   
302   bool hasDisplayDevice() const { return mDisplayDevice != NULL; }
303   IDisplayDevice* getDisplayDevice() const { return mDisplayDevice; }
304   void setDisplayDevice(IDisplayDevice* display) { if (mDisplayDevice) mDisplayDevice->setDrawCanvas(NULL); mDisplayDevice = display; }
305   void clearDisplayDevice() { mDisplayDevice = NULL; }
306
307   void setControlSchemeParameters(bool absoluteRotation, bool addYawToAbsRot, bool addPitchToAbsRot);
308   bool getControlSchemeAbsoluteRotation() {return mAbsoluteRotation;}
309   bool getControlSchemeAddYawToAbsRot() {return mAddYawToAbsRot;}
310   bool getControlSchemeAddPitchToAbsRot() {return mAddPitchToAbsRot;}
311
312   /// @}
313
314   void detectLag();
315
316   /// @name Datablock management
317   /// @{
318
319   S32  getDataBlockModifiedKey     ()  { return mDataBlockModifiedKey; }
320   void setDataBlockModifiedKey     (S32 key)  { mDataBlockModifiedKey = key; }
321   S32  getMaxDataBlockModifiedKey  ()  { return mMaxDataBlockModifiedKey; }
322   void setMaxDataBlockModifiedKey  (S32 key)  { mMaxDataBlockModifiedKey = key; }
323
324   /// Return the datablock sequence number that this game connection is on.
325   /// The datablock sequence number is synchronized to the mission sequence number
326   /// on each datablock transmission.
327   U32 getDataBlockSequence() { return mDataBlockSequence; }
328   
329   /// Set the datablock sequence number.
330   void setDataBlockSequence(U32 seq) { mDataBlockSequence = seq; }
331
332   /// @}
333
334   /// @name Fade control
335   /// @{
336
337   F32 getDamageFlash() const { return mDamageFlash; }
338   F32 getWhiteOut() const { return mWhiteOut; }
339
340   void setBlackOut(bool fadeToBlack, S32 timeMS);
341   F32  getBlackOut();
342   /// @}
343
344   /// @name Authentication
345   ///
346   /// This is remnant code from Tribes 2.
347   /// @{
348
349   void            setAuthInfo(const AuthInfo *info);
350   const AuthInfo *getAuthInfo();
351   /// @}
352
353   /// @name Sound
354   /// @{
355
356   void play2D(SFXProfile *profile);
357   void play3D(SFXProfile *profile, const MatrixF *transform);
358   /// @}
359
360   /// @name Misc.
361   /// @{
362
363   bool isFirstPerson() const  { return mCameraPos == 0; }
364   bool isAIControlled() { return mAIControlled; }
365
366   void doneScopingScene();
367   void demoPlaybackComplete();
368
369   void setMissionCRC(U32 crc)           { mMissionCRC = crc; }
370   U32  getMissionCRC()           { return(mMissionCRC); }
371   /// @}
372
373   static Signal<void(F32)> smFovUpdate;
374   static Signal<void()> smPlayingDemo;
375
376protected:
377   DECLARE_CALLBACK( void, onConnectionTimedOut, () );
378   DECLARE_CALLBACK( void, onConnectionAccepted, () );
379   DECLARE_CALLBACK( void, onConnectRequestTimedOut, () );
380   DECLARE_CALLBACK( void, onConnectionDropped, (const char* reason) );
381   DECLARE_CALLBACK( void, onConnectRequestRejected, (const char* reason) );
382   DECLARE_CALLBACK( void, onConnectionError, (const char* errorString) );
383   DECLARE_CALLBACK( void, onDrop, (const char* disconnectReason) );
384   DECLARE_CALLBACK( void, initialControlSet, () );
385   DECLARE_CALLBACK( void, onControlObjectChange, () );
386   DECLARE_CALLBACK( void, setLagIcon, (bool state) );
387   DECLARE_CALLBACK( void, onDataBlocksDone, (U32 sequence) );
388   DECLARE_CALLBACK( void, onFlash, (bool state) );
389
390#ifdef TORQUE_AFX_ENABLED
391   // GameConnection is modified to keep track of object selections which are used in
392   // spell targeting. This code stores the current object selection as well as the
393   // current rollover object beneath the cursor. The rollover object is treated as a
394   // pending object selection and actual object selection is usually made by promoting
395   // the rollover object to the current object selection.
396private:   
397   SimObjectPtr<SceneObject> mRolloverObj;  
398   SimObjectPtr<SceneObject> mPreSelectedObj;  
399   SimObjectPtr<SceneObject> mSelectedObj;  
400   bool          mChangedSelectedObj;
401   U32           mPreSelectTimestamp;
402protected:
403   virtual void  onDeleteNotify(SimObject*);
404public:   
405   void          setRolloverObj(SceneObject*);   
406   SceneObject*  getRolloverObj() { return  mRolloverObj; }   
407   void          setSelectedObj(SceneObject*, bool propagate_to_client=false);   
408   SceneObject*  getSelectedObj() { return  mSelectedObj; }  
409   void          setPreSelectedObjFromRollover();
410   void          clearPreSelectedObj();
411   void          setSelectedObjFromPreSelected();
412   // Flag is added to indicate when a client is fully connected or "zoned-in". 
413   // This information determines when AFX will startup active effects on a newly
414   // added client. 
415private:
416   bool          zoned_in;
417public:
418   bool          isZonedIn() const { return zoned_in; }
419   void          setZonedIn() { zoned_in = true; }
420#endif
421#ifdef AFX_CAP_DATABLOCK_CACHE
422private:
423   static StringTableEntry  server_cache_filename;
424   static StringTableEntry  client_cache_filename;
425   static bool   server_cache_on;
426   static bool   client_cache_on;
427   BitStream*    client_db_stream;
428   U32           server_cache_CRC;
429public:
430   void          repackClientDatablock(BitStream*, S32 start_pos);
431   void          saveDatablockCache(bool on_server);
432   void          loadDatablockCache();
433   bool          loadDatablockCache_Begin();
434   bool          loadDatablockCache_Continue();
435   void          tempDisableStringBuffering(BitStream* bs) const;
436   void          restoreStringBuffering(BitStream* bs) const;
437   void          setServerCacheCRC(U32 crc) { server_cache_CRC = crc; }
438
439   static void   resetDatablockCache();
440   static bool   serverCacheEnabled() { return server_cache_on; }
441   static bool   clientCacheEnabled() { return client_cache_on; }
442   static const char* serverCacheFilename() { return server_cache_filename; }
443   static const char* clientCacheFilename() { return client_cache_filename; }
444#endif
445};
446
447#endif
448