MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Nexus::Presence Class Reference

Agent that affects its surroundings by being there. More...

#include <Presence.hpp>

+ Inheritance diagram for MayaFlux::Nexus::Presence:
+ Collaboration diagram for MayaFlux::Nexus::Presence:

Public Types

enum class  FalloffCurve : uint8_t { Linear , Cosine , Exponential , InverseSquare }
 Built-in falloff curves that survive state encode/decode. More...
 
using FalloffFn = std::function< float(float)>
 Falloff curve mapping normalized distance to weight.
 
using RadiateFn = std::function< void(uint32_t id, float weight)>
 Per-neighbor radiation callable.
 
- Public Types inherited from MayaFlux::Nexus::Agent
using InfluenceFn = std::function< void(const InfluenceContext &)>
 
using PerceptionFn = std::function< void(const PerceptionContext &)>
 

Public Member Functions

std::optional< FalloffCurvefalloff_curve () const
 Current named curve, or nullopt if a custom lambda was set via set_falloff().
 
float falloff_radius () const
 Current falloff radius, or the query radius if none was set.
 
void invoke_influence (const InfluenceContext &ctx) const override
 Invoke the influence function with the supplied context.
 
void invoke_perception (const PerceptionContext &ctx) override
 Invoke the perception function with the supplied context.
 
const std::vector< std::pair< uint32_t, float > > & neighbors () const
 Neighbors captured on the most recent perception, with weights.
 
 Presence (float query_radius, PerceptionFn perception, InfluenceFn influence, RadiateFn radiate)
 Construct with perception, influence, and radiation functions.
 
 Presence (float query_radius, std::string perception_fn_name, PerceptionFn perception, std::string influence_fn_name, InfluenceFn influence, std::string radiate_fn_name, RadiateFn radiate)
 Construct with all named callables.
 
const std::string & radiate_fn_name () const
 Identifier for the radiate callable, empty if anonymous.
 
void set_falloff (FalloffFn fn)
 Replace the falloff curve.
 
void set_falloff_curve (FalloffCurve curve)
 Set the falloff curve to a named built-in.
 
void set_falloff_radius (float r)
 Set the falloff radius, the distance over which the weight decays.
 
void set_radiate (RadiateFn fn)
 Replace the per-neighbor radiation callable.
 
void set_radiate_fn_name (std::string name)
 Set or replace the radiate callable identifier.
 
- Public Member Functions inherited from MayaFlux::Nexus::Agent
void add_influence_target (std::shared_ptr< Buffers::RenderProcessor > proc)
 Add a render processor to receive GPU-side influence data.
 
 Agent (float query_radius, PerceptionFn perception, InfluenceFn influence)
 Construct with query radius, perception function, and influence function.
 
 Agent (float query_radius, std::string perception_fn_name, PerceptionFn perception, std::string influence_fn_name, InfluenceFn influence)
 Construct with named perception and influence functions.
 
const std::vector< AudioSink > & audio_sinks () const
 
void clear_color ()
 Clear the color, resetting it to an unset state.
 
void clear_influence_targets ()
 Unbind and remove all influence targets and free the UBO.
 
void clear_position ()
 Clear the position, removing this object from spatial operations.
 
void clear_size ()
 Clear the size, resetting it to an unset state.
 
const std::optional< glm::vec3 > & color () const
 Get the current color, if set.
 
std::shared_ptr< Buffers::RenderProcessorget_render_processor (const std::shared_ptr< Core::Window > &window) const
 
uint32_t id () const
 Return the stable object id assigned by Fabric.
 
const InfluenceFninfluence_fn () const
 The influence function itself.
 
const std::string & influence_fn_name () const
 Identifier assigned to the influence function, empty if anonymous.
 
const std::vector< std::shared_ptr< Buffers::RenderProcessor > > & influence_targets () const
 All render processors currently receiving influence data.
 
float intensity () const
 Get the current intensity.
 
const PerceptionFnperception_fn () const
 The perception function itself.
 
const std::string & perception_fn_name () const
 Identifier assigned to the perception function, empty if anonymous.
 
