gameConnectionEvents.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. class QuitEvent : public SimEvent
  37. {
  38. void process(SimObject *object)
  39. {
  40. Platform::postQuitMessage(0);
  41. }
  42. };
  43. /// Event for sending a datablock over the net from the server to the client.
  44. ///
  45. /// Datablock events are GuaranteedOrdered client events.
  46. ///
  47. class SimDataBlockEvent : public NetEvent
  48. {
  49. public:
  50. typedef NetEvent Parent;
  51. protected:
  52. /// Id of the datablock object to be sent. This must be a datablock ID
  53. /// (as opposed to a normal object ID).
  54. SimObjectId id;
  55. ///
  56. U32 mIndex;
  57. /// Total number of datablocks that are part of this datablock transmission.
  58. /// Each datablock is transmitted in an independent datablock event.
  59. U32 mTotal;
  60. /// The mission sequence number to which this datablock transmission
  61. /// belongs.
  62. ///
  63. /// @see GameConnection::getDataBlockSequence
  64. U32 mMissionSequence;
  65. /// Datablock object constructed on the client side.
  66. SimDataBlock *mObj;
  67. ///
  68. bool mProcess;
  69. public:
  70. SimDataBlockEvent(SimDataBlock* obj = NULL, U32 index = 0, U32 total = 0, U32 missionSequence = 0);
  71. ~SimDataBlockEvent();
  72. void pack(NetConnection *, BitStream *bstream);
  73. void write(NetConnection *, BitStream *bstream);
  74. void unpack(NetConnection *cptr, BitStream *bstream);
  75. void process(NetConnection*);
  76. void notifyDelivered(NetConnection *, bool);
  77. #ifdef TORQUE_DEBUG_NET
  78. const char *getDebugName();
  79. #endif
  80. DECLARE_CONOBJECT( SimDataBlockEvent );
  81. DECLARE_CATEGORY( "Game Networking" );
  82. };
  83. class Sim2DAudioEvent: public NetEvent
  84. {
  85. private:
  86. SFXProfile *mProfile;
  87. public:
  88. typedef NetEvent Parent;
  89. Sim2DAudioEvent(SFXProfile *profile=NULL);
  90. void pack(NetConnection *, BitStream *bstream);
  91. void write(NetConnection *, BitStream *bstream);
  92. void unpack(NetConnection *, BitStream *bstream);
  93. void process(NetConnection *);
  94. DECLARE_CONOBJECT(Sim2DAudioEvent);
  95. };
  96. class Sim3DAudioEvent: public NetEvent
  97. {
  98. private:
  99. SFXProfile *mProfile;
  100. MatrixF mTransform;
  101. public:
  102. typedef NetEvent Parent;
  103. Sim3DAudioEvent(SFXProfile *profile=NULL,const MatrixF* mat=NULL);
  104. void pack(NetConnection *, BitStream *bstream);
  105. void write(NetConnection *, BitStream *bstream);
  106. void unpack(NetConnection *, BitStream *bstream);
  107. void process(NetConnection *);
  108. DECLARE_CONOBJECT(Sim3DAudioEvent);
  109. };
  110. //----------------------------------------------------------------------------
  111. // used to set the crc for the current mission (mission lighting)
  112. //----------------------------------------------------------------------------
  113. class SetMissionCRCEvent : public NetEvent
  114. {
  115. private:
  116. U32 mCrc;
  117. public:
  118. typedef NetEvent Parent;
  119. SetMissionCRCEvent(U32 crc = 0xffffffff)
  120. { mCrc = crc; }
  121. void pack(NetConnection *, BitStream * bstream)
  122. { bstream->write(mCrc); }
  123. void write(NetConnection * con, BitStream * bstream)
  124. { pack(con, bstream); }
  125. void unpack(NetConnection *, BitStream * bstream)
  126. { bstream->read(&mCrc); }
  127. void process(NetConnection * con)
  128. { static_cast<GameConnection*>(con)->setMissionCRC(mCrc); }
  129. DECLARE_CONOBJECT(SetMissionCRCEvent);
  130. };
  131. #endif