DDraceNetwork Docs
snapshot.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef ENGINE_SHARED_SNAPSHOT_H
4#define ENGINE_SHARED_SNAPSHOT_H
5
6#include <cstddef>
7#include <cstdint>
8
11
12// CSnapshot
13
15{
16 friend class CSnapshotBuilder;
17
18 int *Data() { return (int *)(this + 1); }
19
20public:
22
23 const int *Data() const { return (int *)(this + 1); }
24 int Type() const { return m_TypeAndId >> 16; }
25 int Id() const { return m_TypeAndId & 0xffff; }
26 int Key() const { return m_TypeAndId; }
27 void Invalidate() { m_TypeAndId = -1; }
28};
29
31{
32 friend class CSnapshotBuilder;
33 int m_DataSize = 0;
34 int m_NumItems = 0;
35
36 int *Offsets() const { return (int *)(this + 1); }
37 char *DataStart() const { return (char *)(Offsets() + m_NumItems); }
38
39 size_t OffsetSize() const { return sizeof(int) * m_NumItems; }
40 size_t TotalSize() const { return sizeof(CSnapshot) + OffsetSize() + m_DataSize; }
41
43
44public:
45 enum
46 {
48 MAX_TYPE = 0x7fff,
49 MAX_ID = 0xffff,
50 MAX_ITEMS = 1024,
52 MAX_SIZE = MAX_PARTS * 1024
53 };
54
55 int NumItems() const { return m_NumItems; }
56 const CSnapshotItem *GetItem(int Index) const;
57 int GetItemSize(int Index) const;
58 int GetItemIndex(int Key) const;
59 void InvalidateItem(int Index);
60 int GetItemType(int Index) const;
61 int GetExternalItemType(int InternalType) const;
62 const void *FindItem(int Type, int Id) const;
63
64 unsigned Crc() const;
65 void DebugDump() const;
66 bool IsValid(size_t ActualSize) const;
67
68 static const CSnapshot *EmptySnapshot() { return &ms_EmptySnapshot; }
69};
70
71// CSnapshotDelta
72
74{
75public:
76 class CData
77 {
78 public:
81 int m_NumTempItems; // needed?
82 int m_aData[1];
83 };
84
85private:
86 enum
87 {
89 };
95
96 static void UndiffItem(const int *pPast, const int *pDiff, int *pOut, int Size, uint64_t *pDataRate);
97
98public:
99 static int DiffItem(const int *pPast, const int *pCurrent, int *pOut, int Size);
101 CSnapshotDelta(const CSnapshotDelta &Old);
102 uint64_t GetDataRate(int Index) const { return m_aSnapshotDataRate[Index]; }
103 uint64_t GetDataUpdates(int Index) const { return m_aSnapshotDataUpdates[Index]; }
104 void SetStaticsize(int ItemType, size_t Size);
105 void SetStaticsize7(int ItemType, size_t Size);
106 const CData *EmptyDelta() const;
107 int CreateDelta(const CSnapshot *pFrom, const CSnapshot *pTo, void *pDstData);
108 int UnpackDelta(const CSnapshot *pFrom, CSnapshot *pTo, const void *pSrcData, int DataSize, bool Sixup);
109 int DebugDumpDelta(const void *pSrcData, int DataSize);
110};
111
112// CSnapshotStorage
113
115{
116public:
118 {
119 public:
122
123 int64_t m_Tagtime;
125
128
131 };
132
135
138 void Init();
139 void PurgeAll();
140 void PurgeUntil(int Tick);
141 void Add(int Tick, int64_t Tagtime, size_t DataSize, const void *pData, size_t AltDataSize, const void *pAltData);
142 int Get(int Tick, int64_t *pTagtime, const CSnapshot **ppData, const CSnapshot **ppAltData) const;
143};
144
146{
147 enum
148 {
150 };
151
154
157
160
161 bool AddExtendedItemType(int Index);
162 int GetExtendedItemTypeIndex(int TypeId);
163 int GetTypeFromIndex(int Index) const;
164
165 bool m_Sixup = false;
166
167public:
169
170 void Init(bool Sixup = false);
171 void Init7(const CSnapshot *pSnapshot);
172
173 void *NewItem(int Type, int Id, int Size);
174
175 CSnapshotItem *GetItem(int Index);
176 int *GetItemData(int Key);
177
178 int Finish(void *pSnapdata);
179};
180
181#endif // ENGINE_SNAPSHOT_H
Definition: snapshot.h:146
int m_NumItems
Definition: snapshot.h:156
int m_aExtendedItemTypes[MAX_EXTENDED_ITEM_TYPES]
Definition: snapshot.h:158
CSnapshotItem * GetItem(int Index)
Definition: snapshot.cpp:736
bool m_Sixup
Definition: snapshot.h:165
void Init(bool Sixup=false)
Definition: snapshot.cpp:724
char m_aData[CSnapshot::MAX_SIZE]
Definition: snapshot.h:152
@ MAX_EXTENDED_ITEM_TYPES
Definition: snapshot.h:149
int m_aOffsets[CSnapshot::MAX_ITEMS]
Definition: snapshot.h:155
int Finish(void *pSnapdata)
Definition: snapshot.cpp:754
int m_NumExtendedItemTypes
Definition: snapshot.h:159
CSnapshotBuilder()
Definition: snapshot.cpp:719
void * NewItem(int Type, int Id, int Size)
Definition: snapshot.cpp:812
int GetExtendedItemTypeIndex(int TypeId)
Definition: snapshot.cpp:791
int * GetItemData(int Key)
Definition: snapshot.cpp:741
int GetTypeFromIndex(int Index) const
Definition: snapshot.cpp:768
void Init7(const CSnapshot *pSnapshot)
Definition: sixup_translate_snapshot.cpp:5
int m_DataSize
Definition: snapshot.h:153
bool AddExtendedItemType(int Index)
Definition: snapshot.cpp:773
Definition: snapshot.h:77
int m_NumUpdateItems
Definition: snapshot.h:80
int m_aData[1]
Definition: snapshot.h:82
int m_NumTempItems
Definition: snapshot.h:81
int m_NumDeletedItems
Definition: snapshot.h:79
Definition: snapshot.h:74
int CreateDelta(const CSnapshot *pFrom, const CSnapshot *pTo, void *pDstData)
Definition: snapshot.cpp:294
CData m_Empty
Definition: snapshot.h:94
short m_aItemSizes7[MAX_NETOBJSIZES]
Definition: snapshot.h:91
const CData * EmptyDelta() const
Definition: snapshot.cpp:288
uint64_t GetDataUpdates(int Index) const
Definition: snapshot.h:103
static void UndiffItem(const int *pPast, const int *pDiff, int *pOut, int Size, uint64_t *pDataRate)
Definition: snapshot.cpp:233
void SetStaticsize(int ItemType, size_t Size)
Definition: snapshot.cpp:274
int UnpackDelta(const CSnapshot *pFrom, CSnapshot *pTo, const void *pSrcData, int DataSize, bool Sixup)
Definition: snapshot.cpp:509
uint64_t m_aSnapshotDataRate[CSnapshot::MAX_TYPE+1]
Definition: snapshot.h:92
int DebugDumpDelta(const void *pSrcData, int DataSize)
Definition: snapshot.cpp:377
static int DiffItem(const int *pPast, const int *pCurrent, int *pOut, int Size)
Definition: snapshot.cpp:216
uint64_t GetDataRate(int Index) const
Definition: snapshot.h:102
uint64_t m_aSnapshotDataUpdates[CSnapshot::MAX_TYPE+1]
Definition: snapshot.h:93
CSnapshotDelta()
Definition: snapshot.cpp:256
@ MAX_NETOBJSIZES
Definition: snapshot.h:88
void SetStaticsize7(int ItemType, size_t Size)
Definition: snapshot.cpp:281
short m_aItemSizes[MAX_NETOBJSIZES]
Definition: snapshot.h:90
Definition: snapshot.h:15
void Invalidate()
Definition: snapshot.h:27
int Id() const
Definition: snapshot.h:25
int m_TypeAndId
Definition: snapshot.h:21
const int * Data() const
Definition: snapshot.h:23
int Type() const
Definition: snapshot.h:24
int Key() const
Definition: snapshot.h:26
int * Data()
Definition: snapshot.h:18
Definition: snapshot.h:118
int m_Tick
Definition: snapshot.h:124
int m_SnapSize
Definition: snapshot.h:126
int m_AltSnapSize
Definition: snapshot.h:127
CHolder * m_pPrev
Definition: snapshot.h:120
CHolder * m_pNext
Definition: snapshot.h:121
CSnapshot * m_pAltSnap
Definition: snapshot.h:130
int64_t m_Tagtime
Definition: snapshot.h:123
CSnapshot * m_pSnap
Definition: snapshot.h:129
Definition: snapshot.h:115
~CSnapshotStorage()
Definition: snapshot.h:137
CSnapshotStorage()
Definition: snapshot.h:136
void PurgeAll()
Definition: snapshot.cpp:620
void Add(int Tick, int64_t Tagtime, size_t DataSize, const void *pData, size_t AltDataSize, const void *pAltData)
Definition: snapshot.cpp:660
void Init()
Definition: snapshot.cpp:614
void PurgeUntil(int Tick)
Definition: snapshot.cpp:633
CHolder * m_pLast
Definition: snapshot.h:134
int Get(int Tick, int64_t *pTagtime, const CSnapshot **ppData, const CSnapshot **ppAltData) const
Definition: snapshot.cpp:695
CHolder * m_pFirst
Definition: snapshot.h:133
Definition: snapshot.h:31
int GetExternalItemType(int InternalType) const
Definition: snapshot.cpp:38
static const CSnapshot * EmptySnapshot()
Definition: snapshot.h:68
int * Offsets() const
Definition: snapshot.h:36
const CSnapshotItem * GetItem(int Index) const
Definition: snapshot.cpp:18
size_t TotalSize() const
Definition: snapshot.h:40
char * DataStart() const
Definition: snapshot.h:37
int m_NumItems
Definition: snapshot.h:34
const void * FindItem(int Type, int Id) const
Definition: snapshot.cpp:74
int GetItemIndex(int Key) const
Definition: snapshot.cpp:58
int GetItemType(int Index) const
Definition: snapshot.cpp:32
@ MAX_ID
Definition: snapshot.h:49
@ MAX_ITEMS
Definition: snapshot.h:50
@ MAX_SIZE
Definition: snapshot.h:52
@ MAX_TYPE
Definition: snapshot.h:48
@ MAX_PARTS
Definition: snapshot.h:51
@ OFFSET_UUID_TYPE
Definition: snapshot.h:47
void InvalidateItem(int Index)
Definition: snapshot.cpp:69
void DebugDump() const
Definition: snapshot.cpp:122
unsigned Crc() const
Definition: snapshot.cpp:107
size_t OffsetSize() const
Definition: snapshot.h:39
bool IsValid(size_t ActualSize) const
Definition: snapshot.cpp:135
int m_DataSize
Definition: snapshot.h:33
int NumItems() const
Definition: snapshot.h:55
static const CSnapshot ms_EmptySnapshot
Definition: snapshot.h:42
int GetItemSize(int Index) const
Definition: snapshot.cpp:25