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::BackgroundBuffer & | GetLayerBuffer (Room &room, LayerType layer) |
| Get the bitmap buffer for a layer type. | |
| static const gfx::BackgroundBuffer & | GetLayerBuffer (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< ObjectTranslucency > | object_translucency_ |
| bool | bg2_on_top_ = false |
| bool | layers_merged_ = false |
| uint8_t | current_merge_type_id_ = 0 |
| bool | use_priority_compositing_ = false |
RoomLayerManager - Manages layer visibility and compositing.
This class provides:
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.
|
inline |
Definition at line 81 of file room_layer_manager.h.
References Reset().

|
inline |
Definition at line 84 of file room_layer_manager.h.
References bg2_on_top_, current_merge_type_id_, layer_alpha_, layer_blend_mode_, layer_visible_, layers_merged_, yaze::zelda3::Normal, object_translucency_, and use_priority_compositing_.
Referenced by RoomLayerManager().
|
inline |
Definition at line 100 of file room_layer_manager.h.
References use_priority_compositing_.
|
inline |
Definition at line 101 of file room_layer_manager.h.
References use_priority_compositing_.
|
inline |
Definition at line 104 of file room_layer_manager.h.
References layer_visible_.
Referenced by ApplyLayerMergingPreserveVisibility(), and yaze::editor::DungeonCanvasViewer::SetLayerVisible().
|
inline |
Definition at line 108 of file room_layer_manager.h.
References layer_visible_.
Referenced by ApplyLayerMergingPreserveVisibility(), and CompositeToOutput().
|
inline |
Definition at line 113 of file room_layer_manager.h.
References yaze::zelda3::Addition, yaze::zelda3::Dark, layer_alpha_, layer_blend_mode_, yaze::zelda3::Normal, yaze::zelda3::Off, and yaze::zelda3::Translucent.
Referenced by ApplyLayerMerging(), and yaze::editor::DungeonCanvasViewer::SetLayerBlendMode().
|
inline |
Definition at line 135 of file room_layer_manager.h.
References layer_blend_mode_.
Referenced by CompositeToOutput().
|
inline |
Definition at line 139 of file room_layer_manager.h.
References layer_alpha_.
Referenced by CompositeToOutput().
|
inline |
Definition at line 144 of file room_layer_manager.h.
References object_translucency_.
Referenced by yaze::editor::DungeonCanvasViewer::SetObjectTranslucent().
|
inline |
Definition at line 157 of file room_layer_manager.h.
References object_translucency_.
|
inline |
Definition at line 166 of file room_layer_manager.h.
References object_translucency_.
|
inline |
Definition at line 175 of file room_layer_manager.h.
References object_translucency_.
|
inline |
Definition at line 181 of file room_layer_manager.h.
References bg2_on_top_.
Referenced by ApplyLayerMerging().
|
inline |
Definition at line 182 of file room_layer_manager.h.
References bg2_on_top_.
|
inline |
Definition at line 185 of file room_layer_manager.h.
References bg2_on_top_.
|
inline |
Definition at line 186 of file room_layer_manager.h.
References bg2_on_top_.
|
inline |
Definition at line 192 of file room_layer_manager.h.
References yaze::zelda3::BG1_Layout, yaze::zelda3::BG1_Objects, yaze::zelda3::BG2_Layout, yaze::zelda3::BG2_Objects, current_merge_type_id_, yaze::zelda3::Dark, yaze::zelda3::LayerMergeType::ID, yaze::zelda3::LayerMergeType::Layer2OnTop, yaze::zelda3::LayerMergeType::Layer2Translucent, layers_merged_, yaze::zelda3::Normal, SetBG2ColorMathEnabled(), SetLayerBlendMode(), and yaze::zelda3::Translucent.
Referenced by ApplyLayerMergingPreserveVisibility().

|
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().

|
inline |
Check if layers are currently merged.
Definition at line 251 of file room_layer_manager.h.
References layers_merged_.
|
inline |
Get the current merge type ID.
Definition at line 257 of file room_layer_manager.h.
References current_merge_type_id_.
|
inline |
Get object layer value for buffer assignment.
Objects are assigned to buffers based on their layer value:
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.
| object_layer | The object's layer value (0, 1, 2) |
Definition at line 278 of file room_layer_manager.h.
|
inline |
Definition at line 284 of file room_layer_manager.h.
|
inlinestatic |
Check if an object on a given layer should render to BG2.
| object_layer | The object's layer value |
Definition at line 293 of file room_layer_manager.h.
Referenced by GetObjectLayerType().
|
inlinestatic |
Get the appropriate background layer type for an object.
| object_layer | The object's layer value (0, 1, 2) |
Definition at line 303 of file room_layer_manager.h.
References yaze::zelda3::BG1_Objects, yaze::zelda3::BG2_Objects, and IsObjectOnBG2().

|
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.
|
inlinestatic |
Get the bitmap buffer for a layer type.
Definition at line 331 of file room_layer_manager.h.
References yaze::zelda3::Room::bg1_buffer(), yaze::zelda3::BG1_Layout, yaze::zelda3::BG1_Objects, yaze::zelda3::Room::bg2_buffer(), yaze::zelda3::BG2_Layout, yaze::zelda3::BG2_Objects, yaze::zelda3::Room::object_bg1_buffer(), and yaze::zelda3::Room::object_bg2_buffer().
Referenced by CompositeToOutput().

|
inlinestatic |
Definition at line 346 of file room_layer_manager.h.
References yaze::zelda3::Room::bg1_buffer(), yaze::zelda3::BG1_Layout, yaze::zelda3::BG1_Objects, yaze::zelda3::Room::bg2_buffer(), yaze::zelda3::BG2_Layout, yaze::zelda3::BG2_Objects, yaze::zelda3::Room::object_bg1_buffer(), and yaze::zelda3::Room::object_bg2_buffer().

|
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.
|
inlinestatic |
Get blend mode name.
Definition at line 382 of file room_layer_manager.h.
References yaze::zelda3::Addition, yaze::zelda3::Dark, yaze::zelda3::Normal, yaze::zelda3::Off, and yaze::zelda3::Translucent.
|
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.
| surface | The SDL surface to apply modulation to |
Definition at line 407 of file room_layer_manager.h.
References current_merge_type_id_.
| 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).
| room | The room containing the layer buffers |
| output | Output bitmap to receive composited result (512x512) |
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().
|
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:
Definition at line 467 of file room_layer_manager.h.
Referenced by CompositeToOutput().
|
private |
Definition at line 471 of file room_layer_manager.h.
Referenced by IsLayerVisible(), Reset(), and SetLayerVisible().
|
private |
Definition at line 472 of file room_layer_manager.h.
Referenced by GetLayerBlendMode(), Reset(), and SetLayerBlendMode().
|
private |
Definition at line 473 of file room_layer_manager.h.
Referenced by GetLayerAlpha(), Reset(), and SetLayerBlendMode().
|
private |
Definition at line 474 of file room_layer_manager.h.
Referenced by ClearObjectTranslucency(), GetObjectAlpha(), IsObjectTranslucent(), Reset(), and SetObjectTranslucency().
|
private |
Definition at line 479 of file room_layer_manager.h.
Referenced by IsBG2ColorMathEnabled(), IsBG2OnTop(), Reset(), SetBG2ColorMathEnabled(), and SetBG2OnTop().
|
private |
Definition at line 482 of file room_layer_manager.h.
Referenced by ApplyLayerMerging(), AreLayersMerged(), and Reset().
|
private |
Definition at line 483 of file room_layer_manager.h.
Referenced by ApplyLayerMerging(), ApplySurfaceColorMod(), CompositeToOutput(), GetMergeTypeId(), and Reset().
|
private |
Definition at line 490 of file room_layer_manager.h.
Referenced by IsPriorityCompositingEnabled(), Reset(), and SetPriorityCompositing().