MCPcopy Create free account
hub / github.com/ddnet/ddnet / AddItem

Method AddItem

src/engine/shared/datafile.cpp:1034–1084  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1032}
1033
1034int CDataFileWriter::AddItem(int Type, int Id, size_t Size, const void *pData, const CUuid *pUuid)
1035{
1036 dbg_assert((Type >= 0 && Type <= MAX_ITEM_TYPE) || Type >= OFFSET_UUID || (Type == -1 && pUuid != nullptr), "Invalid Type: %d", Type);
1037 dbg_assert(Id >= 0 && Id <= MAX_ITEM_ID, "Invalid Id: %d", Id);
1038 dbg_assert(Size == 0 || pData != nullptr, "Data missing"); // Items without data are allowed
1039 dbg_assert(Size <= (size_t)std::numeric_limits<int>::max(), "Data too large");
1040 dbg_assert(Size % sizeof(int) == 0, "Invalid data boundary");
1041 dbg_assert(m_vItems.size() < (size_t)std::numeric_limits<int>::max(), "Too many items");
1042
1043 if(Type == -1 || Type >= OFFSET_UUID)
1044 {
1045 Type = GetTypeFromIndex(GetExtendedItemTypeIndex(Type, pUuid));
1046 }
1047
1048 const int NumItems = m_vItems.size();
1049 m_vItems.emplace_back();
1050 CItemInfo &Info = m_vItems.back();
1051 Info.m_Type = Type;
1052 Info.m_Id = Id;
1053 Info.m_Size = Size;
1054
1055 // copy data
1056 if(Size > 0)
1057 {
1058 Info.m_pData = malloc(Size);
1059 mem_copy(Info.m_pData, pData, Size);
1060 }
1061 else
1062 {
1063 Info.m_pData = nullptr;
1064 }
1065
1066 // link
1067 CItemTypeInfo &ItemType = m_ItemTypes[Type];
1068 Info.m_Prev = ItemType.m_Last;
1069 Info.m_Next = -1;
1070
1071 if(ItemType.m_Last != -1)
1072 {
1073 m_vItems[ItemType.m_Last].m_Next = NumItems;
1074 }
1075 ItemType.m_Last = NumItems;
1076
1077 if(ItemType.m_First == -1)
1078 {
1079 ItemType.m_First = NumItems;
1080 }
1081
1082 ItemType.m_Num++;
1083 return NumItems;
1084}
1085
1086int CDataFileWriter::AddData(size_t Size, const void *pData, ECompressionLevel CompressionLevel)
1087{

Callers 10

SaveMethod · 0.80
OnMapChangeMethod · 0.80
ResaveMapFunction · 0.80
ProcessFunction · 0.80
mainFunction · 0.80
SaveOutputMapFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
CreateEmptyMapFunction · 0.80
TESTFunction · 0.80

Calls 1

mem_copyFunction · 0.85

Tested by 1

TESTFunction · 0.64