Jazz2::Tiles::LayerDescription struct

Describes the configuration of a tile map layer.

Holds the parallax and rendering properties of a single layer — its depth, per-axis scroll and auto-scroll speeds, scroll offsets, repeat flags, speed models and the renderer type with its color parameter. One is stored in each TileMapLayer and drives how that layer is positioned and drawn relative to the camera.

Where the game places a layer for a view is worked out here rather than by the tile map, so it's the same without one — the preview of a level made when the level is converted (see Formats::LevelPreview) places the layers this way too.

Public static variables

static std::int32_t HardcodedOffset constexpr
Hardcoded offset for layer positioning.
static float OriginalAutoSpeedScale constexpr
How much further an auto speed of the original game moves a layer each frame than the same auto speed here.

Public static functions

static auto FromRecord(const Formats::LayerRecord& record, std::int32_t mainPlaneDepth) -> LayerDescription
Makes the description of a layer from a layer of a level file.
static auto IsSpriteLayerRenderer(LayerRendererType type) -> bool
Returns true if the sprite layer can be drawn with a renderer type.
static auto IsBehindBlend(LayerBlend blend) -> bool
Returns true if a blend is computed with what is behind the layer, LayerBlend::Darken and those after it.
static auto FromSpriteMode(std::uint32_t spriteMode) -> LayerBlend
Returns the blend of a sprite mode of JJ2+ (SPRITE::Mode) a layer can be drawn with, LayerBlend::Normal for any other.
static auto IsTexturedBackground(LayerRendererType type) -> bool
Returns true if a renderer type is a textured background, LayerRendererType::Sky, LayerRendererType::Tunnel, LayerRendererType::TileMenu, LayerRendererType::Wave or LayerRendererType::Cylinder.
static auto FromOriginalAutoSpeed(float autoSpeed, LayerSpeedModel model) -> float
Converts an auto speed of the original game or of JJ2+ to one of a layer, on an axis of a speed model.
static auto ToOriginalAutoSpeed(float autoSpeed, LayerSpeedModel model) -> float
Converts an auto speed of a layer back to one of the original game or of JJ2+, see FromOriginalAutoSpeed().
static auto TranslateCoordinate(float coordinate, float speed, float offset, std::int32_t viewSize, bool isY) -> float
Returns the coordinate of a layer of the default speed model at a coordinate of the view.

Public functions

void SetTexturedParams(const Formats::TexturedLayerParams& params)
Takes the parameters of a tunnel, a wave, a cylinder or a reflection that the color has no room for.
auto IsKeyedTileLayer() const -> bool
Returns true if the layer is drawn as tiles that read what is behind them.
auto ReadsBehind() const -> bool
Returns true if the layer may need a copy of what is behind it to be drawn.
auto HasInnerSurface() const -> bool
Returns true if the texture of the layer is drawn only where the layer is placed as an ordinary one.
auto HasPlusPerspective() const -> bool
Returns true if the texture of the layer is drawn in the perspective of JJ2+.
auto IsTexturePlacedByLayer5(bool vertical) const -> bool
Returns true if the texture of a sky, a tunnel or a cylinder over the whole view is placed where layer 5 is on an axis.
auto GetGameplayOrigin(nCine::Vector2i layoutSize, nCine::Vector2i spriteLayoutSize, const nCine::Rectf& view) const -> nCine::Vector2f
Returns where the tile (0, 0) of the layer is drawn in the level, as the game places it for a view.
auto GetDrawOffsets(float viewHeight) const -> nCine::Vector2f
Returns the offsets the layer is drawn with in a view of a height.
auto GetViewCoordinates(nCine::Vector2i layoutSize, nCine::Vector2i spriteLayoutSize, const nCine::Rectf& placementRect, float loX, float loY) const -> nCine::Vector2f
Returns the coordinates of the layer at the top left corner of the view it's placed by, minus HardcodedOffset.

Public variables

