Skip to content

Adding getters and setters to the TPage attribute. #1929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/mips/psyqo/primitives/common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,34 @@ struct TexInfo {
};
static_assert(sizeof(TexInfo) == sizeof(uint32_t), "TexInfo is not 32 bits");

struct TPageAttr;
/**
* @brief A primitive's tpage location.
*
* @details This represents the location of a texture page in the VRAM space, and is
* used in the `TPageAttr` struct. This can be used to easily set the page location
* in a primitive's attribute while keeping the other attributes intact.
*/
struct TPageLoc {
TPageLoc& setPageX(uint8_t x) {
info &= ~0x000f;
x &= 0x000f;
info |= x;
return *this;
}
TPageLoc& setPageY(uint8_t y) {
info &= ~0x0010;
y &= 0x0001;
info |= y << 4;
return *this;
}

private:
uint8_t info = 0;
friend struct TPageAttr;
};
static_assert(sizeof(TPageLoc) == sizeof(uint8_t), "TPageLoc is not 8 bits");

/**
* @brief A primitive's tpage attribute.
*
Expand All @@ -156,6 +184,21 @@ static_assert(sizeof(TexInfo) == sizeof(uint32_t), "TexInfo is not 32 bits");
* as the compiler will better optimize the former sequence of operations.
*/
struct TPageAttr {
TPageAttr() {}
TPageAttr(TPageAttr&& other) : info(other.info) {}
TPageAttr(const TPageAttr& other) : info(other.info) {}
TPageAttr& operator=(TPageAttr&& other) {
info = other.info;
return *this;
}
TPageAttr& operator=(const TPageAttr& other) {
info = other.info;
return *this;
}
Comment on lines +187 to +197
Copy link
Preview

Copilot AI May 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Since the default constructor and the copy/move operators perform only trivial member-wise operations, you could consider using the default implementations (i.e., '= default') to reduce boilerplate code.

Suggested change
TPageAttr() {}
TPageAttr(TPageAttr&& other) : info(other.info) {}
TPageAttr(const TPageAttr& other) : info(other.info) {}
TPageAttr& operator=(TPageAttr&& other) {
info = other.info;
return *this;
}
TPageAttr& operator=(const TPageAttr& other) {
info = other.info;
return *this;
}
TPageAttr() = default;
TPageAttr(TPageAttr&& other) = default;
TPageAttr(const TPageAttr& other) = default;
TPageAttr& operator=(TPageAttr&& other) = default;
TPageAttr& operator=(const TPageAttr& other) = default;

Copilot uses AI. Check for mistakes.

TPageAttr& copy(const TPageAttr& other) {
info = other.info;
return *this;
}
Comment on lines +198 to +201
Copy link
Preview

Copilot AI May 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The copy() method in TPageAttr is redundant since the copy assignment operator already handles member-wise copying. Consider removing it to reduce duplication and simplify maintenance.

Suggested change
TPageAttr& copy(const TPageAttr& other) {
info = other.info;
return *this;
}
// Removed the redundant copy() method as the copy assignment operator already handles member-wise copying.

Copilot uses AI. Check for mistakes.

TPageAttr& setPageX(uint8_t x) {
info &= ~0x000f;
x &= 0x000f;
Expand All @@ -168,6 +211,11 @@ struct TPageAttr {
info |= y << 4;
return *this;
}
TPageAttr& setPageLoc(TPageLoc loc) {
info &= ~0x001f;
info |= loc.info;
return *this;
}
TPageAttr& set(Prim::TPageAttr::SemiTrans trans) {
info &= ~0x0060;
uint32_t t = static_cast<uint32_t>(trans);
Expand Down Expand Up @@ -196,6 +244,17 @@ struct TPageAttr {
info |= 0x0400;
return *this;
}
uint8_t getPageX() const { return info & 0x000f; }
uint8_t getPageY() const { return (info >> 4) & 0x0001; }
uint8_t getPageLoc() const { return info & 0x001f; }
Prim::TPageAttr::SemiTrans getSemiTrans() const {
return static_cast<Prim::TPageAttr::SemiTrans>((info >> 5) & 0x0003);
}
Prim::TPageAttr::ColorMode getColorMode() const {
return static_cast<Prim::TPageAttr::ColorMode>((info >> 7) & 0x0003);
}
bool hasDithering() const { return (info & 0x0200) != 0; }
bool isDisplayAreaEnabled() const { return (info & 0x0400) != 0; }

private:
uint16_t info = 0;
Expand Down
Loading