yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::zelda3::RoomLayerManager Class Reference

RoomLayerManager - Manages layer visibility and compositing. More...

#include <room_layer_manager.h>

Public Member Functions

 RoomLayerManager ()
 
void Reset ()
 
void SetPriorityCompositing (bool enabled)
 
bool IsPriorityCompositingEnabled () const
 
void SetLayerVisible (LayerType layer, bool visible)
 
bool IsLayerVisible (LayerType layer) const
 
void SetLayerBlendMode (LayerType layer, LayerBlendMode mode)
 
LayerBlendMode GetLayerBlendMode (LayerType layer) const
 
uint8_t GetLayerAlpha (LayerType layer) const
 
void SetObjectTranslucency (size_t object_index, bool translucent, uint8_t alpha=128)
 
bool IsObjectTranslucent (size_t object_index) const
 
uint8_t GetObjectAlpha (size_t object_index) const
 
void ClearObjectTranslucency ()
 
void SetBG2ColorMathEnabled (bool enabled)
 
bool IsBG2ColorMathEnabled () const
 
void SetBG2OnTop (bool on_top)
 
bool IsBG2OnTop () const
 
void ApplyLayerMerging (const LayerMergeType &merge_type)
 
void ApplyLayerMergingPreserveVisibility (const LayerMergeType &merge_type)
 Apply layer merge settings without changing visibility.
 
bool AreLayersMerged () const
 Check if layers are currently merged.
 
uint8_t GetMergeTypeId () const
 Get the current merge type ID.
 
int GetObjectLayerValue (int object_layer) const
 Get object layer value for buffer assignment.
 
int CalculateObjectPriority (int object_layer) const
 
std::array< LayerType, 4 > GetDrawOrder () const
 Get the draw order for layers.
 
void ApplySurfaceColorMod (SDL_Surface *surface) const
 Apply surface color modulation for DarkRoom effect.
 
void CompositeToOutput (Room &room, gfx::Bitmap &output) const
 Composite all visible layers into a single output bitmap.
 

Static Public Member Functions

static bool IsObjectOnBG2 (int object_layer)
 Check if an object on a given layer should render to BG2.
 
static LayerType GetObjectLayerType (int object_layer)
 Get the appropriate background layer type for an object.
 
static gfx::BackgroundBufferGetLayerBuffer (Room &room, LayerType layer)
 Get the bitmap buffer for a layer type.
 
static const gfx::BackgroundBufferGetLayerBuffer (const Room &room, LayerType layer)
 
static const char * GetLayerName (LayerType layer)
 Get human-readable name for layer type.
 
static const char * GetBlendModeName (LayerBlendMode mode)
 Get blend mode name.
 

Static Private Member Functions

static bool IsTransparent (uint8_t pixel)
 Check if a pixel index represents transparency.
 

Private Attributes

std::array< bool, 4 > layer_visible_
 
std::array< LayerBlendMode, 4 > layer_blend_mode_
 
std::array< uint8_t, 4 > layer_alpha_
 
std::vector< ObjectTranslucencyobject_translucency_
 
bool bg2_on_top_ = false
 
bool layers_merged_ = false
 
uint8_t current_merge_type_id_ = 0
 
bool use_priority_compositing_ = false
 

Detailed Description

RoomLayerManager - Manages layer visibility and compositing.

This class provides:

  • 4-way layer visibility (BG1_Layout, BG1_Objects, BG2_Layout, BG2_Objects)
  • Layer blend mode control
  • Per-object translucency settings
  • Compositing layers to a final output bitmap

Usage: RoomLayerManager manager; manager.SetLayerVisible(LayerType::BG1_Objects, false); // Hide objects manager.SetLayerBlendMode(LayerType::BG2_Layout, LayerBlendMode::Translucent); manager.CompositeToOutput(room, output_bitmap);

Definition at line 79 of file room_layer_manager.h.

Constructor & Destructor Documentation

◆ RoomLayerManager()

yaze::zelda3::RoomLayerManager::RoomLayerManager ( )
inline

Definition at line 81 of file room_layer_manager.h.

References Reset().

Here is the call graph for this function:

Member Function Documentation

◆ Reset()

void yaze::zelda3::RoomLayerManager::Reset ( )
inline

◆ SetPriorityCompositing()

void yaze::zelda3::RoomLayerManager::SetPriorityCompositing ( bool enabled)
inline

Definition at line 100 of file room_layer_manager.h.

