Torque3D Documentation / _generateds / connectionStringTable.h

connectionStringTable.h

Engine/source/sim/connectionStringTable.h

More...

Classes:

class

Maintain a table of strings which are shared across the network.

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 _H_CONNECTIONSTRINGTABLE
 25#define _H_CONNECTIONSTRINGTABLE
 26
 27/// Maintain a table of strings which are shared across the network.
 28///
 29/// This allows us to reference strings in our network streams more efficiently.
 30class ConnectionStringTable
 31{
 32public:
 33   enum Constants {
 34      EntryCount = 32,
 35      EntryBitSize = 5,
 36      InvalidEntryId = 32,
 37   };
 38private:
 39   struct Entry {
 40      NetStringHandle string;   ///< Global string table entry of this string
 41                             ///  will be 0 if this string is unused.
 42
 43      U32 index;             ///< index of this entry
 44      Entry *nextHash;       ///< the next hash entry for this id
 45      Entry *nextLink;       ///< the next in the LRU list
 46      Entry *prevLink;       ///< the prev entry in the LRU list
 47      bool receiveConfirmed; ///< The other side now has this string.
 48   };
 49
 50   Entry mEntryTable[EntryCount];
 51   Entry *mHashTable[EntryCount];
 52   NetStringHandle mRemoteStringTable[EntryCount];
 53   Entry mLRUHead, mLRUTail;
 54
 55   /// Connection over which we are maintaining this string table.
 56   NetConnection *mParent;
 57
 58   inline void pushBack(Entry *entry) // pushes an entry to the back of the LRU list
 59   {
 60      entry->prevLink->nextLink = entry->nextLink;
 61      entry->nextLink->prevLink = entry->prevLink;
 62      entry->nextLink = &mLRUTail;
 63      entry->prevLink = mLRUTail.prevLink;
 64      entry->nextLink->prevLink = entry;
 65      entry->prevLink->nextLink = entry;
 66   }
 67
 68public:
 69   /// Initialize the connection string table.
 70   ///
 71   /// @param  parent   Connection over which we are maintaining this string table.
 72   ConnectionStringTable(NetConnection *parent);
 73
 74   /// Has the specified string been received on the other side?
 75   inline void confirmStringReceived(NetStringHandle &string, U32 index)
 76   {
 77      if(mEntryTable[index].string == string)
 78         mEntryTable[index].receiveConfirmed = true;
 79   }
 80
 81   U32 checkString(NetStringHandle &stringTableId, bool *stringOnOtherSide = NULL);  ///< Checks if the global string ID is
 82                                                                                  ///  currently valid for this connection
 83                                                                                  ///  and returns the table ID.
 84                                                                                  ///  Sends a string event to the other side
 85                                                                                  ///  if it is not active.
 86                                                                                  ///  It will fill in stringOnOtherSide.
 87
 88   U32 getNetSendId(NetStringHandle &stringTableId); ///< Same return value as checkString
 89                                                  ///  but will assert if the string is not
 90                                                  ///  valid.
 91
 92   void mapString(U32 netId, NetStringHandle &string); ///< Maps a string that
 93                                                    ///  was just sent over the net
 94                                                    ///  to the corresponding net ID.
 95
 96   inline NetStringHandle lookupString(U32 netId) ///< looks up the string ID and returns
 97   {                                           /// the global string table ID for that string.
 98      return mRemoteStringTable[netId];
 99   }
100
101   /// @name Demo functionality
102   /// @{
103
104   void readDemoStartBlock(BitStream *stream);
105   void writeDemoStartBlock(ResizeBitStream *stream);
106   /// @}
107};
108
109#endif
110
111