Shadowrun: Awakened 29 September 2011 - Build 871
Classes | Public Member Functions | Static Public Member Functions | Protected Attributes
RakNet::VariableListDeltaTracker Class Reference

#include <VariableListDeltaTracker.h>

List of all members.

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

Detailed Description

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.


Constructor & Destructor Documentation

RakNet::VariableListDeltaTracker::VariableListDeltaTracker ( )
RakNet::VariableListDeltaTracker::~VariableListDeltaTracker ( )

Member Function Documentation

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]
template<class VarType >
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().

    {
        bool wasWritten;
        if (bitStream->Read(wasWritten)==false)
            return false;
        if (wasWritten)
        {
            if (bitStream->Read(varData)==false)
                return false;
        }
        return wasWritten;
    }
void RakNet::VariableListDeltaTracker::StartWrite ( void  )
template<class VarType >
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)

Precondition:
Call StartWrite() before doing the first of a series of calls to WriteVar or other functions that call WriteVar
Note:
Variables must be of the same type, written in the same order, each time

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
    }
template<class VarType >
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 wasDifferent = WriteVar(varData);
        bitStream->Write(wasDifferent);
        if (wasDifferent)
        {
            bitStream->Write(varData);
            return true;
        }
        return false;
    }
template<class VarType >
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;
        }
    }

Member Data Documentation

Definition at line 127 of file VariableListDeltaTracker.h.

Referenced by IsPastEndOfList(), and WriteVar().

Definition at line 125 of file VariableListDeltaTracker.h.

Referenced by IsPastEndOfList(), and WriteVar().


The documentation for this class was generated from the following file:

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net