Implement M5.5 atomic terrain excavation and debris accounting
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "evo/world/generation.hpp"
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
@@ -18,9 +19,51 @@ enum class ChunkError : std::uint8_t {
|
||||
stale_view,
|
||||
invalid_local,
|
||||
dirty,
|
||||
revision_exhausted
|
||||
revision_exhausted,
|
||||
invalid_edit,
|
||||
digest_mismatch,
|
||||
command_conflict,
|
||||
stale_command,
|
||||
destination_full,
|
||||
insufficient_material
|
||||
};
|
||||
enum class CellLayout : std::uint8_t { uniform, palette, dense };
|
||||
// Exact occupied-volume quanta, NOT mass: one unit = 1/65535 m^3 for v1.
|
||||
struct VolumeUnits {
|
||||
std::uint64_t value{};
|
||||
auto operator<=>(const VolumeUnits&) const = default;
|
||||
};
|
||||
struct DebrisCapacity {
|
||||
std::array<VolumeUnits, 2> materials{};
|
||||
}; // rock, regolith
|
||||
struct CellCut {
|
||||
ChunkAddress chunk{};
|
||||
LocalCell local{};
|
||||
std::uint64_t expected_revision{};
|
||||
std::uint32_t removed_fill{};
|
||||
auto operator<=>(const CellCut&) const = default;
|
||||
};
|
||||
struct ExcavationRequest {
|
||||
std::uint64_t command{};
|
||||
std::uint32_t destination{1}; // the store's finite debris inventory
|
||||
std::span<const CellCut> cuts;
|
||||
std::uint64_t digest{};
|
||||
};
|
||||
struct EditedChunk {
|
||||
ChunkAddress address{};
|
||||
std::uint64_t revision{};
|
||||
auto operator<=>(const EditedChunk&) const = default;
|
||||
};
|
||||
struct EditReceipt {
|
||||
std::uint64_t command{}, digest{};
|
||||
std::array<VolumeUnits, 2> removed{};
|
||||
std::array<EditedChunk, 4> chunks{};
|
||||
std::size_t chunk_count{};
|
||||
auto operator<=>(const EditReceipt&) const = default;
|
||||
};
|
||||
// Validates request shape; digest excludes the digest field itself. Not authentication.
|
||||
[[nodiscard]] std::expected<std::uint64_t, ChunkError>
|
||||
excavation_digest(const ExcavationRequest& request) noexcept;
|
||||
class ChunkStore;
|
||||
// Immutable owned geometry. Construction does not authorize a terrain edit.
|
||||
class CompactCells {
|
||||
@@ -66,9 +109,11 @@ class ChunkView {
|
||||
class ChunkStore {
|
||||
public:
|
||||
static constexpr std::size_t max_slots = 4096;
|
||||
static constexpr std::size_t scratch_bytes = (4096 + 256) * sizeof(std::uint32_t);
|
||||
static constexpr std::size_t scratch_bytes = 32768;
|
||||
static constexpr std::size_t retained_commands = 64;
|
||||
[[nodiscard]] static std::expected<std::unique_ptr<ChunkStore>, ChunkError>
|
||||
create(BaseDescriptor descriptor, std::size_t slots, std::size_t byte_budget);
|
||||
create(BaseDescriptor descriptor, std::size_t slots, std::size_t byte_budget,
|
||||
DebrisCapacity debris = {});
|
||||
ChunkStore(const ChunkStore&) = delete;
|
||||
ChunkStore& operator=(const ChunkStore&) = delete;
|
||||
ChunkStore(ChunkStore&&) = delete;
|
||||
@@ -83,6 +128,8 @@ class ChunkStore {
|
||||
// Conservative pin only: no geometry edit or durability acknowledgement.
|
||||
[[nodiscard]] std::expected<ChunkView, ChunkError> mark_dirty(ChunkView view) noexcept;
|
||||
[[nodiscard]] std::expected<void, ChunkError> evict(ChunkView view) noexcept;
|
||||
[[nodiscard]] std::expected<EditReceipt, ChunkError> excavate(const ExcavationRequest& request);
|
||||
[[nodiscard]] std::expected<VolumeUnits, ChunkError> debris(MaterialId material) const noexcept;
|
||||
[[nodiscard]] std::size_t accounted_bytes() const noexcept {
|
||||
return bytes_;
|
||||
}
|
||||
@@ -92,11 +139,18 @@ class ChunkStore {
|
||||
|
||||
private:
|
||||
struct Entry;
|
||||
ChunkStore(BaseDescriptor descriptor, std::size_t slots, std::size_t budget, std::size_t bytes);
|
||||
struct History;
|
||||
ChunkStore(BaseDescriptor descriptor, std::size_t slots, std::size_t budget, std::size_t bytes,
|
||||
DebrisCapacity debris);
|
||||
[[nodiscard]] bool current(ChunkView view) const noexcept;
|
||||
BaseDescriptor descriptor_;
|
||||
std::size_t slots_, budget_, bytes_, size_{};
|
||||
std::uint64_t revision_{};
|
||||
std::unique_ptr<Entry[]> entries_;
|
||||
DebrisCapacity debris_capacity_;
|
||||
std::array<VolumeUnits, 2> debris_{};
|
||||
std::uint64_t last_command_{};
|
||||
std::size_t history_next_{};
|
||||
std::unique_ptr<History[]> history_;
|
||||
};
|
||||
} // namespace evo::world
|
||||
|
||||
Reference in New Issue
Block a user