Files
sophia/engine/include/sophia/handles.hpp
T
2026-09-20 20:52:09 -07:00

38 lines
768 B
C++

#pragma once
#include <compare>
#include "sophia/types.hpp"
namespace sophia {
template <typename Tag>
struct Handle {
static constexpr u32 INVALID_INDEX = (1u << 20) - 1;
u32 index : 20 = INVALID_INDEX;
u32 generation : 12 = 1;
[[nodiscard]] static constexpr Handle invalid() {
return Handle{INVALID_INDEX, 0};
}
[[nodiscard]] constexpr bool isValid() const {
return index != INVALID_INDEX;
}
[[nodiscard]] auto operator<=>(const Handle&) const = default;
};
struct MeshTag {};
struct PanelTag {};
struct RenderTargetTag {};
struct SceneTag {};
using MeshHandle = Handle<MeshTag>;
using PanelHandle = Handle<PanelTag>;
using RenderTargetHandle = Handle<RenderTargetTag>;
using SceneHandle = Handle<SceneTag>;
} // namespace sophia