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

Manages door position snapping and coordinate conversion. More...

#include <door_position.h>

Static Public Member Functions

static std::vector< int > GetSnapPositions (DoorDirection direction)
 Get all valid snap positions for a given direction.
 
static uint8_t SnapToNearestPosition (int canvas_x, int canvas_y, DoorDirection direction)
 Convert canvas coordinates to nearest valid door position.
 
static std::pair< int, int > PositionToTileCoords (uint8_t position, DoorDirection direction)
 Convert encoded position to tile coordinates.
 
static std::pair< int, int > PositionToPixelCoords (uint8_t position, DoorDirection direction)
 Convert encoded position to pixel coordinates.
 
static int GetWallEdge (DoorDirection direction)
 Get the wall edge coordinate for a direction.
 
static bool IsValidPosition (uint8_t position, DoorDirection direction)
 Check if a position is valid for door placement.
 
static bool DetectWallFromPosition (int canvas_x, int canvas_y, DoorDirection &out_direction)
 Detect which wall the cursor is near.
 
static bool DetectWallSection (int canvas_x, int canvas_y, DoorDirection &out_direction, bool &out_is_inner)
 Detect wall with inner/outer section information.
 
static uint8_t GetSectionStartPosition (DoorDirection direction, bool is_inner)
 Get the starting position index for outer/inner section.
 
static std::pair< uint8_t, uint8_t > EncodeDoorBytes (uint8_t position, DoorType type, DoorDirection direction)
 Encode door data for ROM storage.
 
static std::tuple< int, int, int, int > GetDoorBounds (uint8_t position, DoorDirection direction)
 Get the bounding rectangle for a door.
 

Static Public Attributes

static constexpr int kRoomWidthTiles = 64
 
static constexpr int kRoomHeightTiles = 64
 
static constexpr int kTileSize = 8
 
static constexpr int kMaxDoorPositions = 32
 
static constexpr int kWallDetectionThreshold = 8
 

Detailed Description

Manages door position snapping and coordinate conversion.

Doors in ALTTP can only be placed at specific positions along room walls. The position is encoded as a 5-bit value that maps to tile coordinates.

Position Encoding:

  • ROM stores position as a full byte, but only bits 0-4 are used
  • Tile coordinate = (position & 0x1F) * 2
  • This gives 32 possible positions at tiles 0, 2, 4, ..., 62

Wall Edges:

  • North: doors placed at y=0 (top row)
  • South: doors placed at y=61 (3 tiles from bottom for door height)
  • West: doors placed at x=0 (left column)
  • East: doors placed at x=61 (3 tiles from right for door width)

Definition at line 31 of file door_position.h.

Member Function Documentation

◆ GetSnapPositions()

std::vector< int > yaze::zelda3::DoorPositionManager::GetSnapPositions ( DoorDirection direction)
static

Get all valid snap positions for a given direction.

Parameters
directionWhich wall the door is on
Returns
Vector of valid tile positions (0, 2, 4, ..., 62)

Definition at line 39 of file door_position.cc.

References yaze::zelda3::East, yaze::zelda3::North, yaze::zelda3::South, and yaze::zelda3::West.

Referenced by SnapToNearestPosition().

◆ SnapToNearestPosition()

uint8_t yaze::zelda3::DoorPositionManager::SnapToNearestPosition ( int canvas_x,
int canvas_y,
DoorDirection direction )
static

◆ PositionToTileCoords()

◆ PositionToPixelCoords()

std::pair< int, int > yaze::zelda3::DoorPositionManager::PositionToPixelCoords ( uint8_t position,
DoorDirection direction )
static

Convert encoded position to pixel coordinates.

Parameters
positionEncoded position byte from ROM (0-31)
directionDoor direction
Returns
Pair of (pixel_x, pixel_y) coordinates

Definition at line 206 of file door_position.cc.

References kTileSize, and PositionToTileCoords().

Referenced by GetDoorBounds(), and yaze::zelda3::Room::Door::GetPixelCoords().

Here is the call graph for this function:

◆ GetWallEdge()

int yaze::zelda3::DoorPositionManager::GetWallEdge ( DoorDirection direction)
static

Get the wall edge coordinate for a direction.

Returns the fixed coordinate for the wall edge:

  • North: y=0
  • South: y=61 (accounting for door height)
  • West: x=0
  • East: x=61 (accounting for door width)
Parameters
directionDoor direction
Returns
Tile coordinate of the wall edge

Definition at line 212 of file door_position.cc.

References yaze::zelda3::East, kRoomHeightTiles, kRoomWidthTiles, yaze::zelda3::North, yaze::zelda3::South, and yaze::zelda3::West.

◆ IsValidPosition()

bool yaze::zelda3::DoorPositionManager::IsValidPosition ( uint8_t position,
DoorDirection direction )
static

Check if a position is valid for door placement.

Parameters
positionEncoded position (0-31)
directionDoor direction
Returns
true if position is valid

Definition at line 226 of file door_position.cc.

References yaze::zelda3::GetDoorDimensions(), kRoomHeightTiles, kRoomWidthTiles, yaze::zelda3::North, and yaze::zelda3::South.

Referenced by yaze::editor::DungeonObjectInteraction::HandleEntityDrag(), yaze::editor::DoorInteractionHandler::HandleRelease(), yaze::editor::DungeonObjectInteraction::PlaceDoorAtPosition(), and yaze::editor::DoorInteractionHandler::PlaceDoorAtSnappedPosition().

