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

Convert vector macros to template functions #1181

Merged
merged 2 commits into from
Jun 8, 2024

Conversation

slipher
Copy link
Member

@slipher slipher commented Jun 7, 2024

The point of this is to prevent the arguments from being evaluated multiple times. In the commit message I give an example of this happening in cgame.

Also it can be useful for assigning a temporary GLM vector to a vec3_t. This is one more GLM/vec3_t adaptor we need in addition to GLM4READ and GLM4RW. I was motivated to make this branch upon seeing, in a GLM conversion branch, VectorCopy used to assign a function's GLM return value to a vec3_t (heretofore a bad idea as the function is called 3 times).

slipher added 2 commits June 6, 2024 19:48
This is good because it prevents multiple evaluation of the arguments.
As a live example of this bug, the CG_CalculateTimeFrac inside a
VectorMA in CG_RenderParticle in Unvanquished/src/cgame/cg_particles.cpp
would be evaluated 3 times.

Also it may be useful to copy a glm::vec3 returned from a function into
a vec3_t without needing a temporary variable.
Comment on lines +39 to +41
#define DotProduct4(x, y) (( x )[ 0 ] * ( y )[ 0 ] + ( x )[ 1 ] * ( y )[ 1 ] + ( x )[ 2 ] * ( y )[ 2 ] + ( x )[ 3 ] * ( y )[ 3 ] )
#define VectorMultiply( a,b,c ) ( ( c )[ 0 ] = ( a )[ 0 ] * ( b )[ 0 ],( c )[ 1 ] = ( a )[ 1 ] * ( b )[ 1 ],( c )[ 2 ] = ( a )[ 2 ] * ( b )[ 2 ] )

Copy link
Contributor

Choose a reason for hiding this comment

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

why not these two?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since they were only used in one file, it seemed to me they are not suitable for inclusion in the header included by all files. And with only 1-2 uses in 1 file they should probably be normal functions not templates, but I didn't want to spend time on them.

@slipher slipher merged commit 5cf0f16 into DaemonEngine:master Jun 8, 2024
9 checks passed
@slipher slipher deleted the vectormacros branch June 8, 2024 16:18
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