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

Object that both perceives nearby entities and acts on MayaFlux objects. More...

#include <Agent.hpp>

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

Public Types

using InfluenceFn = std::function< void(const InfluenceContext &)>
 
using PerceptionFn = std::function< void(const PerceptionContext &)>
 

Public Member Functions

template<typename T >
std::shared_ptr< Influence< T > > add_influence (typename Influence< T >::Producer producer)
 Add an influence of any type, with as many targets as are wanted.
 
template<typename T >
std::shared_ptr< Perception< T > > add_perception (typename Perception< T >::Source source)
 Add a perception of any type, with as many targets as are wanted.
 
 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.
 
 Agent (float query_radius=1.0F)
 Construct with only a query radius, for an Agent whose behaviour comes from typed influences and perceptions.
 
void attach (const std::shared_ptr< Buffers::VKBuffer > &buf, const AttachConfig &config={})
 Make an existing, already rendered buffer the look of this object.
 
bool attached () const
 True while a buffer is attached.
 
const std::vector< AudioSink > & audio_sinks () const
 
void clear_color ()
 Clear the color, resetting it to an unset state.
 
void clear_influences ()
 Stop every influence added with add_influence().
 
void clear_orientation ()
 Clear the orientation.
 
void clear_perceptions ()
 Stop every perception added with add_perception().
 
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.
 
void detach ()
 Release the attached buffer and reset its placement.
 
std::shared_ptr< Buffers::RenderProcessor > get_render_processor (const std::shared_ptr< Core::Window > &window) const
 
uint32_t id () const
 Return the stable object id assigned by Fabric.
 
const InfluenceFn & influence_fn () const
 The influence function itself.
 
const std::string & influence_fn_name () const
 Identifier assigned to the influence function, empty if anonymous.
 
float intensity () const
 Get the current intensity.
 
virtual void invoke_influence (const InfluenceContext &ctx) const
 Invoke the influence function with the supplied context.
 
virtual void invoke_perception (const PerceptionContext &ctx)
 Invoke the perception function with the supplied context.
 
const std::optional< glm::quat > & orientation () const
 Get the current orientation, if set.
 
const PerceptionFn & perception_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 recenter ()
 Read the attached buffer's geometry again and move the anchor to match.
 
void remove_audio_sink (Buffers::BufferManager &mgr, uint32_t channel)
 Unregister the audio sink on channel.
 
template<typename T >
void remove_influence (const std::shared_ptr< Influence< T > > &influence)
 Stop an influence added with add_influence().
 
template<typename T >
void remove_perception (const std::shared_ptr< Perception< T > > &perception)
 Stop a perception added with add_perception().
 
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_orientation (const glm::quat &q)
 Set the orientation.
 
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 Member Functions

void follow_attachment ()
 

Private Attributes

std::optional< Attachment > m_attachment
 
std::vector< AudioSink > m_audio_sinks
 
std::optional< glm::vec3 > m_color
 
uint32_t m_id {}
 
InfluenceFn m_influence_fn
 
std::string m_influence_fn_name
 
std::vector< std::pair< std::shared_ptr< void >, InfluenceFn > > m_influences
 
float m_intensity { 1.0F }
 
std::optional< glm::quat > m_orientation
 
PerceptionFn m_perception_fn
 
std::string m_perception_fn_name
 
std::vector< std::pair< std::shared_ptr< void >, PerceptionFn > > m_perceptions
 
std::optional< glm::vec3 > m_position
 
float m_query_radius
 
float m_radius { 1.0F }
 
std::vector< RenderSink > m_render_sinks
 
std::optional< float > m_size
 

Friends

class Fabric
 

Detailed Description

Object that both perceives nearby entities and acts on MayaFlux objects.

Constructed with a query radius and, optionally, a perception function and an influence function. Position is optional: call set_position before registering with Fabric if spatial behaviour is required. Without a position the spatial index is not consulted and spatial_results will be empty on each commit.

On each commit the perception function is invoked first, then the influence function. Both receive contexts populated from the same spatial snapshot.

The id is assigned by Fabric::wire and is stable for the object's lifetime.

RenderConfig and AttachConfig take designated initializers.

agent->attach(buf, { .on_move = AttachConfig::OnMove::Carry });
agent->render(mgr, { .target_window = window });
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
@ Carry
The buffer is moved along with the Agent.

Definition at line 36 of file Agent.hpp.


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