make Scene_BoundsSelected lazily evaluatable

This commit is contained in:
Garux 2018-08-19 16:40:48 +03:00
parent c5f2279f4a
commit afdf2a76e0
5 changed files with 35 additions and 16 deletions

View File

@ -56,6 +56,8 @@ template<typename Element> class BasicVector4;
typedef BasicVector4<float> Vector4; typedef BasicVector4<float> Vector4;
typedef Vector4 Quaternion; typedef Vector4 Quaternion;
class AABB;
typedef Callback1<const Selectable&> SelectionChangeCallback; typedef Callback1<const Selectable&> SelectionChangeCallback;
typedef SignalHandler1<const Selectable&> SelectionChangeHandler; typedef SignalHandler1<const Selectable&> SelectionChangeHandler;
@ -127,6 +129,8 @@ virtual void scaleSelected( const Vector3& scaling, bool snapOrigin = false ) =
virtual void pivotChanged() const = 0; virtual void pivotChanged() const = 0;
virtual void setCustomTransformOrigin( const Vector3& origin, const bool set[3] ) 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" #include "modulesystem.h"

View File

@ -42,7 +42,6 @@
#include "patch.h" #include "patch.h"
#include "patchmanip.h" #include "patchmanip.h"
#include "patchdialog.h" #include "patchdialog.h"
#include "selection.h"
#include "texwindow.h" #include "texwindow.h"
#include "gtkmisc.h" #include "gtkmisc.h"
#include "mainframe.h" #include "mainframe.h"
@ -535,16 +534,13 @@ void Select_SetFlags( const ContentsFlagsValue& flags ){
} }
void Select_GetBounds( Vector3& mins, Vector3& maxs ){ void Select_GetBounds( Vector3& mins, Vector3& maxs ){
AABB bounds; const AABB bounds = GlobalSelectionSystem().getBoundsSelected();
Scene_BoundsSelected( GlobalSceneGraph(), bounds );
maxs = vector3_added( bounds.origin, bounds.extents ); maxs = vector3_added( bounds.origin, bounds.extents );
mins = vector3_subtracted( bounds.origin, bounds.extents ); mins = vector3_subtracted( bounds.origin, bounds.extents );
} }
void Select_GetMid( Vector3& mid ){ void Select_GetMid( Vector3& mid ){
AABB bounds; mid = vector3_snapped( GlobalSelectionSystem().getBoundsSelected().origin );
Scene_BoundsSelected( GlobalSceneGraph(), bounds );
mid = vector3_snapped( bounds.origin );
} }

View File

@ -4261,6 +4261,26 @@ void Scene_SelectAll_Component( bool select, SelectionSystem::EComponentMode com
GlobalSceneGraph().traverse( select_all_component( select, componentMode ) ); 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 // RadiantSelectionSystem
class RadiantSelectionSystem : class RadiantSelectionSystem :
@ -4274,6 +4294,7 @@ class RadiantSelectionSystem :
{ {
mutable Matrix4 m_pivot2world; mutable Matrix4 m_pivot2world;
mutable AABB m_bounds; mutable AABB m_bounds;
mutable LazyBounds m_lazy_bounds;
Matrix4 m_pivot2world_start; Matrix4 m_pivot2world_start;
Matrix4 m_manip2pivot_start; Matrix4 m_manip2pivot_start;
Translation m_translation; Translation m_translation;
@ -4359,6 +4380,7 @@ RadiantSelectionSystem() :
} }
void pivotChanged() const { void pivotChanged() const {
m_pivotChanged = true; m_pivotChanged = true;
m_lazy_bounds.setInvalid();
SceneChangeNotify(); SceneChangeNotify();
} }
typedef ConstMemberCaller<RadiantSelectionSystem, &RadiantSelectionSystem::pivotChanged> PivotChangedCaller; typedef ConstMemberCaller<RadiantSelectionSystem, &RadiantSelectionSystem::pivotChanged> PivotChangedCaller;
@ -4367,6 +4389,10 @@ void pivotChangedSelection( const Selectable& selectable ){
} }
typedef MemberCaller1<RadiantSelectionSystem, const Selectable&, &RadiantSelectionSystem::pivotChangedSelection> PivotChangedSelectionCaller; typedef MemberCaller1<RadiantSelectionSystem, const Selectable&, &RadiantSelectionSystem::pivotChangedSelection> PivotChangedSelectionCaller;
const AABB& getBoundsSelected() const {
return m_lazy_bounds.getBounds();
}
void SetMode( EMode mode ){ void SetMode( EMode mode ){
if ( m_mode != mode ) { if ( m_mode != mode ) {
m_mode = mode; m_mode = mode;
@ -5417,11 +5443,11 @@ AABB RadiantSelectionSystem::getSelectionAABB() const {
if ( Mode() == eComponent || g_bTmpComponentMode ) { if ( Mode() == eComponent || g_bTmpComponentMode ) {
Scene_BoundsSelectedComponent( GlobalSceneGraph(), bounds ); Scene_BoundsSelectedComponent( GlobalSceneGraph(), bounds );
if( !aabb_valid( bounds ) ) /* selecting PlaneSelectables sets g_bTmpComponentMode, but only brushes return correct componentEditable->getSelectedComponentsBounds() */ if( !aabb_valid( bounds ) ) /* selecting PlaneSelectables sets g_bTmpComponentMode, but only brushes return correct componentEditable->getSelectedComponentsBounds() */
Scene_BoundsSelected( GlobalSceneGraph(), bounds ); bounds = getBoundsSelected();
} }
else else
{ {
Scene_BoundsSelected( GlobalSceneGraph(), bounds ); bounds = getBoundsSelected();
} }
} }
return bounds; return bounds;

View File

@ -40,11 +40,4 @@ virtual void incMouseMove( const WindowVector& delta ) = 0;
SelectionSystemWindowObserver* NewWindowObserver(); SelectionSystemWindowObserver* NewWindowObserver();
class AABB;
namespace scene
{
class Graph;
}
void Scene_BoundsSelected( scene::Graph& graph, AABB& bounds );
#endif #endif

View File

@ -2545,7 +2545,7 @@ void XY_Centralize(){
void GetSelectionBbox( AABB& bounds ){ void GetSelectionBbox( AABB& bounds ){
if ( GlobalSelectionSystem().countSelected() != 0 ) { if ( GlobalSelectionSystem().countSelected() != 0 ) {
Scene_BoundsSelected( GlobalSceneGraph(), bounds ); bounds = GlobalSelectionSystem().getBoundsSelected();
} }
else else
{ {