Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
More message filters #5605
More message filters #5605
Changes from 4 commits
9586f21
04a5778
f13a5b3
0811c70
15db3b1
2bcedc3
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be sticking to making things like this name parameter const as often as we can
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is somewhere where my C++ is a little lacking.
SCP_string const &
means "a reference to an SCP_string which we promise not to change" and potentially allows for compiler optimizations, right? What about declaring the function itselfconst
? (To be clear, I'm asking from an educational perspective ^^ )There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, basically.
SCP_string const &
gives you a reference to a string you cannot change. The compiler will stop you from any things that would change the string, so not only allows it for more optimization, but also is simply a safeguard for you as the developer to not do things you shouldn't.Declaring the function const in this context is not possible. You could declare the return type const (
const int lookup_mood
), but declaring the function const (int lookup_mood(...) const {
) is only possible if it's a member function of a class (which it isn't, as a global function), and will basically mean "disallow any modification of member variables", which allows you to call the function on an object of that class which is const itself.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a mood isn't found, msg.mood will now be set to -1 instead of 0. Which in turn means that erroneous moods for messages caused the messages to be boosted when the mood was actually 0.
While I doubt that that has been taken advantage off in an existing mod, it should probably at least get a comment here acknowledging that change, in case anyone comes looking in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it? Looking at the code on
master
, I'm not sure thatmsg.mood
is actually initialized on a missing mood. Isn't that UB?e: following up on Discord
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, turns out I was confusing things, and the default-initialization implicitly causing a zero-initialization is only correct for variables with a static lifetime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>= ?
I mean, I guess an uninitialized range is set to -1, but is there ever a case where range == 0 is sensible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the sender itself is ignored (
if (sender->objnum == i->objnum) { continue; }
), the only way a range of 0 could ever be satisfied is with non-colliding objects in exactly the same position. I don't think it matters in practice, but> 0
is probably clearer, so I'm happy to make that change.