Files
dingoandClaude Opus 5.5 131ed5f254
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m29s
Foundation / postgres-tools (push) Successful in 29s
Foundation / server-image (push) Successful in 4m24s
Foundation / image (push) Successful in 4m58s
feat(cellular): playtest fixes - edge, cell count, mixed bubbles, still pools
From the first rules-13 playtest:
- An earned offer waits until a single cell can split (keeping its count),
  so choices are no longer refused one after another.
- The client draws the region's walls (dimming outside), names the edge
  when the cell is against it, shows the region's cell count, and says when
  upkeep is burning kept matter because no energy is left.
- Mixed bubbles hold every nutrient at once (--mixed-motes; none leaves the
  scatter stream unchanged) and are drawn as small pools of their nutrients.
  With intake split by the body's recipe, single-nutrient phosphorus
  bubbles fed slowly; mixed ones carry it with everything else.
- Liquid openings move each pool out of the currents to the nearest still
  water (cellular_still_centre).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 09:02:43 -04:00

91 lines
4.0 KiB
C++

#pragma once
#include "evo/biology/cellular_habitat.hpp"
#include "evo/biology/cellular_kinematics.hpp"
#include <compare>
#include <cstddef>
#include <cstdint>
#include <expected>
#include <memory>
#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);
// 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<std::shared_ptr<const CellularFlowField>,
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<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_{};
};
// 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