References use_priority_compositing_.

◆ IsPriorityCompositingEnabled()

bool yaze::zelda3::RoomLayerManager::IsPriorityCompositingEnabled ( ) const
inline

Definition at line 101 of file room_layer_manager.h.

References use_priority_compositing_.

◆ SetLayerVisible()

void yaze::zelda3::RoomLayerManager::SetLayerVisible ( LayerType layer,
bool visible )
inline

◆ IsLayerVisible()

bool yaze::zelda3::RoomLayerManager::IsLayerVisible ( LayerType layer) const
inline

Definition at line 108 of file room_layer_manager.h.

References layer_visible_.

Referenced by ApplyLayerMergingPreserveVisibility(), and CompositeToOutput().

◆ SetLayerBlendMode()

◆ GetLayerBlendMode()

LayerBlendMode yaze::zelda3::RoomLayerManager::GetLayerBlendMode ( LayerType layer) const
inline

Definition at line 135 of file room_layer_manager.h.

References layer_blend_mode_.

Referenced by CompositeToOutput().

◆ GetLayerAlpha()

uint8_t yaze::zelda3::RoomLayerManager::GetLayerAlpha ( LayerType layer) const
inline

Definition at line 139 of file room_layer_manager.h.

References layer_alpha_.

Referenced by CompositeToOutput().

◆ SetObjectTranslucency()

void yaze::zelda3::RoomLayerManager::SetObjectTranslucency ( size_t object_index,
bool translucent,
uint8_t alpha = 128 )
inline

◆ IsObjectTranslucent()

bool yaze::zelda3::RoomLayerManager::IsObjectTranslucent ( size_t object_index) const
inline

Definition at line 157 of file room_layer_manager.h.

References object_translucency_.

◆ GetObjectAlpha()

uint8_t yaze::zelda3::RoomLayerManager::GetObjectAlpha ( size_t object_index) const
inline

Definition at line 166 of file room_layer_manager.h.

References object_translucency_.

◆ ClearObjectTranslucency()

void yaze::zelda3::RoomLayerManager::ClearObjectTranslucency ( )
inline

Definition at line 175 of file room_layer_manager.h.

References object_translucency_.

◆ SetBG2ColorMathEnabled()

void yaze::zelda3::RoomLayerManager::SetBG2ColorMathEnabled ( bool enabled)
inline

Definition at line 181 of file room_layer_manager.h.

References bg2_on_top_.

Referenced by ApplyLayerMerging().

◆ IsBG2ColorMathEnabled()

bool yaze::zelda3::RoomLayerManager::IsBG2ColorMathEnabled ( ) const
inline

Definition at line 182 of file room_layer_manager.h.

References bg2_on_top_.

◆ SetBG2OnTop()

void yaze::zelda3::RoomLayerManager::SetBG2OnTop ( bool on_top)
inline

Definition at line 185 of file room_layer_manager.h.

References bg2_on_top_.

◆ IsBG2OnTop()

bool yaze::zelda3::RoomLayerManager::IsBG2OnTop ( ) const
inline

Definition at line 186 of file room_layer_manager.h.

References bg2_on_top_.

◆ ApplyLayerMerging()

◆ ApplyLayerMergingPreserveVisibility()

void yaze::zelda3::RoomLayerManager::ApplyLayerMergingPreserveVisibility ( const LayerMergeType & merge_type)
inline

Apply layer merge settings without changing visibility.

Use this when you want to update blend/ordering from ROM data but preserve the user's manual visibility overrides.

Definition at line 230 of file room_layer_manager.h.

References ApplyLayerMerging(), yaze::zelda3::BG1_Layout, yaze::zelda3::BG1_Objects, yaze::zelda3::BG2_Layout, yaze::zelda3::BG2_Objects, IsLayerVisible(), and SetLayerVisible().

Here is the call graph for this function:

◆ AreLayersMerged()

bool yaze::zelda3::RoomLayerManager::AreLayersMerged ( ) const
inline

Check if layers are currently merged.

Returns
true if any layer merging is active

Definition at line 251 of file room_layer_manager.h.

References layers_merged_.

◆ GetMergeTypeId()

uint8_t yaze::zelda3::RoomLayerManager::GetMergeTypeId ( ) const
inline

Get the current merge type ID.

Returns
The LayerMergeType ID (0-8)

Definition at line 257 of file room_layer_manager.h.

References current_merge_type_id_.

