-
Notifications
You must be signed in to change notification settings - Fork 37
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
pre/post: reworked changes in AddToFullPack for correctness and portability #551
base: master
Are you sure you want to change the base?
Conversation
…cific flag, not the old states of all flags I know this might only be partially suitable for this pull request (due to the addition of the SET_OR_UNSET_FLAG macro), but I'm really too lazy to split it into a new pull request and then rebase it for this little thing.
ent->v.iuser1 = oldIUser1; | ||
ent->v.iuser2 = oldIUser2; | ||
if (status != BXT_ADDTOFULLPACK_STATE_NO) { | ||
ent->v.effects = SET_OR_UNSET_FLAG(oldEffectsNodraw, ent->v.effects, EF_NODRAW); |
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.
Damn, how did I let this happen and the compiler didn't even complain? Will fix it later simply to:
SET_OR_UNSET_FLAG(oldEffectsNodraw, ent->v.effects, EF_NODRAW);
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.
Not sure I would've caught this. It's difficult to review when two different changes are bundled together in one commit like this, especially when the diff is completely messed up too
ent->v.iuser1 = oldIUser1; | ||
ent->v.iuser2 = oldIUser2; | ||
if (status != BXT_ADDTOFULLPACK_STATE_NO) { | ||
ent->v.effects = SET_OR_UNSET_FLAG(oldEffectsNodraw, ent->v.effects, EF_NODRAW); |
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.
Not sure I would've caught this. It's difficult to review when two different changes are bundled together in one commit like this, especially when the diff is completely messed up too
#define GET_PEV(thisptr) *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + off_pev); | ||
#define SET_OR_UNSET_FLAG(boolVar, setVar, flag) boolVar ? (setVar |= flag) : (setVar &= ~flag); |
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.
#define SET_OR_UNSET_FLAG(boolVar, setVar, flag) boolVar ? (setVar |= flag) : (setVar &= ~flag); | |
#define SET_OR_UNSET_FLAG(boolVar, setVar, flag) (boolVar) ? (setVar |= (flag)) : (setVar &= ~(flag)); |
Otherwise it's possible to get unintended splitting.
Three reasons why this request exists:
SV_AddToFullPack
So using such a pre/post implementation, we can easily make the same changes in several similar functions, i.e. no need to stupidly copy-paste the code every time
We return old states only when they have actually been changed, thereby removing the possibility of accidentally overwriting the new state for objects to which we should not even make changes!
For integer variables that serve to store flags for performing bitwise operations with them, we now return not their entire old state, but only the old state of a specific flag that we changed!