diff --git a/include/iselection.h b/include/iselection.h index 9a9a5880..a5e78b99 100644 --- a/include/iselection.h +++ b/include/iselection.h @@ -56,6 +56,8 @@ template class BasicVector4; typedef BasicVector4 Vector4; typedef Vector4 Quaternion; +class AABB; + typedef Callback1 SelectionChangeCallback; typedef SignalHandler1 SelectionChangeHandler; @@ -127,6 +129,8 @@ virtual void scaleSelected( const Vector3& scaling, bool snapOrigin = false ) = virtual void pivotChanged() const = 0; virtual void setCustomTransformOrigin( const Vector3& origin, const bool set[3] ) const = 0; + +virtual const AABB& getBoundsSelected() const = 0; /* object bounds */ }; #include "modulesystem.h" diff --git a/radiant/select.cpp b/radiant/select.cpp index 81190297..457b61d0 100644 --- a/radiant/select.cpp +++ b/radiant/select.cpp @@ -42,7 +42,6 @@ #include "patch.h" #include "patchmanip.h" #include "patchdialog.h" -#include "selection.h" #include "texwindow.h" #include "gtkmisc.h" #include "mainframe.h" @@ -535,16 +534,13 @@ void Select_SetFlags( const ContentsFlagsValue& flags ){ } void Select_GetBounds( Vector3& mins, Vector3& maxs ){ - AABB bounds; - Scene_BoundsSelected( GlobalSceneGraph(), bounds ); + const AABB bounds = GlobalSelectionSystem().getBoundsSelected(); maxs = vector3_added( bounds.origin, bounds.extents ); mins = vector3_subtracted( bounds.origin, bounds.extents ); } void Select_GetMid( Vector3& mid ){ - AABB bounds; - Scene_BoundsSelected( GlobalSceneGraph(), bounds ); - mid = vector3_snapped( bounds.origin ); + mid = vector3_snapped( GlobalSelectionSystem().getBoundsSelected().origin ); } diff --git a/radiant/selection.cpp b/radiant/selection.cpp index 91266254..92f3c216 100644 --- a/radiant/selection.cpp +++ b/radiant/selection.cpp @@ -4261,6 +4261,26 @@ void Scene_SelectAll_Component( bool select, SelectionSystem::EComponentMode com GlobalSceneGraph().traverse( select_all_component( select, componentMode ) ); } +void Scene_BoundsSelected( scene::Graph& graph, AABB& bounds ); +class LazyBounds +{ + AABB m_bounds; + bool m_valid; +public: + LazyBounds() : m_valid( false ){ + } + void setInvalid(){ + m_valid = false; + } + const AABB& getBounds(){ + if( !m_valid ){ + Scene_BoundsSelected( GlobalSceneGraph(), m_bounds ); + m_valid = true; + } + return m_bounds; + } +}; + // RadiantSelectionSystem class RadiantSelectionSystem : @@ -4274,6 +4294,7 @@ class RadiantSelectionSystem : { mutable Matrix4 m_pivot2world; mutable AABB m_bounds; +mutable LazyBounds m_lazy_bounds; Matrix4 m_pivot2world_start; Matrix4 m_manip2pivot_start; Translation m_translation; @@ -4359,6 +4380,7 @@ RadiantSelectionSystem() : } void pivotChanged() const { m_pivotChanged = true; + m_lazy_bounds.setInvalid(); SceneChangeNotify(); } typedef ConstMemberCaller PivotChangedCaller; @@ -4367,6 +4389,10 @@ void pivotChangedSelection( const Selectable& selectable ){ } typedef MemberCaller1 PivotChangedSelectionCaller; +const AABB& getBoundsSelected() const { + return m_lazy_bounds.getBounds(); +} + void SetMode( EMode mode ){ if ( m_mode != mode ) { m_mode = mode; @@ -5417,11 +5443,11 @@ AABB RadiantSelectionSystem::getSelectionAABB() const { if ( Mode() == eComponent || g_bTmpComponentMode ) { Scene_BoundsSelectedComponent( GlobalSceneGraph(), bounds ); if( !aabb_valid( bounds ) ) /* selecting PlaneSelectables sets g_bTmpComponentMode, but only brushes return correct componentEditable->getSelectedComponentsBounds() */ - Scene_BoundsSelected( GlobalSceneGraph(), bounds ); + bounds = getBoundsSelected(); } else { - Scene_BoundsSelected( GlobalSceneGraph(), bounds ); + bounds = getBoundsSelected(); } } return bounds; diff --git a/radiant/selection.h b/radiant/selection.h index 01c7d599..1e5294c9 100644 --- a/radiant/selection.h +++ b/radiant/selection.h @@ -40,11 +40,4 @@ virtual void incMouseMove( const WindowVector& delta ) = 0; SelectionSystemWindowObserver* NewWindowObserver(); -class AABB; -namespace scene -{ -class Graph; -} -void Scene_BoundsSelected( scene::Graph& graph, AABB& bounds ); - #endif diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 0ea69865..680e0773 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -2545,7 +2545,7 @@ void XY_Centralize(){ void GetSelectionBbox( AABB& bounds ){ if ( GlobalSelectionSystem().countSelected() != 0 ) { - Scene_BoundsSelected( GlobalSceneGraph(), bounds ); + bounds = GlobalSelectionSystem().getBoundsSelected(); } else {