载入中...
搜索中...
未找到
SceneLink.cpp
浏览该文件的文档.
1#include "scene/SceneLink.h"
2
3#include <cstring>
4#include <string>
5#include <vector>
6
7namespace eve::scene {
8namespace {
9
10struct Entry {
11 std::string name;
12 LinkOps ops;
13};
14
20std::vector<Entry>& table() {
21 static std::vector<Entry> t;
22 return t;
23}
24
25} // namespace
26
28 if (!ops.kind || !ops.pushWorld) return -1;
29 const int existing = findLinkKind(ops.kind);
30 if (existing >= 0) return existing;
31 table().push_back({ops.kind, ops});
32 // Point the stored ops at our own copy of the name so a caller may pass a
33 // temporary.
34 Entry& e = table().back();
35 e.ops.kind = e.name.c_str();
36 return int(table().size()) - 1;
37}
38
39int findLinkKind(const char* kind) {
40 if (!kind) return -1;
41 const auto& t = table();
42 for (size_t i = 0; i < t.size(); ++i)
43 if (t[i].name == kind) return int(i);
44 return -1;
45}
46
47const LinkOps* linkOps(int kindId) {
48 const auto& t = table();
49 if (kindId < 0 || size_t(kindId) >= t.size()) return nullptr;
50 return &t[size_t(kindId)].ops;
51}
52
53const char* linkKindName(int kindId) {
54 const LinkOps* ops = linkOps(kindId);
55 return ops ? ops->kind : "";
56}
57
58} // namespace eve::scene
Tok kind
const char * name
Definition RockMesh.cpp:21
const LinkOps * linkOps(int kindId)
Definition SceneLink.cpp:47
const char * linkKindName(int kindId)
Definition SceneLink.cpp:53
int registerLinkKind(const LinkOps &ops)
Definition SceneLink.cpp:27
int findLinkKind(const char *kind)
Definition SceneLink.cpp:39
void(* pushWorld)(const SceneNode &node, void *target)
Definition SceneLink.h:32
const char * kind
Definition SceneLink.h:29