MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ evaluate()

void MayaFlux::Nexus::Expanse::evaluate ( uint32_t  fabric_id,
std::span< const std::pair< uint32_t, glm::vec3 > >  snapshot 
)

Evaluate a spatial snapshot from one Fabric against this Expanse.

Tests each position in snapshot with contains(), diffs the result against the previous occupant set for fabric_id, fires the entry and exit actions for the difference and the inside actions for everything inside, and updates the stored set. Each Fabric maintains independent occupant state.

Parameters
fabric_idStable id of the calling Fabric.
snapshotEntity id and position of every positioned entity in that Fabric.

Definition at line 33 of file Expanse.cpp.

35{
37
38 auto& prev = m_occupants_by_fabric[fabric_id];
39
40 std::unordered_set<uint32_t> inside;
41 for (const auto& [eid, pos] : snapshot) {
42 if (contains(pos))
43 inside.insert(eid);
44 }
45
46 if (!m_perceptions.empty()) {
47 const auto [center, radius] = reach();
48
49 std::vector<Kinesis::QueryResult> occupants;
50 occupants.reserve(inside.size());
51 for (const auto& [eid, pos] : snapshot) {
52 if (inside.contains(eid)) {
53 const glm::vec3 offset = pos - center;
54 occupants.push_back({ .id = eid, .distance_sq = glm::dot(offset, offset) });
55 }
56 }
57
58 const PerceptionContext pctx { .position = center, .radius = radius, .spatial_results = occupants };
59 for (const auto& [handle, perception] : m_perceptions)
60 perception(pctx);
61 }
62
63 for (const auto& [eid, pos] : snapshot) {
64 if (!inside.contains(eid))
65 continue;
66
67 const CrossingContext ctx { .fabric_id = fabric_id, .entity = eid, .position = pos };
68
69 if (!prev.contains(eid)) {
70 if (m_on_enter)
71 m_on_enter(eid);
72 for (const auto& [handle, action] : m_entries)
73 action(ctx);
74 }
75
76 for (const auto& [handle, action] : m_insides)
77 action(ctx);
78 }
79
80 std::unordered_map<uint32_t, glm::vec3> where;
81 if (!m_exits.empty() && !prev.empty()) {
82 where.reserve(snapshot.size());
83 for (const auto& [eid, pos] : snapshot)
84 where.emplace(eid, pos);
85 }
86
87 for (uint32_t eid : prev) {
88 if (inside.contains(eid))
89 continue;
90
91 if (m_on_exit)
92 m_on_exit(eid);
93
94 if (m_exits.empty())
95 continue;
96
97 CrossingContext ctx { .fabric_id = fabric_id, .entity = eid };
98 if (const auto it = where.find(eid); it != where.end())
99 ctx.position = it->second;
100 for (const auto& [handle, action] : m_exits)
101 action(ctx);
102 }
103
104 if (inside.empty()) {
105 m_occupants_by_fabric.erase(fabric_id);
106 } else {
107 prev = std::move(inside);
108 }
109}
uint64_t offset
Definition Composite.cpp:10
Expanse::ContainsFn contains
Definition Decoder.cpp:517
float radius
const std::unordered_set< uint32_t > * occupants(uint32_t fabric_id) const
Entity ids inside this Expanse for fabric_id, or nullptr if that fabric has no occupants.
Definition Expanse.hpp:177
std::unordered_map< uint32_t, std::unordered_set< uint32_t > > m_occupants_by_fabric
Definition Expanse.hpp:354
std::vector< std::pair< std::shared_ptr< void >, PerceptionFn > > m_perceptions
Definition Expanse.hpp:349
virtual std::pair< glm::vec3, float > reach() const
Where the region is centred and how far it reaches, for perceptions.
Definition Expanse.hpp:314
virtual void begin_evaluate()
Called at the start of every evaluate(), before any position is tested.
Definition Expanse.hpp:306

References begin_evaluate(), contains, MayaFlux::Nexus::CrossingContext::fabric_id, m_entries, m_exits, m_insides, m_occupants_by_fabric, m_on_enter, m_on_exit, m_perceptions, occupants(), offset, MayaFlux::Nexus::PerceptionContext::position, radius, and reach().

+ Here is the call graph for this function: