2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef ENGINE_SHARED_SNAPSHOT_H
|
|
|
|
#define ENGINE_SHARED_SNAPSHOT_H
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2022-05-29 12:03:16 +00:00
|
|
|
#include <stdint.h>
|
2007-08-22 18:40:31 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// CSnapshot
|
2009-10-27 14:38:53 +00:00
|
|
|
|
|
|
|
class CSnapshotItem
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
public:
|
|
|
|
int m_TypeAndID;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
int *Data() { return (int *)(this + 1); }
|
2021-02-08 21:26:26 +00:00
|
|
|
int Type() const { return m_TypeAndID >> 16; }
|
|
|
|
int ID() const { return m_TypeAndID & 0xffff; }
|
|
|
|
int Key() const { return m_TypeAndID; }
|
2007-08-22 07:52:33 +00:00
|
|
|
};
|
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
class CSnapshot
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
friend class CSnapshotBuilder;
|
|
|
|
int m_DataSize;
|
|
|
|
int m_NumItems;
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
int *Offsets() const { return (int *)(this + 1); }
|
|
|
|
char *DataStart() const { return (char *)(Offsets() + m_NumItems); }
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
OFFSET_UUID_TYPE = 0x4000,
|
|
|
|
MAX_TYPE = 0x7fff,
|
2022-01-14 16:52:23 +00:00
|
|
|
MAX_ID = 0xffff,
|
|
|
|
MAX_ITEMS = 1024,
|
2020-09-26 19:41:58 +00:00
|
|
|
MAX_PARTS = 64,
|
|
|
|
MAX_SIZE = MAX_PARTS * 1024
|
2009-10-27 14:38:53 +00:00
|
|
|
};
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
m_DataSize = 0;
|
|
|
|
m_NumItems = 0;
|
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
int NumItems() const { return m_NumItems; }
|
2021-02-08 21:26:26 +00:00
|
|
|
CSnapshotItem *GetItem(int Index) const;
|
|
|
|
int GetItemSize(int Index) const;
|
|
|
|
int GetItemIndex(int Key) const;
|
|
|
|
int GetItemType(int Index) const;
|
2021-11-07 00:02:20 +00:00
|
|
|
void *FindItem(int Type, int ID) const;
|
2009-10-27 14:38:53 +00:00
|
|
|
|
2020-10-10 10:30:02 +00:00
|
|
|
unsigned Crc();
|
2009-10-27 14:38:53 +00:00
|
|
|
void DebugDump();
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
2009-10-27 14:38:53 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// CSnapshotDelta
|
|
|
|
|
|
|
|
class CSnapshotDelta
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class CData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int m_NumDeletedItems;
|
|
|
|
int m_NumUpdateItems;
|
|
|
|
int m_NumTempItems; // needed?
|
2020-10-27 17:57:14 +00:00
|
|
|
int m_aData[1];
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2020-10-11 16:14:12 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
MAX_NETOBJSIZES = 64
|
|
|
|
};
|
|
|
|
short m_aItemSizes[MAX_NETOBJSIZES];
|
2022-01-14 16:52:23 +00:00
|
|
|
int m_aSnapshotDataRate[CSnapshot::MAX_TYPE + 1];
|
|
|
|
int m_aSnapshotDataUpdates[CSnapshot::MAX_TYPE + 1];
|
2010-05-29 07:25:38 +00:00
|
|
|
CData m_Empty;
|
|
|
|
|
2022-01-14 16:52:23 +00:00
|
|
|
static void UndiffItem(int *pPast, int *pDiff, int *pOut, int Size, int *pDataRate);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
public:
|
2017-09-12 12:58:44 +00:00
|
|
|
static int DiffItem(int *pPast, int *pCurrent, int *pOut, int Size);
|
2010-05-29 07:25:38 +00:00
|
|
|
CSnapshotDelta();
|
2020-10-27 17:57:14 +00:00
|
|
|
CSnapshotDelta(const CSnapshotDelta &Old);
|
2022-01-14 16:52:23 +00:00
|
|
|
int GetDataRate(int Index) const { return m_aSnapshotDataRate[Index]; }
|
|
|
|
int GetDataUpdates(int Index) const { return m_aSnapshotDataUpdates[Index]; }
|
2010-05-29 07:25:38 +00:00
|
|
|
void SetStaticsize(int ItemType, int Size);
|
2022-01-14 16:52:23 +00:00
|
|
|
const CData *EmptyDelta() const;
|
2022-01-22 13:12:59 +00:00
|
|
|
int CreateDelta(class CSnapshot *pFrom, class CSnapshot *pTo, void *pDstData);
|
|
|
|
int UnpackDelta(class CSnapshot *pFrom, class CSnapshot *pTo, const void *pSrcData, int DataSize);
|
2009-10-27 14:38:53 +00:00
|
|
|
};
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// CSnapshotStorage
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
class CSnapshotStorage
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
public:
|
|
|
|
class CHolder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CHolder *m_pPrev;
|
|
|
|
CHolder *m_pNext;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2021-06-23 05:05:49 +00:00
|
|
|
int64_t m_Tagtime;
|
2009-10-27 14:38:53 +00:00
|
|
|
int m_Tick;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
int m_SnapSize;
|
|
|
|
CSnapshot *m_pSnap;
|
|
|
|
CSnapshot *m_pAltSnap;
|
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
CHolder *m_pFirst;
|
|
|
|
CHolder *m_pLast;
|
|
|
|
|
2022-03-08 19:01:26 +00:00
|
|
|
CSnapshotStorage() { Init(); }
|
|
|
|
~CSnapshotStorage() { PurgeAll(); }
|
2009-10-27 14:38:53 +00:00
|
|
|
void Init();
|
|
|
|
void PurgeAll();
|
|
|
|
void PurgeUntil(int Tick);
|
2021-06-23 05:05:49 +00:00
|
|
|
void Add(int Tick, int64_t Tagtime, int DataSize, void *pData, int CreateAlt);
|
|
|
|
int Get(int Tick, int64_t *pTagtime, CSnapshot **ppData, CSnapshot **ppAltData);
|
2009-10-27 14:38:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CSnapshotBuilder
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-05-21 23:07:13 +00:00
|
|
|
MAX_EXTENDED_ITEM_TYPES = 64,
|
2009-10-27 14:38:53 +00:00
|
|
|
};
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
char m_aData[CSnapshot::MAX_SIZE];
|
|
|
|
int m_DataSize;
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2022-01-14 16:52:23 +00:00
|
|
|
int m_aOffsets[CSnapshot::MAX_ITEMS];
|
2009-10-27 14:38:53 +00:00
|
|
|
int m_NumItems;
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2017-05-21 23:07:13 +00:00
|
|
|
int m_aExtendedItemTypes[MAX_EXTENDED_ITEM_TYPES];
|
|
|
|
int m_NumExtendedItemTypes;
|
|
|
|
|
|
|
|
void AddExtendedItemType(int Index);
|
|
|
|
int GetExtendedItemTypeIndex(int TypeID);
|
|
|
|
|
2020-03-29 02:36:38 +00:00
|
|
|
bool m_Sixup;
|
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
public:
|
2017-05-21 23:07:13 +00:00
|
|
|
CSnapshotBuilder();
|
|
|
|
|
2020-03-29 02:36:38 +00:00
|
|
|
void Init(bool Sixup = false);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
void *NewItem(int Type, int ID, int Size);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
CSnapshotItem *GetItem(int Index);
|
|
|
|
int *GetItemData(int Key);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-10-27 17:57:14 +00:00
|
|
|
int Finish(void *pSnapdata);
|
2007-05-22 15:03:32 +00:00
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#endif // ENGINE_SNAPSHOT_H
|