std::uint16_t Depth
Layer depth (Z position).
float SpeedX
Horizontal speed.
float SpeedY
Vertical speed.
float AutoSpeedX
Horizontal auto speed.
float AutoSpeedY
Vertical auto speed.
float OffsetX
Horizontal scroll offset.
float OffsetY
Vertical scroll offset.
bool RepeatX
Whether layer should repeat horizontally.
bool RepeatY
Whether layer should repeat vertically.
bool UseInherentOffset
Whether inherent offset should be used, where it applies (see GetDrawOffsets()).
LayerSpeedModel SpeedModelX
Horizontal speed model.
LayerSpeedModel SpeedModelY
Vertical speed model.
LayerRendererType RendererType
Layer renderer type.
nCine::Vector4f Color
Layer color parameter.
nCine::Vector2f TextureFadePosition
Vanishing point and horizon of a sky, center of a tunnel or of the horizon of a cylinder, pivot of a tile menu, or the vanishing point and the horizon of a reflection, as a fraction of the view, the amplitudes of a wave.
std::uint8_t TextureFade
Non-zero if a sky fades out into its horizon, a tunnel into its center or a cylinder into its horizon, the palette entry a reflection is tinted with.
std::uint8_t TextureFlags
Combination of the flags of Formats::TexturedLayerParams, whether a tunnel spirals, whether a cylinder is drawn at half size, which way the waves of a wave move and where a textured layer is drawn.
nCine::Vector2f TextureInnerSpeed
Speeds of the texture of a textured layer drawn only where the layer is, against the view, see Formats::TexturedLayerParams::InnerSpeedX.
nCine::Vector2f TextureInnerAutoSpeed
Speeds the texture of a textured layer drawn only where the layer is moves at by itself, see Formats::TexturedLayerParams::InnerAutoSpeedX.
std::uint8_t TextureMapping
One more than the index of the additional palette the texture of a textured layer is drawn through, see Formats::TexturedLayerParams::Mapping.
LayerBlend Blend
How the layer is blended over what is behind it.
std::uint8_t BlendParam
Opacity of a translucent, screened or multiplied layer, or the palette entry of the key of a textured background (see Blend).

Function documentation

static LayerDescription Jazz2::Tiles::LayerDescription::FromRecord(const Formats::LayerRecord& record, std::int32_t mainPlaneDepth)

Makes the description of a layer from a layer of a level file.

The depth of the layer is relative to mainPlaneDepth, the depth of the sprite layer's plane (see ILevelHandler::MainPlaneZ). The sprite layer is always placed and moves with its defaults, only its renderer type and color are taken from the record, if it's one the sprite layer can be drawn with (see IsSpriteLayerRenderer()), otherwise it's drawn as ordinary tiles.

static bool Jazz2::Tiles::LayerDescription::IsSpriteLayerRenderer(LayerRendererType type)

Returns true if the sprite layer can be drawn with a renderer type.

Only those that draw each tile where it is — LayerRendererType::Default, LayerRendererType::Solid, LayerRendererType::Tinted, LayerRendererType::PaletteShift, LayerRendererType::SingleColor, LayerRendererType::AlphaMap and LayerRendererType::PaletteMapping. An x-ray layer hides its tiles away from the objects and changes its animated tiles, a blur or a reflection layer doesn't show its tiles at all, a sky, a tunnel or a cylinder is drawn far away from where its tiles are, and a wave moves them, while the objects of the level walk on the tiles of the sprite layer.

static LayerBlend Jazz2::Tiles::LayerDescription::FromSpriteMode(std::uint32_t spriteMode)

Returns the blend of a sprite mode of JJ2+ (SPRITE::Mode) a layer can be drawn with, LayerBlend::Normal for any other.

BLEND_DARKEN to BLEND_EXCLUSION, CHROMAKEY, and TRANSLUCENT, TRANSLUCENTTILE and BLEND_NORMAL (LayerBlend::Translucent, only a textured background takes it).

static bool Jazz2::Tiles::LayerDescription::IsTexturedBackground(LayerRendererType type)

Returns true if a renderer type is a textured background, LayerRendererType::Sky, LayerRendererType::Tunnel, LayerRendererType::TileMenu, LayerRendererType::Wave or LayerRendererType::Cylinder.

A LayerRendererType::Reflection isn't one, though it takes the tiles of its layer as a texture too.

static float Jazz2::Tiles::LayerDescription::FromOriginalAutoSpeed(float autoSpeed, LayerSpeedModel model)

Converts an auto speed of the original game or of JJ2+ to one of a layer, on an axis of a speed model.

Multiplied by OriginalAutoSpeedScale, so the layer moves as far each second as there. The auto speed of LayerSpeedModel::SpeedMultipliers isn't a speed but where the layer is at the end of the level, it's kept.

void Jazz2::Tiles::LayerDescription::SetTexturedParams(const Formats::TexturedLayerParams& params)

