slot 0.0.1
A real time UI render framework
载入中...
搜索中...
未找到
ResourceRef.h
浏览该文件的文档.
1#pragma once
2
3#include <cstdint>
4#include <functional>
5#include <limits>
6#include <string>
7#include <string_view>
8
9namespace z8 {
10enum class ResourceTy {
11 None,
12 Mesh,
15 Shader,
16 Texture,
17 Audio,
18};
19
20class Resource {
21public:
22 std::string Id;
24
25 virtual ~Resource() = default;
26 [[nodiscard]] bool IsValid() const { return !Id.empty(); }
27};
28
36template <typename ResourceTy> class ResourceRef {
37private:
38 static constexpr uint32_t Invalid = std::numeric_limits<uint32_t>::max();
39 std::string Id;
40
41public:
43
45 ResourceRef() = default;
49 explicit ResourceRef(std::string_view id) : Id(id) {}
50
52 [[nodiscard]] const std::string &GetId() const { return Id; }
54 [[nodiscard]] bool IsResolved() const { return Index != Invalid; }
56 [[nodiscard]] bool IsValid() const { return IsResolved() || !Id.empty(); }
57
59 bool operator==(const ResourceRef &other) const {
60 return Index == other.Index && Id == other.Id;
61 }
62
64 bool operator!=(const ResourceRef &other) const { return !(*this == other); }
65};
66
68template <typename ResourceTy> struct ResourceRefHash {
69 size_t operator()(const ResourceRef<ResourceTy> &reference) const noexcept {
70 const size_t index = std::hash<uint32_t>{}(reference.Index);
71 const size_t id = std::hash<std::string>{}(reference.GetId());
72 return index ^ (id << 1U);
73 }
74};
75
76} // namespace z8
Definition ResourceRef.h:20
std::string Id
Definition ResourceRef.h:22
bool IsValid() const
Definition ResourceRef.h:26
virtual ~Resource()=default
ResourceTy Type
Definition ResourceRef.h:23
资源的强类型引用,同时覆盖持久化 ID 与运行时索引两种边界。
Definition ResourceRef.h:36
uint32_t Index
Definition ResourceRef.h:42
bool operator==(const ResourceRef &other) const
Definition ResourceRef.h:59
ResourceRef(std::string_view id)
Definition ResourceRef.h:49
bool IsValid() const
Definition ResourceRef.h:56
std::string Id
Definition ResourceRef.h:39
bool operator!=(const ResourceRef &other) const
Definition ResourceRef.h:64
const std::string & GetId() const
Definition ResourceRef.h:52
static constexpr uint32_t Invalid
Definition ResourceRef.h:38
bool IsResolved() const
Definition ResourceRef.h:54
ResourceRef()=default
ResourceRef(uint32_t index)
Definition ResourceRef.h:47
世界矩阵 描述坐标系,左手坐标系 使用 DirectX12 坐标系的描述
Definition Application.h:15
ResourceTy
Definition ResourceRef.h:10
Definition ResourceRef.h:68
size_t operator()(const ResourceRef< ResourceTy > &reference) const noexcept
Definition ResourceRef.h:69