#pragma once #include "evo/biology/cellular_habitat.hpp" #include "evo/biology/cellular_kinematics.hpp" #include #include #include #include #include #include #include // 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 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 generate(const CellularCurrentConfig& config); // The same field, generated once per process and shared: fields are immutable and fully // determined by their configuration, and restoring an owner must not regenerate one. [[nodiscard]] static std::expected, CellularCurrentError> shared(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 routes() const noexcept { return routes_; } [[nodiscard]] std::span 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 routes_; std::vector nodes_; std::size_t columns_{}, rows_{}; }; // A pool (a fixed deposit) cannot sit in a current. The nearest centre to the pool's within the // region whose whole disc is in still water (no current at its centre, rim or half-rim), or // the pool's own centre when it already is or none is found within 30 mm. [[nodiscard]] CellularPatchAddress cellular_still_centre(const CellularFlowField& field, CellularPatchAddress centre, std::uint32_t radius_um) noexcept; } // namespace evo::biology