#pragma once #include "evo/world/environment.hpp" #include #include #include #include #include #include #include namespace evo::client { inline constexpr std::size_t max_environment_cells = world::max_environment_footprint; // Authority revision a presentation was copied from. Not a capability or session grant. struct EnvironmentRevision { world::WorldIdentity identity; std::uint64_t tick{}, field_revision{}; auto operator<=>(const EnvironmentRevision&) const = default; }; enum class FieldPresence : std::uint8_t { not_requested, missing, present }; // Copied presentation values for one habitat in the selected Z slice. Public aggregates // are unvalidated input; EnvironmentPresentation::create validates them. struct EnvironmentCell { world::VoxelAddress voxel; std::uint64_t chunk_revision{}; world::HabitatBox habitat{}; world::CubicMicrometres volume{}; world::MaterialId substrate, terrain_material; std::uint16_t terrain_fill{}; std::array presence{}; // Femtograms for mass fields, picojoules for energy fields; zero unless present. std::array quantity{}; world::MoistureStatus moisture_status{world::MoistureStatus::not_requested}; world::WaterSaturation moisture{}; // Meaningful only when moisture_status is available. }; enum class ViewError : std::uint8_t { invalid_view, empty_slice, too_many_cells, foreign_world, regressed }; // Immutable owned copy; never retains world stores, chunk tokens or native handles. class EnvironmentPresentation { public: [[nodiscard]] static std::expected create(EnvironmentRevision revision, std::uint32_t requested_mask, std::int64_t slice_z, std::span cells); [[nodiscard]] EnvironmentRevision revision() const noexcept { return revision_; } [[nodiscard]] std::uint32_t requested_mask() const noexcept { return mask_; } [[nodiscard]] std::int64_t slice_z() const noexcept { return slice_z_; } // Strictly ordered by voxel (x, then y), all at slice_z. [[nodiscard]] std::span cells() const noexcept { return cells_; } private: EnvironmentPresentation(EnvironmentRevision revision, std::uint32_t mask, std::int64_t z, std::span cells) : revision_{revision}, mask_{mask}, slice_z_{z}, cells_(cells.begin(), cells.end()) {} EnvironmentRevision revision_; std::uint32_t mask_; std::int64_t slice_z_; std::vector cells_; }; // Copies the samples at slice_z from a local M6.3 view. Reads only; the view's // validation tokens and store identities are not copied. [[nodiscard]] std::expected present_environment(const world::EnvironmentView& view, std::int64_t slice_z); enum class Freshness : std::uint8_t { none, current, stale }; // Latest accepted presentation plus the newest authority revision observed. // Bounded to one presentation; no history or update queue. class EnvironmentLayer { public: // Rejects a different world/frame or any regression of tick, field revision or a // shared voxel's chunk revision. Equal revisions are accepted (e.g. a new footprint). [[nodiscard]] std::expected accept(EnvironmentPresentation next); // Records that the authority has reached `latest` (also before any presentation); // the presentation is stale while it differs from the newest observed revision. // A different world/frame or a regressed revision rejects without mutation. [[nodiscard]] std::expected observe(EnvironmentRevision latest); // Host evidence (e.g. failed local validation) that the presentation is out of date. void mark_stale() noexcept; // Required after restore/reconnect to a different authority lineage. void reset() noexcept; [[nodiscard]] const EnvironmentPresentation* current() const noexcept { return current_ ? &*current_ : nullptr; } [[nodiscard]] Freshness freshness() const noexcept; private: std::optional current_; std::optional latest_; bool stale_{}; }; } // namespace evo::client