◆ GetObjectLayerValue()

int yaze::zelda3::RoomLayerManager::GetObjectLayerValue ( int object_layer) const
inline

Get object layer value for buffer assignment.

Objects are assigned to buffers based on their layer value:

  • Layer 0: BG1 buffer (main floor/walls)
  • Layer 1: BG2 buffer (background details)
  • Layer 2: BG1 buffer with priority (overlays on BG1)

NOTE: Visual Z-order is fixed by SNES Mode 1 hardware (BG1 > BG2). This layer value only determines which buffer the object draws to, not the visual stacking order.

Parameters
object_layerThe object's layer value (0, 1, 2)
Returns
Layer value (same as input - used for buffer routing)

Definition at line 278 of file room_layer_manager.h.

◆ CalculateObjectPriority()

int yaze::zelda3::RoomLayerManager::CalculateObjectPriority ( int object_layer) const
inline

Definition at line 284 of file room_layer_manager.h.

◆ IsObjectOnBG2()

static bool yaze::zelda3::RoomLayerManager::IsObjectOnBG2 ( int object_layer)
inlinestatic

Check if an object on a given layer should render to BG2.

Parameters
object_layerThe object's layer value
Returns
true if object renders to BG2 buffer

Definition at line 293 of file room_layer_manager.h.

Referenced by GetObjectLayerType().

◆ GetObjectLayerType()

static LayerType yaze::zelda3::RoomLayerManager::GetObjectLayerType ( int object_layer)
inlinestatic

Get the appropriate background layer type for an object.

Parameters
object_layerThe object's layer value (0, 1, 2)
Returns
The LayerType for this object's background

Definition at line 303 of file room_layer_manager.h.

References yaze::zelda3::BG1_Objects, yaze::zelda3::BG2_Objects, and IsObjectOnBG2().

Here is the call graph for this function:

◆ GetDrawOrder()

std::array< LayerType, 4 > yaze::zelda3::RoomLayerManager::GetDrawOrder ( ) const
inline

Get the draw order for layers.

Returns layers in the order they should be drawn (back to front).

SNES Mode 1 default priority: BG1 > BG2 (BG1 on top) The "Layer2OnTop" flag from ROM controls COLOR MATH effects (sub-screen participation for transparency/additive blend), NOT the actual Z-order of opaque pixels.

Draw order is ALWAYS: BG2 (back) -> BG1 (front) Blend modes handle the visual effects separately.

Definition at line 321 of file room_layer_manager.h.

References yaze::zelda3::BG1_Layout, yaze::zelda3::BG1_Objects, yaze::zelda3::BG2_Layout, and yaze::zelda3::BG2_Objects.

◆ GetLayerBuffer() [1/2]

static gfx::BackgroundBuffer & yaze::zelda3::RoomLayerManager::GetLayerBuffer ( Room & room,
LayerType layer )
inlinestatic

◆ GetLayerBuffer() [2/2]

static const gfx::BackgroundBuffer & yaze::zelda3::RoomLayerManager::GetLayerBuffer ( const Room & room,
LayerType layer )
inlinestatic

◆ GetLayerName()

static const char * yaze::zelda3::RoomLayerManager::GetLayerName ( LayerType layer)
inlinestatic

Get human-readable name for layer type.

Definition at line 365 of file room_layer_manager.h.

References yaze::zelda3::BG1_Layout, yaze::zelda3::BG1_Objects, yaze::zelda3::BG2_Layout, and yaze::zelda3::BG2_Objects.

◆ GetBlendModeName()

static const char * yaze::zelda3::RoomLayerManager::GetBlendModeName ( LayerBlendMode mode)
inlinestatic

◆ ApplySurfaceColorMod()

void yaze::zelda3::RoomLayerManager::ApplySurfaceColorMod ( SDL_Surface * surface) const
inline

Apply surface color modulation for DarkRoom effect.

In DarkRoom mode (merge type 0x08), surfaces should be darkened to 50%. This should be called before drawing each layer in separate mode to match the composite mode appearance.

Parameters
surfaceThe SDL surface to apply modulation to

Definition at line 407 of file room_layer_manager.h.

References current_merge_type_id_.

◆ CompositeToOutput()

void yaze::zelda3::RoomLayerManager::CompositeToOutput ( Room & room,
gfx::Bitmap & output ) const

Composite all visible layers into a single output bitmap.

