载入中...
搜索中...
未找到
CrowdInteraction.cpp
浏览该文件的文档.
1#include <unordered_set>
2#include "common/Profile.h"
4
5// CrowdInteraction.cpp
6namespace eve::crowd {
7
9 return {policy.pushability, policy.holdPosition, policy.layer, policy.mask, policy.layer, policy.mask};
10}
11
13 return std::isfinite(policy.pushability) && policy.pushability >= 0.f && policy.pushability <= 1.f &&
14 policy.avoidanceLayer >= 0 && policy.avoidanceMask >= 0 && policy.contactLayer >= 0 &&
15 policy.contactMask >= 0;
16}
17
23
25 const int slot = impl_->resolveAgent(reference);
26 if (slot < 0)
27 return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "Crowd agent not found", "reference"));
28 if (!validInteraction(policy))
30 Diagnostic::error(DiagnosticCode::InvalidArgument, "Invalid crowd interaction policy", "policy"));
31 const size_t index = size_t(slot);
32 impl_->interactions[index] = policy;
33 if (policy.holdPosition) {
34 impl_->vxs[index] = impl_->vys[index] = impl_->speeds[index] = 0.f;
35 }
37}
38
40 if (!impl_->validId(id))
42 Diagnostic::error(DiagnosticCode::NotFound, "Crowd agent not found", "id"));
43 const auto policy = impl_->interactions[size_t(id)];
45 {policy.pushability, policy.holdPosition, policy.contactLayer, policy.contactMask});
46}
47
49 const int slot = impl_->resolveAgent(reference);
50 if (slot < 0)
52 Diagnostic::error(DiagnosticCode::NotFound, "Crowd agent not found", "reference"));
53 return Result<InteractionPolicy>::success(impl_->interactions[std::size_t(slot)]);
54}
55
56} // namespace eve::crowd
AuthorityStoreHandleRef reference
Definition Authority.cpp:24
std::string slot
uint32_t index
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
Result< void > setInteractionPolicy(AgentRef reference, InteractionPolicy policy)
Atomically replace independent steering/contact rules by owner-qualified identity.
Result< InteractionPolicy > readInteractionPolicy(AgentRef reference) const
Read an owning canonical policy snapshot; stale or wrong-owner references return NotFound....
Result< void > setAgentInteraction(int id, AgentInteraction policy)
Atomically replace the local interaction policy for a current compact slot.
Result< AgentInteraction > getAgentInteraction(int id) const
Read an owning policy snapshot, or NotFound for an invalid compact slot. @thread Simulation thread on...
Result< AgentRef > agentRef(int slot) const
Resolve a compatibility dense slot to an owning identity value.
bool validInteraction(InteractionPolicy policy)
Check finite mobility and nonnegative filter masks without modifying state.
InteractionPolicy canonicalInteraction(AgentInteraction policy)
Normalize a compatibility filter into the canonical two-filter policy.
Independent local interaction policy, copied into Crowd storage.
Definition Crowd.h:137
float pushability
Relative contact mobility in [0,1]; zero cannot be pushed by agents.
Definition Crowd.h:138
int mask
Both agents must accept the other's layer for interaction.
Definition Crowd.h:141
int layer
Non-negative membership bit mask; zero disables agent interaction.
Definition Crowd.h:140
bool holdPosition
Suppress locomotion and agent pushes; terrain constraints still apply.
Definition Crowd.h:139
Agent identity qualified by the Crowd instance that owns its registry. @ownership Value only; it neit...
Definition CrowdTypes.h:90
Canonical independent predictive-steering and body-contact policy; both filters are symmetric.
Definition Crowd.h:145