载入中...
搜索中...
未找到
SocialGraph.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <cstdint>
6#include <map>
7#include <optional>
8#include <string>
9#include <tuple>
10#include <vector>
11
12namespace eve::social {
13
15using EntityId = std::string;
16
19 std::uint64_t sequence = 0;
20 std::string action;
23 std::string type;
24 double oldValue = 0.0;
25 double newValue = 0.0;
26};
27
35public:
37 static EntityId integerId(std::int64_t id);
38
40 bool setOwner(const EntityId& entity, const EntityId& owner);
42 EntityId ownerOf(const EntityId& entity) const;
44 std::vector<EntityId> ownedBy(const EntityId& owner) const;
45
47 bool setController(const EntityId& entity, const EntityId& controller);
49 EntityId controllerOf(const EntityId& entity) const;
51 std::vector<EntityId> controlledBy(const EntityId& controller) const;
52
54 bool assign(const EntityId& source, const std::string& role, const EntityId& target);
56 bool unassign(const EntityId& source, const std::string& role, const EntityId& target);
58 bool isAssigned(const EntityId& source, const std::string& role, const EntityId& target) const;
60 std::vector<EntityId> targetsOf(const EntityId& source, const std::string& role) const;
62 std::vector<EntityId> assigneesOf(const EntityId& target, const std::string& role) const;
63
65 bool setRelation(const EntityId& source, const EntityId& target, const std::string& type, double value);
67 double addRelation(const EntityId& source, const EntityId& target, const std::string& type, double delta);
69 bool link(const EntityId& source, const EntityId& target, const std::string& type);
71 bool removeRelation(const EntityId& source, const EntityId& target, const std::string& type);
73 bool hasRelation(const EntityId& source, const EntityId& target, const std::string& type) const;
75 double relation(const EntityId& source, const EntityId& target, const std::string& type,
76 double fallback = 0.0) const;
78 std::vector<EntityId> relationTargets(const EntityId& source, const std::string& type, double minimum = 0.0) const;
80 std::vector<EntityId> relationSources(const EntityId& target, const std::string& type, double minimum = 0.0) const;
81
83 bool removeEntity(const EntityId& entity);
85 void clear();
86
88 const std::vector<SocialChangeEvent>& events() const { return events_; }
90 void clearEvents() { events_.clear(); }
91
92private:
93 using EntitySet = std::map<EntityId, bool>;
94 using PairKey = std::pair<EntityId, std::string>;
95 using EdgeKey = std::tuple<EntityId, EntityId, std::string>;
96
97 void emit(std::string action, EntityId source = {}, EntityId target = {}, std::string type = {},
98 double oldValue = 0.0, double newValue = 0.0);
99 static std::vector<EntityId> values(const EntitySet* set);
100
101 std::map<EntityId, EntityId> owners_;
102 std::map<EntityId, EntitySet> owned_;
103 std::map<EntityId, EntityId> controllers_;
104 std::map<EntityId, EntitySet> controlled_;
105 std::map<PairKey, EntitySet> assignmentTargets_;
106 std::map<PairKey, EntitySet> assignmentSources_;
107 std::map<EdgeKey, double> relations_;
108 std::map<PairKey, EntitySet> relationTargets_;
109 std::map<PairKey, EntitySet> relationSources_;
110 std::vector<SocialChangeEvent> events_;
111 std::uint64_t nextSequence_ = 1;
112};
113
114} // namespace eve::social
LogicalId target
double value
std::map< std::string, Var > values
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
float minimum[3]
std::string action
Definition PlayHost.cpp:117
const UnitySourceAsset & source
Indexed ownership, control, assignment, and typed-relation graph.
Definition SocialGraph.h:34
void clearEvents()
Clears queued events without changing graph state.
Definition SocialGraph.h:90
const std::vector< SocialChangeEvent > & events() const
Returns queued mutation events in sequence order.
Definition SocialGraph.h:88
std::string EntityId
Stable, game-defined identifier used by the social graph.
Definition SocialGraph.h:15
Immutable description of one social graph mutation.
Definition SocialGraph.h:18