-
Notifications
You must be signed in to change notification settings - Fork 126
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.
| } | ||
| } | ||
| } | ||
| if( rider->isKindOf( KINDOF_HERO ) && m_heroUnitsContained > 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.
Make the m_heroUnitsContained > 0 an assert, because we do not expect this to be 0 here, right?
| 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.
Summary
Optimizes
Object::isHero()by caching hero count in containers instead of iterating through all contained objects on every call.