Implements SNES Mode 1 per-tile priority compositing. Each tile's priority bit affects its effective Z-order:

Layer Priority Effective Order
BG1 0 0 (back)
BG2 0 1
BG2 1 2
BG1 1 3 (front)

This allows BG2 tiles with priority 1 to appear above BG1 tiles with priority 0, matching authentic SNES hardware behavior.

Applies per-layer visibility and blend modes at pixel level. Transparency is detected via palette index 255 (object buffer fill color).

Note
PALETTE HANDLING: Room layer buffers have their palettes applied via SetPalette(vector<SDL_Color>), which means their internal SnesPalette (accessible via bitmap.palette()) is EMPTY. This method extracts the palette directly from the first visible layer's SDL surface and applies it to the output bitmap. See the "Bitmap Dual Palette System" section in docs/public/developer/palette-system-overview.md for details.
Parameters
roomThe room containing the layer buffers
outputOutput bitmap to receive composited result (512x512)
See also
ApplySDLPaletteToBitmap() for the palette extraction implementation
docs/internal/agents/composite-layer-system.md for full documentation

Definition at line 46 of file room_layer_manager.cc.

References yaze::zelda3::Addition, yaze::zelda3::Room::bg1_buffer(), yaze::zelda3::BG1_Layout, yaze::zelda3::BG1_Objects, yaze::zelda3::BG2_Layout, yaze::zelda3::BG2_Objects, yaze::gfx::BackgroundBuffer::bitmap(), yaze::gfx::Bitmap::Create(), current_merge_type_id_, yaze::zelda3::Dark, yaze::gfx::Bitmap::Fill(), GetLayerAlpha(), GetLayerBlendMode(), GetLayerBuffer(), yaze::gfx::Bitmap::height(), IsLayerVisible(), IsTransparent(), yaze::gfx::Bitmap::mutable_data(), yaze::zelda3::Normal, yaze::zelda3::Off, yaze::gfx::Bitmap::set_modified(), yaze::gfx::Bitmap::surface(), yaze::zelda3::Translucent, yaze::gfx::Bitmap::UpdateSurfacePixels(), and yaze::gfx::Bitmap::width().

Referenced by yaze::zelda3::Room::GetCompositeBitmap().

◆ IsTransparent()

static bool yaze::zelda3::RoomLayerManager::IsTransparent ( uint8_t pixel)
inlinestaticprivate

Check if a pixel index represents transparency.

IMPORTANT: Only treat 255 as transparent (fill color for undrawn areas). Do NOT treat 0 as transparent! In dungeon rendering:

  • Source pixel 1 with palette_offset 0 writes final_color = 0 to the buffer
  • This represents palette[0] (actual color), NOT transparency
  • Buffers should be initialized to 255, not 0

Definition at line 467 of file room_layer_manager.h.

Referenced by CompositeToOutput().

Member Data Documentation

◆ layer_visible_

std::array<bool, 4> yaze::zelda3::RoomLayerManager::layer_visible_
private

Definition at line 471 of file room_layer_manager.h.

Referenced by IsLayerVisible(), Reset(), and SetLayerVisible().

◆ layer_blend_mode_

std::array<LayerBlendMode, 4> yaze::zelda3::RoomLayerManager::layer_blend_mode_
private

Definition at line 472 of file room_layer_manager.h.

Referenced by GetLayerBlendMode(), Reset(), and SetLayerBlendMode().

◆ layer_alpha_

std::array<uint8_t, 4> yaze::zelda3::RoomLayerManager::layer_alpha_
private

Definition at line 473 of file room_layer_manager.h.

Referenced by GetLayerAlpha(), Reset(), and SetLayerBlendMode().

◆ object_translucency_

std::vector<ObjectTranslucency> yaze::zelda3::RoomLayerManager::object_translucency_
private

◆ bg2_on_top_

bool yaze::zelda3::RoomLayerManager::bg2_on_top_ = false
private

◆ layers_merged_

bool yaze::zelda3::RoomLayerManager::layers_merged_ = false
private

Definition at line 482 of file room_layer_manager.h.

Referenced by ApplyLayerMerging(), AreLayersMerged(), and Reset().

◆ current_merge_type_id_

uint8_t yaze::zelda3::RoomLayerManager::current_merge_type_id_ = 0
private

◆ use_priority_compositing_

bool yaze::zelda3::RoomLayerManager::use_priority_compositing_ = false
private

The documentation for this class was generated from the following files: