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

Commit ad8c6b8

Browse files
committed
Added exists in movableman MO flag and used it to re-efficientize movableman::validmo
1 parent d7771fb commit ad8c6b8

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

Entities/MovableObject.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ void MovableObject::Clear()
7171
m_MOID = g_NoMOID;
7272
m_RootMOID = g_NoMOID;
7373
m_HasEverBeenAddedToMovableMan = false;
74+
m_ExistsInMovableMan = false;
7475
m_MOIDFootprint = 0;
7576
m_AlreadyHitBy.clear();
7677
m_VelOscillations = 0;

Entities/MovableObject.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,17 @@ enum MOType
441441
int GetMOIDFootprint() const { return m_MOIDFootprint; }
442442

443443
/// <summary>
444-
/// Returns whether or not this object has ever been added to MovableMan. Does not account for removal from MovableMan.
444+
/// Returns whether or not this MovableObject has ever been added to MovableMan. Does not account for removal from MovableMan.
445445
/// </summary>
446-
/// <returns></returns>
446+
/// <returns>Whether or not this MovableObject has ever been added to MovableMan.</returns>
447447
bool HasEverBeenAddedToMovableMan() const { return m_HasEverBeenAddedToMovableMan; }
448448

449+
/// <summary>
450+
/// Returns whether or not this MovableObject exists in MovableMan, accounting for removal from MovableMan.
451+
/// </summary>
452+
/// <returns>Whether or not this MovableObject currently exists in MovableMan.</returns>
453+
bool ExistsInMovableMan() const { return m_ExistsInMovableMan; }
454+
449455

450456
//////////////////////////////////////////////////////////////////////////////////////////
451457
// Virtual method: GetSharpness
@@ -774,10 +780,11 @@ enum MOType
774780
/// </summary>
775781
virtual void SetAsNoID() { m_MOID = g_NoMOID; }
776782

777-
/// <summary>
778-
/// Sets this object as having been added to MovableMan. Should only really be done in MovableMan::AddObject.
783+
/// <summary>
784+
/// Sets this MovableObject as having been added to MovableMan. Should only really be done in MovableMan::Add/Remove Actor/Item/Particle.
779785
/// </summary>
780-
void SetAsAddedToMovableMan() { m_HasEverBeenAddedToMovableMan = true; }
786+
/// <param name="addedToMovableMan">Whether or not this MovableObject has been added to MovableMan.</param>
787+
void SetAsAddedToMovableMan(bool addedToMovableMan = true) { if (addedToMovableMan) { m_HasEverBeenAddedToMovableMan = true; } m_ExistsInMovableMan = addedToMovableMan; }
781788

782789

783790
//////////////////////////////////////////////////////////////////////////////////////////
@@ -1927,8 +1934,9 @@ enum MOType
19271934
// How many total (subsequent) MOID's this MO and all its children are taking up this frame.
19281935
// ie if this MO has no children, this will likely be 1.
19291936
int m_MOIDFootprint;
1930-
// Whether or not this object has been added to MovableMan. Does not take into account the object being removed from MovableMan, though in practice it usually will.
1937+
// Whether or not this object has ever been added to MovableMan. Does not take into account the object being removed from MovableMan, though in practice it usually will, cause objects are usually only removed when they're deleted.
19311938
bool m_HasEverBeenAddedToMovableMan;
1939+
bool m_ExistsInMovableMan; //<! Whether or not this object currently exists in MovableMan. Takes into account the object being removed from MovableMan.
19321940
// A set of ID:s of MO:s that already have collided with this MO during this frame.
19331941
std::set<MOID> m_AlreadyHitBy;
19341942
int m_VelOscillations; //!< A counter for oscillations in translational velocity, in order to detect settling.

Managers/MovableMan.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ bool MovableMan::RemoveActor(MovableObject *pActorToRem)
927927
}
928928
}
929929
RemoveActorFromTeamRoster(dynamic_cast<Actor *>(pActorToRem));
930+
pActorToRem->SetAsAddedToMovableMan(false);
930931
}
931932
return removed;
932933
}
@@ -967,6 +968,7 @@ bool MovableMan::RemoveItem(MovableObject *pItemToRem)
967968
}
968969
}
969970
}
971+
pItemToRem->SetAsAddedToMovableMan(false);
970972
}
971973
return removed;
972974
}
@@ -1082,6 +1084,7 @@ bool MovableMan::RemoveParticle(MovableObject *pMOToRem)
10821084
}
10831085
}
10841086
}
1087+
pMOToRem->SetAsAddedToMovableMan(false);
10851088
}
10861089
return removed;
10871090
}
@@ -1111,11 +1114,7 @@ bool MovableMan::ValidateMOIDs() {
11111114
// MO that's currently active in the simulation, and kept by this MovableMan.
11121115

11131116
bool MovableMan::ValidMO(const MovableObject *pMOToCheck) {
1114-
if (pMOToCheck && pMOToCheck->GetID() != g_NoMOID && pMOToCheck->GetParent() == nullptr) {
1115-
return true;
1116-
} else {
1117-
return IsActor(pMOToCheck) || IsDevice(pMOToCheck) || IsParticle(pMOToCheck);
1118-
}
1117+
return pMOToCheck && pMOToCheck->ExistsInMovableMan();
11191118
}
11201119

11211120

0 commit comments

Comments
 (0)