const std::optional< glm::vec3 > & position () const
 Return the current position, if set.
 
float query_radius () const
 Return the query radius.
 
float radius () const
 Get the current radius.
 
void remove_audio_sink (Buffers::BufferManager &mgr, uint32_t channel)
 Unregister the audio sink on channel.
 
void remove_influence_target (const std::shared_ptr< Buffers::RenderProcessor > &proc)
 Remove a single influence target and unbind its UBO.
 
void remove_render (Buffers::BufferManager &mgr, const std::shared_ptr< Core::Window > &window)
 Unregister the render sink targeting window.
 
void render (Buffers::BufferManager &mgr, const Portal::Graphics::RenderConfig &config)
 Register a render output targeting window.
 
void render (Buffers::BufferManager &mgr, const Portal::Graphics::RenderConfig &config, std::string fn_name, RenderFn fn)
 Register a render output targeting window with a producer function.
 
const std::vector< RenderSink > & render_sinks () const
 
void set_audio_data (std::span< const double > samples)
 Push samples to all registered audio sinks.
 
void set_color (const glm::vec3 &c)
 Set the color, a general-purpose parameter for influence functions.
 
void set_influence_fn_name (std::string name)
 Set or replace the influence function's identifier.
 
void set_intensity (float i)
 Set the intensity, a general-purpose parameter for influence functions.
 
void set_perception_fn_name (std::string name)
 Set or replace the perception function's identifier.
 
void set_position (const glm::vec3 &p)
 Set the position, enabling spatial indexing and queries for this object.
 
void set_query_radius (float r)
 Set the query radius.
 
void set_radius (float r)
 Set the radius, a general-purpose parameter for influence functions.
 
void set_size (float s)
 Set the size, a general-purpose parameter for influence functions.
 
void set_vertices (const void *data, size_t byte_count)
 Set pre-packed interleaved vertex bytes to all registered render sinks.
 
template<typename T >
void set_vertices (std::span< const T > vertices)
 Set typed vertex data to all registered render sinks.
 
void sink_audio (Buffers::BufferManager &mgr, uint32_t channel)
 Register an audio output on channel.
 
void sink_audio (Buffers::BufferManager &mgr, uint32_t channel, std::function< Kakshya::DataVariant(const InfluenceContext &)> fn, std::string fn_name="")
 Register an audio output on channel with a producer function.
 
const std::optional< float > & size () const
 Get the current size, if set.
 
virtual ~Agent ()=default
 

Private Attributes

FalloffFn m_falloff
 
std::optional< FalloffCurvem_falloff_curve { FalloffCurve::Linear }
 
float m_falloff_radius { 0.0F }
 
std::vector< std::pair< uint32_t, float > > m_neighbors
 
RadiateFn m_radiate
 
std::string m_radiate_fn_name
 

Detailed Description

Agent that affects its surroundings by being there.

An Agent already carries both a perception function and an influence function plus a query radius. Presence makes both concrete around the act of radiating into nearby entities:

Perception is sensing the neighborhood. The spatial query Fabric runs on each commit populates the perception context with the entities inside the query radius. Presence stores that result so the influence half can act on it, after the user perception callable runs.

Influence is radiation. For every neighbor found, Presence computes a falloff weight from the neighbor's squared distance against the falloff radius, then invokes a per-neighbor callable with the neighbor's id and its weight. The user callable decides what being near this Presence does to that neighbor: a parameter written, a force applied, a value pushed, anything. The Presence does not know what a neighbor is, only how near it is.

The falloff radius is independent of the query radius. The query radius decides who is a neighbor; the falloff radius decides how the weight decays across that neighborhood. By default the falloff radius tracks the query radius. The falloff curve is linear by default and replaceable.

The base perception and influence callables still fire. Presence layers its neighborhood sensing and radiation on top: the user perception callable runs, then the result is captured; the user influence callable runs, then each neighbor is radiated into.

Wiring a Presence with every(1.0/60.0) drives the whole cycle each frame. A Presence without a position senses an empty neighborhood and radiates into nothing.

Definition at line 41 of file Presence.hpp.


The documentation for this class was generated from the following files: