-
Notifications
You must be signed in to change notification settings - Fork 130
perf(fps): optimize Object::isHero with cached hero counter #1841
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
base: main
Are you sure you want to change the base?
perf(fps): optimize Object::isHero with cached hero counter #1841
Conversation
bcbf169 to
386443b
Compare
xezon
left a comment
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.
A number of questions.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp
Show resolved
Hide resolved
Generals/Code/GameEngine/Include/GameLogic/Module/OpenContain.h
Outdated
Show resolved
Hide resolved
Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp
Outdated
Show resolved
Hide resolved
4482d08 to
df4e579
Compare
xezon
left a comment
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.
Currently this will break Xfer Save and Load.
Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp
Outdated
Show resolved
Hide resolved
| xfer->xferUnsignedInt( &m_stealthUnitsContained ); | ||
|
|
||
| // hero units contained | ||
| xfer->xferUnsignedInt( &m_heroUnitsContained ); |
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.
This requires Xfer version increment. And version history documentation. Also needs to be put behind RETAIL_COMPATIBLE_XFER_SAVE. See other code that does it.
In RETAIL_COMPATIBLE_XFER_SAVE, the count needs to be restored by iterating hero objects like the original code did it.
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.
Done. It's version 3 in MD and 2 in Generals now
| } | ||
| if( rider->isKindOf( KINDOF_HERO ) ) | ||
| { | ||
| DEBUG_ASSERTCRASH( m_heroUnitsContained > 0, ("Removing hero but hero count is 0") ); |
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.
Text is not quite accurate:
"OpenContain::removeFromContainViaIterator - Removing hero but hero count is %d", m_heroUnitsContained
Could add the same assert to stealth units above.
| * Version Info: | ||
| * 1: Initial version */ | ||
| * 1: Initial version | ||
| * 2: Added m_heroUnitsContained cached hero count (bobtista) */ |
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.
TheSuperHackers @tweak Serialize hero units contained count
Do not use trailing (bobtista) because this is not part of our comment convention for authors.
Can put */ in new line.
| { | ||
| m_heroUnitsContained = 0; | ||
| } | ||
| #endif |
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.
This whole block looks overengineered. Can it be simplifed to just
if (version >= 2)
{
xfer->xferUnsignedInt( &m_heroUnitsContained );
}?
|
|
||
| } | ||
|
|
||
| #if RETAIL_COMPATIBLE_XFER_SAVE |
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.
Use same technique as in #2024 for particle cannon to condition it.
Summary
Optimizes
Object::isHero()by caching hero count in containers instead of iterating through all contained objects on every call.