3#include <glm/gtc/constants.hpp>
9 float linear_falloff(
float t)
11 return 1.0F - std::clamp(t, 0.0F, 1.0F);
20 :
Agent(query_radius,
std::move(perception),
std::move(influence))
21 , m_falloff(linear_falloff)
22 , m_radiate(
std::move(radiate))
28 std::string influence_fn_name,
InfluenceFn influence,
29 std::string radiate_fn_name,
RadiateFn radiate)
31 std::move(perception_fn_name),
std::move(perception),
32 std::move(influence_fn_name),
std::move(influence))
33 , m_falloff(linear_falloff)
34 , m_radiate_fn_name(
std::move(radiate_fn_name))
35 , m_radiate(
std::move(radiate))
44 m_falloff = [](
float t) {
return 1.0F - std::clamp(t, 0.0F, 1.0F); };
47 m_falloff = [](
float t) {
return 0.5F * (1.0F + std::cos(std::clamp(t, 0.0F, 1.0F) * glm::pi<float>())); };
50 m_falloff = [](
float t) {
return std::exp(-4.0F * std::clamp(t, 0.0F, 1.0F)); };
53 m_falloff = [](
float t) {
const float c = std::clamp(t, 0.0F, 1.0F);
return 1.0F / (1.0F + 16.0F * c * c); };
65 const float fr_sq = fr * fr;
68 if (result.distance_sq > fr_sq) {
71 const float t = fr > 0.0F
72 ? std::sqrt(result.distance_sq) / fr
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.
std::function< void(const PerceptionContext &)> PerceptionFn
std::function< void(const InfluenceContext &)> InfluenceFn
Object that both perceives nearby entities and acts on MayaFlux objects.
std::vector< std::pair< uint32_t, float > > m_neighbors
Presence(float query_radius, PerceptionFn perception, InfluenceFn influence, RadiateFn radiate)
Construct with perception, influence, and radiation functions.
void invoke_perception(const PerceptionContext &ctx) override
Invoke the perception function with the supplied context.
std::optional< FalloffCurve > m_falloff_curve
float falloff_radius() const
Current falloff radius, or the query radius if none was set.
FalloffCurve
Built-in falloff curves that survive state encode/decode.
void invoke_influence(const InfluenceContext &ctx) const override
Invoke the influence function with the supplied context.
void set_falloff_curve(FalloffCurve curve)
Set the falloff curve to a named built-in.
std::function< void(uint32_t id, float weight)> RadiateFn
Per-neighbor radiation callable.
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.