moveList.h

Engine/source/T3D/gameBase/moveList.h

More...

Classes:

Detailed Description

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