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

Commit 3888232

Browse files
committed
Little fix to finally properly make attachable scripts only run when they're supposed to. Was trying to avoid adding another member variable to MO but there seems to be no other way, oh well.
1 parent bbf0795 commit 3888232

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

Entities/Attachable.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ void Attachable::Attach(MOSRotating *pParent)
274274
// Reset the attachables timers so things that have been sitting in inventory don't make backed up emissions
275275
ResetAllTimers();
276276

277-
if (m_pParent != NULL && m_pParent->GetID() != 255) {
277+
if (m_pParent != NULL && GetRootParent()->HasEverBeenAddedToMovableMan()) {
278278
RunScriptedFunctionInAppropriateScripts("OnAttach", false, false, {m_pParent});
279279
}
280280
}
@@ -306,7 +306,7 @@ void Attachable::Detach()
306306

307307
m_RestTimer.Reset();
308308

309-
if (temporaryParent != NULL && temporaryParent->GetID() != 255) {
309+
if (temporaryParent != NULL && temporaryParent->GetRootParent()->HasEverBeenAddedToMovableMan()) {
310310
RunScriptedFunctionInAppropriateScripts("OnDetach", false, false, {temporaryParent});
311311
}
312312
}
@@ -554,7 +554,7 @@ void Attachable::Update()
554554
MOSRotating::Update();
555555

556556
// If we're attached to something, MoveableMan doesn't own us, and therefore isn't calling our ScriptUpdate (and our parent isn't calling it either), so we should here
557-
if (m_pParent != NULL && m_pParent->GetID() != 255) { UpdateScripts(); }
557+
if (m_pParent != NULL && GetRootParent()->HasEverBeenAddedToMovableMan()) { UpdateScripts(); }
558558
}
559559

560560

Entities/MovableObject.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void MovableObject::Clear()
6666
m_DidWrap = false;
6767
m_MOID = g_NoMOID;
6868
m_RootMOID = g_NoMOID;
69+
m_HasEverBeenAddedToMovableMan = false;
6970
m_MOIDFootprint = 0;
7071
m_AlreadyHitBy.clear();
7172
m_VelOscillations = 0;

Entities/MovableObject.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,12 @@ ENTITYALLOCATION(MovableObject)
515515

516516
int GetMOIDFootprint() const { return m_MOIDFootprint; }
517517

518+
/// <summary>
519+
/// Returns whether or not this object has ever been added to MovableMan. Does not account for removal from MovableMan.
520+
/// </summary>
521+
/// <returns></returns>
522+
bool HasEverBeenAddedToMovableMan() const { return m_HasEverBeenAddedToMovableMan; }
523+
518524

519525
//////////////////////////////////////////////////////////////////////////////////////////
520526
// Virtual method: GetSharpness
@@ -833,6 +839,11 @@ ENTITYALLOCATION(MovableObject)
833839

834840
virtual void SetID(const MOID newID) { m_MOID = newID; }
835841

842+
/// <summary>
843+
/// Sets this object as having been added to MovableMan. Should only really be done in MovableMan::AddObject.
844+
/// </summary>
845+
virtual void SetAsAddedToMovableMan() { m_HasEverBeenAddedToMovableMan = true; }
846+
836847

837848
//////////////////////////////////////////////////////////////////////////////////////////
838849
// Virtual method: SetSharpness
@@ -1917,6 +1928,8 @@ ENTITYALLOCATION(MovableObject)
19171928
// How many total (subsequent) MOID's this MO and all its children are taking up this frame.
19181929
// ie if this MO has no children, this will likely be 1.
19191930
int m_MOIDFootprint;
1931+
// 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.
1932+
bool m_HasEverBeenAddedToMovableMan;
19201933
// A set of ID:s of MO:s that already have collided with this MO during this frame.
19211934
std::set<MOID> m_AlreadyHitBy;
19221935
// A counter to count the oscillations in translational velocity, in order to detect settling.

Managers/MovableMan.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,8 @@ bool MovableMan::AddMO(MovableObject *pMOToAdd)
797797
if (!pMOToAdd)
798798
return false;
799799

800+
pMOToAdd->SetAsAddedToMovableMan();
801+
800802
// Find out what kind it is and apply accordingly
801803
if (Actor *pActor = dynamic_cast<Actor *>(pMOToAdd))
802804
{
@@ -840,6 +842,7 @@ void MovableMan::AddActor(Actor *pActorToAdd)
840842
// pActorToAdd->SetPrevPos(pActorToAdd->GetPos());
841843
// pActorToAdd->Update();
842844
// pActorToAdd->PostTravel();
845+
pActorToAdd->SetAsAddedToMovableMan();
843846

844847
// Filter out stupid fast objects
845848
if (pActorToAdd->IsTooFast())
@@ -876,6 +879,7 @@ void MovableMan::AddItem(MovableObject *pItemToAdd)
876879
// pItemToAdd->SetPrevPos(pItemToAdd->GetPos());
877880
// pItemToAdd->Update();
878881
// pItemToAdd->PostTravel();
882+
pItemToAdd->SetAsAddedToMovableMan();
879883

880884
// Filter out stupid fast objects
881885
if (pItemToAdd->IsTooFast())
@@ -913,6 +917,7 @@ void MovableMan::AddParticle(MovableObject *pMOToAdd)
913917
// pMOToAdd->Update();
914918
// pMOToAdd->Travel();
915919
// pMOToAdd->PostTravel();
920+
pMOToAdd->SetAsAddedToMovableMan();
916921

917922
// Filter out stupid fast objects
918923
if (pMOToAdd->IsTooFast())

0 commit comments

Comments
 (0)