From cedc2482e319c5e62443f6843915303c44e2a5bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Mei=C3=9Fner?= Date: Thu, 23 Jan 2014 16:27:11 +0100 Subject: [PATCH] Fixes for plAvatar --- .../PubUtilLib/plAvatar/plAGModifier.cpp | 2 +- .../PubUtilLib/plAvatar/plAnimStage.cpp | 2 +- .../PubUtilLib/plAvatar/plAvBrainClimb.cpp | 29 ++++++++++--------- .../PubUtilLib/plAvatar/plAvBrainCoop.cpp | 2 +- .../PubUtilLib/plAvatar/plAvBrainCoop.h | 2 +- .../PubUtilLib/plAvatar/plAvBrainGeneric.cpp | 2 +- .../PubUtilLib/plAvatar/plAvBrainGeneric.h | 2 +- .../PubUtilLib/plAvatar/plAvBrainSwim.cpp | 5 ++-- .../PubUtilLib/plAvatar/plAvatarClothing.cpp | 13 +++++---- .../PubUtilLib/plAvatar/plAvatarTasks.cpp | 3 -- .../plAvatar/plClothingSDLModifier.cpp | 3 +- .../PubUtilLib/plAvatar/plCoopCoordinator.cpp | 8 ++--- .../PubUtilLib/plAvatar/plMatrixChannel.cpp | 19 +++++------- .../PubUtilLib/plAvatar/plPointChannel.cpp | 15 ++++------ .../PubUtilLib/plAvatar/plQuatChannel.cpp | 16 ++++------ .../PubUtilLib/plAvatar/plSittingModifier.cpp | 15 +++++----- 16 files changed, 64 insertions(+), 74 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAGModifier.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAGModifier.cpp index 3cbe480e..51450f6e 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAGModifier.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAGModifier.cpp @@ -171,7 +171,7 @@ void plAGModifier::SetApplicator(plAGApplicator *newApp) plAGChannel *newChannel = newApp->GetChannel(); - hsAssert(newChannel = nil, "Trying to merge in new applicator which already has channel. Incomplete."); + hsAssert(!newChannel, "Trying to merge in new applicator which already has channel. Incomplete."); // *** right now I just want to support the case of putting in a new applicator - not merging animations diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAnimStage.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAnimStage.cpp index 90a15a94..90f5ca13 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAnimStage.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAnimStage.cpp @@ -309,7 +309,7 @@ bool plAnimStage::ISendNotify(uint32_t notifyMask, uint32_t notifyType, plArmatu int stageNum = genBrain ? genBrain->GetStageNum(this) : -1; msg->AddMultiStageEvent(stageNum, notifyType, armature->GetTarget(0)->GetKey()); - if (! genBrain->RelayNotifyMsg(msg) ) + if (!genBrain || !genBrain->RelayNotifyMsg(msg)) { msg->UnRef(); // couldn't send; destroy... } diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainClimb.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainClimb.cpp index 9ef89a2c..48c3415a 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainClimb.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainClimb.cpp @@ -177,20 +177,21 @@ plAvBrainClimb::~plAvBrainClimb() if(fExitStage) fExitStage->Detach(fAvMod); } - if(fUp) delete fUp; - if(fDown) delete fDown; - if(fLeft) delete fLeft; - if(fRight) delete fRight; - if(fMountUp) delete fMountUp; - if(fMountDown) delete fMountDown; - if(fMountLeft) delete fMountLeft; - if(fMountRight) delete fMountRight; - if(fDismountUp) delete fDismountUp; - if(fDismountLeft) delete fDismountLeft; - if(fDismountRight) delete fDismountRight; - if(fIdle) delete fIdle; -// if(fRelease) delete fRelease; -// if(fFallOff) delete fFallOff; + delete fUp; + delete fDown; + delete fLeft; + delete fRight; + delete fMountUp; + delete fMountDown; + delete fMountLeft; + delete fMountRight; + delete fDismountUp; + delete fDismountDown; + delete fDismountLeft; + delete fDismountRight; + delete fIdle; + delete fRelease; + delete fFallOff; } // ACTIVATE diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.cpp index 04070174..19b1b8c8 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.cpp @@ -251,7 +251,7 @@ plKey plAvBrainCoop::GetRecipient() return fRecipients[0]; } -void plAvBrainCoop::SetRecipient(plKey &recipient) +void plAvBrainCoop::SetRecipient(const plKey &recipient) { fRecipients.push_back(recipient); } diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.h b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.h index eb7a392c..0c943f04 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.h +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.h @@ -79,7 +79,7 @@ public: uint16_t GetInitiatorSerial(); virtual plKey GetRecipient(); - virtual void SetRecipient(plKey &recipient); + virtual void SetRecipient(const plKey &recipient); private: uint32_t fInitiatorID; diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainGeneric.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainGeneric.cpp index 63e1068d..883c241b 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainGeneric.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainGeneric.cpp @@ -214,7 +214,7 @@ void plAvBrainGeneric::Activate(plArmatureModBase *avMod) fAvMod->SetReverseFBOnIdle(true); } -bool plAvBrainGeneric::IsRunningTask() +bool plAvBrainGeneric::IsRunningTask() const { if ( fStages->size() > 0 ) return true; diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainGeneric.h b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainGeneric.h index c5636f58..29da02f0 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainGeneric.h +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainGeneric.h @@ -169,7 +169,7 @@ public: /** We're leaving the age. Clean up. */ virtual bool LeaveAge(); - virtual bool IsRunningTask(); + virtual bool IsRunningTask() const; /** Compare the names of the anims in our stages. Return true on a match (order matters). */ diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainSwim.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainSwim.cpp index 65d70666..18c8bbe6 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainSwim.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainSwim.cpp @@ -232,9 +232,10 @@ public: const float plAvBrainSwim::kMinSwimDepth = 4.0f; plAvBrainSwim::plAvBrainSwim() : - fSwimStrategy(nil), + fSwimStrategy(nullptr), fMode(kWalking), - fSurfaceDistance(0.f) + fSurfaceDistance(0.f), + fCurrentRegion(nullptr) { fSurfaceProbeMsg = new plLOSRequestMsg(); fSurfaceProbeMsg->SetReportType(plLOSRequestMsg::kReportHitOrMiss); diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp index 8bd97bdd..f55ab3e8 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp @@ -701,10 +701,9 @@ hsColorRGBA plClothingOutfit::GetItemTint(plClothingItem *item, uint8_t layer /* bool plClothingOutfit::IMorphItem(plClothingItem *item, uint8_t layer, uint8_t delta, float weight) { uint32_t index = fItems.Find(item); - if (index != fItems.kMissingIndex) + if (fAvatar && index != fItems.kMissingIndex) { - int i; - for (i = 0; i < fAvatar->GetNumLOD(); i++) + for (uint8_t i = 0; i < fAvatar->GetNumLOD(); i++) { if (item->fMeshes[i]->fMorphSet == nil) continue; @@ -1420,14 +1419,16 @@ bool plClothingOutfit::DirtySynchState(const plString& SDLStateName, uint32_t sy // we'll be good about this, but I wanted to get it working first. void plClothingOutfit::IInstanceSharedMeshes(plClothingItem *item) { - if (fAvatar) - fAvatar->ValidateMesh(); + if (!fAvatar) + return; + + fAvatar->ValidateMesh(); bool partialSort = (item->fCustomText.Find("NeedsSort") >= 0); for (int i = 0; i < plClothingItem::kMaxNumLODLevels; i++) { const plSceneObject *so = fAvatar->GetClothingSO(i); - if (so != nil && item->fMeshes[i] != nil) + if (so && item->fMeshes[i]) { plInstanceDrawInterface *idi = const_cast(plInstanceDrawInterface::ConvertNoRef(so->GetDrawInterface())); if (idi) diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarTasks.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarTasks.cpp index bca53acb..a05276fb 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarTasks.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarTasks.cpp @@ -660,9 +660,6 @@ bool plAvOneShotTask::Process(plArmatureMod *avatar, plArmatureBrain *brain, dou if(--fWaitFrames == 0) { - - plSceneObject *handle = avatar->GetTarget(0); - avatar->DetachAnimation(fAnimInstance); avatar->GetRootAnimator()->Enable(false); plAvBrainHuman *humanBrain = plAvBrainHuman::ConvertNoRef(brain); diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plClothingSDLModifier.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plClothingSDLModifier.cpp index 49bea913..b5b7bd85 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plClothingSDLModifier.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plClothingSDLModifier.cpp @@ -302,7 +302,8 @@ void plClothingSDLModifier::HandleSingleSDR(const plStateDataRecord *sdr, plClot { uint8_t blend; faceBlends->Get(&blend, i); - clothing->fSkinBlends[i] = (float)blend / 255; + if (clothing) + clothing->fSkinBlends[i] = (float)blend / 255; } } } diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plCoopCoordinator.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plCoopCoordinator.cpp index 1eb04215..c1c8b402 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plCoopCoordinator.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plCoopCoordinator.cpp @@ -327,11 +327,9 @@ void plCoopCoordinator::IStartGuest() const plSceneObject *targetBone = hostAv->FindBone(fSynchBone); if(targetBone) { - plAvSeekMsg *seekMsg = new plAvSeekMsg( nil, nil,targetBone->GetKey(), 0, true, kAlignHandle, "", false, plAvSeekMsg::kSeekFlagNoWarpOnTimeout, GetKey()); - plAvTaskSeek *seekT = new plAvTaskSeek(seekMsg); - plAvTaskMsg *seekM = new plAvTaskMsg(GetKey(), fGuestKey, seekT); - seekM->SetBCastFlag(plMessage::kPropagateToModifiers); - seekM->Send(); + plAvSeekMsg *seekMsg = new plAvSeekMsg(GetKey(), fGuestKey, targetBone->GetKey(), 0, true, kAlignHandle, "", false, plAvSeekMsg::kSeekFlagNoWarpOnTimeout, GetKey()); + seekMsg->SetBCastFlag(plMessage::kPropagateToModifiers); + seekMsg->Send(); } } } diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plMatrixChannel.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plMatrixChannel.cpp index 65d9ce67..f3be5ea0 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plMatrixChannel.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plMatrixChannel.cpp @@ -317,9 +317,12 @@ void plMatrixTimeScale::Dump(int indent, bool optimized, double time) // ctor ---------------------- // ----- plMatrixBlend::plMatrixBlend() -: fChannelA(nil), - fChannelB(nil), - fChannelBias(nil) +: fChannelA(nullptr), + fOptimizedA(nullptr), + fChannelB(nullptr), + fOptimizedB(nullptr), + fChannelBias(nullptr), + fPriority(0) { } @@ -793,11 +796,8 @@ void plMatrixDelayedCorrectionApplicator::SetCorrection(hsMatrix44 &cor) bool plMatrixDelayedCorrectionApplicator::CanBlend(plAGApplicator *app) { plMatrixChannelApplicator *matChannelApp = plMatrixChannelApplicator::ConvertNoRef(app); - - if( plMatrixChannelApplicator::ConvertNoRef(app) ) - { + if (matChannelApp) return true; - } return false; } @@ -875,11 +875,8 @@ void plMatrixDifferenceApp::Reset(double time) bool plMatrixDifferenceApp::CanBlend(plAGApplicator *app) { plMatrixChannelApplicator *matChannelApp = plMatrixChannelApplicator::ConvertNoRef(app); - - if( plMatrixChannelApplicator::ConvertNoRef(app) ) - { + if (matChannelApp) return true; - } return false; } diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plPointChannel.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plPointChannel.cpp index a845e288..06102bdc 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plPointChannel.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plPointChannel.cpp @@ -214,8 +214,9 @@ plAGChannel * plPointTimeScale::Detach(plAGChannel * channel) // ctor -------------------- // ----- plPointBlend::plPointBlend() -: fPointA(nil), - fPointB(nil) +: fPointA(nullptr), + fPointB(nullptr), + fChannelBias(nullptr) { } @@ -274,14 +275,10 @@ const hsPoint3 &plPointBlend::Value(double time) } } } else { - if (fPointA) - { + if (fPointA) { fResult = fPointA->Value(time); - } else { - if (fPointB) - { - fResult = fPointA->Value(time); - } + } else if (fPointB) { + fResult = fPointB->Value(time); } } return fResult; diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plQuatChannel.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plQuatChannel.cpp index 27ad62b5..a68c9a04 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plQuatChannel.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plQuatChannel.cpp @@ -82,24 +82,20 @@ void plQuatChannel::Value(hsQuat &quat, double time) // CANCOMBINE bool plQuatChannel::CanCombine(plAGChannel *channelA) { - return false; if(plPointChannel::ConvertNoRef(channelA)) - { return true; - } else { + else return false; - } } // MAKECOMBINE plAGChannel * plQuatChannel::MakeCombine(plAGChannel *channelA) { - if(plPointChannel::ConvertNoRef(channelA)) - { - return new plQuatPointCombine(this, (plPointChannel *)channelA); - } else { - return nil; - } + plPointChannel* channel = plPointChannel::ConvertNoRef(channelA); + if(channel) + return new plQuatPointCombine(this, channel); + else + return nullptr; } // MAKEBLEND diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plSittingModifier.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plSittingModifier.cpp index c644f815..afbc1f6d 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plSittingModifier.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plSittingModifier.cpp @@ -302,20 +302,19 @@ plAvBrainGeneric *plSittingModifier::IBuildSitBrain(plKey avModKey, plKey seekKe { plArmatureMod *avatar = plArmatureMod::ConvertNoRef(avModKey->ObjectIsLoaded()); plSceneObject *seekObj = plSceneObject::ConvertNoRef(seekKey->ObjectIsLoaded()); - hsMatrix44 animEndToStart; - hsMatrix44 sitGoal = seekObj->GetLocalToWorld(); - hsMatrix44 candidateGoal; float closestDist = 0.0f; uint8_t closestApproach = 0; - hsPoint3 curPosition = avatar->GetTarget(0)->GetLocalToWorld().GetTranslate(); - const char* sitAnimName = nil; + const char* sitAnimName = nullptr; const char* standAnimName = "StandUpFront"; // always prefer to stand facing front bool frontClear = fMiscFlags & kApproachFront; - plAvBrainGeneric *brain = nil; + plAvBrainGeneric *brain = nullptr; - if(avatar) + if(avatar && seekObj) { + hsMatrix44 sitGoal = seekObj->GetLocalToWorld(); + hsPoint3 curPosition = avatar->GetTarget(0)->GetLocalToWorld().GetTranslate(); + if(fMiscFlags & kApproachLeft && IIsClosestAnim("SitLeft", sitGoal, closestDist, curPosition, avatar)) { closestApproach = kApproachLeft; @@ -323,6 +322,7 @@ plAvBrainGeneric *plSittingModifier::IBuildSitBrain(plKey avModKey, plKey seekKe if(!frontClear) standAnimName = "StandUpLeft"; } + if(fMiscFlags & kApproachRight && IIsClosestAnim("SitRight", sitGoal, closestDist, curPosition, avatar)) { closestApproach = kApproachRight; @@ -330,6 +330,7 @@ plAvBrainGeneric *plSittingModifier::IBuildSitBrain(plKey avModKey, plKey seekKe if(!frontClear) standAnimName = "StandUpRight"; } + if(frontClear && IIsClosestAnim("SitFront", sitGoal, closestDist, curPosition, avatar)) { sitAnimName = "SitFront";