Jazz2::Editor::TerrainSpline struct

Ground laid along a line, kept so it can be changed and laid again.

The line is kept in pixels of its layer, from its tile (0, 0), so it stays with the layer however the layer moves in the view. Each tile it wrote is remembered with the tile that was there before: when it's laid again, a tile that's still as it wrote it gets back what was there, and a tile changed by hand since is left as it is and isn't written anymore. They're kept in the editor-only chunk spl2, so the exported level has only the tiles.

The chunk is u8 version (1), varuint count, then for each line a varuint size of its record and the record: i32 layer, u8 depth, u8 kind, u8 flags (1 smooth), varuint count of points and f32 X, Y of each, varuint count of tiles and i32 X, Y, the tile written and the one before (u16 index, u8 source, u8 flags) of each. A newer version may add fields at the end of a record, a reader skips those it doesn't know.

Public types

struct OwnedTile
Tile written by the ground, and what was there before.

Public static variables

static std::uint32_t Chunk constexpr
Tag of the chunk they're kept in.
static std::uint32_t LegacyChunk constexpr
Tag of the chunk 3.9.0 kept them in, without a version, only read.

Public static functions

static void Read(const LevelDocument& document, SmallVectorImpl<TerrainSpline>& splines)
Reads all of them from a level, lines with points that make no sense are left out.
static void Write(const SmallVectorImpl<TerrainSpline>& splines, SmallVectorImpl<std::uint8_t>& data)
Writes all of them into bytes of the chunk.
static void GetChunkData(const LevelDocument& document, SmallVectorImpl<std::uint8_t>& data)
Returns the bytes of the chunk as the level has them now, in the current version, none without lines.
static void SetChunkData(LevelDocument& document, ArrayView<const std::uint8_t> data)
Replaces the chunk by the given bytes, the chunk of 3.9.0 is removed.
static void UpgradeLegacyChunk(LevelDocument& document)
Converts the chunk of 3.9.0 to the current one, if the level has it.
static void RemapTiles(LevelDocument& document, Function<bool(TileRef&)>& remap)
Follows tiles that moved to other tile references, as when the tile sets changed.
static void RemapLayers(LevelDocument& document, ArrayView<const std::int32_t> newIndices)
Follows layers that were added, removed or moved.
static void ResizeLayer(LevelDocument& document, std::int32_t layer, Vector2i size, Vector2i offset)
Follows a layer that was resized, its tiles moved by offset, tiles outside of it aren't its own anymore.

Public variables

std::int32_t Layer
Layer of the ground.
SmallVector<Vector2f, 0> Points
Points of the surface in pixels of the layer, from left to right, in the order around the shape for a closed one.
std::int32_t Depth
Most tiles filled below the surface, above it for a ceiling, the thickness of a band.
SplineKind Kind
What is laid.
bool Smooth
Whether the line is a smooth curve through its points, not straight between them.
SmallVector<OwnedTile, 0> Owned
Tiles written.

Function documentation

static void Jazz2::Editor::TerrainSpline::Read(const LevelDocument& document, SmallVectorImpl<TerrainSpline>& splines)

Reads all of them from a level, lines with points that make no sense are left out.

The legacy chunk wins over the current one if the level has both, it was written by 3.9.0 after this version saved the level, as this version never writes it.

static void Jazz2::Editor::TerrainSpline::RemapTiles(LevelDocument& document, Function<bool(TileRef&)>& remap)

Follows tiles that moved to other tile references, as when the tile sets changed.

remap changes a reference in place, or returns false if its tile is gone, it's then the empty tile.

static void Jazz2::Editor::TerrainSpline::RemapLayers(LevelDocument& document, ArrayView<const std::int32_t> newIndices)

Follows layers that were added, removed or moved.

newIndices has the new index of each layer as it was, -1 for a removed one, whose lines are gone.