Files
aevolution/include/evo/biology/cellular_deposit_motion.hpp
T
dingoandClaude Opus 5.5 40dc2b12ad feat(biology): procedural currents, habitat format 3 and moving food
Phase 2 biology. CellularFlowField generates 2-n seeded closed looping currents
inside the region, each with its own width, speed and direction, strongest at the
centreline and still at the stream edges and walls, rasterized to a Q10 grid with
integer bilinear sampling. The field digest matches across g++-14, clang-19 and
MSVC, so clients regenerate it from the configuration.

Habitat format 3 adds per-deposit induced drift, sub-micrometre carry and a merged
count, with up to 8,192 deposits. advect_cellular_deposits moves bubbles with the
flow plus drift from passing cells (falloff and decay), merges touching bubbles
into the lower id up to the merged cap, keeps pools fixed and addresses unique.
A 2,000-tick run of 1,800 bubbles conserves stock exactly and leaves nothing piled
at the walls; it costs under 0.7 ms per tick optimized. The tuned grid pitch is
capped at 10 mm. Refreshes the DEV session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 16:50:45 -04:00

51 lines
2.3 KiB
C++

#pragma once
#include "evo/biology/cellular_currents.hpp"
#include "evo/biology/cellular_habitat.hpp"
#include <compare>
#include <cstdint>
#include <expected>
#include <span>
// Moving food (Cellular_Region_Movement_Plan.md, moving food; rules 12). After each tick's
// lives have fed against the deposits where they were, every bubble moves with the local flow
// plus the drift that passing cells induced, bubbles that touch merge (stock is summed, never
// created), and addresses are made unique again. Pools stay where they were placed.
namespace evo::biology {
// A living cell's world velocity this tick, for the drift it induces on nearby bubbles.
struct CellularWake {
CellularPosition position;
std::uint32_t extent_um{};
std::int32_t velocity_x_q10{}, velocity_y_q10{};
auto operator<=>(const CellularWake&) const = default;
};
struct CellularDepositMotionRules {
std::uint32_t drift_radius_um{}; // Cells push bubbles closer than this.
std::int32_t max_drift_q10{}; // Largest induced drift speed.
std::uint32_t drift_decay_ppm{}; // Induced drift lost per tick.
std::uint16_t merged_cap{}; // Bubbles stop merging at this many scattered ones.
std::uint32_t bubble_radius_um{}; // Radius of one unmerged bubble.
auto operator<=>(const CellularDepositMotionRules&) const = default;
};
struct CellularDepositMotionReport {
std::uint32_t moved{}, merges{}, nudged{};
auto operator<=>(const CellularDepositMotionReport&) const = default;
};
struct CellularDepositMotion {
CellularHabitatConfig config;
CellularDepositMotionReport report;
};
// Radius of a bubble holding `merged` scattered bubbles: area grows with the count.
[[nodiscard]] std::uint32_t cellular_merged_radius(std::uint32_t bubble_radius_um,
std::uint16_t merged) noexcept;
// Detached: returns the next format-3 configuration, or an error when the input is not a
// format-3 habitat matching the field's area. `wakes` must be ordered by stable life id.
[[nodiscard]] std::expected<CellularDepositMotion, CellularHabitatError>
advect_cellular_deposits(const CellularHabitatConfig& config, const CellularFlowField& field,
std::span<const CellularWake> wakes,
const CellularDepositMotionRules& rules);
} // namespace evo::biology