moveList.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 _MOVELIST_H_
  23. #define _MOVELIST_H_
  24. #ifndef _TVECTOR_H_
  25. #include "core/util/tVector.h"
  26. #endif
  27. #ifndef _MOVEMANAGER_H_
  28. #include "T3D/gameBase/moveManager.h"
  29. #endif
  30. class BitStream;
  31. class ResizeBitStream;
  32. class NetObject;
  33. class GameConnection;
  34. class PlayerRep;
  35. class ProcessList;
  36. class MoveList
  37. {
  38. public:
  39. MoveList();
  40. virtual ~MoveList() {}
  41. virtual void init() {}
  42. void setConnection( GameConnection *connection) { mConnection = connection; }
  43. /// @name Move Packets
  44. /// Write/read move data to the packet.
  45. /// @{
  46. virtual void ghostReadExtra( NetObject *, BitStream *, bool newGhost) {};
  47. virtual void ghostWriteExtra( NetObject *,BitStream * ) {};
  48. virtual void ghostPreRead( NetObject *, bool newGhost ) {};
  49. virtual void clientWriteMovePacket( BitStream *bstream ) = 0;
  50. virtual void clientReadMovePacket( BitStream * ) = 0;
  51. virtual void serverWriteMovePacket( BitStream * ) = 0;
  52. virtual void serverReadMovePacket( BitStream *bstream ) = 0;
  53. virtual void writeDemoStartBlock( ResizeBitStream *stream );
  54. virtual void readDemoStartBlock( BitStream *stream );
  55. /// @}
  56. virtual void advanceMove() = 0;
  57. virtual void onAdvanceObjects() = 0;
  58. virtual U32 getMoves( Move**, U32 *numMoves );
  59. /// Reset to beginning of client move list.
  60. void resetClientMoves() { mLastClientMove = mFirstMoveIndex; }
  61. /// Reset move list back to last acknowledged move.
  62. void resetCatchup() { mLastClientMove = mLastMoveAck; }
  63. virtual void collectMove();
  64. virtual void pushMove( const Move &mv );
  65. virtual void clearMoves( U32 count );
  66. virtual void markControlDirty() { mLastClientMove = mLastMoveAck; }
  67. bool isMismatch() { return mControlMismatch; }
  68. void clearMismatch() { mControlMismatch = false; }
  69. /// Clear out all moves in the list and reset to initial state.
  70. virtual void reset();
  71. /// If there are no pending moves and the input queue is full,
  72. /// then the connection to the server must be clogged.
  73. virtual bool isBacklogged();
  74. virtual bool areMovesPending();
  75. virtual void ackMoves( U32 count );
  76. protected:
  77. bool getNextMove( Move &curMove );
  78. protected:
  79. enum
  80. {
  81. MoveCountBits = 5,
  82. /// MaxMoveCount should not exceed the MoveManager's
  83. /// own maximum (MaxMoveQueueSize)
  84. MaxMoveCount = 30,
  85. };
  86. U32 mLastMoveAck;
  87. U32 mLastClientMove;
  88. U32 mFirstMoveIndex;
  89. bool mControlMismatch;
  90. GameConnection *mConnection;
  91. Vector<Move> mMoveVec;
  92. };
  93. #endif // _MOVELIST_H_