mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-07 05:53:59 -07:00
refactor(z-values): removed redundant inline with contexpr, Updated doc, magic numbers removed from TableZone.
This commit is contained in:
parent
652ca041b4
commit
5943ae3427
3 changed files with 36 additions and 11 deletions
|
|
@ -102,7 +102,7 @@ constexpr qreal OVERLAY_BASE = 2000000000.0;
|
|||
* @param zValue The Z-value to validate
|
||||
* @return true if the Z-value is valid for a card
|
||||
*/
|
||||
[[nodiscard]] inline constexpr bool isValidCardZValue(qreal zValue)
|
||||
[[nodiscard]] constexpr bool isValidCardZValue(qreal zValue)
|
||||
{
|
||||
return zValue >= 1.0 && zValue <= CARD_Z_VALUE_MAX;
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ constexpr qreal OVERLAY_BASE = 2000000000.0;
|
|||
* @param zValue The Z-value to validate
|
||||
* @return true if the Z-value is valid for an overlay element
|
||||
*/
|
||||
[[nodiscard]] inline constexpr bool isOverlayZValue(qreal zValue)
|
||||
[[nodiscard]] constexpr bool isOverlayZValue(qreal zValue)
|
||||
{
|
||||
return zValue >= OVERLAY_BASE;
|
||||
}
|
||||
|
|
@ -126,7 +126,7 @@ constexpr qreal OVERLAY_BASE = 2000000000.0;
|
|||
* @param offset Offset from OVERLAY_BASE (0-7 for current elements)
|
||||
* @return The absolute Z-value for the overlay element
|
||||
*/
|
||||
[[nodiscard]] inline constexpr qreal overlayZValue(qreal offset)
|
||||
[[nodiscard]] constexpr qreal overlayZValue(qreal offset)
|
||||
{
|
||||
return OVERLAY_BASE + offset;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,17 +39,41 @@ constexpr qreal DRAG_ITEM = ZValueLayerManager::overlayZValue(5.0);
|
|||
constexpr qreal DRAG_ITEM_CHILD = ZValueLayerManager::overlayZValue(6.0);
|
||||
constexpr qreal TOP_UI = ZValueLayerManager::overlayZValue(7.0);
|
||||
|
||||
/// Compute Z-value for child drag items based on hotspot position.
|
||||
/// When dragging multiple cards together, each child card needs a unique Z-value
|
||||
/// to prevent Z-fighting (flickering/flashing). The Z-values are derived from
|
||||
/// their position when grabbed to conserve original stacking. The formula encodes
|
||||
/// 2D coordinates into a single value where X has higher weight, ensuring
|
||||
/// deterministic visual stacking.
|
||||
/**
|
||||
* @brief Compute Z-value for child drag items based on hotspot position.
|
||||
*
|
||||
* When dragging multiple cards together, each child card needs a unique Z-value
|
||||
* to prevent Z-fighting (flickering/flashing). The Z-values are derived from
|
||||
* their position when grabbed to conserve original stacking. The formula encodes
|
||||
* 2D coordinates into a single value where X has higher weight, ensuring
|
||||
* deterministic visual stacking.
|
||||
*
|
||||
* @param hotSpotX The X coordinate of the grab position
|
||||
* @param hotSpotY The Y coordinate of the grab position
|
||||
* @return Unique Z-value for the child drag item
|
||||
*/
|
||||
[[nodiscard]] constexpr qreal childDragZValue(qreal hotSpotX, qreal hotSpotY)
|
||||
{
|
||||
return DRAG_ITEM_CHILD + hotSpotX * 1000000 + hotSpotY * 1000 + 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compute Z-value for cards on the table zone based on position.
|
||||
*
|
||||
* Cards lower on the table (higher Y) render above cards higher up,
|
||||
* and cards to the right (higher X) render above cards to the left.
|
||||
* This creates natural visual stacking for overlapping cards.
|
||||
*
|
||||
* @param x The X coordinate of the card position
|
||||
* @param y The Y coordinate of the card position
|
||||
* @return Z-value for the card's table position
|
||||
*/
|
||||
[[nodiscard]] constexpr qreal tableCardZValue(qreal x, qreal y)
|
||||
{
|
||||
constexpr qreal CARD_HEIGHT_FOR_Z = 102.0;
|
||||
return (y + CARD_HEIGHT_FOR_Z) * 100000.0 + (x + 1) * 100.0;
|
||||
}
|
||||
|
||||
// Card layering (general architecture, not command-zone specific)
|
||||
constexpr qreal CARD_BASE = 1.0;
|
||||
constexpr qreal CARD_MAX = ZValueLayerManager::CARD_Z_VALUE_MAX;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "../board/card_item.h"
|
||||
#include "../player/player.h"
|
||||
#include "../player/player_actions.h"
|
||||
#include "../z_values.h"
|
||||
#include "logic/table_zone_logic.h"
|
||||
|
||||
#include <QGraphicsScene>
|
||||
|
|
@ -167,7 +168,7 @@ void TableZone::reorganizeCards()
|
|||
actualY += 15;
|
||||
|
||||
getLogic()->getCards()[i]->setPos(actualX, actualY);
|
||||
getLogic()->getCards()[i]->setRealZValue((actualY + CARD_HEIGHT) * 100000 + (actualX + 1) * 100);
|
||||
getLogic()->getCards()[i]->setRealZValue(ZValues::tableCardZValue(actualX, actualY));
|
||||
|
||||
QListIterator<CardItem *> attachedCardIterator(getLogic()->getCards()[i]->getAttachedCards());
|
||||
int j = 0;
|
||||
|
|
@ -177,7 +178,7 @@ void TableZone::reorganizeCards()
|
|||
qreal childX = actualX - j * STACKED_CARD_OFFSET_X;
|
||||
qreal childY = y + 5;
|
||||
attachedCard->setPos(childX, childY);
|
||||
attachedCard->setRealZValue((childY + CARD_HEIGHT) * 100000 + (childX + 1) * 100);
|
||||
attachedCard->setRealZValue(ZValues::tableCardZValue(childX, childY));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue