Implement M9.4 revision-tagged microscopic environment rendering

Add SDL-free owned EnvironmentPresentation copied from M6.3 views (no
store pointers or validation tokens), a single-slot EnvironmentLayer that
rejects foreign/regressed updates and reports none/current/stale against
observed authority watermarks, and a bounded camera projection with
explicit missing, not-requested, present-zero, undefined-moisture and
stale encodings (at most 2313 clipped rectangles, reused buffer).

The engineering app renders a local in-memory fixture authority with
configurable refresh cadence and layer selection. ADR-0080 records the
decision; validation evidence and limits are in VALIDATION.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-01 17:45:53 -04:00
co-authored by Claude Opus 5.5
parent bb0412cd0f
commit feca07f791
20 changed files with 1393 additions and 62 deletions
+102
View File
@@ -0,0 +1,102 @@
#pragma once
#include "evo/world/environment.hpp"
#include <array>
#include <cstddef>
#include <cstdint>
#include <expected>
#include <optional>
#include <span>
#include <vector>
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<FieldPresence, world::field_count> presence{};
// Femtograms for mass fields, picojoules for energy fields; zero unless present.
std::array<std::uint64_t, world::field_count> 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<EnvironmentPresentation, ViewError>
create(EnvironmentRevision revision, std::uint32_t requested_mask, std::int64_t slice_z,
std::span<const EnvironmentCell> 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<const EnvironmentCell> cells() const noexcept {
return cells_;
}
private:
EnvironmentPresentation(EnvironmentRevision revision, std::uint32_t mask, std::int64_t z,
std::span<const EnvironmentCell> 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<EnvironmentCell> 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<EnvironmentPresentation, ViewError>
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<void, ViewError> 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<void, ViewError> 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<EnvironmentPresentation> current_;
std::optional<EnvironmentRevision> latest_;
bool stale_{};
};
} // namespace evo::client
+46
View File
@@ -0,0 +1,46 @@
#pragma once
#include "evo/client/camera.hpp"
#include "evo/client/environment_view.hpp"
#include "evo/render/frame.hpp"
#include <cstddef>
#include <cstdint>
#include <expected>
#include <vector>
namespace evo::render {
// Per cell: terrain square, up to four habitat rectangles (fill, checker or hollow
// outline) and up to four voxel-outline rectangles; plus status and legend.
inline constexpr std::size_t environment_legend_steps = 8;
inline constexpr std::size_t max_environment_rectangles =
client::max_environment_cells * 9 + 1 + environment_legend_steps;
struct EnvironmentDisplay {
enum class Mode : std::uint8_t { field, moisture } mode{Mode::field};
world::Field field{world::Field::water}; // Used by Mode::field only.
};
// Presentation encodings, deliberately distinct from every ramp colour.
namespace palette {
inline constexpr Color present_zero{0, 0, 0, 255};
inline constexpr Color missing_a{150, 40, 150, 255}, missing_b{40, 12, 40, 255};
inline constexpr Color not_requested{210, 210, 210, 255};
inline constexpr Color undefined{150, 50, 30, 255}; // Moisture with zero water capacity.
inline constexpr Color voxel_outline{8, 10, 14, 255};
inline constexpr Color stale_outline{240, 170, 40, 255};
inline constexpr Color status_none{200, 40, 40, 255};
inline constexpr Color status_current{64, 180, 140, 255};
inline constexpr Color status_stale{240, 170, 40, 255};
} // namespace palette
// Field layers map log2(quantity / habitat volume um^3) over [-30, 12] onto the ramp,
// clamping outside it. Moisture maps saturation [0, 1] linearly. Presentation only.
inline constexpr double field_log2_min = -30, field_log2_max = 12;
[[nodiscard]] Color ramp(double t) noexcept;
[[nodiscard]] Color dim(Color color) noexcept; // Stale presentation tint.
enum class EnvironmentRenderError : std::uint8_t { invalid_display };
// Replaces `out` with logical-window rectangles clipped to the camera viewport, in
// cell order, ending with the status chip and legend. Output never exceeds
// max_environment_rectangles; reuse `out` to avoid per-frame allocation. A null
// presentation (or Freshness::none) draws only the "no environment" status.
[[nodiscard]] std::expected<void, EnvironmentRenderError>
build_environment(std::vector<Rectangle>& out, const client::EnvironmentPresentation* presentation,
client::Freshness freshness, const client::Camera& camera,
EnvironmentDisplay display);
} // namespace evo::render