载入中...
搜索中...
未找到
AttributeProjection.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
16#include "common/ECS.h"
17#include "common/Result.h"
18#include "common/Revision.h"
19
20#include <span>
21#include <string>
22#include <string_view>
23#include <vector>
24
25namespace eve::attributes {
26
32
41 ecs::EntityHandle owner{};
43 std::vector<AttributeSnapshotBase> bases;
44 std::vector<AttributeModifier> modifiers;
45};
46
56public:
58 AttributeProjection(std::string subject = {});
59
61 [[nodiscard]] Result<void> bindOwner(ecs::EntityHandle owner);
62
64 [[nodiscard]] const ecs::EntityHandle& owner() const noexcept { return owner_; }
65
67 [[nodiscard]] Revision revision() const noexcept { return revision_; }
68
70 [[nodiscard]] bool isStale() const noexcept;
71
73 [[nodiscard]] bool initialized() const noexcept { return initialized_; }
74
79 [[nodiscard]] Result<void> initialize(std::span<const AttributeSnapshotBase> values);
80
82 [[nodiscard]] Result<void> setBase(std::string_view attribute, double value);
83
85 [[nodiscard]] Result<void> modifyBase(std::string_view attribute, double delta);
86
88 [[nodiscard]] Result<double> getFinal(std::string_view attribute, double fallback = 0.0) const;
89
91 [[nodiscard]] bool has(std::string_view attribute) const;
92
94 [[nodiscard]] Result<ModifierId> addModifier(AttributeModifier modifier);
95
97 [[nodiscard]] int modifierCount() const noexcept { return values_.modifierCount(); }
98
111 [[nodiscard]] const AttributeModifier* modifierAt(int index) const { return values_.modifierAt(index); }
112
117 [[nodiscard]] Result<AttributeProjectionSnapshot> snapshot(std::span<const std::string_view> attributes) const;
118
125 [[nodiscard]] Result<void> restore(const AttributeProjectionSnapshot& snapshot, Revision expectedRevision);
126
127private:
128 [[nodiscard]] Result<void> advanceRevision();
129 [[nodiscard]] bool ownsSameLiveEntity(ecs::EntityHandle owner) const noexcept;
130
131 AttributeSet values_;
132 ecs::EntityHandle owner_{};
133 Revision revision_ = Revision::zero();
134 bool initialized_ = false;
135};
136
138namespace source {
139inline constexpr std::string_view definition = "definition";
140inline constexpr std::string_view runtime = "runtime";
141inline constexpr std::string_view effect = "effect";
142inline constexpr std::string_view equipment = "equipment";
143} // namespace source
144
146namespace priority {
147inline constexpr ModifierPriority definition = 0;
148inline constexpr ModifierPriority runtime = 100;
149inline constexpr ModifierPriority effect = 200;
150inline constexpr ModifierPriority equipment = 300;
151} // namespace priority
152
153} // namespace eve::attributes
double value
int subject
Definition AnimSmr.cpp:163
int priority
std::map< std::string, Var > values
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
Move-only, checked operation results for the common layer.
Monotonic state revision for concurrency and change checks.
uint32_t index
const UnitySourceAsset & source
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Canonical selected-attribute storage with owner and revision checks.
const AttributeModifier * modifierAt(int index) const
Return a modifier in deterministic sequence order.
Revision revision() const noexcept
Return the monotonically changing content revision.
const ecs::EntityHandle & owner() const noexcept
Return the owner handle used for stale detection.
int modifierCount() const noexcept
Return the number of canonical modifiers currently retained.
Generic owning collection of canonical attributes and modifiers.
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
std::string AttributeId
std::int32_t ModifierPriority
One canonical runtime modifier applied to one named attribute.
Transaction-safe snapshot of selected attributes and their modifiers.
std::vector< AttributeModifier > modifiers
std::vector< AttributeSnapshotBase > bases
One base value captured by an attribute projection snapshot.