Files
aevolution/include/evo/biology/cellular_currents.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

78 lines
3.0 KiB
C++

#pragma once
#include "evo/biology/cellular_kinematics.hpp"
#include <compare>
#include <cstddef>
#include <cstdint>
#include <expected>
#include <span>
#include <vector>
// Procedural currents (Cellular_Region_Changes.md, flows; ADR-0177): a fixed environmental
// condition, not stock. A seeded configuration generates 2-n closed looping routes inside the
// region, each with its own width, speed and direction, rasterized once into a Q10 velocity
// grid. Integer-only, so the client regenerates the identical field from the same
// configuration.
namespace evo::biology {
inline constexpr std::uint32_t max_cellular_current_pitch_um = 10'000;
inline constexpr std::size_t max_cellular_current_nodes = 1'048'576;
inline constexpr std::size_t cellular_current_route_points = 32;
struct CellularCurrentConfig {
std::uint64_t seed{};
std::uint32_t width_um{}, height_um{}, pitch_um{};
std::uint32_t min_count{}, max_count{};
std::uint32_t min_route_width_um{}, max_route_width_um{};
std::uint32_t min_speed_um_per_s{}, max_speed_um_per_s{};
auto operator<=>(const CellularCurrentConfig&) const = default;
};
struct CellularRoutePoint {
std::int64_t x_um{}, y_um{};
auto operator<=>(const CellularRoutePoint&) const = default;
};
// A closed loop; points are in flow order (the last joins the first).
struct CellularCurrentRoute {
std::vector<CellularRoutePoint> points;
std::uint32_t width_um{}, speed_um_per_s{};
bool clockwise{};
auto operator<=>(const CellularCurrentRoute&) const = default;
};
enum class CellularCurrentError : std::uint8_t { invalid_config, region_too_small };
class CellularFlowField {
public:
[[nodiscard]] static std::expected<CellularFlowField, CellularCurrentError>
generate(const CellularCurrentConfig& config);
// Liquid velocity at a point, clamped into the region; bilinear between grid nodes.
[[nodiscard]] CellularFlowSample sample(std::int64_t x_um, std::int64_t y_um) const noexcept;
// At the centre of a square footprint whose lower-left corner is `position`.
[[nodiscard]] CellularFlowSample at_footprint(CellularPosition position,
std::uint32_t extent_um) const noexcept;
[[nodiscard]] const CellularCurrentConfig& config() const noexcept {
return config_;
}
[[nodiscard]] std::span<const CellularCurrentRoute> routes() const noexcept {
return routes_;
}
[[nodiscard]] std::span<const CellularFlowSample> nodes() const noexcept {
return nodes_;
}
[[nodiscard]] std::size_t columns() const noexcept {
return columns_;
}
[[nodiscard]] std::size_t rows() const noexcept {
return rows_;
}
// Fingerprint of the generated grid, for comparing server and client fields.
[[nodiscard]] std::uint64_t digest() const noexcept;
private:
CellularFlowField() = default;
CellularCurrentConfig config_{};
std::vector<CellularCurrentRoute> routes_;
std::vector<CellularFlowSample> nodes_;
std::size_t columns_{}, rows_{};
};
} // namespace evo::biology