MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Agent.cpp
Go to the documentation of this file.
1#include "Agent.hpp"
2
5
7
8namespace MayaFlux::Nexus {
9
10void Agent::set_vertices(const void* data, size_t byte_count)
11{
12 for (auto& s : m_render_sinks)
13 s.writer->set_vertices(data, byte_count);
14}
15
16void Agent::add_influence_target(std::shared_ptr<Buffers::RenderProcessor> proc)
17{
18 if (!proc) {
20 "Cannot add null influence target");
21 return;
22 }
23
24 if (std::ranges::find(m_influence_targets, proc) != m_influence_targets.end()) {
25 return;
26 }
27
28 if (!m_influence_ubo) {
29 m_influence_ubo = std::make_shared<Buffers::VKBuffer>(
30 sizeof(InfluenceUBO),
33 }
34
35 proc->add_binding("u_influence",
36 Buffers::ShaderBinding { 1, 0, vk::DescriptorType::eUniformBuffer });
37
38 proc->bind_buffer("u_influence", m_influence_ubo);
39
40 m_influence_targets.push_back(std::move(proc));
41}
42
43void Agent::remove_influence_target(const std::shared_ptr<Buffers::RenderProcessor>& proc)
44{
45 auto it = std::ranges::find(m_influence_targets, proc);
46 if (it == m_influence_targets.end())
47 return;
48
49 (*it)->unbind_buffer("u_influence");
50 m_influence_targets.erase(it);
51
52 if (m_influence_targets.empty())
53 m_influence_ubo.reset();
54}
55
57{
58 for (const auto& proc : m_influence_targets)
59 proc->unbind_buffer("u_influence");
60
61 m_influence_targets.clear();
62 m_influence_ubo.reset();
63}
64
66{
67 if (!m_influence_ubo || !m_influence_ubo->get_mapped_ptr()) {
69 "Cannot upload influence UBO: no target or failed to map buffer");
70 return;
71 }
72
73 InfluenceUBO data {
74 .position = ctx.position,
75 .intensity = ctx.intensity,
76 .color = ctx.color.value_or(glm::vec3(1.0F)),
77 .radius = ctx.radius,
78 .size = ctx.size.value_or(1.0F),
79 };
80
81 std::memcpy(m_influence_ubo->get_mapped_ptr(), &data, sizeof(InfluenceUBO));
82}
83
84} // namespace MayaFlux::Nexus
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
@ UNIFORM
Uniform buffer (host-visible)
std::vector< std::shared_ptr< Buffers::RenderProcessor > > m_influence_targets
Definition Agent.hpp:295
void upload_influence_ubo(const InfluenceContext &ctx) const
Definition Agent.cpp:65
void set_vertices(const void *data, size_t byte_count)
Set pre-packed interleaved vertex bytes to all registered render sinks.
Definition Agent.cpp:10
void clear_influence_targets()
Unbind and remove all influence targets and free the UBO.
Definition Agent.cpp:56
void remove_influence_target(const std::shared_ptr< Buffers::RenderProcessor > &proc)
Remove a single influence target and unbind its UBO.
Definition Agent.cpp:43
std::vector< RenderSink > m_render_sinks
Definition Agent.hpp:306
void add_influence_target(std::shared_ptr< Buffers::RenderProcessor > proc)
Add a render processor to receive GPU-side influence data.
Definition Agent.cpp:16
std::shared_ptr< Buffers::VKBuffer > m_influence_ubo
Definition Agent.hpp:296
@ Init
Engine/subsystem initialization.
@ Runtime
General runtime operations (default fallback)
@ Nexus
Spatial indexing and scheduling for user-defined behaviour.
@ UNKNOWN
Unknown or undefined modality.
Describes how a VKBuffer binds to a shader descriptor.
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.
GPU-side std140 layout matching InfluenceContext plain data fields.