R-Type 0.1
Loading...
Searching...
No Matches
NetworkIdGenerator.hpp
1#pragma once
2
3#include <atomic>
4#include <cstdint>
5
6namespace rtype::server {
16private:
17 std::atomic<std::uint32_t> _nextId{1000};
18
19 NetworkIdGenerator() = default;
20
21public:
27 static NetworkIdGenerator instance;
28 return instance;
29 }
30
31 NetworkIdGenerator(const NetworkIdGenerator &) = delete;
32 NetworkIdGenerator &operator=(const NetworkIdGenerator &) = delete;
33
38 std::uint32_t getNextId() { return _nextId++; }
39};
40
42} // namespace rtype::server
Process wide source of unique network entity ids, starting at 1000.
Definition NetworkIdGenerator.hpp:15
static NetworkIdGenerator & getInstance()
Returns the single generator instance.
Definition NetworkIdGenerator.hpp:26
std::uint32_t getNextId()
Returns a new id, thread safe.
Definition NetworkIdGenerator.hpp:38