//-----------------------------------------------------------------------------
// Purpose: Something happened in the world that requires us to refresh our
//			dependencies. Try to reacquire face IDs in our deleted faces list.
// Input  : pWorld - 
//-----------------------------------------------------------------------------
void CMapSideList::UpdateDependencies(CMapWorld *pWorld, CMapClass *pObject)
{
	CMapClass::UpdateDependencies(pWorld, pObject);

	//
	// See if it is a solid that holds faces in our lost faces list.
	//
	CMapSolid *pSolid = dynamic_cast <CMapSolid *>(pObject);
	if ((pSolid != NULL) && (m_LostFaceIDs.Count() > 0))
	{
		//
		// Walk the list backwards so we can remove as we go.
		//
		for (int i = m_LostFaceIDs.Count() - 1; i >= 0; i--)
		{
			int nFaceID = m_LostFaceIDs.Element(i);

			CMapFace *pFace = pSolid->FindFaceID(nFaceID);
			if (pFace != NULL)
			{
				if (m_Faces.Find(pFace) == -1)
				{
					m_Faces.AddToTail(pFace);
				}

				//
				// We've reacquired the face, so it's no longer lost.
				//
				m_LostFaceIDs.FastRemove(i);
			}
		}

		UpdateParentKey();
	}
}
//-----------------------------------------------------------------------------
// Purpose: Overridden to transform our endpoints.
//-----------------------------------------------------------------------------
void CMapSweptPlayerHull::DoTransform(const VMatrix &matrix)
{
	BaseClass::DoTransform(matrix);

	m_Point[0]->Transform(matrix);
	m_Point[1]->Transform(matrix);

	UpdateParentKey();
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pObject - 
//			eNotifyType - 
//-----------------------------------------------------------------------------
void CMapSideList::OnNotifyDependent(CMapClass *pObject, Notify_Dependent_t eNotifyType)
{
	if (eNotifyType == Notify_Removed)
	{
		//
		// Check for a solid that we refer to via face ID going away.
		//
		CMapSolid *pSolid = dynamic_cast<CMapSolid *>(pObject);
		if ((pSolid != NULL) && (m_Faces.Count() > 0))
		{
			//
			// Remove faces from our list that are in this solid.
			// Do it backwards so we can remove them as we go. Also, add
			// the face IDs to our list of lost IDs so that we can reacquire
			// the face in our list if the solid comes back later.
			//
			for (int i = m_Faces.Count() - 1; i >= 0; i--)
			{
				CMapFace *pFace = m_Faces.Element(i);
				if (pFace != NULL)
				{
					CMapSolid *pParent = (CMapSolid *)pFace->GetParent();
					if (pParent == pSolid)
					{
						m_LostFaceIDs.AddToTail(pFace->GetFaceID());
						m_Faces.FastRemove(i);
					}
				}
			}
		
			//
			// Submit the updated face list to our parent entity.
			//
			UpdateParentKey();
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Sets the keyvalue in our parent after the map is loaded.
// Input  : pWorld - 
//-----------------------------------------------------------------------------
void CMapPointHandle::PostloadWorld(CMapWorld *pWorld)
{
	BaseClass::PostloadWorld(pWorld);
	UpdateParentKey();
}
//-----------------------------------------------------------------------------
// Purpose: Called when we change because of an Undo or Redo.
//-----------------------------------------------------------------------------
void CMapPointHandle::OnUndoRedo(void)
{
	// We've changed but our parent entity may not have. Update our parent.
	UpdateParentKey();
}
//-----------------------------------------------------------------------------
// Purpose: Sets the keyvalue in our parent when we are	added to the world.
// Input  : pWorld - 
//-----------------------------------------------------------------------------
void CMapPointHandle::OnAddToWorld(CMapWorld *pWorld)
{
	BaseClass::OnAddToWorld(pWorld);
	UpdateParentKey();
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pTransBox - 
//-----------------------------------------------------------------------------
void CMapPointHandle::DoTransform(const VMatrix &matrix)
{
	BaseClass::DoTransform(matrix);
	UpdateParentKey();
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : vecOrigin - 
//-----------------------------------------------------------------------------
void CMapPointHandle::UpdateOrigin(const Vector &vecOrigin)
{
	m_Origin = vecOrigin;
	CalcBounds();
	UpdateParentKey();
}
//-----------------------------------------------------------------------------
// Purpose: Sets the keyvalue in our parent after the map is loaded.
// Input  : pWorld - 
//-----------------------------------------------------------------------------
void CMapSweptPlayerHull::PostloadWorld(CMapWorld *pWorld)
{
	BaseClass::PostloadWorld(pWorld);
	UpdateParentKey();
}
//-----------------------------------------------------------------------------
// Purpose: Sets the keyvalue in our parent when we are	added to the world.
// Input  : pWorld - 
//-----------------------------------------------------------------------------
void CMapSweptPlayerHull::OnAddToWorld(CMapWorld *pWorld)
{
	BaseClass::OnAddToWorld(pWorld);
	UpdateParentKey();
}
//-----------------------------------------------------------------------------
// Purpose: Called by the axis tool to update the position of the endpoint.
//-----------------------------------------------------------------------------
void CMapSweptPlayerHull::UpdateEndPoint(Vector &vecPos, int nPointIndex)
{
	m_Point[nPointIndex]->SetOrigin( vecPos );
	PostUpdate(Notify_Changed);
	UpdateParentKey();
}