-
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?
Changes from all commits
f789849
29bc6b0
1435034
bf1c4bb
df4e579
8e2f067
200e0f6
464efc8
d979f92
e8ae78b
df0caad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,6 +125,7 @@ OpenContain::OpenContain( Thing *thing, const ModuleData* moduleData ) : UpdateM | |
| m_lastLoadSoundFrame = 0; | ||
| m_containListSize = 0; | ||
| m_stealthUnitsContained = 0; | ||
| m_heroUnitsContained = 0; | ||
| m_doorCloseCountdown = 0; | ||
|
|
||
| m_rallyPoint.zero(); | ||
|
|
@@ -352,6 +353,10 @@ void OpenContain::addToContainList( Object *rider ) | |
| { | ||
| m_stealthUnitsContained++; | ||
| } | ||
| if( rider->isKindOf( KINDOF_HERO ) ) | ||
| { | ||
| m_heroUnitsContained++; | ||
| } | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
|
|
@@ -542,6 +547,11 @@ void OpenContain::removeFromContainViaIterator( ContainedItemsList::iterator it, | |
| } | ||
| } | ||
| } | ||
| if( rider->isKindOf( KINDOF_HERO ) ) | ||
| { | ||
| DEBUG_ASSERTCRASH( m_heroUnitsContained > 0, ("Removing hero but hero count is 0") ); | ||
| m_heroUnitsContained--; | ||
| } | ||
|
|
||
|
|
||
| if (isEnclosingContainerFor( rider )) | ||
|
|
@@ -620,7 +630,7 @@ void OpenContain::scatterToNearbyPosition(Object* rider) | |
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| void OpenContain::onContaining( Object * /*rider*/ ) | ||
| void OpenContain::onContaining( Object *rider ) | ||
| { | ||
| // Play audio | ||
| if( m_loadSoundsEnabled ) | ||
|
|
@@ -1442,13 +1452,18 @@ void OpenContain::crc( Xfer *xfer ) | |
| // ------------------------------------------------------------------------------------------------ | ||
| /** Xfer method | ||
| * 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Do not use trailing Can put */ in new line. |
||
| // ------------------------------------------------------------------------------------------------ | ||
| void OpenContain::xfer( Xfer *xfer ) | ||
| { | ||
|
|
||
| // version | ||
| const XferVersion currentVersion = 1; | ||
| #if RETAIL_COMPATIBLE_XFER_SAVE | ||
| XferVersion currentVersion = 1; | ||
| #else | ||
| XferVersion currentVersion = 2; | ||
| #endif | ||
| XferVersion version = currentVersion; | ||
| xfer->xferVersion( &version, currentVersion ); | ||
|
|
||
|
|
@@ -1526,6 +1541,24 @@ void OpenContain::xfer( Xfer *xfer ) | |
| // stealth units contained | ||
| xfer->xferUnsignedInt( &m_stealthUnitsContained ); | ||
|
|
||
| // hero units contained | ||
| #if !RETAIL_COMPATIBLE_XFER_SAVE | ||
| if (version >= 2) | ||
| { | ||
| xfer->xferUnsignedInt( &m_heroUnitsContained ); | ||
| } | ||
| else if (xfer->getXferMode() == XFER_LOAD) | ||
| { | ||
| m_heroUnitsContained = 0; | ||
| } | ||
| #else | ||
| // In retail compatibility mode, hero count is restored by iterating hero objects in loadPostProcess | ||
| if (xfer->getXferMode() == XFER_LOAD) | ||
| { | ||
| m_heroUnitsContained = 0; | ||
| } | ||
| #endif | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 );
}? |
||
|
|
||
| // door close countdown | ||
| xfer->xferUnsignedInt( &m_doorCloseCountdown ); | ||
|
|
||
|
|
@@ -1658,6 +1691,18 @@ void OpenContain::loadPostProcess( void ) | |
|
|
||
| } | ||
|
|
||
| #if RETAIL_COMPATIBLE_XFER_SAVE | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use same technique as in #2024 for particle cannon to condition it. |
||
| // In retail compatibility mode, restore hero count by iterating hero objects | ||
| m_heroUnitsContained = 0; | ||
| for( ContainedItemsList::const_iterator it = m_containList.begin(); it != m_containList.end(); ++it ) | ||
| { | ||
| if( (*it)->isKindOf( KINDOF_HERO ) ) | ||
| { | ||
| m_heroUnitsContained++; | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| // sanity | ||
| DEBUG_ASSERTCRASH( m_containListSize == m_containList.size(), | ||
| ("OpenContain::loadPostProcess - contain list count mismatch") ); | ||
|
|
||
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_heroUnitsContainedCould add the same assert to stealth units above.