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