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