perf(particlesys): Optimize angleBetween() in Particle System#2218
Merged
xezon merged 1 commit intoTheSuperHackers:mainfrom Feb 1, 2026
Merged
Conversation
Greptile Overview
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Source/GameClient/System/ParticleSys.cpp | Optimized angleBetween() by caching length calculations, eliminating 2 redundant sqrt operations per call |
Sequence Diagram
sequenceDiagram
participant Particle as Particle::updateParticle()
participant angleBetween as angleBetween()
participant Coord2D as Coord2D::length()
Note over Particle: m_particleUpTowardsEmitter == true
Particle->>Particle: Create upVec {0, 1}
Particle->>Particle: Create emitterDir from positions
Particle->>angleBetween: angleBetween(&upVec, &emitterDir)
Note over angleBetween: Before optimization:<br/>4 calls to length()
Note over angleBetween: After optimization:<br/>2 calls to length()
angleBetween->>Coord2D: vecA->length()
Coord2D-->>angleBetween: lengthA
angleBetween->>Coord2D: vecB->length()
Coord2D-->>angleBetween: lengthB
Note over angleBetween: Check if both lengths != 0
alt Both lengths are zero
angleBetween-->>Particle: return 0.0f
else Valid vectors
Note over angleBetween: Calculate dot product<br/>Calculate cosTheta<br/>Calculate theta using ACos
angleBetween-->>Particle: return ±theta
end
Particle->>Particle: Set m_angleZ = theta + PI
Mauller
reviewed
Jan 30, 2026
githubawn
pushed a commit
to githubawn/GeneralsGameCode
that referenced
this pull request
Feb 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This change optimizes the
angleBetween()function a bit by removing 2 redundantlengthfunction calls, which each containIt is used by the Particle System update.
Not measured, because impact is expected very minor.