2
0

gameConnectionEvents.h 5.6 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) override
  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) override;
  74. void write(NetConnection *, BitStream *bstream) override;
  75. void unpack(NetConnection *cptr, BitStream *bstream) override;
  76. void process(NetConnection*) override;
  77. void notifyDelivered(NetConnection *, bool) override;
  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. bool sentTransform;
  90. public:
  91. typedef NetEvent Parent;
  92. SimSoundAssetEvent(StringTableEntry assetId = StringTable->EmptyString(), const MatrixF* mat = NULL);
  93. void pack(NetConnection*, BitStream* bstream) override;
  94. void write(NetConnection*, BitStream* bstream) override;
  95. void unpack(NetConnection*, BitStream* bstream) override;
  96. void process(NetConnection*) override;
  97. DECLARE_CONOBJECT(SimSoundAssetEvent);
  98. };
  99. class Sim2DAudioEvent: public NetEvent
  100. {
  101. private:
  102. SFXProfile *mProfile;
  103. public:
  104. typedef NetEvent Parent;
  105. Sim2DAudioEvent(SFXProfile *profile=NULL);
  106. void pack(NetConnection *, BitStream *bstream) override;
  107. void write(NetConnection *, BitStream *bstream) override;
  108. void unpack(NetConnection *, BitStream *bstream) override;
  109. void process(NetConnection *) override;
  110. DECLARE_CONOBJECT(Sim2DAudioEvent);
  111. };
  112. class Sim3DAudioEvent: public NetEvent
  113. {
  114. private:
  115. SFXProfile *mProfile;
  116. MatrixF mTransform;
  117. public:
  118. typedef NetEvent Parent;
  119. Sim3DAudioEvent(SFXProfile *profile=NULL,const MatrixF* mat=NULL);
  120. void pack(NetConnection *, BitStream *bstream) override;
  121. void write(NetConnection *, BitStream *bstream) override;
  122. void unpack(NetConnection *, BitStream *bstream) override;
  123. void process(NetConnection *) override;
  124. DECLARE_CONOBJECT(Sim3DAudioEvent);
  125. };
  126. //----------------------------------------------------------------------------
  127. // used to set the crc for the current mission (mission lighting)
  128. //----------------------------------------------------------------------------
  129. class SetMissionCRCEvent : public NetEvent
  130. {
  131. private:
  132. U32 mCrc;
  133. public:
  134. typedef NetEvent Parent;
  135. SetMissionCRCEvent(U32 crc = 0xffffffff)
  136. { mCrc = crc; }
  137. void pack(NetConnection *, BitStream * bstream) override
  138. { bstream->write(mCrc); }
  139. void write(NetConnection * con, BitStream * bstream) override
  140. { pack(con, bstream); }
  141. void unpack(NetConnection *, BitStream * bstream) override
  142. { bstream->read(&mCrc); }
  143. void process(NetConnection * con) override
  144. { static_cast<GameConnection*>(con)->setMissionCRC(mCrc); }
  145. DECLARE_CONOBJECT(SetMissionCRCEvent);
  146. };
  147. #endif