show alpha2 country code strings next to the flag in the country code selectors....
[twcon.git] / src / engine / shared / snapshot.h
blobebd13f202065e8b2f033c882b82d29150a695e3f
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
6 #include <base/system.h>
8 // CSnapshot
10 class CSnapshotItem
12 public:
13 int m_TypeAndID;
15 int *Data() { return (int *)(this+1); }
16 int Type() { return m_TypeAndID>>16; }
17 int ID() { return m_TypeAndID&0xffff; }
18 int Key() { return m_TypeAndID; }
22 class CSnapshot
24 friend class CSnapshotBuilder;
25 int m_DataSize;
26 int m_NumItems;
28 int *Offsets() const { return (int *)(this+1); }
29 char *DataStart() const { return (char*)(Offsets()+m_NumItems); }
31 public:
32 enum
34 MAX_SIZE=64*1024
37 void Clear() { m_DataSize = 0; m_NumItems = 0; }
38 int NumItems() const { return m_NumItems; }
39 CSnapshotItem *GetItem(int Index);
40 int GetItemSize(int Index);
41 int GetItemIndex(int Key);
43 int Crc();
44 void DebugDump();
48 // CSnapshotDelta
50 class CSnapshotDelta
52 public:
53 class CData
55 public:
56 int m_NumDeletedItems;
57 int m_NumUpdateItems;
58 int m_NumTempItems; // needed?
59 int m_pData[1];
62 private:
63 // TODO: strange arbitrary number
64 short m_aItemSizes[64];
65 int m_aSnapshotDataRate[0xffff];
66 int m_aSnapshotDataUpdates[0xffff];
67 int m_SnapshotCurrent;
68 CData m_Empty;
70 void UndiffItem(int *pPast, int *pDiff, int *pOut, int Size);
72 public:
73 CSnapshotDelta();
74 int GetDataRate(int Index) { return m_aSnapshotDataRate[Index]; }
75 int GetDataUpdates(int Index) { return m_aSnapshotDataUpdates[Index]; }
76 void SetStaticsize(int ItemType, int Size);
77 CData *EmptyDelta();
78 int CreateDelta(class CSnapshot *pFrom, class CSnapshot *pTo, void *pData);
79 int UnpackDelta(class CSnapshot *pFrom, class CSnapshot *pTo, void *pData, int DataSize);
83 // CSnapshotStorage
85 class CSnapshotStorage
87 public:
88 class CHolder
90 public:
91 CHolder *m_pPrev;
92 CHolder *m_pNext;
94 int64 m_Tagtime;
95 int m_Tick;
97 int m_SnapSize;
98 CSnapshot *m_pSnap;
99 CSnapshot *m_pAltSnap;
103 CHolder *m_pFirst;
104 CHolder *m_pLast;
106 void Init();
107 void PurgeAll();
108 void PurgeUntil(int Tick);
109 void Add(int Tick, int64 Tagtime, int DataSize, void *pData, int CreateAlt);
110 int Get(int Tick, int64 *Tagtime, CSnapshot **pData, CSnapshot **ppAltData);
113 class CSnapshotBuilder
115 enum
117 MAX_ITEMS = 1024
120 char m_aData[CSnapshot::MAX_SIZE];
121 int m_DataSize;
123 int m_aOffsets[MAX_ITEMS];
124 int m_NumItems;
126 public:
127 void Init();
129 void *NewItem(int Type, int ID, int Size);
131 CSnapshotItem *GetItem(int Index);
132 int *GetItemData(int Key);
134 int Finish(void *Snapdata);
138 #endif // ENGINE_SNAPSHOT_H