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