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
|
|
|
|
2008-08-14 17:19:13 +00:00
|
|
|
#include <base/system.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
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
int *Data() { return (int *)(this+1); }
|
|
|
|
int Type() { return m_TypeAndID>>16; }
|
|
|
|
int ID() { return m_TypeAndID&0xffff; }
|
|
|
|
int Key() { 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;
|
|
|
|
|
|
|
|
int *Offsets() const { return (int *)(this+1); }
|
|
|
|
char *DataStart() const { return (char*)(Offsets()+m_NumItems); }
|
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MAX_SIZE=64*1024
|
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void Clear() { m_DataSize = 0; m_NumItems = 0; }
|
|
|
|
int NumItems() const { return m_NumItems; }
|
2009-10-27 14:38:53 +00:00
|
|
|
CSnapshotItem *GetItem(int Index);
|
|
|
|
int GetItemSize(int Index);
|
|
|
|
int GetItemIndex(int Key);
|
|
|
|
|
|
|
|
int Crc();
|
|
|
|
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?
|
|
|
|
int m_pData[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
// TODO: strange arbitrary number
|
|
|
|
short m_aItemSizes[64];
|
|
|
|
int m_aSnapshotDataRate[0xffff];
|
|
|
|
int m_aSnapshotDataUpdates[0xffff];
|
|
|
|
int m_SnapshotCurrent;
|
|
|
|
CData m_Empty;
|
|
|
|
|
|
|
|
void UndiffItem(int *pPast, int *pDiff, int *pOut, int Size);
|
|
|
|
|
|
|
|
public:
|
|
|
|
CSnapshotDelta();
|
|
|
|
int GetDataRate(int Index) { return m_aSnapshotDataRate[Index]; }
|
|
|
|
int GetDataUpdates(int Index) { return m_aSnapshotDataUpdates[Index]; }
|
|
|
|
void SetStaticsize(int ItemType, int Size);
|
|
|
|
CData *EmptyDelta();
|
|
|
|
int CreateDelta(class CSnapshot *pFrom, class CSnapshot *pTo, void *pData);
|
|
|
|
int UnpackDelta(class CSnapshot *pFrom, class CSnapshot *pTo, void *pData, 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
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
int64 m_Tagtime;
|
|
|
|
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;
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
void PurgeAll();
|
|
|
|
void PurgeUntil(int Tick);
|
|
|
|
void Add(int Tick, int64 Tagtime, int DataSize, void *pData, int CreateAlt);
|
|
|
|
int Get(int Tick, int64 *Tagtime, CSnapshot **pData, CSnapshot **ppAltData);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CSnapshotBuilder
|
2007-08-22 07:52:33 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
enum
|
|
|
|
{
|
2011-01-18 17:09:09 +00:00
|
|
|
MAX_ITEMS = 1024
|
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
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
int m_aOffsets[MAX_ITEMS];
|
|
|
|
int m_NumItems;
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
public:
|
|
|
|
void Init();
|
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
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
int Finish(void *Snapdata);
|
2007-05-22 15:03:32 +00:00
|
|
|
};
|
|
|
|
|
2007-07-13 13:40:04 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#endif // ENGINE_SNAPSHOT_H
|