Implement M5.6 canonical world snapshots and edit journals
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <expected>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
namespace evo::world {
|
||||
enum class ChunkError : std::uint8_t {
|
||||
@@ -64,6 +65,24 @@ struct EditReceipt {
|
||||
// Validates request shape; digest excludes the digest field itself. Not authentication.
|
||||
[[nodiscard]] std::expected<std::uint64_t, ChunkError>
|
||||
excavation_digest(const ExcavationRequest& request) noexcept;
|
||||
struct WorldIdentity {
|
||||
std::uint64_t world{}, frame{};
|
||||
auto operator<=>(const WorldIdentity&) const = default;
|
||||
};
|
||||
enum class WorldCodecError : std::uint8_t {
|
||||
format,
|
||||
version,
|
||||
checksum,
|
||||
identity,
|
||||
bounds,
|
||||
state,
|
||||
budget,
|
||||
edit,
|
||||
predecessor
|
||||
};
|
||||
using WorldBytes = std::vector<std::uint8_t>;
|
||||
inline constexpr std::size_t max_world_snapshot_bytes = std::size_t{70} * 1024 * 1024;
|
||||
inline constexpr std::size_t max_world_journal_bytes = std::size_t{256} * 1024;
|
||||
class ChunkStore;
|
||||
// Immutable owned geometry. Construction does not authorize a terrain edit.
|
||||
class CompactCells {
|
||||
@@ -130,6 +149,9 @@ class ChunkStore {
|
||||
[[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::expected<WorldBytes, WorldCodecError> snapshot(WorldIdentity identity) const;
|
||||
[[nodiscard]] static std::expected<std::unique_ptr<ChunkStore>, WorldCodecError>
|
||||
restore(std::span<const std::uint8_t> bytes, WorldIdentity identity, std::size_t byte_budget);
|
||||
[[nodiscard]] std::size_t accounted_bytes() const noexcept {
|
||||
return bytes_;
|
||||
}
|
||||
@@ -149,8 +171,15 @@ class ChunkStore {
|
||||
std::unique_ptr<Entry[]> entries_;
|
||||
DebrisCapacity debris_capacity_;
|
||||
std::array<VolumeUnits, 2> debris_{};
|
||||
std::uint64_t last_command_{};
|
||||
std::uint64_t last_command_{}, committed_edits_{};
|
||||
std::size_t history_next_{};
|
||||
std::unique_ptr<History[]> history_;
|
||||
};
|
||||
// Journals admit only fresh commands against the supplied loaded base, no cache operations.
|
||||
[[nodiscard]] std::expected<WorldBytes, WorldCodecError>
|
||||
make_edit_journal(std::span<const std::uint8_t> base, WorldIdentity identity,
|
||||
std::span<const ExcavationRequest> requests, std::size_t byte_budget);
|
||||
[[nodiscard]] std::expected<std::unique_ptr<ChunkStore>, WorldCodecError>
|
||||
replay_edit_journal(std::span<const std::uint8_t> base, std::span<const std::uint8_t> journal,
|
||||
WorldIdentity identity, std::size_t byte_budget);
|
||||
} // namespace evo::world
|
||||
|
||||
Reference in New Issue
Block a user