载入中...
搜索中...
未找到
ResourceType.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <vector>
5
6namespace eve::economy {
7
8std::unordered_map<std::string, ResourceTypeDef>& ResourceTypeRegistry::types() {
9 static std::unordered_map<std::string, ResourceTypeDef> s_types;
10 return s_types;
11}
12
14 if (def.id.empty()) return false;
15 types()[def.id] = def;
16 return true;
17}
18
19const ResourceTypeDef* ResourceTypeRegistry::find(const std::string& id) {
20 auto& all = types();
21 auto it = all.find(id);
22 return it == all.end() ? nullptr : &it->second;
23}
24
25int ResourceTypeRegistry::count() { return static_cast<int>(types().size()); }
26
28 if (index < 0) return nullptr;
29 std::vector<const std::string*> ids;
30 ids.reserve(types().size());
31 for (const auto& entry : types()) ids.push_back(&entry.first);
32 if (index >= static_cast<int>(ids.size())) return nullptr;
33 std::sort(ids.begin(), ids.end(), [](const std::string* left, const std::string* right) { return *left < *right; });
34 return find(*ids[static_cast<std::size_t>(index)]);
35}
36
37void ResourceTypeRegistry::clear() { types().clear(); }
38
39} // namespace eve::economy
glm::uvec4 ids
HexVec3 left
HexVec3 right
float size
Definition TreeMesh.cpp:156
uint32_t index
static void clear()
清空注册表(测试用)。
static const ResourceTypeDef * find(const std::string &id)
按 id 查询;未注册时返回 nullptr。
static int count()
已注册类型数量。
static bool registerType(const ResourceTypeDef &def)
注册或替换一个资源类型定义。
static const ResourceTypeDef * typeAt(int index)
按 id 字典序返回第 index 个类型定义。
资源类型的静态定义(数据驱动配置的最小单元)。