Jazz2::Tiles::TileMap class

Represents a renderable tile map, consists of multiple layers.

Owns the level's tile layers and tile sets and renders them as a scene node. Besides drawing, it advances animated tiles, performs tile collision queries, handles destructible/collapsing/trigger tiles and spawns debris, notifying its ITileMapOwner of the resulting events.

Base classes

class nCine::SceneNode
Base node of the scene graph transformation hierarchy.

Public types

struct DestructibleDebris
Describes a visual debris (particle effect).
enum class DebrisFlags { None = 0x00, Disappear = 0x01, Bounce = 0x02, AdditiveBlending = 0x04 }
Flags that modify behaviour of DestructibleDebris, supports a bitwise combination of its member values.

Constructors, destructors, conversion operators

TileMap(StringView tileSetPath, std::uint16_t captionTileId, bool applyPalette)
Creates a new instance.
~TileMap()

Public functions

auto IsValid() const -> bool
Returns true if all used tile sets are loaded.
void SetOwner(ITileMapOwner* owner)
Sets an owner of tile map.
auto GetSize() const -> Vector2i
Returns size of tile map in tiles.
auto GetLevelBounds() const -> Vector2i
Returns size of tile map in pixels.
auto GetPitType() const -> PitType
Returns pit type.
void SetPitType(PitType value)
Sets pit type.
void OnUpdate(float timeMult) override
Called every frame to update the node state.
void OnEndFrame()
Called at the end of each frame.
auto OnDraw(RenderQueue& renderQueue) -> bool override
Called when the node needs to be drawn, returning true if a command was added.
auto IsTileEmpty(std::int32_t tx, std::int32_t ty) -> bool
Returns true if the mask of a tile on the main (sprite) layer is completely empty.
auto IsTileEmpty(const AABBf& aabb, TileCollisionParams& params) -> bool
Returns true if the mask of tiles on the main (sprite) layer intersecting a given AABB is empty.
auto CanBeDestroyed(const AABBf& aabb, TileCollisionParams& params) -> bool
Returns true if tiles on the main (sprite) layer intersecting a given AABB can be destroyed.
auto GetTileSuspendState(float x, float y) -> SuspendType
Returns suspend state of a given position.
auto AdvanceDestructibleTileAnimation(std::int32_t tx, std::int32_t ty, std::int32_t amount) -> bool
Advances descructible animation of a given tile.
void AddTileSet(StringView tileSetPath, std::uint16_t offset, std::uint16_t count, const std::uint8_t* paletteRemapping = nullptr)
Adds an additional tile set as a continuation of the previous one.
void ReadLayerConfiguration(Stream& s)
Reads layer configuration from a stream.
void ReadAnimatedTiles(Stream& s)
Reads description of animated tiles from a stream.
void SetTileEventFlags(std::int32_t x, std::int32_t y, EventType tileEvent, std::uint8_t* tileParams)
Sets tile event flags.
auto OverrideTileDiffuse(std::int32_t tileId, StaticArrayView<(TileSet::DefaultTileSize+2)*(TileSet::DefaultTileSize+2), std::uint32_t> tileDiffuse) -> bool
Overrides the diffuse texture of the specified tile.
auto IsTileSetIndexed(std::int32_t tileId) -> bool
Returns true if the tileset containing the given tile stores indexed (palette) diffuse.
auto OverrideTileMask(std::int32_t tileId, StaticArrayView<TileSet::DefaultTileSize*TileSet::DefaultTileSize, std::uint8_t> tileMask) -> bool
Overrides the collision mask of the specified tile.
auto GetCaptionTile() const -> StaticArrayView<TileSet::DefaultTileSize*TileSet::DefaultTileSize, Color>
Returns a caption tile.
auto GetUsedTileSetPaths() const -> Array<StringView>
Returns relative paths of all used tile sets.
void CreateDebris(const DestructibleDebris& debris)
Creates a generic debris.
void CreateTileDebris(std::int32_t tileId, std::int32_t x, std::int32_t y)
Creates a tile debris.
void CreateParticleDebris(const GraphicResource* res, Vector3f pos, Vector2f force, std::int32_t currentFrame, bool isFacingLeft)
Creates a particle debris from a sprite.
void CreateSpriteDebris(const GraphicResource* res, Vector3f pos, std::int32_t count)
Creates a sprite debris.
auto GetTrigger(std::uint8_t triggerId) -> bool
Returns state of a given trigger.
void SetTrigger(std::uint8_t triggerId, bool newState)
Sets state of a given trigger.
auto GetLayerCount() const -> std::int32_t
Returns number of layers.
auto GetLayerSize(std::int32_t layerIndex) const -> Vector2i
Returns size of a given layer in tiles, or an empty vector if the layer doesn't exist.
auto GetTile(std::int32_t layerIndex, std::int32_t x, std::int32_t y) const -> std::uint16_t
Returns the tile at the given coordinates on a given layer as a packed value.
auto SetTile(std::int32_t layerIndex, std::int32_t x, std::int32_t y, std::uint16_t tileValue) -> bool
Sets the tile at the given coordinates on a given layer from a packed value.
void CreateCheckpointForRollback()
Creates a checkpoint for eventual rollback.
void RollbackToCheckpoint()
Rolls back to the last checkpoint.
void InitializeFromStream(Stream& src)
Initializes tile map state from a stream.
void SerializeResumableToStream(Stream& dest, bool fromCheckpoint = false)
Serializes tile map state to a stream.
void OnInitializeViewport()
Called when the viewport needs to be initialized (e.g., when the resolution is changed).

