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
4#ifndef ENGINE_SERVER_SNAP_ID_POOL_H
5#define ENGINE_SERVER_SNAP_ID_POOL_H
6
7class CSnapIdPool
8{
9 enum
10 {
11 MAX_IDS = 32 * 1024,
12 };
13
14 // State of a Snap ID
15 enum
16 {
17 ID_FREE = 0,
18 ID_ALLOCATED = 1,
19 ID_TIMED = 2,
20 };
21
22 class CID
23 {
24 public:
25 short m_Next;
26 short m_State; // 0 = free, 1 = allocated, 2 = timed
27 int m_Timeout;
28 };
29
30 CID m_aIds[MAX_IDS];
31
32 int m_FirstFree;
33 int m_FirstTimed;
34 int m_LastTimed;
35 int m_Usage;
36 int m_InUsage;
37
38public:
39 CSnapIdPool();
40
41 void Reset();
42 void RemoveFirstTimeout();
43 int NewId();
44 void TimeoutIds();
45 void FreeId(int Id);
46};
47
48#endif
49