diff --git a/Code/Editor/Include/IDisplayViewport.h b/Code/Editor/Include/IDisplayViewport.h index 813c54355b..c7dff33e50 100644 --- a/Code/Editor/Include/IDisplayViewport.h +++ b/Code/Editor/Include/IDisplayViewport.h @@ -35,8 +35,6 @@ struct IDisplayViewport */ virtual float GetDistanceToLine(const Vec3& lineP1, const Vec3& lineP2, const QPoint& point) const = 0; - virtual CBaseObjectsCache* GetVisibleObjectsCache() = 0; - enum EAxis { AXIS_NONE, diff --git a/Code/Editor/Objects/ObjectManager.cpp b/Code/Editor/Objects/ObjectManager.cpp index 06aa8866b3..f67cf24553 100644 --- a/Code/Editor/Objects/ObjectManager.cpp +++ b/Code/Editor/Objects/ObjectManager.cpp @@ -33,10 +33,6 @@ AZ_CVAR_EXTERNED(bool, ed_visibility_logTiming); -AZ_CVAR( - bool, ed_visibility_use, true, nullptr, AZ::ConsoleFunctorFlags::Null, - "Enable/disable using the new IVisibilitySystem for Entity visibility determination"); - /*! * Class Description used for object templates. * This description filled from Xml template files. @@ -76,17 +72,6 @@ public: int GameCreationOrder() override { return superType->GameCreationOrder(); }; }; -void CBaseObjectsCache::AddObject(CBaseObject* object) -{ - m_objects.push_back(object); - if (object->GetType() == OBJTYPE_AZENTITY) - { - auto componentEntityObject = static_cast(object); - m_entityIds.push_back(componentEntityObject->GetAssociatedEntityId()); - } -} - - ////////////////////////////////////////////////////////////////////////// // CObjectManager implementation. ////////////////////////////////////////////////////////////////////////// @@ -1267,25 +1252,8 @@ void CObjectManager::Display(DisplayContext& dc) UpdateVisibilityList(); } - bool viewIsDirty = dc.settings->IsDisplayHelpers(); // displaying helpers require computing all the bound boxes and things anyway. - - if (!viewIsDirty) + if (dc.settings->IsDisplayHelpers()) { - if (CBaseObjectsCache* cache = dc.view->GetVisibleObjectsCache()) - { - // if the current rendering viewport has an out-of-date cache serial number, it needs to be refreshed too. - // views set their cache empty when they indicate they need to force a refresh. - if ((cache->GetObjectCount() == 0) || (cache->GetSerialNumber() != m_visibilitySerialNumber)) - { - viewIsDirty = true; - } - } - } - - if (viewIsDirty) - { - FindDisplayableObjects(dc, true); // this also actually draws the helpers. - // Also broadcast for anyone else that needs to draw global debug to do so now AzFramework::DebugDisplayEventBus::Broadcast(&AzFramework::DebugDisplayEvents::DrawGlobalDebugInfo); } @@ -1296,94 +1264,14 @@ void CObjectManager::Display(DisplayContext& dc) } } -void CObjectManager::ForceUpdateVisibleObjectCache(DisplayContext& dc) +void CObjectManager::ForceUpdateVisibleObjectCache([[maybe_unused]] DisplayContext& dc) { - FindDisplayableObjects(dc, false); + AZ_Assert(false, "CObjectManager::ForceUpdateVisibleObjectCache is legacy/deprecated and should not be used."); } -void CObjectManager::FindDisplayableObjects(DisplayContext& dc, [[maybe_unused]] bool bDisplay) +void CObjectManager::FindDisplayableObjects([[maybe_unused]] DisplayContext& dc, [[maybe_unused]] bool bDisplay) { - // if the new IVisibilitySystem is being used, do not run this logic - if (ed_visibility_use) - { - return; - } - - AZ_PROFILE_FUNCTION(Editor); - - auto start = std::chrono::steady_clock::now(); - CBaseObjectsCache* pDispayedViewObjects = dc.view->GetVisibleObjectsCache(); - if (!pDispayedViewObjects) - { - return; - } - - pDispayedViewObjects->SetSerialNumber(m_visibilitySerialNumber); // update viewport to be latest serial number - - AABB bbox; - bbox.min.zero(); - bbox.max.zero(); - - pDispayedViewObjects->ClearObjects(); - pDispayedViewObjects->Reserve(static_cast(m_visibleObjects.size())); - - if (dc.flags & DISPLAY_2D) - { - int numVis = static_cast(m_visibleObjects.size()); - for (int i = 0; i < numVis; i++) - { - CBaseObject* obj = m_visibleObjects[i]; - - obj->GetBoundBox(bbox); - if (dc.box.IsIntersectBox(bbox)) - { - pDispayedViewObjects->AddObject(obj); - } - } - } - else - { - CSelectionGroup* pSelection = GetSelection(); - if (pSelection && pSelection->GetCount() > 1) - { - AABB mergedAABB; - mergedAABB.Reset(); - for (int i = 0, iCount(pSelection->GetCount()); i < iCount; ++i) - { - CBaseObject* pObj(pSelection->GetObject(i)); - if (pObj == nullptr) - { - continue; - } - AABB aabb; - pObj->GetBoundBox(aabb); - mergedAABB.Add(aabb); - } - - pSelection->GetObject(0)->CBaseObject::DrawDimensions(dc, &mergedAABB); - } - - int numVis = static_cast(m_visibleObjects.size()); - for (int i = 0; i < numVis; i++) - { - CBaseObject* obj = m_visibleObjects[i]; - - if (obj) - { - if ((dc.flags & DISPLAY_SELECTION_HELPERS) || obj->IsSelected()) - { - pDispayedViewObjects->AddObject(obj); - } - } - } - } - - if (ed_visibility_logTiming && !ed_visibility_use) - { - auto stop = std::chrono::steady_clock::now(); - std::chrono::duration diff = stop - start; - AZ_Printf("Visibility", "FindDisplayableObjects (old) - Duration: %f", diff); - } + AZ_Assert(false, "CObjectManager::FindDisplayableObjects is legacy/deprecated and should not be used."); } void CObjectManager::BeginEditParams(CBaseObject* obj, int flags) @@ -1630,214 +1518,24 @@ bool CObjectManager::HitTestObject(CBaseObject* obj, HitContext& hc) return (bSelectionHelperHit || obj->HitTest(hc)); } - ////////////////////////////////////////////////////////////////////////// -bool CObjectManager::HitTest(HitContext& hitInfo) +bool CObjectManager::HitTest([[maybe_unused]] HitContext& hitInfo) { - AZ_PROFILE_FUNCTION(Editor); - - hitInfo.object = nullptr; - hitInfo.dist = FLT_MAX; - hitInfo.axis = 0; - hitInfo.manipulatorMode = 0; - - HitContext hcOrg = hitInfo; - if (hcOrg.view) - { - hcOrg.view->GetPerpendicularAxis(nullptr, &hcOrg.b2DViewport); - } - hcOrg.rayDir = hcOrg.rayDir.GetNormalized(); - - HitContext hc = hcOrg; - - float mindist = FLT_MAX; - - if (!hitInfo.bIgnoreAxis && !hc.bUseSelectionHelpers) - { - // Test gizmos. - if (m_gizmoManager->HitTest(hc)) - { - if (hc.axis != 0) - { - hitInfo.object = hc.object; - hitInfo.gizmo = hc.gizmo; - hitInfo.axis = hc.axis; - hitInfo.manipulatorMode = hc.manipulatorMode; - hitInfo.dist = hc.dist; - return true; - } - } - } - - if (hitInfo.bOnlyGizmo) - { - return false; - } - - // Only HitTest objects, that where previously Displayed. - CBaseObjectsCache* pDispayedViewObjects = hitInfo.view->GetVisibleObjectsCache(); - - const bool iconsPrioritized = true; // Force icons to always be prioritized over other things you hit. Can change to be a configurable option in the future. - - CBaseObject* selected = nullptr; - const char* name = nullptr; - bool iconHit = false; - int numVis = pDispayedViewObjects->GetObjectCount(); - for (int i = 0; i < numVis; i++) - { - CBaseObject* obj = pDispayedViewObjects->GetObject(i); - - if (obj == hitInfo.pExcludedObject) - { - continue; - } - - if (HitTestObject(obj, hc)) - { - if (m_selectCallback && !m_selectCallback->CanSelectObject(obj)) - { - continue; - } - - // Check if this object is nearest. - if (hc.axis != 0) - { - hitInfo.object = obj; - hitInfo.axis = hc.axis; - hitInfo.dist = hc.dist; - return true; - } - - // When prioritizing icons, we don't allow non-icon hits to beat icon hits - if (iconsPrioritized && iconHit && !hc.iconHit) - { - continue; - } - - if (hc.dist < mindist || (!iconHit && hc.iconHit)) - { - if (hc.iconHit) - { - iconHit = true; - } - - mindist = hc.dist; - name = hc.name; - selected = obj; - } - - // Clear the object pointer if an object was hit, not just if the collision - // was closer than any previous. Not all paths from HitTestObject set the object pointer and so you could get - // an object from a previous (rejected) result but with collision information about a closer hit. - hc.object = nullptr; - hc.iconHit = false; - - // If use deep selection - if (hitInfo.pDeepSelection) - { - hitInfo.pDeepSelection->AddObject(hc.dist, obj); - } - } - } - - if (selected) - { - hitInfo.object = selected; - hitInfo.dist = mindist; - hitInfo.name = name; - hitInfo.iconHit = iconHit; - return true; - } + AZ_Assert(false, "CObjectManager::HitTest is legacy/deprecated and should not be used."); return false; } -void CObjectManager::FindObjectsInRect(CViewport* view, const QRect& rect, std::vector& guids) + +void CObjectManager::FindObjectsInRect( + [[maybe_unused]] CViewport* view, [[maybe_unused]] const QRect& rect, [[maybe_unused]] std::vector& guids) { - AZ_PROFILE_FUNCTION(Editor); - - if (rect.width() < 1 || rect.height() < 1) - { - return; - } - - HitContext hc; - hc.view = view; - hc.b2DViewport = view->GetType() != ET_ViewportCamera; - hc.rect = rect; - hc.bUseSelectionHelpers = view->GetAdvancedSelectModeFlag(); - - guids.clear(); - - CBaseObjectsCache* pDispayedViewObjects = view->GetVisibleObjectsCache(); - - int numVis = pDispayedViewObjects->GetObjectCount(); - for (int i = 0; i < numVis; ++i) - { - CBaseObject* pObj = pDispayedViewObjects->GetObject(i); - - HitTestObjectAgainstRect(pObj, view, hc, guids); - } + AZ_Assert(false, "CObjectManager::FindObjectsInRect is legacy/deprecated and should not be used."); } ////////////////////////////////////////////////////////////////////////// -void CObjectManager::SelectObjectsInRect(CViewport* view, const QRect& rect, bool bSelect) +void CObjectManager::SelectObjectsInRect( + [[maybe_unused]] CViewport* view, [[maybe_unused]] const QRect& rect, [[maybe_unused]] bool bSelect) { - AZ_PROFILE_FUNCTION(Editor); - - // Ignore too small rectangles. - if (rect.width() < 1 || rect.height() < 1) - { - return; - } - - CUndo undo("Select Object(s)"); - - HitContext hc; - hc.view = view; - hc.b2DViewport = view->GetType() != ET_ViewportCamera; - hc.rect = rect; - hc.bUseSelectionHelpers = view->GetAdvancedSelectModeFlag(); - - bool isUndoRecording = GetIEditor()->IsUndoRecording(); - if (isUndoRecording) - { - m_processingBulkSelect = true; - } - - CBaseObjectsCache* displayedViewObjects = view->GetVisibleObjectsCache(); - int numVis = displayedViewObjects->GetObjectCount(); - - // Tracking the previous selection allows proper undo/redo functionality of additional - // selections (CTRL + drag select) - AZStd::unordered_set previousSelection; - - for (int i = 0; i < numVis; ++i) - { - CBaseObject* object = displayedViewObjects->GetObject(i); - - if (object->IsSelected()) - { - previousSelection.insert(object); - } - else - { - // This will update m_currSelection - SelectObjectInRect(object, view, hc, bSelect); - - // Legacy undo/redo does not go through the Ebus system and must be done individually - if (isUndoRecording && object->GetType() != OBJTYPE_AZENTITY) - { - GetIEditor()->RecordUndo(new CUndoBaseObjectSelect(object, true)); - } - } - } - - if (isUndoRecording && m_currSelection) - { - // Component Entities can handle undo/redo in bulk due to Ebuses - GetIEditor()->RecordUndo(new CUndoBaseObjectBulkSelect(previousSelection, *m_currSelection)); - } - - m_processingBulkSelect = false; + AZ_Assert(false, "CObjectManager::SelectObjectsInRect is legacy/deprecated and should not be used."); } ////////////////////////////////////////////////////////////////////////// @@ -3011,6 +2709,4 @@ namespace AzToolsFramework } } -} - - +} // namespace AzToolsFramework diff --git a/Code/Editor/Objects/ObjectManager.h b/Code/Editor/Objects/ObjectManager.h index 4ffa5e9a07..0ad5d8323e 100644 --- a/Code/Editor/Objects/ObjectManager.h +++ b/Code/Editor/Objects/ObjectManager.h @@ -52,40 +52,6 @@ public: } }; -////////////////////////////////////////////////////////////////////////// -// Array of editor objects. -////////////////////////////////////////////////////////////////////////// -class CBaseObjectsCache -{ -public: - int GetObjectCount() const { return static_cast(m_objects.size()); } - CBaseObject* GetObject(int nIndex) const { return m_objects[nIndex]; } - void AddObject(CBaseObject* object); - - void ClearObjects() - { - m_objects.clear(); - m_entityIds.clear(); - } - - void Reserve(int nCount) - { - m_objects.reserve(nCount); - m_entityIds.reserve(nCount); - } - - const AZStd::vector& GetEntityIdCache() const { return m_entityIds; } - - /// Checksum is used as a dirty flag. - unsigned int GetSerialNumber() { return m_serialNumber; } - void SetSerialNumber(unsigned int serialNumber) { m_serialNumber = serialNumber; } -private: - //! List of objects that was displayed at last frame. - std::vector<_smart_ptr > m_objects; - AZStd::vector m_entityIds; - unsigned int m_serialNumber = 0; -}; - /*! * CObjectManager is a singleton object that * manages global set of objects in level. diff --git a/Code/Editor/Viewport.cpp b/Code/Editor/Viewport.cpp index 2d41538d92..5b4f4a4df3 100644 --- a/Code/Editor/Viewport.cpp +++ b/Code/Editor/Viewport.cpp @@ -173,8 +173,6 @@ QtViewport::QtViewport(QWidget* parent) m_bAdvancedSelectMode = false; - m_pVisibleObjectsCache = new CBaseObjectsCache; - m_constructionPlane.SetPlane(Vec3_OneZ, Vec3_Zero); m_constructionPlaneAxisX = Vec3_Zero; m_constructionPlaneAxisY = Vec3_Zero; @@ -204,8 +202,6 @@ QtViewport::QtViewport(QWidget* parent) ////////////////////////////////////////////////////////////////////////// QtViewport::~QtViewport() { - delete m_pVisibleObjectsCache; - GetIEditor()->GetViewManager()->UnregisterViewport(this); } @@ -376,11 +372,6 @@ void QtViewport::OnDeactivate() void QtViewport::ResetContent() { m_pMouseOverObject = nullptr; - - // Need to clear visual object cache. - // Right after loading new level, some code(e.g. OnMouseMove) access invalid - // previous level object before cache updated. - GetVisibleObjectsCache()->ClearObjects(); } ////////////////////////////////////////////////////////////////////////// @@ -398,11 +389,8 @@ void QtViewport::Update() m_viewportUi.Update(); m_bAdvancedSelectMode = false; - bool bSpaceClick = false; - { - bSpaceClick = CheckVirtualKey(Qt::Key_Space) & !CheckVirtualKey(Qt::Key_Shift) /*& !CheckVirtualKey(Qt::Key_Control)*/; - } - if (bSpaceClick && hasFocus()) + + if (CheckVirtualKey(Qt::Key_Space) && !CheckVirtualKey(Qt::Key_Shift) && hasFocus()) { m_bAdvancedSelectMode = true; } diff --git a/Code/Editor/Viewport.h b/Code/Editor/Viewport.h index 60c1306420..fdb8332479 100644 --- a/Code/Editor/Viewport.h +++ b/Code/Editor/Viewport.h @@ -491,10 +491,6 @@ public: void ResetCursor() override; void SetSupplementaryCursorStr(const QString& str) override; - ////////////////////////////////////////////////////////////////////////// - // Return visble objects cache. - CBaseObjectsCache* GetVisibleObjectsCache() override { return m_pVisibleObjectsCache; }; - void RegisterRenderListener(IRenderListener* piListener) override; bool UnregisterRenderListener(IRenderListener* piListener) override; bool IsRenderListenerRegistered(IRenderListener* piListener) override; @@ -612,8 +608,6 @@ protected: int m_nLastUpdateFrame; int m_nLastMouseMoveFrame; - CBaseObjectsCache* m_pVisibleObjectsCache; - QRect m_rcClient; AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING