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

pre/post: reworked changes in AddToFullPack for correctness and portability #551

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

SmileyAG
Copy link
Collaborator

Three reasons why this request exists:

  • In HLSDK 1.0-based engines and game directories, AddToFullPack is not in the server-side (hl.dll), but in the engine (hw.dll) under the name 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!

…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);
Copy link
Collaborator Author

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);

Copy link
Owner

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);
Copy link
Owner

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);
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
#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.

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.

2 participants