// // Created by atdunbg on 2026/9/22. // // UUID:64 位随机唯一标识,实体的稳定外部身份。 // // 用途:序列化、跨场景引用、编辑器对象选择——这些场景需要 // "实体销毁重建后 ID 不变"或"独立于槽位分配"的稳定标识。 // ECS 内部遍历仍用 (index, generation) 句柄(性能),UUID 只做外部身份。 // #ifndef HELLOVULKAN_UUID_H #define HELLOVULKAN_UUID_H #include #include #include namespace Engine { struct UUID { UUID() = default; explicit UUID(u64 value) : m_Value(value) {} // 生成全局唯一 ID(非确定性种子,跨进程不重复) static UUID New() { static std::mt19937_64 rng{std::random_device{}()}; return UUID{rng()}; } u64 Value() const { return m_Value; } bool Valid() const { return m_Value != 0; } bool operator==(const UUID& o) const = default; bool operator!=(const UUID& o) const = default; private: u64 m_Value = 0; // 0 保留为"无效" }; } // namespace Engine namespace std { template<> struct hash { size_t operator()(const Engine::UUID& id) const noexcept { return std::hash{}(id.Value()); } }; } #endif //HELLOVULKAN_UUID_H