TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TSparseArray Class Reference

#include <CascMndx.h>

Public Member Functions

 TSparseArray ()
 
void ExchangeWith (TSparseArray &TargetObject)
 
int LoadFromStream (TByteStream &InStream)
 
int LoadFromStream_Exchange (TByteStream &InStream)
 
DWORD IsItemPresent (DWORD ItemIndex)
 
DWORD GetItemValue (DWORD ItemIndex)
 

Public Attributes

TGenericArray ItemBits
 
DWORD TotalItemCount
 
DWORD ValidItemCount
 
TGenericArray BaseValues
 
TGenericArray ArrayDwords_38
 
TGenericArray ArrayDwords_50
 

Constructor & Destructor Documentation

TSparseArray::TSparseArray ( )
966 {
967  TotalItemCount = 0;
968  ValidItemCount = 0;
969 }
DWORD TotalItemCount
Definition: CascMndx.h:228
DWORD ValidItemCount
Definition: CascMndx.h:229

Member Function Documentation

void TSparseArray::ExchangeWith ( TSparseArray TargetObject)
973 {
974  TSparseArray WorkBuff;
975 
976  WorkBuff = *this;
977  *this = Target;
978  Target = WorkBuff;
979 }
Definition: CascMndx.h:209

+ Here is the caller graph for this function:

DWORD TSparseArray::GetItemValue ( DWORD  ItemIndex)
1035 {
1036  PTRIPLET pTriplet;
1037  DWORD DwordIndex;
1038  DWORD BaseValue;
1039  DWORD BitMask;
1040 
1041  //
1042  // Divide the low-8-bits index to four parts:
1043  //
1044  // |-----------------------|---|------------|
1045  // | A (23 bits) | B | C |
1046  // |-----------------------|---|------------|
1047  //
1048  // A (23-bits): Index to the table (60 bits per entry)
1049  //
1050  // Layout of the table entry:
1051  // |--------------------------------|-------|--------|--------|---------|---------|---------|---------|-----|
1052  // | Base Value | val[0]| val[1] | val[2] | val[3] | val[4] | val[5] | val[6] | - |
1053  // | 32 bits | 7 bits| 8 bits | 8 bits | 9 bits | 9 bits | 9 bits | 9 bits |5bits|
1054  // |--------------------------------|-------|--------|--------|---------|---------|---------|---------|-----|
1055  //
1056  // B (3 bits) : Index of the variable-bit value in the array (val[#], see above)
1057  //
1058  // C (32 bits): Number of bits to be checked (up to 0x3F bits).
1059  // Number of set bits is then added to the values obtained from A and B
1060 
1061  // Upper 23 bits contain index to the table
1062  pTriplet = BaseValues.TripletArray + (ItemIndex >> 0x09);
1063  BaseValue = pTriplet->BaseValue;
1064 
1065  // Next 3 bits contain the index to the VBR
1066  switch(((ItemIndex >> 0x06) & 0x07) - 1)
1067  {
1068  case 0: // Add the 1st value (7 bits)
1069  BaseValue += (pTriplet->Value2 & 0x7F);
1070  break;
1071 
1072  case 1: // Add the 2nd value (8 bits)
1073  BaseValue += (pTriplet->Value2 >> 0x07) & 0xFF;
1074  break;
1075 
1076  case 2: // Add the 3rd value (8 bits)
1077  BaseValue += (pTriplet->Value2 >> 0x0F) & 0xFF;
1078  break;
1079 
1080  case 3: // Add the 4th value (9 bits)
1081  BaseValue += (pTriplet->Value2 >> 0x17);
1082  break;
1083 
1084  case 4: // Add the 5th value (9 bits)
1085  BaseValue += (pTriplet->Value3 & 0x1FF);
1086  break;
1087 
1088  case 5: // Add the 6th value (9 bits)
1089  BaseValue += (pTriplet->Value3 >> 0x09) & 0x1FF;
1090  break;
1091 
1092  case 6: // Add the 7th value (9 bits)
1093  BaseValue += (pTriplet->Value3 >> 0x12) & 0x1FF;
1094  break;
1095  }
1096 
1097  //
1098  // Take the upper 27 bits as an index to DWORD array, take lower 5 bits
1099  // as number of bits to mask. Then calculate number of set bits in the value
1100  // masked value.
1101  //
1102 
1103  // Get the index into the array of DWORDs
1104  DwordIndex = (ItemIndex >> 0x05);
1105 
1106  // Add number of set bits in the masked value up to 0x3F bits
1107  if(ItemIndex & 0x20)
1108  BaseValue += GetNumbrOfSetBits32(ItemBits.Uint32Array[DwordIndex - 1]);
1109 
1110  BitMask = (1 << (ItemIndex & 0x1F)) - 1;
1111  return BaseValue + GetNumbrOfSetBits32(ItemBits.Uint32Array[DwordIndex] & BitMask);
1112 }
#define GetNumbrOfSetBits32(x)
Definition: CascRootFile_Mndx.cpp:249
DWORD BaseValue
Definition: CascMndx.h:27
DWORD Value3
Definition: CascMndx.h:29
TGenericArray BaseValues
Definition: CascMndx.h:230
DWORD Value2
Definition: CascMndx.h:28
unsigned int DWORD
Definition: CascPort.h:139
Definition: CascMndx.h:25
TGenericArray ItemBits
Definition: CascMndx.h:227

