#pragma once #include "evo/biology/development.hpp" #include "evo/client/environment_view.hpp" #include #include #include #include #include #include namespace evo::client { inline constexpr std::size_t max_organism_cells = 1024; // Authority revision an organism presentation was copied from (e.g. a community // command watermark). Not a capability or session grant. struct OrganismRevision { world::WorldIdentity identity; std::uint64_t tick{}, revision{}; auto operator<=>(const OrganismRevision&) const = default; }; // Dead organisms remain as remnants until their terminal inventory is gone; removal // is absence from a later presentation, never a state. enum class OrganismState : std::uint8_t { alive, dead }; // Copied presentation values. Deliberately has no controller, owner, account, // player/NPC, level or name field: every organism is presented by biology alone. struct OrganismCell { std::uint64_t id{}; // Opaque stable draw-order key; never displayed. world::VoxelAddress voxel; world::Micrometres x, y; // Centre offset inside the voxel, each in [0, 1e6). biology::Phenotype phenotype; biology::GrowthState growth; OrganismState state{OrganismState::alive}; }; // Immutable owned copy of up to 1024 organisms in one Z slice; may be empty. class OrganismPresentation { public: [[nodiscard]] static std::expected create(OrganismRevision revision, std::int64_t slice_z, std::span cells); [[nodiscard]] OrganismRevision revision() const noexcept { return revision_; } [[nodiscard]] std::int64_t slice_z() const noexcept { return slice_z_; } // Strictly ascending by id, which is also draw order. [[nodiscard]] std::span cells() const noexcept { return cells_; } private: OrganismPresentation(OrganismRevision revision, std::int64_t z, std::span cells) : revision_{revision}, slice_z_{z}, cells_(cells.begin(), cells.end()) {} OrganismRevision revision_; std::int64_t slice_z_; std::vector cells_; }; // Derives the phenotype with the M3 contract; visual parameters never come from // anything but the genome, growth state and environment supplied here. [[nodiscard]] std::expected present_organism(std::uint64_t id, world::VoxelAddress voxel, world::Micrometres x, world::Micrometres y, const biology::Genome& genome, biology::GrowthState growth, const biology::EnvironmentState& environment, OrganismState state); // Same ordering/freshness semantics as EnvironmentLayer (ADR-0080), without chunks. class OrganismLayer { public: [[nodiscard]] std::expected accept(OrganismPresentation next); [[nodiscard]] std::expected observe(OrganismRevision latest); void mark_stale() noexcept; void reset() noexcept; [[nodiscard]] const OrganismPresentation* current() const noexcept { return current_ ? &*current_ : nullptr; } [[nodiscard]] Freshness freshness() const noexcept; private: std::optional current_; std::optional latest_; bool stale_{}; }; } // namespace evo::client