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

Conversation

nicolasnoble
Copy link
Member

No description provided.

Copy link
Contributor

coderabbitai bot commented May 18, 2025

Walkthrough

The update introduces a TPageLoc struct for managing texture page locations and significantly extends the TPageAttr struct with new constructors, assignment operators, a copy method, a setter for page locations, and several getter methods to access internal bitfields, enhancing encapsulation and control over texture page attributes.

Changes

File Change Summary
src/mips/psyqo/primitives/common.hh Added TPageLoc struct with setters for X/Y; extended TPageAttr with constructors, assignment, copy, setter, and multiple getters for bitfields.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TPageLoc
    participant TPageAttr

    User->>TPageLoc: setPageX(x), setPageY(y)
    User->>TPageAttr: setPageLoc(TPageLoc)
    User->>TPageAttr: getPageX(), getPageY(), getPageLoc()
    User->>TPageAttr: getSemiTrans(), getColorMode()
    User->>TPageAttr: hasDithering(), isDisplayAreaEnabled()
Loading

Poem

In fields of bits where textures roam,
New structs and getters call it home.
Page X and Y now set with grace,
Constructors, copies—an interface!
With flags and modes all neatly shown,
The rabbit hops through VRAM zones.
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between dec9cd9 and d722aa3.

📒 Files selected for processing (1)
  • src/mips/psyqo/primitives/common.hh (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: pcsx-redux (aarch64-linux)
  • GitHub Check: pcsx-redux (x86_64-linux)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: toolchain
  • GitHub Check: macos-build-and-test-toolchain
  • GitHub Check: asan
  • GitHub Check: coverage
  • GitHub Check: aur-build
  • GitHub Check: build-openbios
  • GitHub Check: build
  • GitHub Check: cross-arm64
🔇 Additional comments (5)
src/mips/psyqo/primitives/common.hh (5)

154-165: Use explicit masks & constexpr to prevent sign-extension and magic numbers

Both setters rely on expressions such as ~0x000f and ~0x0010.
Because ~ promotes the operand to int, the result contains all upper bits set, which are then truncated when assigned back to uint8_t. While this works, it is easy to mis-read and becomes brittle if info ever changes type.

A safer and clearer pattern is to define named constexpr masks whose type already matches the field, then invert that value. This removes the promotion issue, documents intent, and allows the compiler to fold everything at compile-time.

-        info &= ~0x000f;
-        x &= 0x000f;
+        static constexpr uint8_t kPageXMask = 0x0f;
+        info &= static_cast<uint8_t>(~kPageXMask);
+        x &= kPageXMask;

-        info &= ~0x0010;
-        y &= 0x0001;
+        static constexpr uint8_t kPageYMask = 0x10;
+        info &= static_cast<uint8_t>(~kPageYMask);
+        y &= 0x01;

[ suggest_essential_refactor ]


187-201: Prefer = default + noexcept for the trivial special members

All special members just copy a uint16_t; the compiler-generated versions are already optimal and noexcept.
Manually writing them:

  1. Adds maintenance overhead (any new fields require edits).
  2. Forfeits the implicit noexcept guarantee, potentially hurting move semantics of containing classes.

Recommend:

-    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(const TPageAttr&)         = default;
+    TPageAttr(TPageAttr&&) noexcept     = default;
+    TPageAttr& operator=(const TPageAttr&) = default;
+    TPageAttr& operator=(TPageAttr&&) noexcept = default;

[ suggest_essential_refactor ]


198-201: copy() duplicates assignment – consider removing

copy() offers the same semantics as operator= minus self-assignment safety, and its extra name marginally increases the API surface.

Unless there is a strong ABI reason, removing it (or marking it [[deprecated]]) will keep the interface tighter.

[ suggest_optional_refactor ]


214-218: Pass TPageLoc by const reference (or uint8_t) to prevent accidental copies

TPageLoc is small, but passing by value invites inadvertent temporaries and makes the call site a bit noisier (requires an l-value or explicit move). Either:

-    TPageAttr& setPageLoc(TPageLoc loc) {
+    TPageAttr& setPageLoc(const TPageLoc& loc) {

or accept a raw uint8_t holding the five bits – the intent is the same and the call site becomes attr.setPageLoc(loc.info);.

[ suggest_optional_refactor ]


247-257: Mark cheap, side-effect-free accessors constexpr & [[nodiscard]]

These getters are pure bit-grabs that can run at compile-time and whose results should not be ignored.

-    uint8_t getPageX() const { return info & 0x000f; }
+    [[nodiscard]] constexpr uint8_t getPageX() const { return info & 0x000f; }

Apply the same to the other getters. This improves compile-time evaluation opportunities and helps static-analysis tools catch accidental ignored results.

[ suggest_optional_refactor ]

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nicolasnoble nicolasnoble requested a review from Copilot May 18, 2025 00:37
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

The PR adds new getters and setters for the TPage attribute and introduces the TPageLoc struct to facilitate manipulation of texture page locations.

  • Introduces the TPageLoc struct with setters for page X and Y coordinate manipulation.
  • Adds copy/move constructors, assignment operators, and a new setter to set the page location from a TPageLoc instance in TPageAttr.
  • Provides getter functions in TPageAttr for page attributes and related settings.

Comment on lines +198 to +201
TPageAttr& copy(const TPageAttr& other) {
info = other.info;
return *this;
}
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.

Comment on lines +187 to +197
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;
}
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.

@nicolasnoble nicolasnoble merged commit a5ad923 into grumpycoders:main May 18, 2025
22 checks passed
@nicolasnoble nicolasnoble deleted the tpage-getters-setters branch May 18, 2025 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant