Added generic serialized class and changed to random 128 bit IDs for objects

This commit is contained in:
Yousef Khadadeh 2025-12-08 14:28:01 +03:00
parent 35b46d9d2b
commit 5d24b34200
11 changed files with 113 additions and 69 deletions

View file

@ -0,0 +1,26 @@
#pragma once
#include <cstdint>
#include <array>
#include <Helpers/Random.hpp>
#include <Helpers/Hashes.hpp>
namespace NetworkingObjects {
struct NetObjID {
std::array<uint64_t, 2> data;
template <typename Archive> void serialize(Archive& a) {
a(data[1], data[0]);
}
NetObjID& operator=(const NetObjID&) = default;
bool operator==(const NetObjID&) const = default;
static NetObjID random_gen();
};
};
template <> struct std::hash<NetworkingObjects::NetObjID> {
size_t operator()(const NetworkingObjects::NetObjID& v) const
{
uint64_t h = 0;
hash_combine(h, v.data[1], v.data[0]);
return h;
}
};