+ Here is the caller graph for this function:

DWORD TSparseArray::IsItemPresent ( DWORD  ItemIndex)
inline
221  {
222  return (ItemBits.Uint32Array[ItemIndex >> 0x05] & (1 << (ItemIndex & 0x1F)));
223  }
TGenericArray ItemBits
Definition: CascMndx.h:227

+ Here is the caller graph for this function:

int TSparseArray::LoadFromStream ( TByteStream InStream)
983 {
984  ARRAY_POINTER Pointer;
985  int nError;
986 
987  nError = ItemBits.LoadDwordsArray_Copy(InStream);
988  if(nError != ERROR_SUCCESS)
989  return nError;
990 
991  nError = InStream.GetBytes(sizeof(DWORD), &Pointer);
992  if(nError != ERROR_SUCCESS)
993  return nError;
994  TotalItemCount = Pointer.Uint32s[0];
995 
996  nError = InStream.GetBytes(sizeof(DWORD), &Pointer);
997  if(nError != ERROR_SUCCESS)
998  return nError;
999  ValidItemCount = Pointer.Uint32s[0];
1000 
1002  return ERROR_FILE_CORRUPT;
1003 
1004  nError = BaseValues.LoadTripletsArray_Copy(InStream);
1005  if(nError != ERROR_SUCCESS)
1006  return nError;
1007 
1008  nError = ArrayDwords_38.LoadDwordsArray_Copy(InStream);
1009  if(nError != ERROR_SUCCESS)
1010  return nError;
1011 
1012  nError = ArrayDwords_50.LoadDwordsArray_Copy(InStream);
1013  if(nError != ERROR_SUCCESS)
1014  return nError;
1015 
1016  return ERROR_SUCCESS;
1017 }
Definition: CascMndx.h:49
#define ERROR_FILE_CORRUPT
Definition: CascPort.h:218
int LoadDwordsArray_Copy(TByteStream &InStream)
Definition: CascRootFile_Mndx.cpp:758
TGenericArray ArrayDwords_50
Definition: CascMndx.h:232
TGenericArray BaseValues
Definition: CascMndx.h:230
PDWORD Uint32s
Definition: CascMndx.h:53
TGenericArray ArrayDwords_38
Definition: CascMndx.h:231
int GetBytes(DWORD cbByteCount, PARRAY_POINTER PtrArray)
Definition: CascRootFile_Mndx.cpp:347
unsigned int DWORD
Definition: CascPort.h:139
DWORD TotalItemCount
Definition: CascMndx.h:228
int LoadTripletsArray_Copy(TByteStream &InStream)
Definition: CascRootFile_Mndx.cpp:772
TGenericArray ItemBits
Definition: CascMndx.h:227
DWORD ValidItemCount
Definition: CascMndx.h:229
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int TSparseArray::LoadFromStream_Exchange ( TByteStream InStream)
1021 {
1022  TSparseArray NewStruct68;
1023  int nError;
1024 
1025  nError = NewStruct68.LoadFromStream(InStream);
1026  if(nError != ERROR_SUCCESS)
1027  return nError;
1028 
1029  ExchangeWith(NewStruct68);
1030  return ERROR_SUCCESS;
1031 }
Definition: CascMndx.h:209
int LoadFromStream(TByteStream &InStream)
Definition: CascRootFile_Mndx.cpp:982
void ExchangeWith(TSparseArray &TargetObject)
Definition: CascRootFile_Mndx.cpp:972
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

TGenericArray TSparseArray::ArrayDwords_38
TGenericArray TSparseArray::ArrayDwords_50
TGenericArray TSparseArray::BaseValues
TGenericArray TSparseArray::ItemBits
DWORD TSparseArray::TotalItemCount
DWORD TSparseArray::ValidItemCount

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