Thread: [Opentnl-cvs] tnl/tnl byteBuffer.cpp,1.1,1.2 tnlBitStream.h,1.1,1.2 tnlByteBuffer.h,1.1,1.2
Brought to you by:
mark_frohnmayer,
s_alanet
From: Mark F. <mar...@us...> - 2004-04-22 20:42:33
|
Update of /cvsroot/opentnl/tnl/tnl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23137/tnl Modified Files: byteBuffer.cpp tnlBitStream.h tnlByteBuffer.h Log Message: Reduced bandwidth usage of ship updates Does not send server state of control object if it is unchanged on client Added CRC capability to ByteBuffer class Index: byteBuffer.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/tnl/byteBuffer.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** byteBuffer.cpp 20 Apr 2004 04:27:18 -0000 1.1 --- byteBuffer.cpp 22 Apr 2004 20:42:25 -0000 1.2 *************** *** 49,52 **** --- 49,87 ---- } + U32 ByteBuffer::calculateCRC(U32 start, U32 end, U32 crcVal) const + { + static U32 crcTable[256]; + static bool crcTableValid = false; + + if(!crcTableValid) + { + U32 val; + + for(S32 i = 0; i < 256; i++) + { + val = i; + for(S32 j = 0; j < 8; j++) + { + if(val & 0x01) + val = 0xedb88320 ^ (val >> 1); + else + val = val >> 1; + } + crcTable[i] = val; + } + crcTableValid = true; + } + + if(start >= mBufSize) + return 0; + if(end > mBufSize) + end = mBufSize; + + // now calculate the crc + const U8 * buf = getBuffer(); + for(U32 i = start; i < end; i++) + crcVal = crcTable[(crcVal ^ buf[i]) & 0xff] ^ (crcVal >> 8); + return(crcVal); + } }; Index: tnlBitStream.h =================================================================== RCS file: /cvsroot/opentnl/tnl/tnl/tnlBitStream.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tnlBitStream.h 20 Apr 2004 04:27:18 -0000 1.1 --- tnlBitStream.h 22 Apr 2004 20:42:25 -0000 1.2 *************** *** 114,117 **** --- 114,120 ---- void advanceBitPosition(const S32 numBits); + /// Pads the bits up to the next byte boundary with 0's. + void zeroToByteBoundary(); + /// Writes an unsigned integer value between 0 and 2^(bitCount - 1) into the stream. void writeInt(U32 value, U8 bitCount); *************** *** 291,294 **** --- 294,303 ---- } + inline void BitStream::zeroToByteBoundary() + { + if(bitNum & 0x7) + writeInt(0, 8 - (bitNum & 0x7)); + } + inline bool BitStream::write(const U32 in_numBytes, const void* in_pBuffer) { Index: tnlByteBuffer.h =================================================================== RCS file: /cvsroot/opentnl/tnl/tnl/tnlByteBuffer.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tnlByteBuffer.h 20 Apr 2004 04:27:18 -0000 1.1 --- tnlByteBuffer.h 22 Apr 2004 20:42:25 -0000 1.2 *************** *** 170,173 **** --- 170,176 ---- /// Decode the buffer from base 64, in place. Resizes the buffer. RefPtr<ByteBuffer> decodeBase64() const; + + /// Returns a 32 bit CRC for the buffer. + U32 calculateCRC(U32 start = 0, U32 end = 0xFFFFFFFF, U32 crcVal = 0xFFFFFFFF) const; }; |