![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
#include <VariableListDeltaTracker.h>
Classes | |
| struct | VariableLastValueNode |
Public Member Functions | |
| void | FlagDirtyFromBitArray (unsigned char *bArray) |
| bool | IsPastEndOfList (void) const |
| void | StartWrite (void) |
| VariableListDeltaTracker () | |
| template<class VarType > | |
| bool | WriteVar (const VarType &varData) |
| template<class VarType > | |
| bool | WriteVarToBitstream (const VarType &varData, RakNet::BitStream *bitStream, unsigned char *bArray, unsigned short writeOffset) |
| Calls WriteVarToBitstream(). Additionally, adds the boolean result of WriteVar() to boolean bit array. | |
| template<class VarType > | |
| bool | WriteVarToBitstream (const VarType &varData, RakNet::BitStream *bitStream) |
| Calls WriteVar. If the variable has changed, writes true, and writes the variable. Otherwise writes false. | |
| ~VariableListDeltaTracker () | |
Static Public Member Functions | |
| template<class VarType > | |
| static bool | ReadVarFromBitstream (const VarType &varData, RakNet::BitStream *bitStream) |
| Paired with a call to WriteVarToBitstream(), will read a variable if it had changed. Otherwise the values remains the same. | |
Protected Attributes | |
| unsigned int | nextWriteIndex |
| DataStructures::List < VariableLastValueNode > | variableList |
Class to write a series of variables, copy the contents to memory, and return if the newly written value is different than what was last written Can also encode the reads, writes, and results directly to/from a bitstream
Definition at line 10 of file VariableListDeltaTracker.h.
| RakNet::VariableListDeltaTracker::VariableListDeltaTracker | ( | ) |
| RakNet::VariableListDeltaTracker::~VariableListDeltaTracker | ( | ) |
| void RakNet::VariableListDeltaTracker::FlagDirtyFromBitArray | ( | unsigned char * | bArray | ) |
Variables flagged dirty will cause WriteVar() to return true, even if the variable had not otherwise changed This updates all the variables in the list, where in each index varsWritten is true, so will the variable at the corresponding index be flagged dirty
| bool RakNet::VariableListDeltaTracker::IsPastEndOfList | ( | void | ) | const [inline] |
Definition at line 19 of file VariableListDeltaTracker.h.
References nextWriteIndex, DataStructures::List< list_type >::Size(), and variableList.
Referenced by RakNet::VariableDeltaSerializer::SerializeVariable().
{return nextWriteIndex>=variableList.Size();}
| static bool RakNet::VariableListDeltaTracker::ReadVarFromBitstream | ( | const VarType & | varData, |
| RakNet::BitStream * | bitStream | ||
| ) | [inline, static] |
Definition at line 95 of file VariableListDeltaTracker.h.
References RakNet::BitStream::Read().
Referenced by RakNet::VariableDeltaSerializer::DeserializeVariable().
| void RakNet::VariableListDeltaTracker::StartWrite | ( | void | ) |
| bool RakNet::VariableListDeltaTracker::WriteVar | ( | const VarType & | varData | ) | [inline] |
Records the passed value of the variable to memory, and returns true if the value is different from the write before that (or if it is the first write)
Definition at line 25 of file VariableListDeltaTracker.h.
References _FILE_AND_LINE_, RakNet::BitStream::GetData(), RakNet::BitStream::GetNumberOfBytesUsed(), nextWriteIndex, DataStructures::List< list_type >::Push(), rakRealloc_Ex, DataStructures::List< list_type >::Size(), variableList, and RakNet::BitStream::Write().
Referenced by WriteVarToBitstream().
{
RakNet::BitStream temp;
temp.Write(varData);
if (nextWriteIndex>=variableList.Size())
{
variableList.Push(VariableLastValueNode(temp.GetData(),temp.GetNumberOfBytesUsed()),_FILE_AND_LINE_);
nextWriteIndex++;
return true; // Different because it's new
}
if (temp.GetNumberOfBytesUsed()!=variableList[nextWriteIndex].byteLength)
{
variableList[nextWriteIndex].lastData=(char*) rakRealloc_Ex(variableList[nextWriteIndex].lastData, temp.GetNumberOfBytesUsed(),_FILE_AND_LINE_);
variableList[nextWriteIndex].byteLength=temp.GetNumberOfBytesUsed();
memcpy(variableList[nextWriteIndex].lastData,temp.GetData(),temp.GetNumberOfBytesUsed());
nextWriteIndex++;
variableList[nextWriteIndex].isDirty=false;
return true; // Different because the serialized size is different
}
if (variableList[nextWriteIndex].isDirty==false && memcmp(temp.GetData(),variableList[nextWriteIndex].lastData, variableList[nextWriteIndex].byteLength)==0)
{
nextWriteIndex++;
return false; // Same because not dirty and memcmp is the same
}
variableList[nextWriteIndex].isDirty=false;
memcpy(variableList[nextWriteIndex].lastData,temp.GetData(),temp.GetNumberOfBytesUsed());
nextWriteIndex++;
return true; // Different because dirty or memcmp was different
}
| bool RakNet::VariableListDeltaTracker::WriteVarToBitstream | ( | const VarType & | varData, |
| RakNet::BitStream * | bitStream | ||
| ) | [inline] |
Definition at line 58 of file VariableListDeltaTracker.h.
References RakNet::BitStream::Write(), and WriteVar().
Referenced by RakNet::VariableDeltaSerializer::SerializeVariable(), and WriteVarToBitstream().
| bool RakNet::VariableListDeltaTracker::WriteVarToBitstream | ( | const VarType & | varData, |
| RakNet::BitStream * | bitStream, | ||
| unsigned char * | bArray, | ||
| unsigned short | writeOffset | ||
| ) | [inline] |
Definition at line 71 of file VariableListDeltaTracker.h.
References WriteVarToBitstream().
{
if (WriteVarToBitstream(varData,bitStream)==true)
{
BitSize_t numberOfBitsMod8 = writeOffset & 7;
if ( numberOfBitsMod8 == 0 )
bArray[ writeOffset >> 3 ] = 0x80;
else
bArray[ writeOffset >> 3 ] |= 0x80 >> ( numberOfBitsMod8 ); // Set the bit to 1
return true;
}
else
{
if ( ( writeOffset & 7 ) == 0 )
bArray[ writeOffset >> 3 ] = 0;
return false;
}
}
unsigned int RakNet::VariableListDeltaTracker::nextWriteIndex [protected] |
Definition at line 127 of file VariableListDeltaTracker.h.
Referenced by IsPastEndOfList(), and WriteVar().
DataStructures::List<VariableLastValueNode> RakNet::VariableListDeltaTracker::variableList [protected] |
Definition at line 125 of file VariableListDeltaTracker.h.
Referenced by IsPastEndOfList(), and WriteVar().
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.