14 : m_scheduler(scheduler)
15 , m_event_manager(event_manager)
16 , m_index(Kinesis::make_spatial_index_3d(cell_size))
23 if (!reg.task_name.empty()) {
26 if (!reg.chain_name.empty()) {
29 if (!reg.event_name.empty()) {
44 if (emitter->m_position.has_value()) {
45 reg.spatial_id =
m_index->insert(*emitter->m_position);
48 return Wiring { *
this,
id };
56 if (sensor->m_position.has_value()) {
57 reg.spatial_id =
m_index->insert(*sensor->m_position);
60 return Wiring { *
this,
id };
68 if (agent->m_position.has_value()) {
69 reg.spatial_id =
m_index->insert(*agent->m_position);
72 return Wiring { *
this,
id };
82 auto& reg = it->second;
84 if (!reg.task_name.empty()) {
87 if (!reg.chain_name.empty()) {
90 if (!reg.event_name.empty()) {
93 if (reg.spatial_id.has_value()) {
94 m_index->remove(*reg.spatial_id);
102 std::vector<uint32_t> ids;
113 return std::visit([](
const auto& ptr) ->
Kind {
114 using T = std::decay_t<
decltype(*ptr)>;
115 if constexpr (std::is_same_v<T, Emitter>) {
117 }
else if constexpr (std::is_same_v<T, Sensor>) {
131 if (
auto* ptr = std::get_if<std::shared_ptr<Emitter>>(&it->second.member)) {
142 if (
auto* ptr = std::get_if<std::shared_ptr<Sensor>>(&it->second.member)) {
153 if (
auto* ptr = std::get_if<std::shared_ptr<Agent>>(&it->second.member)) {
166 if (reg.spatial_id.has_value()) {
167 std::visit([&](
const auto& ptr) {
168 if (ptr->m_position.has_value()) {
169 m_index->update(*reg.spatial_id, *ptr->m_position);
179 if (reg.commit_driven) {
190 "Fabric::fire: id {} not registered",
id);
201 const glm::vec3& center,
float radius)
const
207 const glm::vec3& center, uint32_t k)
const
209 return m_index->k_nearest(center, k);
218 return &*it->second.wiring;
228 std::visit([
id](
const auto& ptr) {
237 std::visit([&](
const auto& ptr) {
238 using T = std::decay_t<
decltype(*ptr)>;
240 if constexpr (std::is_same_v<T, Emitter>) {
242 if (ptr->m_position.has_value()) {
246 ctx.
radius = ptr->m_radius;
247 ctx.
color = ptr->m_color;
248 ctx.
size = ptr->m_size;
252 }
else if constexpr (std::is_same_v<T, Sensor>) {
254 if (ptr->m_position.has_value()) {
256 auto results =
m_index->within_radius(*ptr->m_position, ptr->m_query_radius);
261 }
else if constexpr (std::is_same_v<T, Agent>) {
262 if (ptr->m_position.has_value()) {
263 auto results =
m_index->within_radius(*ptr->m_position, ptr->m_query_radius);
267 ptr->invoke_perception(pctx);
272 ictx.
radius = ptr->m_radius;
273 ictx.
color = ptr->m_color;
274 ictx.
size = ptr->m_size;
276 ptr->invoke_influence(ictx);
281 ictx.
radius = ptr->m_radius;
282 ictx.
color = ptr->m_color;
283 ictx.
size = ptr->m_size;
285 ptr->invoke_influence(ictx);
#define MF_WARN(comp, ctx,...)
std::vector< Kinesis::QueryResult > k_nearest(const glm::vec3 ¢er, uint32_t k) const
Find the k nearest objects to a point.
std::shared_ptr< Sensor > get_sensor(uint32_t id) const
Get the Sensor registered under id.
std::vector< uint32_t > all_ids() const
List all registered entity ids in insertion order.
std::shared_ptr< Emitter::InfluenceFn > resolve_influence_fn(std::string_view name) const
Look up a registered influence function by name.
std::unique_ptr< Kinesis::SpatialIndex3D > m_index
std::variant< std::shared_ptr< Emitter >, std::shared_ptr< Sensor >, std::shared_ptr< Agent > > Member
void fire(uint32_t id)
Fire a single object against the current snapshot without republishing.
void remove(uint32_t id)
Remove a registered object by id, cancelling any associated tasks.
Fabric(Vruta::TaskScheduler &scheduler, Vruta::EventManager &event_manager, float cell_size=1.0F)
Construct with scheduler and event manager from the engine.
std::unordered_map< std::string, std::shared_ptr< Sensor::PerceptionFn > > m_perception_fns
std::shared_ptr< Sensor::PerceptionFn > resolve_perception_fn(std::string_view name) const
Look up a registered perception function by name.
std::shared_ptr< Agent > get_agent(uint32_t id) const
Get the Agent registered under id.
const Wiring * wiring_for(uint32_t id) const
Access the finalised wiring for an entity for introspection.
const std::string & name() const
Assigned name, empty if the Fabric was constructed outside a Tapestry.
Kind kind(uint32_t id) const
Return the kind of entity registered under id.
uint32_t assign_id(Member &m)
Vruta::TaskScheduler & m_scheduler
std::vector< Kinesis::QueryResult > within_radius(const glm::vec3 ¢er, float radius) const
Find all objects within a radius of a point.
std::shared_ptr< Emitter > get_emitter(uint32_t id) const
Get the Emitter registered under id.
Wiring wire(std::shared_ptr< Emitter > emitter)
Begin wiring an Emitter into the Fabric.
std::unordered_map< uint32_t, Registration > m_registrations
void commit()
Update all positions, publish the snapshot, fire all registered objects.
std::unordered_map< std::string, std::shared_ptr< Emitter::InfluenceFn > > m_influence_fns
Vruta::EventManager & m_event_manager
Fluent builder that wires an entity into Fabric's scheduling infrastructure.
bool cancel_event(const std::shared_ptr< Event > &event)
Cancels and removes a event from the manager.
bool cancel_task(const std::shared_ptr< Routine > &routine)
Cancels and removes a task from the scheduler.
Token-based multimodal task scheduling system for unified coroutine processing.
@ Runtime
General runtime operations (default fallback)
@ Nexus
Spatial indexing and scheduling for user-defined behaviour.
std::weak_ptr< Buffers::RenderProcessor > render_proc
glm::vec3 position
Position of the influence point in world space.
std::optional< glm::vec3 > color
Optional color hint for the influence, may be used for visualisation or shader effects.
std::optional< float > size
Optional size hint for the influence, may be used for visualisation or shader effects.
float intensity
Intensity of the influence, typically in the range [0, 1], but may exceed 1 for strong influences.
float radius
Radius of influence around the position, defining the area of effect for spatially-dependent influenc...
Data passed to an Emitter or Agent influence function on each commit.
std::span< const Kinesis::QueryResult > spatial_results
Data passed to a Sensor or Agent perception function on each commit.