gameConnectionEvents.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GAMECONNECTIONEVENTS_H_
  23. #define _GAMECONNECTIONEVENTS_H_
  24. #ifndef _SIMBASE_H_
  25. #include "console/simBase.h"
  26. #endif
  27. #ifndef _GAMECONNECTION_H_
  28. #include "T3D/gameBase/gameConnection.h"
  29. #endif
  30. #ifndef _SFXPROFILE_H_
  31. #include "sfx/sfxProfile.h"
  32. #endif
  33. #ifndef _BITSTREAM_H_
  34. #include "core/stream/bitStream.h"
  35. #endif
  36. #include "T3D/assets/SoundAsset.h"
  37. class QuitEvent : public SimEvent
  38. {
  39. void process(SimObject *object)
  40. {
  41. Platform::postQuitMessage(0);
  42. }
  43. };
  44. /// Event for sending a datablock over the net from the server to the client.
  45. ///
  46. /// Datablock events are GuaranteedOrdered client events.
  47. ///
  48. class SimDataBlockEvent : public NetEvent
  49. {
  50. public:
  51. typedef NetEvent Parent;
  52. protected:
  53. /// Id of the datablock object to be sent. This must be a datablock ID
  54. /// (as opposed to a normal object ID).
  55. SimObjectId id;
  56. ///
  57. U32 mIndex;
  58. /// Total number of datablocks that are part of this datablock transmission.
  59. /// Each datablock is transmitted in an independent datablock event.
  60. U32 mTotal;
  61. /// The mission sequence number to which this datablock transmission
  62. /// belongs.
  63. ///
  64. /// @see GameConnection::getDataBlockSequence
  65. U32 mMissionSequence;
  66. /// Datablock object constructed on the client side.
  67. SimDataBlock *mObj;
  68. ///
  69. bool mProcess;
  70. public:
  71. SimDataBlockEvent(SimDataBlock* obj = NULL, U32 index = 0, U32 total = 0, U32 missionSequence = 0);
  72. ~SimDataBlockEvent();
  73. void pack(NetConnection *, BitStream *bstream);
  74. void write(NetConnection *, BitStream *bstream);
  75. void unpack(NetConnection *cptr, BitStream *bstream);
  76. void process(NetConnection*);
  77. void notifyDelivered(NetConnection *, bool);
  78. #ifdef TORQUE_DEBUG_NET
  79. const char *getDebugName();
  80. #endif
  81. DECLARE_CONOBJECT( SimDataBlockEvent );
  82. DECLARE_CATEGORY( "Game Networking" );
  83. };
  84. class SimSoundAssetEvent : public NetEvent
  85. {
  86. private:
  87. AssetPtr<SoundAsset> mAsset;
  88. MatrixF mTransform;
  89. public:
  90. typedef NetEvent Parent;
  91. SimSoundAssetEvent(StringTableEntry assetId = StringTable->EmptyString(), const MatrixF& mat = MatrixF::Identity);
  92. void pack(NetConnection*, BitStream* bstream);
  93. void write(NetConnection*, BitStream* bstream);
  94. void unpack(NetConnection*, BitStream* bstream);
  95. void process(NetConnection*);
  96. DECLARE_CONOBJECT(SimSoundAssetEvent);
  97. };
  98. class Sim2DAudioEvent: public NetEvent
  99. {
  100. private:
  101. SFXProfile *mProfile;
  102. public:
  103. typedef NetEvent Parent;
  104. Sim2DAudioEvent(SFXProfile *profile=NULL);
  105. void pack(NetConnection *, BitStream *bstream);
  106. void write(NetConnection *, BitStream *bstream);
  107. void unpack(NetConnection *, BitStream *bstream);
  108. void process(NetConnection *);
  109. DECLARE_CONOBJECT(Sim2DAudioEvent);
  110. };
  111. class Sim3DAudioEvent: public NetEvent
  112. {
  113. private:
  114. SFXProfile *mProfile;
  115. MatrixF mTransform;
  116. public:
  117. typedef NetEvent Parent;
  118. Sim3DAudioEvent(SFXProfile *profile=NULL,const MatrixF* mat=NULL);
  119. void pack(NetConnection *, BitStream *bstream);
  120. void write(NetConnection *, BitStream *bstream);
  121. void unpack(NetConnection *, BitStream *bstream);
  122. void process(NetConnection *);
  123. DECLARE_CONOBJECT(Sim3DAudioEvent);
  124. };
  125. //----------------------------------------------------------------------------
  126. // used to set the crc for the current mission (mission lighting)
  127. //----------------------------------------------------------------------------
  128. class SetMissionCRCEvent : public NetEvent
  129. {
  130. private:
  131. U32 mCrc;
  132. public:
  133. typedef NetEvent Parent;
  134. SetMissionCRCEvent(U32 crc = 0xffffffff)
  135. { mCrc = crc; }
  136. void pack(NetConnection *, BitStream * bstream)
  137. { bstream->write(mCrc); }
  138. void write(NetConnection * con, BitStream * bstream)
  139. { pack(con, bstream); }
  140. void unpack(NetConnection *, BitStream * bstream)
  141. { bstream->read(&mCrc); }
  142. void process(NetConnection * con)
  143. { static_cast<GameConnection*>(con)->setMissionCRC(mCrc); }
  144. DECLARE_CONOBJECT(SetMissionCRCEvent);
  145. };
  146. #endif