载入中...
搜索中...
未找到
TagStore.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "tags/GameplayTag.h"
6
7#include <cstdint>
8#include <map>
9#include <set>
10#include <string>
11#include <vector>
12
13namespace eve::tags {
14
16using SubjectId = std::string;
17
20 std::uint64_t sequence = 0;
21 std::string action;
23 std::string value;
24};
25
28public:
30 bool addTag(const SubjectId& subject, const std::string& tag);
32 bool removeTag(const SubjectId& subject, const std::string& tag);
34 bool hasTag(const SubjectId& subject, const std::string& tag) const;
36 bool hasTagMatching(const SubjectId& subject, const std::string& tag, GameplayTagMatch match) const;
38 std::vector<std::string> tagsOf(const SubjectId& subject) const;
40 std::vector<SubjectId> subjectsWithTag(const std::string& tag) const;
42 std::vector<SubjectId> subjectsWithTagMatching(const std::string& tag, GameplayTagMatch match) const;
44 bool requireAllTags(const SubjectId& subject, const std::vector<std::string>& tags) const;
46 bool requireAnyTag(const SubjectId& subject, const std::vector<std::string>& tags) const;
48 bool matchesAllTags(const SubjectId& subject, const std::vector<std::string>& tags,
49 GameplayTagMatch match) const;
51 bool matchesAnyTag(const SubjectId& subject, const std::vector<std::string>& tags,
52 GameplayTagMatch match) const;
53
55 bool addCapability(const SubjectId& subject, const std::string& capability);
57 bool removeCapability(const SubjectId& subject, const std::string& capability);
59 bool hasCapability(const SubjectId& subject, const std::string& capability) const;
61 std::vector<std::string> capabilitiesOf(const SubjectId& subject) const;
63 bool requireAllCapabilities(const SubjectId& subject, const std::vector<std::string>& capabilities) const;
65 bool requireAnyCapability(const SubjectId& subject, const std::vector<std::string>& capabilities) const;
66
68 bool removeSubject(const SubjectId& subject);
70 void clear();
72 const std::vector<TagChangeEvent>& events() const { return events_; }
74 void clearEvents() { events_.clear(); }
75
76private:
77 using ValueSet = std::set<std::string>;
78 using Index = std::map<std::string, std::set<SubjectId>>;
79
80 bool mutate(std::map<SubjectId, ValueSet>& values, Index* reverse, const SubjectId& subject,
81 const std::string& value, bool add, const char* addedAction, const char* removedAction);
82 static std::vector<std::string> values(const ValueSet* set);
83 static bool requireAll(const ValueSet* held, const std::vector<std::string>& requested);
84 static bool requireAny(const ValueSet* held, const std::vector<std::string>& requested);
85 void emit(std::string action, SubjectId subject, std::string value);
86
87 std::map<SubjectId, ValueSet> tags_;
88 std::map<SubjectId, ValueSet> capabilities_;
89 Index subjectsByTag_;
90 std::vector<TagChangeEvent> events_;
91 std::uint64_t nextSequence_ = 1;
92};
93
94} // namespace eve::tags
double value
int subject
Definition AnimSmr.cpp:163
std::map< std::string, Var > values
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
Stable hierarchical gameplay-tag definitions and registry.
const std::string * tag
std::string action
Definition PlayHost.cpp:117
Deterministic storage for generic tags and capabilities.
Definition TagStore.h:27
void clearEvents()
Clears queued changes without changing tag state.
Definition TagStore.h:74
const std::vector< TagChangeEvent > & events() const
Returns queued changes in deterministic sequence order.
Definition TagStore.h:72
GameplayTagMatch
Selects exact or hierarchical descendant matching.
Definition GameplayTag.h:23
std::string SubjectId
Stable, game-defined identifier for an object carrying tags.
Definition TagStore.h:16
Immutable description of one tag or capability mutation.
Definition TagStore.h:19
std::uint64_t sequence
Definition TagStore.h:20