Constants

static std::int32_t TriggerCount constexpr
Maximum number of triggers.
static std::int32_t HardcodedOffset constexpr
Hardcoded offset for layer positioning.
static std::uint16_t TileIndexMask constexpr
Mask of the tile index inside a packed tile value (see GetTile()).
static std::uint16_t TileFlagFlipX constexpr
Flag of a packed tile value that is flipped horizontally.
static std::uint16_t TileFlagFlipY constexpr
Flag of a packed tile value that is flipped vertically.
static std::uint16_t TileFlagAnimated constexpr
Flag of a packed tile value that refers to an animated tile (index is relative to the first animated tile).

Enum documentation

enum class Jazz2::Tiles::TileMap::DebrisFlags

Flags that modify behaviour of DestructibleDebris, supports a bitwise combination of its member values.

Enumerators
None

None

Disappear

Debris disappears over time

Bounce

Debris bounces off solid tiles

AdditiveBlending

Debris is rendered with additive blending

Function documentation

Jazz2::Tiles::TileMap::TileMap(StringView tileSetPath, std::uint16_t captionTileId, bool applyPalette)

Creates a new instance.

Parameters
tileSetPath Relative path to the main tile set
captionTileId Tile used to render the level-preview caption thumbnail
applyPalette Whether to apply the tile set's palette to the live sprite palette

bool Jazz2::Tiles::TileMap::IsTileSetIndexed(std::int32_t tileId)

Returns true if the tileset containing the given tile stores indexed (palette) diffuse.

When indexed, an overridden tile must be supplied as palette indices (red channel) rather than baked colors.

std::uint16_t Jazz2::Tiles::TileMap::GetTile(std::int32_t layerIndex, std::int32_t x, std::int32_t y) const

Returns the tile at the given coordinates on a given layer as a packed value.

The low 12 bits are the tile index (see TileIndexMask), combined with TileFlagFlipX / TileFlagFlipY / TileFlagAnimated. Returns 0 if the layer or coordinates are out of range.

bool Jazz2::Tiles::TileMap::SetTile(std::int32_t layerIndex, std::int32_t x, std::int32_t y, std::uint16_t tileValue)

Sets the tile at the given coordinates on a given layer from a packed value.

The value is packed as in GetTile(). Unrelated tile state (transparency, collision flags) is preserved. Returns false if out of range.