Jazz2::Resources::GenericGraphicResource struct

Public static variables

static std::int32_t FrameBorder constexpr
Transparent margin each converted frame carries on every side, counted into FrameDimensions.

Public static functions

static auto GetDefaultBoundingBox(Vector2i frameDimensions) -> Vector2i constexpr
The hitbox a metadata falls back to when it declares no Metadata::BoundingBox of its own.

Constructors, destructors, conversion operators

GenericGraphicResource() noexcept
Creates a new instance.

Public functions

auto GetMaskStride() const -> std::int32_t
Returns the distance between two rows of Mask, in bits (the sheet width in pixels).
auto GetFrameRect(std::int32_t frame) const -> Recti
Returns the area the given frame occupies in the sheet, in pixels.
auto GetFrameOffset(std::int32_t frame) const -> Vector2i
Returns where the given frame's area begins inside its logical cell.
auto GetFrameAnchor(std::int32_t frame, bool flippedX = false, bool flippedY = false) const -> Vector2i
Returns the hotspot of the given frame, relative to the frame's own area.

Public variables

GenericGraphicResourceFlags Flags
Resource flags.
std::unique_ptr<Texture> TextureDiffuse
Diffuse texture.
std::unique_ptr<uint8_t[]> Mask
Collision mask, one bit per pixel (set = solid), rows packed continuously.
Vector2i FrameDimensions
Frame dimensions.
Vector2i FrameConfiguration
Frame configuration.
float AnimDuration
Animation duration (in normalized frames).
std::int32_t FrameCount
Frame count.
Vector2i Hotspot
Hotspot.
Vector2i Coldspot
Optional coldspot.
Vector2i Gunspot
Optional gunspot.
SmallVector<FrameRect, 0> FrameRects
Where each frame sits in the sheet, empty when the frames form a regular grid.
std::int32_t MaskStride
Distance between two rows of Mask, in bits (the sheet width in pixels).

Function documentation

static Vector2i Jazz2::Resources::GenericGraphicResource::GetDefaultBoundingBox(Vector2i frameDimensions) constexpr

The hitbox a metadata falls back to when it declares no Metadata::BoundingBox of its own.

The height is the artwork's, both margins dropped, because Jazz2::Actors::ActorBase::UpdateHitbox() rests the box on the frame's lower margin and counts the height up from there: a height that kept one would reach that far above the sprite and an actor would be stood on that far above its own top. The width's figure is not a margin and is left as it was - that box is centred on the actor rather than anchored to the frame, so it is a deliberate inset either way.

Vector2i Jazz2::Resources::GenericGraphicResource::GetFrameOffset(std::int32_t frame) const

Returns where the given frame's area begins inside its logical cell.

Anything that positions a frame by aligning FrameDimensions should add this, so trimming the transparent margin away does not move the frame on screen.

Vector2i Jazz2::Resources::GenericGraphicResource::GetFrameAnchor(std::int32_t frame, bool flippedX = false, bool flippedY = false) const

Returns the hotspot of the given frame, relative to the frame's own area.

Flipping mirrors the texture inside the quad that the frame is drawn on, so a flipped frame needs its hotspot mirrored within that same area. For a regular grid the area is the whole cell, which is why mirroring within FrameDimensions is right there; for a packed frame the area is only the space its pixels occupy, and mirroring within the cell would displace it by the trimmed margin. Both cases fall out of the same expression.

Variable documentation

static std::int32_t Jazz2::Resources::GenericGraphicResource::FrameBorder constexpr

Transparent margin each converted frame carries on every side, counted into FrameDimensions.

Put there by the importer (JJ2Anims::AddBorder, whose value this mirrors) so that a frame cannot bleed into its neighbour under bilinear filtering. Hotspot is written with the same value added, which cancels the margin at the top and leaves the one at the bottom standing - so anything deriving a size from FrameDimensions has to drop both, and anything resting an actor on the frame's lower edge has to drop one, or it rests on the margin rather than on the artwork.

std::unique_ptr<uint8_t[]> Jazz2::Resources::GenericGraphicResource::Mask

Collision mask, one bit per pixel (set = solid), rows packed continuously.

Per-pixel collision only ever asks whether a pixel is solid, so the mask stores a single bit instead of the source alpha - at one byte per pixel the masks of a large level's sprite sheets ran to several megabytes, which is a sizeable share of a console's whole heap. Index it with IsMaskPixelSolid() rather than by hand.

SmallVector<FrameRect, 0> Jazz2::Resources::GenericGraphicResource::FrameRects

Where each frame sits in the sheet, empty when the frames form a regular grid.

Sprite sheets can be packed two ways. The regular grid gives every frame a cell of FrameDimensions, which wastes the difference between each frame's own extent and the largest one in the animation - on a sheet padded to power-of-two dimensions that easily doubles its size. When the frames are packed tightly instead, each one keeps only the space its opaque pixels need and this table says where it ended up; GetFrameRect() and GetFrameAnchor() hide the difference from everything that draws a frame.