DocumentSnapshot class
Parts of a level being edited, compressed in memory.
Keeps what an edit command changes in a large way — resized layers, replaced tile sets — so it can be put back. What isn't a change of the level stays as it is when a snapshot is restored: the editor state of layers that are still there (hidden, locked), and the chunks the editor writes on its own when the level is saved, such as the view or the preview (see IsVolatileChunk()).
The data is kept in the native byte order and layout of the records, and a recovery copy keeps it as it is (see CommandArchive), so any change of what is written changes EncodingVersion too.
Public static variables
-
static std::
uint32_t EncodingVersion constexpr - Version of how the parts are written, a part of the fingerprint of a recovery copy.
Public static functions
-
static auto Capture(const LevelDocument& document,
SnapshotParts parts,
std::
int32_t layer = -1, const DocumentSnapshot* previous = nullptr) -> DocumentSnapshot - Takes a snapshot of parts of a document.
- static auto GetChangeKinds(SnapshotParts parts) -> DocumentChangeKind
- Returns the changes of a document caused by restoring the given parts.
-
static auto IsVolatileChunk(std::
uint32_t tag) -> bool - Returns
truefor a chunk the editor writes on its own when the level is saved. -
static auto IsLayerChunk(std::
uint32_t tag) -> bool - Returns
truefor a chunk that belongs to layers, kept by SnapshotParts::Layers. - static void CompressLayer(const DocumentLayer& layer, CompressedBuffer& buffer)
- Compresses a single layer, with its tiles and its editor state.
- static auto DecompressLayer(const CompressedBuffer& buffer, DocumentLayer& layer) -> bool
- Decompresses a layer compressed by CompressLayer(), returns
falseif it's damaged. - static auto RemapLayerId(CompressedBuffer& buffer, LayerIdRemap& remap) -> bool
- Gives a layer compressed by CompressLayer() the identity of this run of the editor, returns
falseif it's damaged.
Constructors, destructors, conversion operators
Public functions
- auto Restore(LevelDocument& document) const -> bool
- Puts the parts kept by the snapshot back into a document.
- auto GetParts() const -> SnapshotParts
- Returns the parts kept by the snapshot.
-
auto GetLayer() const -> std::
int32_t - Returns the only layer kept, or -1 if all of them are.
-
auto GetMemoryUsage() const -> std::
size_t - Returns the memory taken by the snapshot.
- auto RemapLayerIds(LayerIdRemap& remap) -> bool
- Gives the layers kept by the snapshot the identities of this run of the editor, returns
falseif it's damaged. - void ShareBlobsWith(const DocumentSnapshot& other)
- Shares the data kept aside as it is with another snapshot where it's the same, so it's kept only once.
Function documentation
static DocumentSnapshot Jazz2:: Editor:: DocumentSnapshot:: Capture(const LevelDocument& document,
SnapshotParts parts,
std:: int32_t layer = -1,
const DocumentSnapshot* previous = nullptr)
Takes a snapshot of parts of a document.
With layer, SnapshotParts::Layers keeps only that layer, for a change that doesn't add or remove any. Data kept aside as it is (the tile sets the level stores in itself) is shared with previous where it's the same, as with the snapshot before a change.
static bool Jazz2:: Editor:: DocumentSnapshot:: IsVolatileChunk(std:: uint32_t tag)
Returns true for a chunk the editor writes on its own when the level is saved.
Such as the view (edoc), the preview (PRVW), the paths of the play-tests (ppth) or the path of a recovery copy (rcov). They aren't changes of the level, so restoring SnapshotParts::Chunks leaves them as they are.
bool Jazz2:: Editor:: DocumentSnapshot:: Restore(LevelDocument& document) const
Puts the parts kept by the snapshot back into a document.
All of them are read before any is put back, so a damaged snapshot leaves the document as it is and returns false.
Variable documentation
static std:: uint32_t Jazz2:: Editor:: DocumentSnapshot:: EncodingVersion constexpr
Version of how the parts are written, a part of the fingerprint of a recovery copy.
Has to change whenever what any part writes changes (the properties, the tile sets, a layer as CompressLayer() writes it too, the events, the chunks), a recovery copy of another version would be misread otherwise.