MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ operator()() [2/4]

template<typename Seed >
requires std::invocable<Seed&, uint32_t, uint32_t> && GridCellData<std::remove_cvref_t<std::invoke_result_t<Seed&, uint32_t, uint32_t>>>
auto MayaFlux::Evolve::operator() ( const Buffers::RelaxationGridBuffer::GridConfig &  config,
Seed &&  seed,
const RenderConfig &  render 
) -> std::shared_ptr<Buffers::RelaxationGridBuffer>
inline

Build a relaxation grid seeded from a host callable.

Parameters
configGrid arrangement.
seedCallable taking cell coordinates (x, y) and returning the cell's state. x runs over [0, width) and y over [0, height).
renderRender target. target_window is required.
Returns
The registered grid, or nullptr if the target window is null or the seed's return type does not match the grid's cell stride.

The seed's return type is the cell type, constrained by GridCellData and checked against the stride the config resolved. The state is written before registration, so the first generation steps from it.

Definition at line 154 of file Evolve.hpp.

159 {
160 using State = std::remove_cvref_t<std::invoke_result_t<Seed&, uint32_t, uint32_t>>;
161
162 std::vector<std::byte> cells(static_cast<size_t>(config.width) * config.height * sizeof(State));
163 for (uint32_t y = 0; y < config.height; ++y) {
164 for (uint32_t x = 0; x < config.width; ++x) {
165 const State value = seed(x, y);
166 std::memcpy(
167 cells.data() + (static_cast<size_t>(y) * config.width + x) * sizeof(State),
168 &value,
169 sizeof(State));
170 }
171 }
172
173 auto grid = build_grid(config, render, cells, sizeof(State));
174 if (grid) {
176 }
177 return grid;
178 }
#define MF_LIVE_EXPOSE_AUTO(ptr)
Auto-expose variant that deduces the key prefix from the shared_ptr element type.
glm::vec3 value
std::shared_ptr< Buffers::RelaxationGridBuffer > build_grid(const Buffers::RelaxationGridBuffer::GridConfig &config, const RenderConfig &render, const std::vector< std::byte > &seed, size_t seed_stride)
Construct, optionally seed, register and render a relaxation grid.
Definition Evolve.cpp:280

References MF_LIVE_EXPOSE_AUTO, and value.