Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Improved cache coherency with large number of wounds (and slight bugf…
Browse files Browse the repository at this point in the history
…ix where script state wasn't properly destroyed)
  • Loading branch information
Causeless committed Nov 27, 2023
1 parent 78723ee commit 26ce658
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions Entities/MOSRotating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@ int MOSRotating::Save(Writer &writer) const
writer.NewProperty("OrientToVel");
writer << m_OrientToVel;
for (std::list<AEmitter *>::const_iterator itr = m_Wounds.begin(); itr != m_Wounds.end(); ++itr)
for (auto itr = m_Wounds.begin(); itr != m_Wounds.end(); ++itr)
{
writer.NewProperty("AddEmitter");
writer << (*itr);
}
for (std::list<Attachable *>::const_iterator aItr = m_Attachables.begin(); aItr != m_Attachables.end(); ++aItr)
for (auto aItr = m_Attachables.begin(); aItr != m_Attachables.end(); ++aItr)
{
writer.NewProperty("AddAttachable");
writer << (*aItr);
Expand Down Expand Up @@ -555,10 +555,12 @@ float MOSRotating::RemoveWounds(int numberOfWoundsToRemove, bool includePositive
if (m_Wounds.empty()) {
return 0.0F;
}
float woundDamage = m_Wounds.front()->GetBurstDamage();
AEmitter *wound = m_Wounds.front();
float woundDamage = wound->GetBurstDamage();
m_AttachableAndWoundMass -= wound->GetMass();
m_Wounds.pop_front();
std::iter_swap(m_Wounds.begin(), m_Wounds.end() - 1);
m_Wounds.pop_back();
wound->DestroyScriptState();
delete wound;
return woundDamage;
};
Expand Down Expand Up @@ -1573,12 +1575,12 @@ void MOSRotating::Update() {

for (auto woundItr = m_Wounds.begin(); woundItr != m_Wounds.end(); ) {
AEmitter* wound = *woundItr;
++woundItr;
RTEAssert(wound && wound->IsAttachedTo(this), "Broken wound AEmitter in Update");
wound->Update();

if (wound->IsSetToDelete() || (wound->GetLifetime() > 0 && wound->GetAge() > wound->GetLifetime())) {
m_Wounds.remove(wound);
std::iter_swap(woundItr, m_Wounds.end() - 1);
m_Wounds.pop_back();
m_AttachableAndWoundMass -= wound->GetMass();
delete wound;
} else {
Expand All @@ -1593,6 +1595,7 @@ void MOSRotating::Update() {
}

wound->ClearImpulseForces();
++woundItr;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Entities/MOSRotating.h
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ ClassInfoGetters;
/// Gets a const reference to the list of wounds on this MOSRotating.
/// </summary>
/// <returns>A const reference to the list of wounds on this MOSRotating.</returns>
const std::list<AEmitter *> & GetWoundList() const { return m_Wounds; }
const std::vector<AEmitter *> & GetWoundList() const { return m_Wounds; }

/// <summary>
/// Gets the number of wounds attached to this MOSRotating.
Expand Down Expand Up @@ -903,7 +903,7 @@ ClassInfoGetters;
// The vector that the recoil offsets the sprite when m_Recoiled is true.
Vector m_RecoilOffset;
// The list of wound AEmitters currently attached to this MOSRotating, and owned here as well.
std::list<AEmitter *> m_Wounds;
std::vector<AEmitter *> m_Wounds;
// The list of Attachables currently attached and Owned by this.
std::list<Attachable *> m_Attachables;
std::unordered_set<unsigned long> m_ReferenceHardcodedAttachableUniqueIDs; //!< An unordered set is filled with the Unique IDs of all of the reference object's hardcoded Attachables when using the copy Create.
Expand Down

0 comments on commit 26ce658

Please sign in to comment.