TileMap class
#include <Jazz2/Tiles/TileMap.h>
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.
Public static functions
-
static auto MakeLayerTile(std::
uint8_t fileFlags, std:: uint16_t tileId) -> LayerTile - Makes a layer tile from a tile of a level file.
-
static auto MakeLayerDescription(const Formats::
LayerRecord& record) -> LayerDescription - Makes the description of a layer from a layer of a level file.
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
trueif 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
trueif a command was added. -
auto IsTileEmpty(std::
int32_t tx, std:: int32_t ty) -> bool - Returns
trueif the mask of a tile on the main (sprite) layer is completely empty. -
auto IsTileDestructible(std::
int32_t tx, std:: int32_t ty) -> bool - Returns
trueif the tile on the main (sprite) layer can be destroyed by the player (read-only, no side effects). -
auto IsTileDestroyed(std::
int32_t tx, std:: int32_t ty) -> bool - Returns
trueif the destructible tile on the main (sprite) layer is destroyed, the last frame of its destruction shown. -
auto IsTileOneWay(std::
int32_t tx, std:: int32_t ty) -> bool - Returns
trueif the tile on the main (sprite) layer is a one-way platform (passable from below). -
auto IsTileCornerEmpty(std::
int32_t tx, std:: int32_t ty, std:: int32_t cornerX, std:: int32_t cornerY) -> bool - Returns
trueif the given ~1/3 corner of the tile's collision mask is empty (cornerX/cornerY: -1 = left/top, +1 = right/bottom). -
auto IsTilePartiallySolid(std::
int32_t tx, std:: int32_t ty) -> bool - Returns
trueif the tile's collision mask is neither fully empty nor fully filled (e.g., a slope or a thin solid band). -
auto IsTilePixelDrawn(std::
int32_t x, std:: int32_t y) -> bool - Returns
trueif the main (sprite) layer draws the pixel of the level, whatever its mask. -
auto IsTileTrigger(std::
int32_t tx, std:: int32_t ty) -> bool - Returns
trueif the tile on the main (sprite) layer is controlled by a trigger (toggled solid/empty by a trigger crate). - auto IsTileEmpty(const AABBf& aabb, TileCollisionParams& params) -> bool
- Returns
trueif the mask of tiles on the main (sprite) layer intersecting a given AABB is empty. -
auto IsTilePointEmpty(std::
int32_t x, std:: int32_t y, bool downwards) -> bool - Returns
trueif the collision mask of the main (sprite) layer is empty at a single point. - auto CanBeDestroyed(const AABBf& aabb, TileCollisionParams& params) -> bool
- Returns
trueif 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 GetTileSuspendState(float x, float y, float toleranceX, float toleranceUp, float toleranceDown, Vector2f& snapOffset) -> SuspendType
- Returns suspend state of the closest attachment point around 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 AddTileSet(Stream& s,
StringView name,
std::
uint16_t offset, std:: uint16_t count, const std:: uint8_t* paletteRemapping = nullptr) - Adds an additional tile set read from a stream, as one stored in the level, as a continuation of the previous one.
-
auto AppendTileSet(StringView tileSetPath,
std::
uint16_t offset, std:: uint16_t count, const std:: uint8_t* paletteRemapping = nullptr, const std:: uint32_t* trueColorPalette = nullptr) -> bool - Adds tiles of a tile set after the tiles of the others while the level is played.
-
auto AppendBlankTiles(std::
int32_t tileId) -> bool - Makes the empty tile IDs after the tiles of the tile sets up to
tileIdreal, transparent tiles. -
void LoadLayer(Formats::
LevelReader& reader) - Reads the next layer of a level, its description and its tiles, and adds it.
-
auto AddLayer(Vector2i size,
const LayerDescription& description) -> std::
int32_t - Adds a layer of no tiles after the others, which isn't drawn, returns its index or
-1if the memory isn't there. -
auto ResetLayer(std::
int32_t layerIndex, Vector2i size, const LayerDescription& description) -> bool - Replaces a layer added by AddLayer() with one of no tiles, which isn't drawn.
- auto HasLoadFailed() const -> bool
- Whether reading the layers ran out of memory (the level cannot be played).
-
void SetAnimatedTiles(std::
uint16_t animatedTilesOffset, ArrayView<const Formats:: AnimatedTileRecord> animatedTiles) - Sets the animated tiles of the level.
- void InvalidateTexturedBackground()
- Draws the textured background of the level again, after its tiles changed.
-
auto GetAnimatedTileCount() const -> std::
int32_t - Returns the number of animated tiles.
-
void SetAnimatedTile(std::
int32_t index, const Formats:: AnimatedTileRecord& animatedTile) - Changes the timing and the frames of an animated tile, it goes on playing from where it is.
-
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:: PaddedTileSize*TileSet:: PaddedTileSize, std:: uint32_t> tileDiffuse) -> bool - Overrides the diffuse texture of the specified tile.
-
auto IsTileSetIndexed(std::
int32_t tileId) -> bool - Returns
trueif the tileset containing the given tile stores indexed (palette) diffuse. -
auto OverrideTileMask(std::
int32_t tileId, StaticArrayView<TileSet:: DefaultTileSize*TileSet:: DefaultTileSize, const 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, float elasticity = 0.8f) - 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.
-
void ClearTileTrigger(std::
int32_t x, std:: int32_t y) - Makes a tile of the sprite layer switched by a trigger an ordinary one, as it shows now, what drives it switches it then.
-
auto GetPlacedTile(std::
int32_t x, std:: int32_t y) const -> std:: uint16_t - Returns the tile of the sprite layer as the level placed it (an animated one of scenery or a trigger), in the form of GetTile().
-
auto GetTriggeredTile(std::
uint16_t tileValue, bool triggerOn) const -> std:: uint16_t - Returns the tile a trigger tile shows by the trigger, the second frame of an animated one or none, in the form of GetTile().
-
auto GetLayerCount() const -> std::
int32_t - Returns number of layers.
- auto GetViewOptions() const -> const TileMapViewOptions&
- Returns the options of how the tile map is shown.
- void SetViewOptions(const TileMapViewOptions& options)
- Sets the options of how the tile map is shown, the defaults show it as the game does.
-
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 SetTileModifier(std::
int32_t tileId, std:: uint8_t alpha, bool heat) - Gives every placed tile of an ID that isn't animated a transparency and the heat effect, or not.
-
auto GetLayerRendererType(std::
int32_t layerIndex) const -> LayerRendererType - Returns the renderer type of a given layer, or LayerRendererType::
Default if the layer doesn't exist. -
auto SetLayerRendererType(std::
int32_t layerIndex, LayerRendererType type) -> bool - Changes the renderer type of a given layer.
-
auto ReplaceLayerTile(std::
int32_t layerIndex, std:: int32_t x, std:: int32_t y, const LayerTile& tile) -> bool - Replaces a tile of a layer, as if it was loaded so from the level file.
-
auto GetLayerDescription(std::
int32_t layerIndex) const -> const LayerDescription* - Returns the description of a layer, or
nullptrif the layer doesn't exist. -
auto SetLayerDescription(std::
int32_t layerIndex, const LayerDescription& description, bool visible) -> bool - Changes how a layer is placed and drawn, and whether it's drawn at all.
-
auto SetLayerTexture(std::
int32_t layerIndex, ArrayView<const std:: uint8_t> pixels) -> bool - Gives a textured layer a texture of its own, taken instead of the tiles at its top left.
-
auto GetLayerTexture(std::
int32_t layerIndex) const -> ArrayView<const std:: uint8_t> - Returns the texture of its own of a layer (see SetLayerTexture()), empty if it has none or the layer doesn't exist.
- auto SetSpriteLayerRenderer(LayerRendererType type, const Vector4f& color) -> bool
- Changes how the sprite layer is drawn, it's still placed as always.
-
void SetAdditionalPalettes(ArrayView<const Formats::
PaletteRecord> palettes) - Sets the additional palettes of the level, which layers of LayerRendererType::
PaletteMapping are drawn through. -
auto ReorderLayers(ArrayView<const std::
int32_t> order) -> bool - Puts the layers in another order, as they are with all their state.
-
auto IsLayerVisible(std::
int32_t layerIndex) const -> bool - Returns
trueif a layer is drawn. -
auto GetLayerName(std::
int32_t layerIndex) const -> StringView - Returns the name of a layer (see TileMapLayer::
Name), empty if it has none or the layer doesn't exist. -
auto GetLayerOriginalNumber(std::
int32_t layerIndex) const -> std:: uint8_t - Returns the number of a layer in the original game (see TileMapLayer::
OriginalNumber), 0 if it has none. -
auto GetDepthInFrontOfLayer(std::
int32_t layerIndex) const -> std:: uint16_t - Returns the depth of the nearest visible layer in front of a layer,
0if there is none. -
void SetLayerIdentity(std::
int32_t layerIndex, StringView name, std:: uint8_t originalNumber) - Sets the name and the number in the original game of a layer, which only scripts use.
-
auto GetTileQuad(std::
int32_t tileId, LayerTileFlags flags, Texture*& texture, Vector4f& texCoords, bool& indexed) -> bool - Returns the texture and texture coordinates a tile is drawn with.
-
auto GetStaticTileQuad(std::
int32_t tileId, LayerTileFlags flags, Texture*& texture, Vector4f& texCoords, bool& indexed) -> bool - Returns the texture and texture coordinates a tile of the tile sets is drawn with.
-
auto GetLayerOrigin(std::
int32_t layerIndex, Vector2f viewCenter, Vector2f viewSize) const -> Vector2f - Returns where the tile (0, 0) of a layer is drawn in the level, for a view of a given center and size.
-
auto GetGameplayLayerOrigin(std::
int32_t layerIndex, const Rectf& view) const -> Vector2f - Returns where the tile (0, 0) of a layer is drawn in the level, as the game places it for a view, whatever the view options.
-
auto GetTileSetCount() const -> std::
int32_t - Returns the number of tile sets, the default one and the extra ones.
-
auto GetTileSetTileCount(std::
int32_t index) const -> std:: int32_t - Returns the number of tiles taken from a tile set.
-
auto GetStaticTileCount() const -> std::
int32_t - Returns the number of tiles of all tile sets, which is the first tile ID of the animated tiles.
-
auto GetLoadedTileCount() const -> std::
int32_t - Returns the number of tiles the tile sets give, the IDs from it up to GetStaticTileCount() are empty tiles.
-
auto ResolveStaticTileId(std::
int32_t tileId) const -> std:: int32_t - Returns the tile an animated tile shows now, or the tile itself if it isn't animated.
-
auto GetStaticTileMask(std::
int32_t tileId) -> const std:: uint8_t* - Returns the packed collision mask of a tile that isn't animated (TileSet::
MaskBytesPerTile bytes), or nullptr. - auto HasXRayLayers() const -> bool
- Returns
trueif any layer is a LayerRendererType::XRay layer. - auto HasBlurBehindLayers() const -> bool
- Returns
trueif any layer is a LayerRendererType::BlurBehind layer. - auto BlurBehindLayersNeedSharpCopy() -> bool
- Returns
trueif a LayerRendererType::BlurBehind layer has a tile that reflects or displaces, which needs a sharp copy of the scene behind it. - auto HasReflectionLayers() const -> bool
- Returns
trueif any layer is a LayerRendererType::Reflection layer, which needs a sharp copy of the scene behind it. - auto HasChromaKeyLayers() const -> bool
- Returns
trueif any layer is drawn keyed (see LayerBlend::ChromaKey) or a textured one translucent, or sprites are (see RequestKeyedSprites()), which needs a sharp copy of the scene behind it. - void RequestKeyedSprites()
- Tells the owner that sprites drawn keyed need a sharp copy of the scene behind them from now on, once.
- void CreateCheckpointForRollback()
- Creates a checkpoint for eventual rollback.
- void RollbackToCheckpoint()
- Rolls back to the last checkpoint.
- auto InitializeFromStream(Stream& src) -> bool
- Initializes tile map state from a stream.
- void SerializeResumableToStream(Stream& dest, bool fromCheckpoint = false)
- Serializes tile map state to a stream.
- auto InitializeSnapshotFromStream(Stream& src) -> bool
- Restores complete live state of the sprite layer (including the last checkpoint) from a snapshot.
- void SerializeSnapshotToStream(Stream& dest)
- Serializes complete live state of the sprite layer (including the last checkpoint) to a snapshot.
- void PruneTilesetAtlas()
- Repacks the tileset's atlas around the tiles this level actually references.
- 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).
-
static std::
uint8_t TranslucentTileAlpha constexpr - Alpha of a tile the file marks as translucent, anything that shows the tiles otherwise uses it too.
Debris budget
-
static std::
int32_t MaxDebrisCount constexpr - Maximum number of live debris particles, or
0if the effect is unbounded. -
static std::
int32_t MaxWeatherDebrisCount constexpr - Maximum number of live debris particles the weather effect may occupy, or
0if unbounded. -
static std::
int32_t WeatherDepthStep constexpr - Step the depth of a weather particle is rounded to.
- static bool WeatherDebrisSpins constexpr
- Whether the snowflakes turn as they fall.
-
static std::
int32_t MaxParticleDebrisPerBurst constexpr - Maximum number of particles one CreateParticleDebris() burst emits, or
0if unbounded. -
auto GetDebrisCount() const -> std::
int32_t - Returns number of live debris particles.
-
static auto GetParticleDebrisStep(std::
int32_t debrisSize, std:: int32_t frameWidth, std:: int32_t frameHeight) -> std:: int32_t - Returns the step in which a particle debris burst walks a sprite frame of the given size.
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
static LayerTile Jazz2:: Tiles:: TileMap:: MakeLayerTile(std:: uint8_t fileFlags,
std:: uint16_t tileId)
Makes a layer tile from a tile of a level file.
The flags carry the flips in the low nibble and a modifier in the high one (see Formats::
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:: IsTilePointEmpty(std:: int32_t x,
std:: int32_t y,
bool downwards)
Returns true if the collision mask of the main (sprite) layer is empty at a single point.
A stripped-down IsTileEmpty() for things small enough that one sample is all the precision they need - debris in particular, which is a few pixels across but can be several hundred strong after an enemy dies. It resolves one tile and tests one mask bit, skipping the covered-tile iteration and the whole destructible/collapsing tile machinery that a point sample cannot use.
SuspendType Jazz2:: Tiles:: TileMap:: GetTileSuspendState(float x,
float y,
float toleranceX,
float toleranceUp,
float toleranceDown,
Vector2f& snapOffset)
Returns suspend state of the closest attachment point around a given position.
Searches the whole tolerance box around [x, y] instead of a single point, so that vines and hooks spanning only one tile are not too hard to grab. The lowest reachable row wins, and inside that row the column closest to [x, y] - snapOffset receives the offset that needs to be applied to the given position to align it with the returned attachment point.
Either vertical tolerance can be negative to move that edge of the box past y to the other side.
bool Jazz2:: Tiles:: TileMap:: AppendTileSet(StringView tileSetPath,
std:: uint16_t offset,
std:: uint16_t count,
const std:: uint8_t* paletteRemapping = nullptr,
const std:: uint32_t* trueColorPalette = nullptr)
Adds tiles of a tile set after the tiles of the others while the level is played.
The tiles from offset of the tile set get the tile IDs from GetLoadedTileCount() on. The animated tiles move behind them if they don't fit before them, as JJ2+ has room for 4096 tiles in any level. Returns false and adds nothing if there are more or the tile set can't be loaded. Meant for scripts. With trueColorPalette, the 8-bit tiles are true color tiles in its 256 colors (see ContentResolver::
bool Jazz2:: Tiles:: TileMap:: AppendBlankTiles(std:: int32_t tileId)
Makes the empty tile IDs after the tiles of the tile sets up to tileId real, transparent tiles.
JJ2+ has room for tiles there and scripts save images into them, see GetLoadedTileCount(). Returns false if tileId isn't below 4096, the animated tiles move behind it as in AppendTileSet().
std:: int32_t Jazz2:: Tiles:: TileMap:: AddLayer(Vector2i size,
const LayerDescription& description)
Adds a layer of no tiles after the others, which isn't drawn, returns its index or -1 if the memory isn't there.
A layer drawn other than tile by tile (see LayerDescription::
void Jazz2:: Tiles:: TileMap:: SetAnimatedTiles(std:: uint16_t animatedTilesOffset,
ArrayView<const Formats:: AnimatedTileRecord> animatedTiles)
Sets the animated tiles of the level.
Tile IDs from animatedTilesOffset up refer to them, in the order they are given. An animated tile without frames shows the empty tile, so the ones after it keep their IDs.
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.
void Jazz2:: Tiles:: TileMap:: CreateDebris(const DestructibleDebris& debris)
Creates a generic debris.
All of the debris producers honour PreferencesCache::Particles: nothing is created when particles are off, and the bursts (CreateParticleDebris(), CreateSpriteDebris()) are halved at the low quality. The console budgets above apply on top of that.
void Jazz2:: Tiles:: TileMap:: CreateSpriteDebris(const GraphicResource* res,
Vector3f pos,
std:: int32_t count,
float elasticity = 0.8f)
Creates a sprite debris.
The pieces keep elasticity of their speed when they bounce off a solid tile, see DestructibleDebris::
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.
void Jazz2:: Tiles:: TileMap:: SetTileModifier(std:: int32_t tileId,
std:: uint8_t alpha,
bool heat)
Gives every placed tile of an ID that isn't animated a transparency and the heat effect, or not.
As a tile type of the original game changes all of them (see Formats::
bool Jazz2:: Tiles:: TileMap:: SetLayerRendererType(std:: int32_t layerIndex,
LayerRendererType type)
Changes the renderer type of a given layer.
Meant for tools such as an editor. A layer switched to LayerRendererType::false if the layer doesn't exist or is the sprite layer.
bool Jazz2:: Tiles:: TileMap:: ReplaceLayerTile(std:: int32_t layerIndex,
std:: int32_t x,
std:: int32_t y,
const LayerTile& tile)
Replaces a tile of a layer, as if it was loaded so from the level file.
Unlike SetTile(), nothing of the replaced tile is kept — neither the state it had in the game, nor what the events of the level made of it. Meant for the level editor. Returns false if out of range.
bool Jazz2:: Tiles:: TileMap:: SetLayerDescription(std:: int32_t layerIndex,
const LayerDescription& description,
bool visible)
Changes how a layer is placed and drawn, and whether it's drawn at all.
The renderer type is changed as by SetLayerRendererType(). A layer that becomes a LayerRendererType::false if the layer doesn't exist.
bool Jazz2:: Tiles:: TileMap:: SetLayerTexture(std:: int32_t layerIndex,
ArrayView<const std:: uint8_t> pixels)
Gives a textured layer a texture of its own, taken instead of the tiles at its top left.
pixels are Formats::pixels take the tiles again. Called before the viewport is initialized, as when the level is loaded, the texture is drawn of its own size. Returns false if the layer doesn't exist or the pixels are of another size.
bool Jazz2:: Tiles:: TileMap:: SetSpriteLayerRenderer(LayerRendererType type,
const Vector4f& color)
Changes how the sprite layer is drawn, it's still placed as always.
Only a renderer type the sprite layer can be drawn with is taken (see LayerDescription::false if there's no sprite layer.
void Jazz2:: Tiles:: TileMap:: SetAdditionalPalettes(ArrayView<const Formats:: PaletteRecord> palettes)
Sets the additional palettes of the level, which layers of LayerRendererType::
Each one is 256 colors packed as 0xAABBGGRR, index 0 is always transparent.
bool Jazz2:: Tiles:: TileMap:: ReorderLayers(ArrayView<const std:: int32_t> order)
Puts the layers in another order, as they are with all their state.
order has the index each layer had before, for each new index, and has to have every index once. Only the order of the layers changes, the depths they're drawn at stay. Meant for the level editor. Returns false and changes nothing if order isn't such a list.
bool Jazz2:: Tiles:: TileMap:: GetTileQuad(std:: int32_t tileId,
LayerTileFlags flags,
Texture*& texture,
Vector4f& texCoords,
bool& indexed)
Returns the texture and texture coordinates a tile is drawn with.
The tile ID is as the level file stores it, an animated tile resolves to the frame it shows now. The texture coordinates are in the layout the sprite shaders take (horizontal scale and offset, then vertical). An indexed texture keeps palette indices, which are recolored by the first palette. Returns false if the tile doesn't exist.
bool Jazz2:: Tiles:: TileMap:: GetStaticTileQuad(std:: int32_t tileId,
LayerTileFlags flags,
Texture*& texture,
Vector4f& texCoords,
bool& indexed)
Returns the texture and texture coordinates a tile of the tile sets is drawn with.
As GetTileQuad(), but the tile ID always counts the tiles of the default tile set and then the extra ones, even past the first animated tile, so a tile the level can't address yet is drawn as itself, never as an animated tile. Returns false if no tile set has the tile.
Vector2f Jazz2:: Tiles:: TileMap:: GetLayerOrigin(std:: int32_t layerIndex,
Vector2f viewCenter,
Vector2f viewSize) const
Returns where the tile (0, 0) of a layer is drawn in the level, for a view of a given center and size.
The layer is placed as by the current view options, a position in the level then lies on the tile (position - origin) / 32 of the layer, repeated if the layer repeats.
bool Jazz2:: Tiles:: TileMap:: InitializeFromStream(Stream& src)
Initializes tile map state from a stream.
Returns false if the state belongs to a sprite layer of another size, such as of a level changed since, nothing is changed then and the rest of the state in the stream can't be read either.
void Jazz2:: Tiles:: TileMap:: PruneTilesetAtlas()
Repacks the tileset's atlas around the tiles this level actually references.
Called once the layers, animated tiles and events have been read, which is the first moment the set of referenced tiles is known. Does nothing where the platform can hold the whole atlas.
static std:: int32_t Jazz2:: Tiles:: TileMap:: GetParticleDebrisStep(std:: int32_t debrisSize,
std:: int32_t frameWidth,
std:: int32_t frameHeight)
Returns the step in which a particle debris burst walks a sprite frame of the given size.
debrisSize + 1 (the particle size plus a one pixel gap) unless the frame is big enough for the burst to exceed MaxParticleDebrisPerBurst; the particle size is then the returned step minus one.
Variable documentation
static std:: int32_t Jazz2:: Tiles:: TileMap:: MaxDebrisCount constexpr
Maximum number of live debris particles, or 0 if the effect is unbounded.
A live particle is far more expensive than its 100 bytes in _debrisList: it also rents a pooled RenderCommand for every frame it is visible (~840 bytes on the Dreamcast, see RentRenderCommand()) and its instance uniforms take a slice of both the render batcher's and the streaming uniform buffer's pools, which only ever grow to their high-water mark. Together that is roughly 1.3 KB per particle that a burst pins until the level ends, and one boss death emits over a thousand of them - more than the whole heap the consoles have left. Desktop targets have the memory, so the effect stays unbounded there.
static std:: int32_t Jazz2:: Tiles:: TileMap:: MaxWeatherDebrisCount constexpr
Maximum number of live debris particles the weather effect may occupy, or 0 if unbounded.
Weather spawns every frame and its particles live for about three seconds, so it settles at intensity * ~190 live particles. Left alone it would sit at MaxDebrisCount on its own and leave nothing for a death burst, which is the effect that actually matters.
static std:: int32_t Jazz2:: Tiles:: TileMap:: WeatherDepthStep constexpr
Step the depth of a weather particle is rounded to.
The depth comes from the size of the particle, so nearly each one had a depth of its own and couldn't be batched with the others. Rounded to a few levels on the consoles that budget their particles (see MaxWeatherDebrisCount), the weather is a few draws.
static bool Jazz2:: Tiles:: TileMap:: WeatherDebrisSpins constexpr
Whether the snowflakes turn as they fall.
Off on the Nintendo 64: a turned particle is two triangles instead of one rectangle, about four times the cost, and the turn of a few pixels isn't visible.
static std:: int32_t Jazz2:: Tiles:: TileMap:: MaxParticleDebrisPerBurst constexpr
Maximum number of particles one CreateParticleDebris() burst emits, or 0 if unbounded.
The producers walk the sprite frame in fixed steps, so the count grows with the sprite's area: the biggest one that can perish this way (Devan's demon form, 154x115) yields 1131 particles. Widening the step instead of dropping the tail keeps the burst covering the whole sprite - the particles just get proportionally fewer and bigger (see GetParticleDebrisStep()).