Takes the parameters of a tunnel, a wave, a cylinder or a reflection that the color has no room for.

The level file stores them apart from the record of the layer (see Formats::LayerPropertiesChunk).

bool Jazz2::Tiles::LayerDescription::IsKeyedTileLayer() const

Returns true if the layer is drawn as tiles that read what is behind them.

Only over a color of it (LayerBlend::ChromaKey), or mixed with it by a blend mode (see IsBehindBlend()).

bool Jazz2::Tiles::LayerDescription::ReadsBehind() const

Returns true if the layer may need a copy of what is behind it to be drawn.

A layer of tiles drawn by IsKeyedTileLayer(), and a textured background drawn translucent, keyed or by a blend mode from LayerBlend::Darken on.

bool Jazz2::Tiles::LayerDescription::HasInnerSurface() const

Returns true if the texture of the layer is drawn only where the layer is placed as an ordinary one.

A textured background other than a wave, or a reflection, with Formats::TexturedLayerParams::InnerWindow or Formats::TexturedLayerParams::InnerLayer — SURFACE::INNERWINDOW and INNERLAYER of JJ2+.

bool Jazz2::Tiles::LayerDescription::HasPlusPerspective() const

Returns true if the texture of the layer is drawn in the perspective of JJ2+.

Over the whole view with Formats::TexturedLayerParams::Fullscreen, and always only where the layer is (see HasInnerSurface()). A LayerRendererType::Cylinder is always drawn so, it has no other model.

bool Jazz2::Tiles::LayerDescription::IsTexturePlacedByLayer5(bool vertical) const

Returns true if the texture of a sky, a tunnel or a cylinder over the whole view is placed where layer 5 is on an axis.

In the perspective of JJ2+ (see HasPlusPerspective()) and with LayerSpeedModel::AlwaysOnTop on the axis — LAYERSPEEDMODEL::LAYER8 of JJ2+, the default of the sky layer of the original game. The texture then moves there only by its own auto speed, see TileMap::OnUpdate().

nCine::Vector2f Jazz2::Tiles::LayerDescription::GetGameplayOrigin(nCine::Vector2i layoutSize, nCine::Vector2i spriteLayoutSize, const nCine::Rectf& view) const

Returns where the tile (0, 0) of the layer is drawn in the level, as the game places it for a view.

layoutSize is the size of the layer and spriteLayoutSize the size of the sprite layer, both in tiles. A position in the level then lies on the tile (position - origin) / 32 of the layer, repeated if the layer repeats.

nCine::Vector2f Jazz2::Tiles::LayerDescription::GetDrawOffsets(float viewHeight) const

Returns the offsets the layer is drawn with in a view of a height.

The offsets of the layer. The vertical one is less by the inherent offset where it applies, which moves the layer down by half of how much taller the view is than 200 pixels, as limitVisibleRegion of JJ2+ — only a layer of LayerSpeedModel::Default that doesn't repeat vertically — and more by a pixel, which draws every layer that moves with the level a pixel higher than JJ2+, the sprite layer too. They're what GetViewCoordinates() takes.

nCine::Vector2f Jazz2::Tiles::LayerDescription::GetViewCoordinates(nCine::Vector2i layoutSize, nCine::Vector2i spriteLayoutSize, const nCine::Rectf& placementRect, float loX, float loY) const

Returns the coordinates of the layer at the top left corner of the view it's placed by, minus HardcodedOffset.

The sizes are as in GetGameplayOrigin(), loX and loY are the offsets the layer is drawn with (see GetDrawOffsets()). On each axis, with the view starting at $ c $ and $ v $ long, the layer $ l $ and the level $ L $ pixels long, the speed $ s $ , the auto speed $ a $ and the offset $ o $ , the layer coordinate at the start of the view is, by the speed model:

That's where JJ2+ v6.6h places them, measured with Tests/Level/LayerProbe.j2as in three resolutions (see the TestLayerPlacement() of the editor self-test). The auto speed of the default model and of LayerSpeedModel::FromStart moves the layer by its offset, see TileMap::OnUpdate().

Variable documentation

static float Jazz2::Tiles::LayerDescription::OriginalAutoSpeedScale constexpr

How much further an auto speed of the original game moves a layer each frame than the same auto speed here.

The original game and JJ2+ move a layer by its auto speed each of their 70 ticks a second, a layer here moves by its auto speed each of the 60 frames a second (see TileMap::OnUpdate()), see FromOriginalAutoSpeed().