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 |
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:
Wall Edges:
Definition at line 31 of file door_position.h.
|
static |
Get all valid snap positions for a given direction.
| direction | Which wall the door is on |
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().
|
static |
Convert canvas coordinates to nearest valid door position.
This snaps the mouse position to the nearest valid door placement position on the specified wall.
| canvas_x | X coordinate on canvas (pixels) |
| canvas_y | Y coordinate on canvas (pixels) |
| direction | Which wall the door is on |
Definition at line 63 of file door_position.cc.
References DetectWallSection(), GetSectionStartPosition(), GetSnapPositions(), kTileSize, yaze::zelda3::North, and yaze::zelda3::South.
Referenced by yaze::editor::DungeonObjectInteraction::DrawDoorGhostPreview(), yaze::editor::DungeonObjectInteraction::DrawDoorSnapIndicators(), yaze::editor::DungeonObjectInteraction::DrawEntitySelectionHighlights(), yaze::editor::DoorInteractionHandler::DrawSelectionHighlight(), yaze::editor::DoorInteractionHandler::DrawSnapIndicators(), yaze::editor::DungeonObjectInteraction::HandleEntityDrag(), yaze::editor::DoorInteractionHandler::HandleRelease(), yaze::editor::DungeonObjectInteraction::PlaceDoorAtPosition(), yaze::editor::DoorInteractionHandler::PlaceDoorAtSnappedPosition(), and yaze::editor::DoorInteractionHandler::UpdateSnappedPosition().

|
static |
Convert encoded position to tile coordinates.
| position | Encoded position byte from ROM (0-31) |
| direction | Door direction |
Definition at line 111 of file door_position.cc.
References yaze::zelda3::East, yaze::zelda3::North, yaze::zelda3::South, and yaze::zelda3::West.
Referenced by yaze::editor::DungeonObjectInteraction::DrawDoorGhostPreview(), yaze::editor::DungeonObjectInteraction::DrawDoorSnapIndicators(), yaze::editor::DungeonObjectInteraction::DrawEntitySelectionHighlights(), yaze::editor::DoorInteractionHandler::DrawGhostPreview(), yaze::editor::DoorInteractionHandler::DrawSelectionHighlight(), yaze::editor::DoorInteractionHandler::DrawSnapIndicators(), yaze::zelda3::ObjectDrawer::DoorDef::GetTileCoords(), yaze::zelda3::Room::Door::GetTileCoords(), and PositionToPixelCoords().
|
static |
Convert encoded position to pixel coordinates.
| position | Encoded position byte from ROM (0-31) |
| direction | Door direction |
Definition at line 206 of file door_position.cc.
References kTileSize, and PositionToTileCoords().
Referenced by GetDoorBounds(), and yaze::zelda3::Room::Door::GetPixelCoords().

|
static |
Get the wall edge coordinate for a direction.
Returns the fixed coordinate for the wall edge:
| direction | Door direction |
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.
|
static |
Check if a position is valid for door placement.
| position | Encoded position (0-31) |
| direction | Door direction |
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().

|
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.
| canvas_x | X coordinate on canvas (pixels) |
| canvas_y | Y coordinate on canvas (pixels) |
| out_direction | Output: detected direction (if near a wall) |
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().
|
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:
| canvas_x | X coordinate on canvas (pixels) |
| canvas_y | Y coordinate on canvas (pixels) |
| out_direction | Output: detected direction |
| out_is_inner | Output: true if at inner seam, false if outer wall |
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().
|
static |
Get the starting position index for outer/inner section.
| direction | Door direction |
| is_inner | Whether at inner seam (vs outer wall) |
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().
|
static |
Encode door data for ROM storage.
| position | Encoded position (0-31) |
| type | Door type |
| direction | Door direction |
Definition at line 373 of file door_position.cc.
Referenced by yaze::zelda3::Room::Door::EncodeBytes().
|
static |
Get the bounding rectangle for a door.
| position | Encoded position |
| direction | Door direction |
Definition at line 387 of file door_position.cc.
References yaze::zelda3::GetDoorDimensions(), and PositionToPixelCoords().
Referenced by yaze::zelda3::Room::Door::GetBounds().

|
staticconstexpr |
Definition at line 34 of file door_position.h.
Referenced by DetectWallFromPosition(), DetectWallSection(), GetWallEdge(), and IsValidPosition().
|
staticconstexpr |
Definition at line 35 of file door_position.h.
Referenced by DetectWallFromPosition(), DetectWallSection(), GetWallEdge(), and IsValidPosition().
|
staticconstexpr |
Definition at line 36 of file door_position.h.
Referenced by DetectWallFromPosition(), DetectWallSection(), PositionToPixelCoords(), and SnapToNearestPosition().
|
staticconstexpr |
Definition at line 37 of file door_position.h.
|
staticconstexpr |
Definition at line 40 of file door_position.h.
Referenced by DetectWallFromPosition(), and DetectWallSection().