Browse Source

Merge pull request #160 from Hoikas/camera

Camera Fixes
Branan Purvine-Riley 13 years ago
parent
commit
740412cfb3
  1. 100
      Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.cpp
  2. 38
      Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.h
  3. 25
      Sources/Plasma/PubUtilLib/plPhysical/plCollisionDetector.cpp
  4. 8
      Sources/Plasma/PubUtilLib/plPhysical/plCollisionDetector.h

100
Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.cpp

@ -225,21 +225,21 @@ plVirtualCam1::~plVirtualCam1()
} }
// for saving camera stack // for saving camera stack
plCameraModifier1* plVirtualCam1::GetCameraNumber(int camNumber) plCameraModifier1* plVirtualCam1::GetCameraNumber(size_t camNumber)
{ {
return (fCameraStack[camNumber]); return (fCameraStack[camNumber]);
} }
// for rebuilding camera stack // for rebuilding camera stack
void plVirtualCam1::RebuildStack(const plKey& key) void plVirtualCam1::RebuildStack(const plKey& key)
{ {
if (fCameraStack.Count() == 1) if (fCameraStack.size() == 1)
{ {
plUoid U(kDefaultCameraMod1_KEY); plUoid U(kDefaultCameraMod1_KEY);
plKey pKey = hsgResMgr::ResMgr()->FindKey(U); plKey pKey = hsgResMgr::ResMgr()->FindKey(U);
if (pKey) if (pKey)
{ {
if (fCameraStack[0]->GetKey() == pKey) if (fCameraStack[0]->GetKey() == pKey)
fCameraStack.SetCountAndZero(0); fCameraStack.clear();
} }
} }
plSceneObject* pObj = plSceneObject::ConvertNoRef(key->GetObjectPtr()); plSceneObject* pObj = plSceneObject::ConvertNoRef(key->GetObjectPtr());
@ -398,14 +398,13 @@ void plVirtualCam1::Reset(hsBool bRender)
fPythonOverride = nil; fPythonOverride = nil;
if (fFirstPersonOverride) if (fFirstPersonOverride)
fFirstPersonOverride = nil; fFirstPersonOverride = nil;
fCamerasLoaded.SetCountAndZero(0); fCamerasLoaded.clear();
fCameraStack.SetCountAndZero(0); fCameraStack.clear();
fCameraStack.Append(fDriveCamera); fCameraStack.push_back(fDriveCamera);
plUoid U(kDefaultCameraMod1_KEY); plUoid U(kDefaultCameraMod1_KEY);
plKey pKey = hsgResMgr::ResMgr()->FindKey(U); plKey pKey = hsgResMgr::ResMgr()->FindKey(U);
if (pKey) if (pKey)
PushCamera((plCameraModifier1*)pKey->GetObjectPtr()); PushCamera((plCameraModifier1*)pKey->GetObjectPtr());
//fCameraStack.Append((plCameraModifier1*)pKey->GetObjectPtr());
if (fThirdPersonCam) if (fThirdPersonCam)
PushCamera(fThirdPersonCam); PushCamera(fThirdPersonCam);
@ -429,7 +428,7 @@ void plVirtualCam1::Reset(hsBool bRender)
void plVirtualCam1::ClearStack() void plVirtualCam1::ClearStack()
{ {
fCameraStack.SetCountAndZero(0); fCameraStack.clear();
plUoid U(kDefaultCameraMod1_KEY); plUoid U(kDefaultCameraMod1_KEY);
plKey pKey = hsgResMgr::ResMgr()->FindKey(U); plKey pKey = hsgResMgr::ResMgr()->FindKey(U);
if (pKey) if (pKey)
@ -451,10 +450,9 @@ plCameraModifier1* plVirtualCam1::GetCurrentCamera()
return(fFirstPersonOverride); return(fFirstPersonOverride);
if (fTransPos == POS_TRANS_FOLLOW) if (fTransPos == POS_TRANS_FOLLOW)
return(fTransitionCamera); return(fTransitionCamera);
if (fCameraStack.size())
if (fCameraStack.Count()) return fCameraStack.back();
return fCameraStack[fCameraStack.Count() - 1]; return nil;
else return nil;
} }
hsBool plVirtualCam1::Is1stPersonCamera() hsBool plVirtualCam1::Is1stPersonCamera()
@ -471,9 +469,10 @@ hsBool plVirtualCam1::Is1stPersonCamera()
plCameraModifier1* plVirtualCam1::GetCurrentStackCamera() plCameraModifier1* plVirtualCam1::GetCurrentStackCamera()
{ {
if (fCameraStack.Count()) if (fCameraStack.size())
return fCameraStack[fCameraStack.Count() - 1]; return fCameraStack.back();
else return nil; else
return nil;
} }
void plVirtualCam1::ICreatePlate() void plVirtualCam1::ICreatePlate()
@ -535,11 +534,12 @@ void plVirtualCam1::SetRender(hsBool render)
// hack, hack, hack // hack, hack, hack
hsBool plVirtualCam1::RestoreFromName(const plString& name) hsBool plVirtualCam1::RestoreFromName(const plString& name)
{ {
for(int i = 0; i < fCamerasLoaded.Count(); i++) for(plSOVec::iterator it = fCamerasLoaded.begin(); it != fCamerasLoaded.end(); ++it)
{ {
if (name.Compare(fCamerasLoaded[i]->GetKeyName()) == 0) plKey cam = (*it)->GetKey();
if (name.Compare(cam->GetName(), plString::kCaseInsensitive) == 0)
{ {
RebuildStack(fCamerasLoaded[i]->GetKey()); RebuildStack(cam);
return true; return true;
} }
} }
@ -775,33 +775,34 @@ void plVirtualCam1::IUpdate()
RunTransition(); RunTransition();
for (int i=0; i < fCameraStack.Count(); i++) for (plCameraVec::iterator i = fCameraStack.begin(); i != fCameraStack.end(); ++i)
{ {
hsBool update = true; hsBool update = true;
for (int j=i+1; j<fCameraStack.Count(); j++) for (plCameraVec::iterator j = (i+1); j != fCameraStack.end(); ++j)
{ {
if (fCameraStack[i] == fCameraStack[j]) if (*i != *j)
{ {
update = false; update = false;
break; break;
} }
} }
if ((fCameraStack[i] == GetCurrentStackCamera()) && fTransPos != POS_TRANS_OFF) plCameraModifier1* cam = *i;
if ((cam == GetCurrentStackCamera()) && fTransPos != POS_TRANS_OFF)
update = false; update = false;
if(update) if(update)
{ {
// eek... // eek...
if(alwaysCutForColin && fCameraStack[i]->GetBrain()) if(alwaysCutForColin && cam->GetBrain())
{ {
fCameraStack[i]->GetBrain()->SetFlags(plCameraBrain1::kCutPos); cam->GetBrain()->SetFlags(plCameraBrain1::kCutPos);
fCameraStack[i]->GetBrain()->SetFlags(plCameraBrain1::kCutPOA); cam->GetBrain()->SetFlags(plCameraBrain1::kCutPOA);
} }
if(fForceCutOnce) if(fForceCutOnce)
{ {
fCameraStack[i]->GetBrain()->SetFlags(plCameraBrain1::kCutPosOnce); cam->GetBrain()->SetFlags(plCameraBrain1::kCutPosOnce);
fCameraStack[i]->GetBrain()->SetFlags(plCameraBrain1::kCutPOAOnce); cam->GetBrain()->SetFlags(plCameraBrain1::kCutPOAOnce);
} }
fCameraStack[i]->Update(); cam->Update();
} }
} }
if(fForceCutOnce)fForceCutOnce=false; if(fForceCutOnce)fForceCutOnce=false;
@ -1397,12 +1398,9 @@ hsBool plVirtualCam1::MsgReceive(plMessage* msg)
// array. Since this message indicates it was destroyed anyway, this should be // array. Since this message indicates it was destroyed anyway, this should be
// ok. // ok.
plCameraModifier1* pMod = (plCameraModifier1*)(pRefMsg->GetRef()); plCameraModifier1* pMod = (plCameraModifier1*)(pRefMsg->GetRef());
// we go in reverse so that removes don't mess up our index plCameraVec::iterator it = std::find(fCameraStack.begin(), fCameraStack.end(), pMod);
for (int i = fCameraStack.Count() - 1; i >= 0; --i) if (it != fCameraStack.end())
{ fCameraStack.erase(it);
if (fCameraStack[i] == pMod)
fCameraStack.Remove(i);
}
} }
return true; return true;
} }
@ -1495,7 +1493,7 @@ void plVirtualCam1::CreateDefaultCamera(plSceneObject* subject)
void plVirtualCam1::AddCameraToStack(plCameraModifier1* pCam) void plVirtualCam1::AddCameraToStack(plCameraModifier1* pCam)
{ {
fCameraStack.Append(pCam); fCameraStack.push_back(pCam);
if (pCam->GetBrain()) if (pCam->GetBrain())
{ {
if (HasMovementFlag(B_CONTROL_CAMERA_WALK_PAN)) if (HasMovementFlag(B_CONTROL_CAMERA_WALK_PAN))
@ -1509,13 +1507,8 @@ void plVirtualCam1::AddCameraToStack(plCameraModifier1* pCam)
void plVirtualCam1::PushCamera(plCameraModifier1* pCam, hsBool bDefault) void plVirtualCam1::PushCamera(plCameraModifier1* pCam, hsBool bDefault)
{ {
// pushing the same camera, folks? // pushing the same camera, folks?
// -- disallowed 2/13/2012 --
if (pCam == GetCurrentStackCamera()) if (pCam == GetCurrentStackCamera())
{
AddCameraToStack(pCam);
return;
}
// make sure that we don't keep adding the default camera if we're already in it
if (bDefault && pCam == GetCurrentStackCamera())
return; return;
// look up whatever transition we might have specified // look up whatever transition we might have specified
@ -1670,9 +1663,9 @@ void plVirtualCam1::PushCamera(plCameraModifier1* pCam, hsBool bDefault)
#endif #endif
} }
// make this the default camera if that's what we want... // make this the default camera if that's what we want...
if (fCameraStack.Count() > 0 && bDefault) if (fCameraStack.size() > 0 && bDefault)
{ {
fCameraStack.SetCountAndZero(0); fCameraStack.clear();
AddCameraToStack(pCam); AddCameraToStack(pCam);
#ifdef STATUS_LOG #ifdef STATUS_LOG
camLog->AddLineF("Camera %s is now the DEFAULT camera for this age", pCam->GetKeyName().c_str()); camLog->AddLineF("Camera %s is now the DEFAULT camera for this age", pCam->GetKeyName().c_str());
@ -1684,15 +1677,15 @@ void plVirtualCam1::PushCamera(plCameraModifier1* pCam, hsBool bDefault)
void plVirtualCam1::PopCamera(plCameraModifier1* pCam) void plVirtualCam1::PopCamera(plCameraModifier1* pCam)
{ {
// sanity / new default camera check // sanity / new default camera check
if (fCameraStack.Count() <= 1) if (fCameraStack.size() <= 1)
return; return;
// is it the current camera AND the same camera we would otherwise switch to? // is it the current camera AND the same camera we would otherwise switch to?
if (pCam==GetCurrentStackCamera() && pCam == fCameraStack[fCameraStack.Count() - 2]) if (pCam==GetCurrentStackCamera() && pCam == fCameraStack[fCameraStack.size() - 2])
{ {
// pop but don't transition to a new camera // pop but don't transition to a new camera
// or do anything else: // or do anything else:
fCameraStack.Remove(fCameraStack.Count() - 1); fCameraStack.pop_back();
return; return;
} }
@ -1714,7 +1707,7 @@ void plVirtualCam1::PopCamera(plCameraModifier1* pCam)
!GetCurrentStackCamera()) !GetCurrentStackCamera())
{ {
// special camera mode (like drive) just pop it // special camera mode (like drive) just pop it
fCameraStack.Remove(fCameraStack.Count() - 1); fCameraStack.pop_back();
GetCurrentStackCamera()->Push(!HasFlags(kAvatarWalking)); GetCurrentStackCamera()->Push(!HasFlags(kAvatarWalking));
return; return;
} }
@ -1726,7 +1719,7 @@ void plVirtualCam1::PopCamera(plCameraModifier1* pCam)
#endif #endif
// pop and actually transition to a new camera // pop and actually transition to a new camera
fCameraStack.Remove(fCameraStack.Count() - 1); fCameraStack.pop_back();
if (GetCurrentStackCamera()) if (GetCurrentStackCamera())
{ {
@ -1809,14 +1802,9 @@ void plVirtualCam1::PopCamera(plCameraModifier1* pCam)
IHandleCameraStatusLog(pCam, kBackgroundPop); IHandleCameraStatusLog(pCam, kBackgroundPop);
#endif #endif
// just remove this from the stack // just remove this from the stack
for (int i = 0; i < fCameraStack.Count(); i++) plCameraVec::iterator it = std::find(fCameraStack.begin(), fCameraStack.end(), pCam);
{ if (it != fCameraStack.end())
if (fCameraStack[i] == pCam) fCameraStack.erase(it);
{
fCameraStack.Remove(i);
break;
}
}
} }
if (!InTransition()) if (!InTransition())
SetFOV(GetCurrentStackCamera()->GetFOVw(), GetCurrentStackCamera()->GetFOVh(), GetCurrentStackCamera()); SetFOV(GetCurrentStackCamera()->GetFOVw(), GetCurrentStackCamera()->GetFOVh(), GetCurrentStackCamera());

38
Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.h

@ -73,6 +73,8 @@ struct hsColorRGBA;
class plVirtualCam1 : public hsKeyedObject class plVirtualCam1 : public hsKeyedObject
{ {
typedef std::vector<plCameraModifier1*> plCameraVec;
typedef std::vector<plSceneObject*> plSOVec;
protected: protected:
@ -127,8 +129,8 @@ public:
static float GetFOVh() { return fFOVh; } static float GetFOVh() { return fFOVh; }
static float GetHither() { return fHither; } static float GetHither() { return fHither; }
static float GetYon() { return fYon; } static float GetYon() { return fYon; }
static void SetOffset(float x, float y, float z); static void SetOffset(float x, float y, float z);
static void SetAspectRatio(float aspect) { fAspectRatio = aspect; } static void SetAspectRatio(float aspect) { fAspectRatio = aspect; }
static float GetAspectRatio() { return fAspectRatio; } static float GetAspectRatio() { return fAspectRatio; }
hsBool InTransition() { return fTransPos != POS_TRANS_OFF; } hsBool InTransition() { return fTransPos != POS_TRANS_OFF; }
@ -148,8 +150,8 @@ public:
const hsMatrix44 GetCurrentMatrix() { return fMatrix; } const hsMatrix44 GetCurrentMatrix() { return fMatrix; }
static plVirtualCam1* Instance() { return fInstance; } static plVirtualCam1* Instance() { return fInstance; }
int GetNumCameras() { return fCameraStack.Count(); } size_t GetNumCameras() { return fCameraStack.size(); }
plCameraModifier1* GetCameraNumber(int camNumber); plCameraModifier1* GetCameraNumber(size_t camNumber);
void RebuildStack(const plKey& key); void RebuildStack(const plKey& key);
void SetFlags(int flag) { fFlags.SetBit(flag); } void SetFlags(int flag) { fFlags.SetBit(flag); }
@ -169,7 +171,7 @@ public:
static hsBool IsCurrentCamera(const plCameraModifier1* mod); static hsBool IsCurrentCamera(const plCameraModifier1* mod);
void ClearStack(); void ClearStack();
void AddCameraLoaded(plSceneObject* pCam) { fCamerasLoaded.Append(pCam); } void AddCameraLoaded(plSceneObject* pCam) { fCamerasLoaded.push_back(pCam); }
hsBool RestoreFromName(const plString& name); hsBool RestoreFromName(const plString& name);
void StartUnPan(); void StartUnPan();
// these are for console access // these are for console access
@ -209,25 +211,25 @@ private:
plDebugInputInterface* fCameraDriveInterface; plDebugInputInterface* fCameraDriveInterface;
plPlate* fEffectPlate; plPlate* fEffectPlate;
FILE* foutLog; FILE* foutLog;
hsTArray<plCameraModifier1*> fCameraStack; plCameraVec fCameraStack;
int fFreezeCounter; int fFreezeCounter;
int fFadeCounter; int fFadeCounter;
hsBitVector fFlags; hsBitVector fFlags;
hsTArray<plSceneObject*> fCamerasLoaded; plSOVec fCamerasLoaded;
hsBitVector fMoveFlags; hsBitVector fMoveFlags;
float fX; float fX;
float fY; float fY;
float fXPanLimit; float fXPanLimit;
float fZPanLimit; float fZPanLimit;
float fXPanLimitGoal; float fXPanLimitGoal;
float fZPanLimitGoal; float fZPanLimitGoal;
float fXUnPanRate; float fXUnPanRate;
float fZUnPanRate; float fZUnPanRate;
float fXPanInterpRate; float fXPanInterpRate;
float fZPanInterpRate; float fZPanInterpRate;
double fUnPanEndTime; double fUnPanEndTime;
double fInterpPanLimitTime; double fInterpPanLimitTime;
float fRetainedFY; float fRetainedFY;
// built-in cameras // built-in cameras
plCameraModifier1* fDriveCamera; // for driving around plCameraModifier1* fDriveCamera; // for driving around

25
Sources/Plasma/PubUtilLib/plPhysical/plCollisionDetector.cpp

@ -73,6 +73,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
plArmatureMod* plCollisionDetector::IGetAvatarModifier(plKey key) plArmatureMod* plCollisionDetector::IGetAvatarModifier(plKey key)
{ {
if (!key)
return nil;
plSceneObject* avObj = plSceneObject::ConvertNoRef(key->ObjectIsLoaded()); plSceneObject* avObj = plSceneObject::ConvertNoRef(key->ObjectIsLoaded());
if (avObj) if (avObj)
{ {
@ -242,8 +245,6 @@ plCameraRegionDetector::~plCameraRegionDetector()
void plCameraRegionDetector::ITrigger(plKey hitter, bool entering, bool immediate) void plCameraRegionDetector::ITrigger(plKey hitter, bool entering, bool immediate)
{ {
if (fSavingSendMsg)
DetectorLogRed("%s: Stale messages on ITrigger. This should never happen!", GetKeyName().c_str());
if (fIsInside && entering) if (fIsInside && entering)
DetectorLogRed("%s: Duplicate enter! Did we miss an exit?", GetKeyName().c_str()); DetectorLogRed("%s: Duplicate enter! Did we miss an exit?", GetKeyName().c_str());
else if (!fIsInside && !entering) else if (!fIsInside && !entering)
@ -276,14 +277,12 @@ void plCameraRegionDetector::ISendSavedTriggerMsgs()
if (fSavedMsgEnterFlag) if (fSavedMsgEnterFlag)
{ {
fMessages[i]->SetCmd(plCameraMsg::kEntering); fMessages[i]->SetCmd(plCameraMsg::kEntering);
fMessages[i]->ClearCmd(plCameraMsg::kPop);
DetectorLog("Entering cameraRegion: %s - Evals=%d -msg %d of %d\n", GetKeyName().c_str(),fNumEvals,i+1,fMessages.size()); DetectorLog("Entering cameraRegion: %s - Evals=%d -msg %d of %d\n", GetKeyName().c_str(),fNumEvals,i+1,fMessages.size());
fIsInside = true; fIsInside = true;
} }
else else
{ {
fMessages[i]->ClearCmd(plCameraMsg::kEntering); fMessages[i]->ClearCmd(plCameraMsg::kEntering);
fMessages[i]->SetCmd(plCameraMsg::kPop); // for spawnpoints with a camera stack
DetectorLog("Exiting cameraRegion: %s - Evals=%d -msg %d of %d\n", GetKeyName().c_str(),fNumEvals,i+1,fMessages.size()); DetectorLog("Exiting cameraRegion: %s - Evals=%d -msg %d of %d\n", GetKeyName().c_str(),fNumEvals,i+1,fMessages.size());
fIsInside = false; fIsInside = false;
} }
@ -386,11 +385,18 @@ hsBool plObjectInVolumeDetector::MsgReceive(plMessage* msg)
plCollideMsg* pCollMsg = plCollideMsg::ConvertNoRef(msg); plCollideMsg* pCollMsg = plCollideMsg::ConvertNoRef(msg);
if (pCollMsg) if (pCollMsg)
{ {
fLastHitter = pCollMsg->fOtherKey;
// If the avatar is disabled (flying around), don't trigger // If the avatar is disabled (flying around), don't trigger
if (IIsDisabledAvatar(pCollMsg->fOtherKey)) if (IIsDisabledAvatar(fLastHitter))
return false; return false;
ITrigger(pCollMsg->fOtherKey, (pCollMsg->fEntering != 0)); ITrigger(fLastHitter, (pCollMsg->fEntering != 0));
plgDispatch::Dispatch()->RegisterForExactType(plEvalMsg::Index(), GetKey());
// If we never eval before the exit...
if (fWaitingForEval)
plgDispatch::Dispatch()->UnRegisterForExactType(plEvalMsg::Index(), GetKey());
else
plgDispatch::Dispatch()->RegisterForExactType(plEvalMsg::Index(), GetKey());
fWaitingForEval = !fWaitingForEval;
return true; return true;
} }
@ -398,8 +404,13 @@ hsBool plObjectInVolumeDetector::MsgReceive(plMessage* msg)
if (pEvalMsg) if (pEvalMsg)
{ {
fNumEvals++; fNumEvals++;
// Don't dispatch if we're not in the age
if (plArmatureMod* av = IGetAvatarModifier(fLastHitter))
if (av->IsMidLink())
return true;
ISendSavedTriggerMsgs(); ISendSavedTriggerMsgs();
plgDispatch::Dispatch()->UnRegisterForExactType(plEvalMsg::Index(), GetKey()); plgDispatch::Dispatch()->UnRegisterForExactType(plEvalMsg::Index(), GetKey());
fWaitingForEval = false;
} }
plPlayerPageMsg* pageMsg = plPlayerPageMsg::ConvertNoRef(msg); plPlayerPageMsg* pageMsg = plPlayerPageMsg::ConvertNoRef(msg);

8
Sources/Plasma/PubUtilLib/plPhysical/plCollisionDetector.h

@ -99,15 +99,19 @@ protected:
uint32_t fNumEvals; uint32_t fNumEvals;
uint32_t fLastEnterEval; uint32_t fLastEnterEval;
uint32_t fLastExitEval; uint32_t fLastExitEval;
bool fWaitingForEval;
plKey fLastHitter;
public: public:
plObjectInVolumeDetector() plObjectInVolumeDetector()
: plCollisionDetector(), fSavedActivatorMsg(nil), fNumEvals(0), fLastEnterEval(0), fLastExitEval(0) : plCollisionDetector(), fSavedActivatorMsg(nil), fNumEvals(0), fLastEnterEval(0),
fWaitingForEval(false), fLastHitter(nil)
{ } { }
plObjectInVolumeDetector(int8_t type) plObjectInVolumeDetector(int8_t type)
: plCollisionDetector(type), fSavedActivatorMsg(nil), fNumEvals(0), fLastEnterEval(0), fLastExitEval(0) : plCollisionDetector(type), fSavedActivatorMsg(nil), fNumEvals(0), fLastEnterEval(0),
fWaitingForEval(false), fLastHitter(nil)
{ } { }
virtual ~plObjectInVolumeDetector() { } virtual ~plObjectInVolumeDetector() { }

Loading…
Cancel
Save