tweak(particlesys): Decouple Particles render update from logic step#2709
tweak(particlesys): Decouple Particles render update from logic step#2709xezon wants to merge 8 commits into
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Source/GameClient/System/ParticleSys.cpp | Core of the PR: split into update() (keyframes/lifetime) and draw(timeScale) (physics integration with frame-rate-independent damping). New helper functions scaleDamping/scaleAccelDamping are mathematically correct. |
| Core/GameEngine/Include/GameClient/ParticleSys.h | Adds draw()/updateWindMotion()/updateTransform() family of methods; drops m_lastPos from Particle. ParticleSystemManagerDummy extended with guarded createParticleSystem stub (ID=0 sentinel, never registered in manager map). |
| GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp | Moves setLocalPlayerIndex + ParticleSystemManager::update() call here from GameClient, correctly preceding the logic-step particle update. |
| GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp | Removes updateHeadless() and the old update block from the client path. Leaves a dead-code empty block with a commented-out draw() call. |
| GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp | Single-line change: replaces legacy update() with new draw() in the render path. |
| Core/Libraries/Include/Lib/BaseType.h | Adds compound assignment and binary operators for RGBColor. All binary operators return by value, fixing the dangling-reference issue from a previous review. |
Sequence Diagram
sequenceDiagram
participant GL as GameLogic::update()
participant PSM_U as ParticleSystemManager::update()
participant PS_U as ParticleSystem::update()
participant W3D as W3DDisplay (render path)
participant PSM_D as ParticleSystemManager::draw()
participant PS_D as ParticleSystem::draw(timeScale)
Note over GL,PS_D: New decoupled flow (this PR)
GL->>PSM_U: setLocalPlayerIndex + update()
PSM_U->>PS_U: update() — keyframes, lifetime, isInvisible
PS_U-->>PSM_U: alive / dead
W3D->>PSM_D: draw() — render path
PSM_D->>PS_D: applyForce(gravity) + draw(timeScale)
PS_D-->>PSM_D: physics integrated (vel, pos, color, alpha)
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp:1261-1267
**Dead code block left behind**
The `setLocalPlayerIndex` + `update()` call was moved to `GameLogic::update()` and the draw call is now in `W3DDisplay`, leaving an empty block with only a commented-out line. The surrounding braces and comment have no functional effect and should be removed to keep the call site clean.
Reviews (4): Last reviewed commit: "fixup! fix(particlesys): Simplify Partic..." | Re-trigger Greptile
|
I presume this PR fixes #2467. |
| psys->attachToObject(building); | ||
| Drawable *drawable = building->getDrawable(); | ||
| psys->attachToObject(object); | ||
| Drawable *drawable = object->getDrawable(); |
There was a problem hiding this comment.
This rename was just a side quest from when looking around particle things.
| // vel += accel; | ||
| // vel *= damping; | ||
| // | ||
| static inline Real scaleAccelDamping(Real damping, Real timeScale) |
There was a problem hiding this comment.
This function was crafted by prompting Chat Gippy many times. I do not understand exactly why it works but it works.
| ParticleSystemInfo::WindMotion windMotion = m_system->getWindMotion(); | ||
| // monitor lifetime | ||
| if (m_lifetimeLeft && --m_lifetimeLeft == 0) | ||
| return false; |
There was a problem hiding this comment.
I moved the lifetime check from the bottom of the update to the very top, because there is no reason to go through all the trouble of updating the particle when the lifetime hits zero anyway. So this is a very minor performance improvement maybe.
b94750d to
b86a504
Compare
|
The plane trails do not fade out gracefully. That needs looking into. |
|
The changes in this PR don't seem remotely retail compatible. Like many other replays, this PR makes GR1 mismatch with headless mode for me. The mismatch happens at frame 14227, but only with headless mode. It looks like the CI replay checker is silently broken. |
|
|
||
| RGBColor& operator+=(const RGBColor& c) | ||
| { | ||
| red += c.red; |
There was a problem hiding this comment.
Can this cause colors to go out of bound?
same for the other operations
There was a problem hiding this comment.
Yes it can. The caller needs to clamp then.
There was a problem hiding this comment.
wouldn't it be preferable that the operator deals with the clamp? Makes it less error-prone
There was a problem hiding this comment.
I dont think so. Because it is up to the color user what to do with it. For example the user can normalize the color, or average it like it does in W3DRadar:
// set the color to an average of the colors read
color.red = sampleColor.red / (Real)samples;
color.green = sampleColor.green / (Real)samples;
color.blue = sampleColor.blue / (Real)samples;There was a problem hiding this comment.
oof, this is such a poor design. It takes away the meaning of red, green and blue, which always should have a value between 0 and 255 (even as intermediate result). If we would want an average of colors, it would be better to have a static RGBColor AverageColor(RGBColor[] colors) method that does this, rather then have color implementations in other classes. Otherwise it makes it error prone and fails to adhere to srp.
This is an issue well beyond this PR, so I'll leave this as resolved.
There was a problem hiding this comment.
We can think of this class like a Vector. Vectors are also manipulated in various ways, for example for creating a unit vector we do normalize. I think that is why they made it 3x float to begin with, instead of just 4x byte.
…rticle::update() into additional functions (#2709)
…icle::draw() (#2709)
b86a504 to
278f319
Compare
|
I will break the dummy particle manager changes off of this pull. |
|
ParticleSystemManagerDummy changes split off to #2740 |
Merge with Rebase
This change decouples the Particles render update from the logic step.
Split into 7 commits for ease of understanding and review.
TODO