Skip to content
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

Refactor more constants in TrackPaint.h #21995

Merged

Conversation

Harry-Hopkinson
Copy link
Contributor

Rename more constants to follow the new notation in TrackPaint.h. Move extern consts to constexpr.

extern const CoordsXY defaultRightQuarterTurn5TilesOffsets[4][5];
extern const CoordsXYZ defaultRightQuarterTurn5TilesBoundOffsets[4][5];
extern const CoordsXY defaultRightQuarterTurn5TilesBoundLengths[4][5];
constexpr CoordsXY kDefaultRightQuarterTurn5TilesOffsets[4][5] = {
Copy link
Member

Choose a reason for hiding this comment

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

I think these shouldn't be directly in the header, as this would create a new instance every time the header is included. Rather, they should remain in TrackPaint.cpp and exposed through a getter function.

If you do not feel like introducing such a getter function, you can leave the extern definition in TrackPaint.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I do the same for the others that I did in #21942 etc?

Copy link
Member

Choose a reason for hiding this comment

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

I think that @Harry-Hopkinson did this because Matt requested making the segment declarations constexpr. I can imagine this will be confusing, as it now looks like two team members are asking opposite things.

Let’s ask @ZehMatt to weigh in.

Copy link
Member

Choose a reason for hiding this comment

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

When to use getters instead of constexpr is situational. I think in this case it might be best to move them into a new header and have only cpp files include it, adding getters always adds the risk of adding overhead and I think this is one of those areas in the code where avoiding branching code is probably for the better.

Copy link
Member

Choose a reason for hiding this comment

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

So do you mean they should stay as they are now (extern), or?

Copy link
Member

Choose a reason for hiding this comment

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

I would go for a new header.

Copy link
Member

Choose a reason for hiding this comment

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

A new header, and changing them to constexpr, you mean?

If many cpp files pull from that header, doesn’t that create copies? Or will the compiler handle it correctly?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that would create new instances of the arrays. But it also allows the compiler to inline them, potentially unroll a few loops, etc. As Matt said, it's situational 😅

Copy link
Member

@ZehMatt ZehMatt May 10, 2024

Choose a reason for hiding this comment

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

I'm a bit puzzled to why this PR changes them to begin with, best to revert that and just stick to refactoring the names. This is beyond a style refactor when we start moving data structures around.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. I’ll probably touch them anyway in a future track refactor.

@Harry-Hopkinson Could you take out the constexpr changes and just leave in the name changes?

@Gymnasiast Gymnasiast merged commit 740ee91 into OpenRCT2:develop May 10, 2024
22 checks passed
@Harry-Hopkinson Harry-Hopkinson deleted the refactor-trackpaint-constants branch May 10, 2024 14:05
@tupaschoal tupaschoal added this to the v0.4.12 milestone May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants