Jazz2::Resources::GenericGraphicResource struct

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

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

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.