Here is the call graph for this function:

◆ DetectWallFromPosition()

bool yaze::zelda3::DoorPositionManager::DetectWallFromPosition ( int canvas_x,
int canvas_y,
DoorDirection & out_direction )
static

Detect which wall the cursor is near.

Based on cursor position relative to room edges, determines which wall (if any) the user is trying to place a door on.

Parameters
canvas_xX coordinate on canvas (pixels)
canvas_yY coordinate on canvas (pixels)
out_directionOutput: detected direction (if near a wall)
Returns
true if near a wall edge

Definition at line 248 of file door_position.cc.

References yaze::zelda3::East, kRoomHeightTiles, kRoomWidthTiles, kTileSize, kWallDetectionThreshold, yaze::zelda3::North, yaze::zelda3::South, and yaze::zelda3::West.

Referenced by yaze::editor::DungeonObjectInteraction::DrawDoorGhostPreview(), yaze::editor::DungeonObjectInteraction::HandleEntityDrag(), yaze::editor::DoorInteractionHandler::HandleRelease(), yaze::editor::DungeonObjectInteraction::PlaceDoorAtPosition(), yaze::editor::DoorInteractionHandler::PlaceDoorAtSnappedPosition(), and yaze::editor::DoorInteractionHandler::UpdateSnappedPosition().

◆ DetectWallSection()

bool yaze::zelda3::DoorPositionManager::DetectWallSection ( int canvas_x,
int canvas_y,
DoorDirection & out_direction,
bool & out_is_inner )
static

Detect wall with inner/outer section information.

Extended version that also detects middle seams and indicates whether the position is on the outer wall or inner seam.

Position ranges per direction:

  • North: Outer (0-5), Inner (6-11)
  • South: Inner (0-5), Outer (6-11)
  • West: Outer (0-5), Inner (6-11)
  • East: Inner (0-5), Outer (6-11)
Parameters
canvas_xX coordinate on canvas (pixels)
canvas_yY coordinate on canvas (pixels)
out_directionOutput: detected direction
out_is_innerOutput: true if at inner seam, false if outer wall
Returns
true if near any wall or seam

Definition at line 284 of file door_position.cc.

References yaze::zelda3::East, kRoomHeightTiles, kRoomWidthTiles, kTileSize, kWallDetectionThreshold, yaze::zelda3::North, yaze::zelda3::South, and yaze::zelda3::West.

Referenced by yaze::editor::DungeonObjectInteraction::DrawDoorSnapIndicators(), yaze::editor::DungeonObjectInteraction::DrawEntitySelectionHighlights(), yaze::editor::DoorInteractionHandler::DrawSelectionHighlight(), yaze::editor::DoorInteractionHandler::DrawSnapIndicators(), and SnapToNearestPosition().

◆ GetSectionStartPosition()

uint8_t yaze::zelda3::DoorPositionManager::GetSectionStartPosition ( DoorDirection direction,
bool is_inner )
static

Get the starting position index for outer/inner section.

Parameters
directionDoor direction
is_innerWhether at inner seam (vs outer wall)
Returns
Starting position index (0 or 6)

Definition at line 353 of file door_position.cc.

References yaze::zelda3::East, yaze::zelda3::North, yaze::zelda3::South, and yaze::zelda3::West.

Referenced by yaze::editor::DungeonObjectInteraction::DrawDoorSnapIndicators(), yaze::editor::DoorInteractionHandler::DrawSnapIndicators(), and SnapToNearestPosition().

◆ EncodeDoorBytes()

std::pair< uint8_t, uint8_t > yaze::zelda3::DoorPositionManager::EncodeDoorBytes ( uint8_t position,
DoorType type,
DoorDirection direction )
static

Encode door data for ROM storage.

Parameters
positionEncoded position (0-31)
typeDoor type
directionDoor direction
Returns
Pair of (byte1, byte2) for ROM storage

Definition at line 373 of file door_position.cc.

Referenced by yaze::zelda3::Room::Door::EncodeBytes().

◆ GetDoorBounds()

std::tuple< int, int, int, int > yaze::zelda3::DoorPositionManager::GetDoorBounds ( uint8_t position,
DoorDirection direction )
static

Get the bounding rectangle for a door.

Parameters
positionEncoded position
directionDoor direction
Returns
Tuple of (x, y, width, height) in pixels

Definition at line 387 of file door_position.cc.

References yaze::zelda3::GetDoorDimensions(), and PositionToPixelCoords().

Referenced by yaze::zelda3::Room::Door::GetBounds().

Here is the call graph for this function:

Member Data Documentation

◆ kRoomWidthTiles

constexpr int yaze::zelda3::DoorPositionManager::kRoomWidthTiles = 64
staticconstexpr

◆ kRoomHeightTiles

constexpr int yaze::zelda3::DoorPositionManager::kRoomHeightTiles = 64
staticconstexpr

◆ kTileSize

constexpr int yaze::zelda3::DoorPositionManager::kTileSize = 8
staticconstexpr

◆ kMaxDoorPositions

constexpr int yaze::zelda3::DoorPositionManager::kMaxDoorPositions = 32
staticconstexpr

Definition at line 37 of file door_position.h.

◆ kWallDetectionThreshold

constexpr int yaze::zelda3::DoorPositionManager::kWallDetectionThreshold = 8
staticconstexpr

Definition at line 40 of file door_position.h.

Referenced by DetectWallFromPosition(), and DetectWallSection().


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