From aa8c5aec5c7f578b977abb4322e2322df8edd662 Mon Sep 17 00:00:00 2001 From: Antoine Fontaine Date: Sun, 21 Mar 2021 03:51:11 +0100 Subject: [PATCH] various: reindent classes --- libs/eclasslib.h | 126 +- libs/entitylib.h | 124 +- libs/splines/math_angles.h | 60 +- libs/splines/math_quaternion.h | 52 +- libs/splines/math_vector.h | 66 +- libs/string/string.h | 326 +-- radiant/brush.h | 4001 ++++++++++++++++---------------- radiant/mru.cpp | 70 +- 8 files changed, 2410 insertions(+), 2415 deletions(-) diff --git a/libs/eclasslib.h b/libs/eclasslib.h index 2a92fcdb..a733676a 100644 --- a/libs/eclasslib.h +++ b/libs/eclasslib.h @@ -38,48 +38,48 @@ typedef Vector3 Colour3; class ListAttributeType { -using ListItem = std::pair; -using ListItems = std::vector; -ListItems m_items; + using ListItem = std::pair; + using ListItems = std::vector; + ListItems m_items; public: -typedef ListItems::const_iterator const_iterator; -const_iterator begin() const { - return m_items.begin(); -} -const_iterator end() const { - return m_items.end(); -} + typedef ListItems::const_iterator const_iterator; + const_iterator begin() const { + return m_items.begin(); + } + const_iterator end() const { + return m_items.end(); + } -const ListItem& operator[]( std::size_t i ) const { - return m_items[i]; -} -const_iterator findValue( const char* value ) const { - for ( ListItems::const_iterator i = m_items.begin(); i != m_items.end(); ++i ) - { - if ( string_equal( value, ( *i ).second.c_str() ) ) { - return i; + const ListItem& operator[]( std::size_t i ) const { + return m_items[i]; + } + const_iterator findValue( const char* value ) const { + for ( ListItems::const_iterator i = m_items.begin(); i != m_items.end(); ++i ) + { + if ( string_equal( value, ( *i ).second.c_str() ) ) { + return i; + } } + return m_items.end(); } - return m_items.end(); -} -void push_back( const char* name, const char* value ){ - m_items.push_back( ListItems::value_type( name, value ) ); -} + void push_back( const char* name, const char* value ){ + m_items.push_back( ListItems::value_type( name, value ) ); + } }; class EntityClassAttribute { -public: -CopiedString m_type; -CopiedString m_name; -CopiedString m_value; -CopiedString m_description; -EntityClassAttribute(){ -} -EntityClassAttribute( const char* type, const char* name, const char* value = "", const char* description = "" ) : m_type( type ), m_name( name ), m_value( value ), m_description( description ){ -} + public: + CopiedString m_type; + CopiedString m_name; + CopiedString m_value; + CopiedString m_description; + EntityClassAttribute(){ + } + EntityClassAttribute( const char* type, const char* name, const char* value = "", const char* description = "" ) : m_type( type ), m_name( name ), m_value( value ), m_description( description ){ + } }; typedef std::pair EntityClassAttributePair; @@ -103,44 +103,44 @@ inline const char* EntityClassAttributePair_getDescription( const EntityClassAtt class EntityClass { public: -CopiedString m_name; -StringList m_parent; -bool fixedsize; -bool unknown; // wasn't found in source -Vector3 mins; -Vector3 maxs; + CopiedString m_name; + StringList m_parent; + bool fixedsize; + bool unknown; // wasn't found in source + Vector3 mins; + Vector3 maxs; -Colour3 color; -Shader* m_state_fill; -Shader* m_state_wire; -Shader* m_state_blend; + Colour3 color; + Shader* m_state_fill; + Shader* m_state_wire; + Shader* m_state_blend; -CopiedString m_comments; -char flagnames[MAX_FLAGS][32]; + CopiedString m_comments; + char flagnames[MAX_FLAGS][32]; -CopiedString m_modelpath; -CopiedString m_skin; + CopiedString m_modelpath; + CopiedString m_skin; -void ( *free )( EntityClass* ); + void ( *free )( EntityClass* ); -EntityClassAttributes m_attributes; + EntityClassAttributes m_attributes; -bool inheritanceResolved; -bool sizeSpecified; -bool colorSpecified; + bool inheritanceResolved; + bool sizeSpecified; + bool colorSpecified; -const char* name() const { - return m_name.c_str(); -} -const char* comments() const { - return m_comments.c_str(); -} -const char* modelpath() const { - return m_modelpath.c_str(); -} -const char* skin() const { - return m_skin.c_str(); -} + const char* name() const { + return m_name.c_str(); + } + const char* comments() const { + return m_comments.c_str(); + } + const char* modelpath() const { + return m_modelpath.c_str(); + } + const char* skin() const { + return m_skin.c_str(); + } }; inline const char* EntityClass_valueForKey( const EntityClass& entityClass, const char* key ){ diff --git a/libs/entitylib.h b/libs/entitylib.h index 83f35f02..87ac4fe5 100644 --- a/libs/entitylib.h +++ b/libs/entitylib.h @@ -293,80 +293,80 @@ void render( RenderStateFlags state ) const { /// - Provides undo support through the global undo system. class KeyValue : public EntityKeyValue { -typedef UnsortedSet KeyObservers; - -std::size_t m_refcount; -KeyObservers m_observers; -CopiedString m_string; -const char* m_empty; -ObservedUndoableObject m_undo; -static EntityCreator::KeyValueChangedFunc m_entityKeyValueChanged; -public: + typedef UnsortedSet KeyObservers; -KeyValue( const char* string, const char* empty ) - : m_refcount( 0 ), m_string( string ), m_empty( empty ), m_undo( m_string, UndoImportCaller( *this ) ){ - notify(); -} -~KeyValue(){ - ASSERT_MESSAGE( m_observers.empty(), "KeyValue::~KeyValue: observers still attached" ); -} + std::size_t m_refcount; + KeyObservers m_observers; + CopiedString m_string; + const char* m_empty; + ObservedUndoableObject m_undo; + static EntityCreator::KeyValueChangedFunc m_entityKeyValueChanged; -static void setKeyValueChangedFunc( EntityCreator::KeyValueChangedFunc func ){ - m_entityKeyValueChanged = func; -} +public: + KeyValue( const char* string, const char* empty ) + : m_refcount( 0 ), m_string( string ), m_empty( empty ), m_undo( m_string, UndoImportCaller( *this ) ){ + notify(); + } + ~KeyValue(){ + ASSERT_MESSAGE( m_observers.empty(), "KeyValue::~KeyValue: observers still attached" ); + } -void IncRef(){ - ++m_refcount; -} -void DecRef(){ - if ( --m_refcount == 0 ) { - delete this; + static void setKeyValueChangedFunc( EntityCreator::KeyValueChangedFunc func ){ + m_entityKeyValueChanged = func; } -} -void instanceAttach( MapFile* map ){ - m_undo.instanceAttach( map ); -} -void instanceDetach( MapFile* map ){ - m_undo.instanceDetach( map ); -} + void IncRef(){ + ++m_refcount; + } + void DecRef(){ + if ( --m_refcount == 0 ) { + delete this; + } + } -void attach( const KeyObserver& observer ){ - ( *m_observers.insert ( observer ) )( c_str() ); -} -void detach( const KeyObserver& observer ){ - observer( m_empty ); - m_observers.erase( observer ); -} -const char* c_str() const { - if ( string_empty( m_string.c_str() ) ) { - return m_empty; + void instanceAttach( MapFile* map ){ + m_undo.instanceAttach( map ); } - return m_string.c_str(); -} -void assign( const char* other ){ - if ( !string_equal( m_string.c_str(), other ) ) { - m_undo.save(); - m_string = other; - notify(); + void instanceDetach( MapFile* map ){ + m_undo.instanceDetach( map ); } -} -void notify(){ - m_entityKeyValueChanged(); - KeyObservers::reverse_iterator i = m_observers.rbegin(); - while ( i != m_observers.rend() ) - { - ( *i++ )( c_str() ); + void attach( const KeyObserver& observer ){ + ( *m_observers.insert ( observer ) )( c_str() ); + } + void detach( const KeyObserver& observer ){ + observer( m_empty ); + m_observers.erase( observer ); + } + const char* c_str() const { + if ( string_empty( m_string.c_str() ) ) { + return m_empty; + } + return m_string.c_str(); + } + void assign( const char* other ){ + if ( !string_equal( m_string.c_str(), other ) ) { + m_undo.save(); + m_string = other; + notify(); + } + } + + void notify(){ + m_entityKeyValueChanged(); + KeyObservers::reverse_iterator i = m_observers.rbegin(); + while ( i != m_observers.rend() ) + { + ( *i++ )( c_str() ); + } } -} -void importState( const CopiedString& string ){ - m_string = string; + void importState( const CopiedString& string ){ + m_string = string; - notify(); -} -typedef MemberCaller UndoImportCaller; + notify(); + } + typedef MemberCaller UndoImportCaller; }; /// \brief An unsorted list of key/value pairs. diff --git a/libs/splines/math_angles.h b/libs/splines/math_angles.h index f356b569..ee1d1f82 100644 --- a/libs/splines/math_angles.h +++ b/libs/splines/math_angles.h @@ -34,50 +34,50 @@ typedef idVec3 &vec3_p; class angles_t { public: -float pitch; -float yaw; -float roll; + float pitch; + float yaw; + float roll; -angles_t(); -angles_t( float pitch, float yaw, float roll ); -angles_t( const idVec3 &vec ); + angles_t(); + angles_t( float pitch, float yaw, float roll ); + angles_t( const idVec3 &vec ); -friend void toAngles( idVec3 &src, angles_t &dst ); -friend void toAngles( quat_t &src, angles_t &dst ); -friend void toAngles( mat3_t &src, angles_t &dst ); + friend void toAngles( idVec3 &src, angles_t &dst ); + friend void toAngles( quat_t &src, angles_t &dst ); + friend void toAngles( mat3_t &src, angles_t &dst ); -operator vec3_p(); + operator vec3_p(); -float operator[]( int index ) const; -float& operator[]( int index ); + float operator[]( int index ) const; + float& operator[]( int index ); -void set( float pitch, float yaw, float roll ); + void set( float pitch, float yaw, float roll ); -void operator=( angles_t const &a ); -void operator=( idVec3 const &a ); + void operator=( angles_t const &a ); + void operator=( idVec3 const &a ); -friend angles_t operator+( const angles_t &a, const angles_t &b ); -angles_t &operator+=( angles_t const &a ); -angles_t &operator+=( idVec3 const &a ); + friend angles_t operator+( const angles_t &a, const angles_t &b ); + angles_t &operator+=( angles_t const &a ); + angles_t &operator+=( idVec3 const &a ); -friend angles_t operator-( angles_t &a, angles_t &b ); -angles_t &operator-=( angles_t &a ); + friend angles_t operator-( angles_t &a, angles_t &b ); + angles_t &operator-=( angles_t &a ); -friend angles_t operator*( const angles_t &a, float b ); -friend angles_t operator*( float a, const angles_t &b ); -angles_t &operator*=( float a ); + friend angles_t operator*( const angles_t &a, float b ); + friend angles_t operator*( float a, const angles_t &b ); + angles_t &operator*=( float a ); -friend int operator==( angles_t &a, angles_t &b ); + friend int operator==( angles_t &a, angles_t &b ); -friend int operator!=( angles_t &a, angles_t &b ); + friend int operator!=( angles_t &a, angles_t &b ); -void toVectors( idVec3 *forward, idVec3 *right = NULL, idVec3 *up = NULL ); -idVec3 toForward( void ); + void toVectors( idVec3 *forward, idVec3 *right = NULL, idVec3 *up = NULL ); + idVec3 toForward( void ); -angles_t &Zero( void ); + angles_t &Zero( void ); -angles_t &Normalize360( void ); -angles_t &Normalize180( void ); + angles_t &Normalize360( void ); + angles_t &Normalize180( void ); }; extern angles_t ang_zero; diff --git a/libs/splines/math_quaternion.h b/libs/splines/math_quaternion.h index b33f4425..d428afbd 100644 --- a/libs/splines/math_quaternion.h +++ b/libs/splines/math_quaternion.h @@ -31,44 +31,44 @@ class mat3_t; class quat_t { public: -float x; -float y; -float z; -float w; + float x; + float y; + float z; + float w; -quat_t(); -quat_t( float x, float y, float z, float w ); + quat_t(); + quat_t( float x, float y, float z, float w ); -friend void toQuat( idVec3_t &src, quat_t &dst ); -friend void toQuat( angles_t &src, quat_t &dst ); -friend void toQuat( mat3_t &src, quat_t &dst ); + friend void toQuat( idVec3_t &src, quat_t &dst ); + friend void toQuat( angles_t &src, quat_t &dst ); + friend void toQuat( mat3_t &src, quat_t &dst ); -float *vec4( void ); + float *vec4( void ); -float operator[]( int index ) const; -float &operator[]( int index ); + float operator[]( int index ) const; + float &operator[]( int index ); -void set( float x, float y, float z, float w ); + void set( float x, float y, float z, float w ); -void operator=( quat_t a ); + void operator=( quat_t a ); -friend quat_t operator+( quat_t a, quat_t b ); -quat_t &operator+=( quat_t a ); + friend quat_t operator+( quat_t a, quat_t b ); + quat_t &operator+=( quat_t a ); -friend quat_t operator-( quat_t a, quat_t b ); -quat_t &operator-=( quat_t a ); + friend quat_t operator-( quat_t a, quat_t b ); + quat_t &operator-=( quat_t a ); -friend quat_t operator*( quat_t a, float b ); -friend quat_t operator*( float a, quat_t b ); -quat_t &operator*=( float a ); + friend quat_t operator*( quat_t a, float b ); + friend quat_t operator*( float a, quat_t b ); + quat_t &operator*=( float a ); -friend int operator==( quat_t a, quat_t b ); -friend int operator!=( quat_t a, quat_t b ); + friend int operator==( quat_t a, quat_t b ); + friend int operator!=( quat_t a, quat_t b ); -float Length( void ); -quat_t &Normalize( void ); + float Length( void ); + quat_t &Normalize( void ); -quat_t operator-(); + quat_t operator-(); }; inline quat_t::quat_t() { diff --git a/libs/splines/math_vector.h b/libs/splines/math_vector.h index 4fbe8d9d..3e6372e5 100644 --- a/libs/splines/math_vector.h +++ b/libs/splines/math_vector.h @@ -124,59 +124,59 @@ static inline double idSqrt( double x ) { class idVec3 { public: #ifndef FAT_VEC3 -float x,y,z; + float x,y,z; #else -float x,y,z,dist; + float x,y,z,dist; #endif #ifndef FAT_VEC3 -idVec3() {}; + idVec3() {}; #else -idVec3() {dist = 0.0f; }; + idVec3() {dist = 0.0f; }; #endif -idVec3( const float x, const float y, const float z ); + idVec3( const float x, const float y, const float z ); -operator float *(); + operator float *(); -float operator[]( const int index ) const; -float &operator[]( const int index ); + float operator[]( const int index ) const; + float &operator[]( const int index ); -void set( const float x, const float y, const float z ); + void set( const float x, const float y, const float z ); -idVec3 operator-() const; + idVec3 operator-() const; -idVec3 &operator=( const idVec3 &a ); + idVec3 &operator=( const idVec3 &a ); -float operator*( const idVec3 &a ) const; -idVec3 operator*( const float a ) const; -friend idVec3 operator*( float a, idVec3 b ); + float operator*( const idVec3 &a ) const; + idVec3 operator*( const float a ) const; + friend idVec3 operator*( float a, idVec3 b ); -idVec3 operator+( const idVec3 &a ) const; -idVec3 operator-( const idVec3 &a ) const; + idVec3 operator+( const idVec3 &a ) const; + idVec3 operator-( const idVec3 &a ) const; -idVec3 &operator+=( const idVec3 &a ); -idVec3 &operator-=( const idVec3 &a ); -idVec3 &operator*=( const float a ); + idVec3 &operator+=( const idVec3 &a ); + idVec3 &operator-=( const idVec3 &a ); + idVec3 &operator*=( const float a ); -int operator==( const idVec3 &a ) const; -int operator!=( const idVec3 &a ) const; + int operator==( const idVec3 &a ) const; + int operator!=( const idVec3 &a ) const; -idVec3 Cross( const idVec3 &a ) const; -idVec3 &Cross( const idVec3 &a, const idVec3 &b ); + idVec3 Cross( const idVec3 &a ) const; + idVec3 &Cross( const idVec3 &a, const idVec3 &b ); -float Length( void ) const; -float Normalize( void ); + float Length( void ) const; + float Normalize( void ); -void Zero( void ); -void Snap( void ); -void SnapTowards( const idVec3 &to ); + void Zero( void ); + void Snap( void ); + void SnapTowards( const idVec3 &to ); -float toYaw( void ); -float toPitch( void ); -angles_t toAngles( void ); -friend idVec3 LerpVector( const idVec3 &w1, const idVec3 &w2, const float t ); + float toYaw( void ); + float toPitch( void ); + angles_t toAngles( void ); + friend idVec3 LerpVector( const idVec3 &w1, const idVec3 &w2, const float t ); -char *string( void ); + char *string( void ); }; extern idVec3 vec_zero; diff --git a/libs/string/string.h b/libs/string/string.h index ff7dc453..72423b57 100644 --- a/libs/string/string.h +++ b/libs/string/string.h @@ -259,50 +259,52 @@ inline char* string_to_uppercase( char* string ){ /// \brief A re-entrant string tokeniser similar to strchr. class StringTokeniser { -bool istoken( char c ) const { - if ( strchr( m_delimiters, c ) != 0 ) { - return false; - } - return true; -} -const char* advance(){ - const char* token = m_pos; - bool intoken = true; - while ( !string_empty( m_pos ) ) - { - if ( !istoken( *m_pos ) ) { - *m_pos = '\0'; - intoken = false; +private: + bool istoken( char c ) const { + if ( strchr( m_delimiters, c ) != 0 ) { + return false; } - else if ( !intoken ) { - return token; + return true; + } + const char* advance(){ + const char* token = m_pos; + bool intoken = true; + while ( !string_empty( m_pos ) ) + { + if ( !istoken( *m_pos ) ) { + *m_pos = '\0'; + intoken = false; + } + else if ( !intoken ) { + return token; + } + ++m_pos; } - ++m_pos; + return token; } - return token; -} -std::size_t m_length; -char* m_string; -char* m_pos; -const char* m_delimiters; + std::size_t m_length; + char* m_string; + char* m_pos; + const char* m_delimiters; + public: -StringTokeniser( const char* string, const char* delimiters = " \n\r\t\v" ) : - m_length( string_length( string ) ), - m_string( string_copy( string_new( m_length ), string ) ), - m_pos( m_string ), - m_delimiters( delimiters ){ - while ( !string_empty( m_pos ) && !istoken( *m_pos ) ) - { - ++m_pos; + StringTokeniser( const char* string, const char* delimiters = " \n\r\t\v" ) : + m_length( string_length( string ) ), + m_string( string_copy( string_new( m_length ), string ) ), + m_pos( m_string ), + m_delimiters( delimiters ){ + while ( !string_empty( m_pos ) && !istoken( *m_pos ) ) + { + ++m_pos; + } + } + ~StringTokeniser(){ + string_release( m_string, m_length ); + } + /// \brief Returns the next token or "" if there are no more tokens available. + const char* getToken(){ + return advance(); } -} -~StringTokeniser(){ - string_release( m_string, m_length ); -} -/// \brief Returns the next token or "" if there are no more tokens available. -const char* getToken(){ - return advance(); -} }; /// \brief A non-mutable c-style string. @@ -316,40 +318,39 @@ template class String : public Buffer { public: + String() + : Buffer(){ + } + String( const char* string ) + : Buffer( string ){ + } + String( StringRange range ) + : Buffer( range ){ + } -String() - : Buffer(){ -} -String( const char* string ) - : Buffer( string ){ -} -String( StringRange range ) - : Buffer( range ){ -} - -String& operator=( const String& other ){ - String temp( other ); - temp.swap( *this ); - return *this; -} -String& operator=( const char* string ){ - String temp( string ); - temp.swap( *this ); - return *this; -} -String& operator=( StringRange range ){ - String temp( range ); - temp.swap( *this ); - return *this; -} + String& operator=( const String& other ){ + String temp( other ); + temp.swap( *this ); + return *this; + } + String& operator=( const char* string ){ + String temp( string ); + temp.swap( *this ); + return *this; + } + String& operator=( StringRange range ){ + String temp( range ); + temp.swap( *this ); + return *this; + } -void swap( String& other ){ - Buffer::swap( other ); -} + void swap( String& other ){ + Buffer::swap( other ); + } -bool empty() const { - return string_empty( Buffer::c_str() ); -} + bool empty() const { + return string_empty( Buffer::c_str() ); + } }; template @@ -397,44 +398,45 @@ inline void swap( String& self, String& other ){ template class CopiedBuffer : private Allocator { -char* m_string; + char* m_string; -char* copy_range( StringRange range ){ - return string_clone_range( range, static_cast( *this ) ); -} -char* copy( const char* other ){ - return string_clone( other, static_cast( *this ) ); -} -void destroy( char* string ){ - string_release( string, string_length( string ), static_cast( *this ) ); -} + char* copy_range( StringRange range ){ + return string_clone_range( range, static_cast( *this ) ); + } + char* copy( const char* other ){ + return string_clone( other, static_cast( *this ) ); + } + void destroy( char* string ){ + string_release( string, string_length( string ), static_cast( *this ) ); + } protected: -~CopiedBuffer(){ - destroy( m_string ); -} + ~CopiedBuffer(){ + destroy( m_string ); + } + public: -CopiedBuffer() - : m_string( copy( "" ) ){ -} -explicit CopiedBuffer( const Allocator& allocator ) - : Allocator( allocator ), m_string( copy( "" ) ){ -} -CopiedBuffer( const CopiedBuffer& other ) - : Allocator( other ), m_string( copy( other.m_string ) ){ -} -CopiedBuffer( const char* string, const Allocator& allocator = Allocator() ) - : Allocator( allocator ), m_string( copy( string ) ){ -} -CopiedBuffer( StringRange range, const Allocator& allocator = Allocator() ) - : Allocator( allocator ), m_string( copy_range( range ) ){ -} -const char* c_str() const { - return m_string; -} -void swap( CopiedBuffer& other ){ - string_swap( m_string, other.m_string ); -} + CopiedBuffer() + : m_string( copy( "" ) ){ + } + explicit CopiedBuffer( const Allocator& allocator ) + : Allocator( allocator ), m_string( copy( "" ) ){ + } + CopiedBuffer( const CopiedBuffer& other ) + : Allocator( other ), m_string( copy( other.m_string ) ){ + } + CopiedBuffer( const char* string, const Allocator& allocator = Allocator() ) + : Allocator( allocator ), m_string( copy( string ) ){ + } + CopiedBuffer( StringRange range, const Allocator& allocator = Allocator() ) + : Allocator( allocator ), m_string( copy_range( range ) ){ + } + const char* c_str() const { + return m_string; + } + void swap( CopiedBuffer& other ){ + string_swap( m_string, other.m_string ); + } }; /// \brief A non-mutable string which uses copy-by-value for assignment. @@ -445,65 +447,67 @@ typedef String< CopiedBuffer< DefaultAllocator > > CopiedString; template class SmartBuffer : private Allocator { -char* m_buffer; - -char* copy_range( StringRange range ){ - char* buffer = Allocator::allocate( sizeof( std::size_t ) + ( range.last - range.first ) + 1 ); - strncpy( buffer + sizeof( std::size_t ), range.first, range.last - range.first ); - buffer[sizeof( std::size_t ) + ( range.last - range.first )] = '\0'; - *reinterpret_cast( buffer ) = 0; - return buffer; -} -char* copy( const char* string ){ - char* buffer = Allocator::allocate( sizeof( std::size_t ) + string_length( string ) + 1 ); - strcpy( buffer + sizeof( std::size_t ), string ); - *reinterpret_cast( buffer ) = 0; - return buffer; -} -void destroy( char* buffer ){ - Allocator::deallocate( buffer, sizeof( std::size_t ) + string_length( c_str() ) + 1 ); -} +private: + char* m_buffer; + + char* copy_range( StringRange range ){ + char* buffer = Allocator::allocate( sizeof( std::size_t ) + ( range.last - range.first ) + 1 ); + strncpy( buffer + sizeof( std::size_t ), range.first, range.last - range.first ); + buffer[sizeof( std::size_t ) + ( range.last - range.first )] = '\0'; + *reinterpret_cast( buffer ) = 0; + return buffer; + } + char* copy( const char* string ){ + char* buffer = Allocator::allocate( sizeof( std::size_t ) + string_length( string ) + 1 ); + strcpy( buffer + sizeof( std::size_t ), string ); + *reinterpret_cast( buffer ) = 0; + return buffer; + } + void destroy( char* buffer ){ + Allocator::deallocate( buffer, sizeof( std::size_t ) + string_length( c_str() ) + 1 ); + } -void incref( char* buffer ){ - ++( *reinterpret_cast( buffer ) ); -} -void decref( char* buffer ){ - if ( --( *reinterpret_cast( buffer ) ) == 0 ) { - destroy( buffer ); + void incref( char* buffer ){ + ++( *reinterpret_cast( buffer ) ); + } + void decref( char* buffer ){ + if ( --( *reinterpret_cast( buffer ) ) == 0 ) { + destroy( buffer ); + } } -} protected: -~SmartBuffer(){ - decref( m_buffer ); -} + ~SmartBuffer(){ + decref( m_buffer ); + } + public: -SmartBuffer() - : m_buffer( copy( "" ) ){ - incref( m_buffer ); -} -explicit SmartBuffer( const Allocator& allocator ) - : Allocator( allocator ), m_buffer( copy( "" ) ){ - incref( m_buffer ); -} -SmartBuffer( const SmartBuffer& other ) - : Allocator( other ), m_buffer( other.m_buffer ){ - incref( m_buffer ); -} -SmartBuffer( const char* string, const Allocator& allocator = Allocator() ) - : Allocator( allocator ), m_buffer( copy( string ) ){ - incref( m_buffer ); -} -SmartBuffer( StringRange range, const Allocator& allocator = Allocator() ) - : Allocator( allocator ), m_buffer( copy_range( range ) ){ - incref( m_buffer ); -} -const char* c_str() const { - return m_buffer + sizeof( std::size_t ); -} -void swap( SmartBuffer& other ){ - string_swap( m_buffer, other.m_buffer ); -} + SmartBuffer() + : m_buffer( copy( "" ) ){ + incref( m_buffer ); + } + explicit SmartBuffer( const Allocator& allocator ) + : Allocator( allocator ), m_buffer( copy( "" ) ){ + incref( m_buffer ); + } + SmartBuffer( const SmartBuffer& other ) + : Allocator( other ), m_buffer( other.m_buffer ){ + incref( m_buffer ); + } + SmartBuffer( const char* string, const Allocator& allocator = Allocator() ) + : Allocator( allocator ), m_buffer( copy( string ) ){ + incref( m_buffer ); + } + SmartBuffer( StringRange range, const Allocator& allocator = Allocator() ) + : Allocator( allocator ), m_buffer( copy_range( range ) ){ + incref( m_buffer ); + } + const char* c_str() const { + return m_buffer + sizeof( std::size_t ); + } + void swap( SmartBuffer& other ){ + string_swap( m_buffer, other.m_buffer ); + } }; /// \brief A non-mutable string which uses copy-by-reference for assignment of SmartString. @@ -512,9 +516,9 @@ typedef String< SmartBuffer< DefaultAllocator > > SmartString; class StringEqualNoCase { public: -bool operator()( const CopiedString& key, const CopiedString& other ) const { - return string_equal_nocase( key.c_str(), other.c_str() ); -} + bool operator()( const CopiedString& key, const CopiedString& other ) const { + return string_equal_nocase( key.c_str(), other.c_str() ); + } }; struct StringLessNoCase diff --git a/radiant/brush.h b/radiant/brush.h index 7748327d..9b91386c 100644 --- a/radiant/brush.h +++ b/radiant/brush.h @@ -306,9 +306,8 @@ inline void brush_check_shader( const char* name ){ class FaceShaderObserver { public: -virtual void realiseShader() = 0; - -virtual void unrealiseShader() = 0; + virtual void realiseShader() = 0; + virtual void unrealiseShader() = 0; }; typedef ReferencePair FaceShaderObserverPair; @@ -317,20 +316,20 @@ typedef ReferencePair FaceShaderObserverPair; class ContentsFlagsValue { public: -ContentsFlagsValue(){ -} + ContentsFlagsValue(){ + } -ContentsFlagsValue( int surfaceFlags, int contentFlags, int value, bool specified ) : - m_surfaceFlags( surfaceFlags ), - m_contentFlags( contentFlags ), - m_value( value ), - m_specified( specified ){ -} + ContentsFlagsValue( int surfaceFlags, int contentFlags, int value, bool specified ) : + m_surfaceFlags( surfaceFlags ), + m_contentFlags( contentFlags ), + m_value( value ), + m_specified( specified ){ + } -int m_surfaceFlags; -int m_contentFlags; -int m_value; -bool m_specified; + int m_surfaceFlags; + int m_contentFlags; + int m_value; + bool m_specified; }; inline void ContentsFlagsValue_assignMasked( ContentsFlagsValue& flags, const ContentsFlagsValue& other ){ @@ -349,279 +348,279 @@ inline void ContentsFlagsValue_assignMasked( ContentsFlagsValue& flags, const Co class FaceShader : public ModuleObserver { public: -class SavedState -{ -public: -CopiedString m_shader; -ContentsFlagsValue m_flags; + class SavedState + { + public: + CopiedString m_shader; + ContentsFlagsValue m_flags; -SavedState( const FaceShader& faceShader ){ - m_shader = faceShader.getShader(); - m_flags = faceShader.m_flags; -} + SavedState( const FaceShader& faceShader ){ + m_shader = faceShader.getShader(); + m_flags = faceShader.m_flags; + } -void exportState( FaceShader& faceShader ) const { - faceShader.setShader( m_shader.c_str() ); - faceShader.m_flags = m_flags; -} -}; + void exportState( FaceShader& faceShader ) const { + faceShader.setShader( m_shader.c_str() ); + faceShader.m_flags = m_flags; + } + }; -CopiedString m_shader; -Shader* m_state; -ContentsFlagsValue m_flags; -FaceShaderObserverPair m_observers; -bool m_instanced; -bool m_realised; + CopiedString m_shader; + Shader* m_state; + ContentsFlagsValue m_flags; + FaceShaderObserverPair m_observers; + bool m_instanced; + bool m_realised; -FaceShader( const char* shader, const ContentsFlagsValue& flags = ContentsFlagsValue( 0, 0, 0, false ) ) : - m_shader( shader ), - m_state( 0 ), - m_flags( flags ), - m_instanced( false ), - m_realised( false ){ - captureShader(); -} + FaceShader( const char* shader, const ContentsFlagsValue& flags = ContentsFlagsValue( 0, 0, 0, false ) ) : + m_shader( shader ), + m_state( 0 ), + m_flags( flags ), + m_instanced( false ), + m_realised( false ){ + captureShader(); + } -~FaceShader(){ - releaseShader(); -} + ~FaceShader(){ + releaseShader(); + } -// copy-construction not supported -FaceShader( const FaceShader& other ); + // copy-construction not supported + FaceShader( const FaceShader& other ); -void instanceAttach(){ - m_instanced = true; - m_state->incrementUsed(); -} + void instanceAttach(){ + m_instanced = true; + m_state->incrementUsed(); + } -void instanceDetach(){ - m_state->decrementUsed(); - m_instanced = false; -} + void instanceDetach(){ + m_state->decrementUsed(); + m_instanced = false; + } -void captureShader(){ - ASSERT_MESSAGE( m_state == 0, "shader cannot be captured" ); - brush_check_shader( m_shader.c_str() ); - m_state = GlobalShaderCache().capture( m_shader.c_str() ); - m_state->attach( *this ); -} + void captureShader(){ + ASSERT_MESSAGE( m_state == 0, "shader cannot be captured" ); + brush_check_shader( m_shader.c_str() ); + m_state = GlobalShaderCache().capture( m_shader.c_str() ); + m_state->attach( *this ); + } -void releaseShader(){ - ASSERT_MESSAGE( m_state != 0, "shader cannot be released" ); - m_state->detach( *this ); - GlobalShaderCache().release( m_shader.c_str() ); - m_state = 0; -} + void releaseShader(){ + ASSERT_MESSAGE( m_state != 0, "shader cannot be released" ); + m_state->detach( *this ); + GlobalShaderCache().release( m_shader.c_str() ); + m_state = 0; + } -void realise(){ - ASSERT_MESSAGE( !m_realised, "FaceTexdef::realise: already realised" ); - m_realised = true; - m_observers.forEach([](FaceShaderObserver &observer) { - observer.realiseShader(); - }); -} + void realise(){ + ASSERT_MESSAGE( !m_realised, "FaceTexdef::realise: already realised" ); + m_realised = true; + m_observers.forEach([](FaceShaderObserver &observer) { + observer.realiseShader(); + }); + } -void unrealise(){ - ASSERT_MESSAGE( m_realised, "FaceTexdef::unrealise: already unrealised" ); - m_observers.forEach([](FaceShaderObserver &observer) { - observer.unrealiseShader(); - }); - m_realised = false; -} + void unrealise(){ + ASSERT_MESSAGE( m_realised, "FaceTexdef::unrealise: already unrealised" ); + m_observers.forEach([](FaceShaderObserver &observer) { + observer.unrealiseShader(); + }); + m_realised = false; + } -void attach( FaceShaderObserver& observer ){ - m_observers.attach( observer ); - if ( m_realised ) { - observer.realiseShader(); + void attach( FaceShaderObserver& observer ){ + m_observers.attach( observer ); + if ( m_realised ) { + observer.realiseShader(); + } } -} -void detach( FaceShaderObserver& observer ){ - if ( m_realised ) { - observer.unrealiseShader(); + void detach( FaceShaderObserver& observer ){ + if ( m_realised ) { + observer.unrealiseShader(); + } + m_observers.detach( observer ); } - m_observers.detach( observer ); -} -const char* getShader() const { - return m_shader.c_str(); -} -void setShader( const char* name ){ - if ( m_instanced ) { - m_state->decrementUsed(); + const char* getShader() const { + return m_shader.c_str(); } - releaseShader(); - m_shader = name; - captureShader(); - if ( m_instanced ) { - m_state->incrementUsed(); + void setShader( const char* name ){ + if ( m_instanced ) { + m_state->decrementUsed(); + } + releaseShader(); + m_shader = name; + captureShader(); + if ( m_instanced ) { + m_state->incrementUsed(); + } } -} -ContentsFlagsValue getFlags() const { - ASSERT_MESSAGE( m_realised, "FaceShader::getFlags: flags not valid when unrealised" ); - if ( !m_flags.m_specified ) { - return ContentsFlagsValue( - m_state->getTexture().surfaceFlags, - m_state->getTexture().contentFlags, - m_state->getTexture().value, - true - ); + ContentsFlagsValue getFlags() const { + ASSERT_MESSAGE( m_realised, "FaceShader::getFlags: flags not valid when unrealised" ); + if ( !m_flags.m_specified ) { + return ContentsFlagsValue( + m_state->getTexture().surfaceFlags, + m_state->getTexture().contentFlags, + m_state->getTexture().value, + true + ); + } + return m_flags; } - return m_flags; -} -void setFlags( const ContentsFlagsValue& flags ){ - ASSERT_MESSAGE( m_realised, "FaceShader::setFlags: flags not valid when unrealised" ); - ContentsFlagsValue_assignMasked( m_flags, flags ); -} + void setFlags( const ContentsFlagsValue& flags ){ + ASSERT_MESSAGE( m_realised, "FaceShader::setFlags: flags not valid when unrealised" ); + ContentsFlagsValue_assignMasked( m_flags, flags ); + } -Shader* state() const { - return m_state; -} + Shader* state() const { + return m_state; + } -std::size_t width() const { - if ( m_realised ) { - return m_state->getTexture().width; + std::size_t width() const { + if ( m_realised ) { + return m_state->getTexture().width; + } + return 1; } - return 1; -} -std::size_t height() const { - if ( m_realised ) { - return m_state->getTexture().height; + std::size_t height() const { + if ( m_realised ) { + return m_state->getTexture().height; + } + return 1; } - return 1; -} -unsigned int shaderFlags() const { - if ( m_realised ) { - return m_state->getFlags(); + unsigned int shaderFlags() const { + if ( m_realised ) { + return m_state->getFlags(); + } + return 0; } - return 0; -} }; class FaceTexdef : public FaceShaderObserver { -// not copyable -FaceTexdef( const FaceTexdef& other ); + // not copyable + FaceTexdef( const FaceTexdef& other ); -// not assignable -FaceTexdef& operator=( const FaceTexdef& other ); + // not assignable + FaceTexdef& operator=( const FaceTexdef& other ); public: -class SavedState -{ -public: -TextureProjection m_projection; + class SavedState + { + public: + TextureProjection m_projection; -SavedState( const FaceTexdef& faceTexdef ){ - m_projection = faceTexdef.m_projection; -} + SavedState( const FaceTexdef& faceTexdef ){ + m_projection = faceTexdef.m_projection; + } -void exportState( FaceTexdef& faceTexdef ) const { - Texdef_Assign( faceTexdef.m_projection, m_projection ); -} -}; + void exportState( FaceTexdef& faceTexdef ) const { + Texdef_Assign( faceTexdef.m_projection, m_projection ); + } + }; -FaceShader& m_shader; -TextureProjection m_projection; -bool m_projectionInitialised; -bool m_scaleApplied; + FaceShader& m_shader; + TextureProjection m_projection; + bool m_projectionInitialised; + bool m_scaleApplied; -FaceTexdef( - FaceShader& shader, - const TextureProjection& projection, - bool projectionInitialised = true - ) : - m_shader( shader ), - m_projection( projection ), - m_projectionInitialised( projectionInitialised ), - m_scaleApplied( false ){ - m_shader.attach( *this ); -} + FaceTexdef( + FaceShader& shader, + const TextureProjection& projection, + bool projectionInitialised = true + ) : + m_shader( shader ), + m_projection( projection ), + m_projectionInitialised( projectionInitialised ), + m_scaleApplied( false ){ + m_shader.attach( *this ); + } -~FaceTexdef(){ - m_shader.detach( *this ); -} + ~FaceTexdef(){ + m_shader.detach( *this ); + } -void addScale(){ - ASSERT_MESSAGE( !m_scaleApplied, "texture scale aready added" ); - m_scaleApplied = true; - m_projection.m_brushprimit_texdef.addScale( m_shader.width(), m_shader.height() ); -} + void addScale(){ + ASSERT_MESSAGE( !m_scaleApplied, "texture scale aready added" ); + m_scaleApplied = true; + m_projection.m_brushprimit_texdef.addScale( m_shader.width(), m_shader.height() ); + } -void removeScale(){ - ASSERT_MESSAGE( m_scaleApplied, "texture scale aready removed" ); - m_scaleApplied = false; - m_projection.m_brushprimit_texdef.removeScale( m_shader.width(), m_shader.height() ); -} + void removeScale(){ + ASSERT_MESSAGE( m_scaleApplied, "texture scale aready removed" ); + m_scaleApplied = false; + m_projection.m_brushprimit_texdef.removeScale( m_shader.width(), m_shader.height() ); + } -void realiseShader(){ - if ( m_projectionInitialised && !m_scaleApplied ) { - addScale(); + void realiseShader(){ + if ( m_projectionInitialised && !m_scaleApplied ) { + addScale(); + } } -} -void unrealiseShader(){ - if ( m_projectionInitialised && m_scaleApplied ) { - removeScale(); + void unrealiseShader(){ + if ( m_projectionInitialised && m_scaleApplied ) { + removeScale(); + } } -} -void setTexdef( const TextureProjection& projection ){ - removeScale(); - Texdef_Assign( m_projection, projection ); - addScale(); -} + void setTexdef( const TextureProjection& projection ){ + removeScale(); + Texdef_Assign( m_projection, projection ); + addScale(); + } -void shift( float s, float t ){ - ASSERT_MESSAGE( texdef_sane( m_projection.m_texdef ), "FaceTexdef::shift: bad texdef" ); - removeScale(); - Texdef_Shift( m_projection, s, t ); - addScale(); -} + void shift( float s, float t ){ + ASSERT_MESSAGE( texdef_sane( m_projection.m_texdef ), "FaceTexdef::shift: bad texdef" ); + removeScale(); + Texdef_Shift( m_projection, s, t ); + addScale(); + } -void scale( float s, float t ){ - removeScale(); - Texdef_Scale( m_projection, s, t ); - addScale(); -} + void scale( float s, float t ){ + removeScale(); + Texdef_Scale( m_projection, s, t ); + addScale(); + } -void rotate( float angle ){ - removeScale(); - Texdef_Rotate( m_projection, angle ); - addScale(); -} + void rotate( float angle ){ + removeScale(); + Texdef_Rotate( m_projection, angle ); + addScale(); + } -void fit( const Vector3& normal, const Winding& winding, float s_repeat, float t_repeat ){ - Texdef_FitTexture( m_projection, m_shader.width(), m_shader.height(), normal, winding, s_repeat, t_repeat ); -} + void fit( const Vector3& normal, const Winding& winding, float s_repeat, float t_repeat ){ + Texdef_FitTexture( m_projection, m_shader.width(), m_shader.height(), normal, winding, s_repeat, t_repeat ); + } -void emitTextureCoordinates( Winding& winding, const Vector3& normal, const Matrix4& localToWorld ){ - Texdef_EmitTextureCoordinates( m_projection, m_shader.width(), m_shader.height(), winding, normal, localToWorld ); -} + void emitTextureCoordinates( Winding& winding, const Vector3& normal, const Matrix4& localToWorld ){ + Texdef_EmitTextureCoordinates( m_projection, m_shader.width(), m_shader.height(), winding, normal, localToWorld ); + } -void transform( const Plane3& plane, const Matrix4& matrix ){ - removeScale(); - Texdef_transformLocked( m_projection, m_shader.width(), m_shader.height(), plane, matrix ); - addScale(); -} + void transform( const Plane3& plane, const Matrix4& matrix ){ + removeScale(); + Texdef_transformLocked( m_projection, m_shader.width(), m_shader.height(), plane, matrix ); + addScale(); + } -TextureProjection normalised() const { - brushprimit_texdef_t tmp( m_projection.m_brushprimit_texdef ); - tmp.removeScale( m_shader.width(), m_shader.height() ); - return TextureProjection( m_projection.m_texdef, tmp, m_projection.m_basis_s, m_projection.m_basis_t ); -} + TextureProjection normalised() const { + brushprimit_texdef_t tmp( m_projection.m_brushprimit_texdef ); + tmp.removeScale( m_shader.width(), m_shader.height() ); + return TextureProjection( m_projection.m_texdef, tmp, m_projection.m_basis_s, m_projection.m_basis_t ); + } -void setBasis( const Vector3& normal ){ - Matrix4 basis; - Normal_GetTransform( normal, basis ); - m_projection.m_basis_s = Vector3( basis.xx(), basis.yx(), basis.zx() ); - m_projection.m_basis_t = Vector3( -basis.xy(), -basis.yy(), -basis.zy() ); -} + void setBasis( const Vector3& normal ){ + Matrix4 basis; + Normal_GetTransform( normal, basis ); + m_projection.m_basis_s = Vector3( basis.xx(), basis.yx(), basis.zx() ); + m_projection.m_basis_t = Vector3( -basis.xy(), -basis.yy(), -basis.zy() ); + } }; inline void planepts_print( const PlanePoints& planePoints, TextOutputStream& ostream ){ @@ -643,190 +642,190 @@ inline Plane3 Plane3_applyTransform( const Plane3& plane, const Matrix4& matrix class FacePlane { -PlanePoints m_planepts; -Plane3 m_planeCached; -Plane3 m_plane; + PlanePoints m_planepts; + Plane3 m_planeCached; + Plane3 m_plane; public: -Vector3 m_funcStaticOrigin; - -static EBrushType m_type; - -static bool isDoom3Plane(){ - return FacePlane::m_type == eBrushTypeDoom3 || FacePlane::m_type == eBrushTypeQuake4; -} + Vector3 m_funcStaticOrigin; -class SavedState -{ -public: -PlanePoints m_planepts; -Plane3 m_plane; + static EBrushType m_type; -SavedState( const FacePlane& facePlane ){ - if ( facePlane.isDoom3Plane() ) { - m_plane = facePlane.m_plane; - } - else - { - planepts_assign( m_planepts, facePlane.planePoints() ); + static bool isDoom3Plane(){ + return FacePlane::m_type == eBrushTypeDoom3 || FacePlane::m_type == eBrushTypeQuake4; } -} -void exportState( FacePlane& facePlane ) const { - if ( facePlane.isDoom3Plane() ) { - facePlane.m_plane = m_plane; - facePlane.updateTranslated(); - } - else + class SavedState { - planepts_assign( facePlane.planePoints(), m_planepts ); - facePlane.MakePlane(); - } -} -}; + public: + PlanePoints m_planepts; + Plane3 m_plane; -FacePlane() : m_funcStaticOrigin( 0, 0, 0 ){ -} + SavedState( const FacePlane& facePlane ){ + if ( facePlane.isDoom3Plane() ) { + m_plane = facePlane.m_plane; + } + else + { + planepts_assign( m_planepts, facePlane.planePoints() ); + } + } + + void exportState( FacePlane& facePlane ) const { + if ( facePlane.isDoom3Plane() ) { + facePlane.m_plane = m_plane; + facePlane.updateTranslated(); + } + else + { + planepts_assign( facePlane.planePoints(), m_planepts ); + facePlane.MakePlane(); + } + } + }; -FacePlane( const FacePlane& other ) : m_funcStaticOrigin( 0, 0, 0 ){ - if ( !isDoom3Plane() ) { - planepts_assign( m_planepts, other.m_planepts ); - MakePlane(); + FacePlane() : m_funcStaticOrigin( 0, 0, 0 ){ } - else - { - m_plane = other.m_plane; - updateTranslated(); + + FacePlane( const FacePlane& other ) : m_funcStaticOrigin( 0, 0, 0 ){ + if ( !isDoom3Plane() ) { + planepts_assign( m_planepts, other.m_planepts ); + MakePlane(); + } + else + { + m_plane = other.m_plane; + updateTranslated(); + } } -} -void MakePlane(){ - if ( !isDoom3Plane() ) { + void MakePlane(){ + if ( !isDoom3Plane() ) { #if 0 - if ( check_plane_is_integer( m_planepts ) ) { - globalErrorStream() << "non-integer planepts: "; - planepts_print( m_planepts, globalErrorStream() ); - globalErrorStream() << "\n"; - } + if ( check_plane_is_integer( m_planepts ) ) { + globalErrorStream() << "non-integer planepts: "; + planepts_print( m_planepts, globalErrorStream() ); + globalErrorStream() << "\n"; + } #endif - m_planeCached = plane3_for_points( m_planepts ); + m_planeCached = plane3_for_points( m_planepts ); + } } -} -void reverse(){ - if ( !isDoom3Plane() ) { - vector3_swap( m_planepts[0], m_planepts[2] ); - MakePlane(); - } - else - { - m_planeCached = plane3_flipped( m_plane ); - updateSource(); + void reverse(){ + if ( !isDoom3Plane() ) { + vector3_swap( m_planepts[0], m_planepts[2] ); + MakePlane(); + } + else + { + m_planeCached = plane3_flipped( m_plane ); + updateSource(); + } } -} -void transform( const Matrix4& matrix, bool mirror ){ - if ( !isDoom3Plane() ) { + void transform( const Matrix4& matrix, bool mirror ){ + if ( !isDoom3Plane() ) { #if 0 - bool off = check_plane_is_integer( planePoints() ); + bool off = check_plane_is_integer( planePoints() ); #endif - matrix4_transform_point( matrix, m_planepts[0] ); - matrix4_transform_point( matrix, m_planepts[1] ); - matrix4_transform_point( matrix, m_planepts[2] ); + matrix4_transform_point( matrix, m_planepts[0] ); + matrix4_transform_point( matrix, m_planepts[1] ); + matrix4_transform_point( matrix, m_planepts[2] ); - if ( mirror ) { - reverse(); - } + if ( mirror ) { + reverse(); + } #if 0 - if ( check_plane_is_integer( planePoints() ) ) { - if ( !off ) { - globalErrorStream() << "caused by transform\n"; + if ( check_plane_is_integer( planePoints() ) ) { + if ( !off ) { + globalErrorStream() << "caused by transform\n"; + } } - } #endif - MakePlane(); - } - else - { - m_planeCached = Plane3_applyTransform( m_planeCached, matrix ); - updateSource(); + MakePlane(); + } + else + { + m_planeCached = Plane3_applyTransform( m_planeCached, matrix ); + updateSource(); + } } -} -void offset( float offset ){ - if ( !isDoom3Plane() ) { - Vector3 move( vector3_scaled( m_planeCached.normal(), -offset ) ); + void offset( float offset ){ + if ( !isDoom3Plane() ) { + Vector3 move( vector3_scaled( m_planeCached.normal(), -offset ) ); - vector3_subtract( m_planepts[0], move ); - vector3_subtract( m_planepts[1], move ); - vector3_subtract( m_planepts[2], move ); + vector3_subtract( m_planepts[0], move ); + vector3_subtract( m_planepts[1], move ); + vector3_subtract( m_planepts[2], move ); - MakePlane(); - } - else - { - m_planeCached.d += offset; - updateSource(); + MakePlane(); + } + else + { + m_planeCached.d += offset; + updateSource(); + } } -} - -void updateTranslated(){ - m_planeCached = Plane3_applyTranslation( m_plane, m_funcStaticOrigin ); -} - -void updateSource(){ - m_plane = Plane3_applyTranslation( m_planeCached, vector3_negated( m_funcStaticOrigin ) ); -} + void updateTranslated(){ + m_planeCached = Plane3_applyTranslation( m_plane, m_funcStaticOrigin ); + } -PlanePoints& planePoints(){ - return m_planepts; -} + void updateSource(){ + m_plane = Plane3_applyTranslation( m_planeCached, vector3_negated( m_funcStaticOrigin ) ); + } -const PlanePoints& planePoints() const { - return m_planepts; -} -const Plane3& plane3() const { - return m_planeCached; -} + PlanePoints& planePoints(){ + return m_planepts; + } -void setDoom3Plane( const Plane3& plane ){ - m_plane = plane; - updateTranslated(); -} + const PlanePoints& planePoints() const { + return m_planepts; + } -const Plane3& getDoom3Plane() const { - return m_plane; -} + const Plane3& plane3() const { + return m_planeCached; + } -void copy( const FacePlane& other ){ - if ( !isDoom3Plane() ) { - planepts_assign( m_planepts, other.m_planepts ); - MakePlane(); + void setDoom3Plane( const Plane3& plane ){ + m_plane = plane; + updateTranslated(); } - else - { - m_planeCached = other.m_plane; - updateSource(); + + const Plane3& getDoom3Plane() const { + return m_plane; } -} -void copy( const Vector3& p0, const Vector3& p1, const Vector3& p2 ){ - if ( !isDoom3Plane() ) { - m_planepts[0] = p0; - m_planepts[1] = p1; - m_planepts[2] = p2; - MakePlane(); + void copy( const FacePlane& other ){ + if ( !isDoom3Plane() ) { + planepts_assign( m_planepts, other.m_planepts ); + MakePlane(); + } + else + { + m_planeCached = other.m_plane; + updateSource(); + } } - else - { - m_planeCached = plane3_for_points( p2, p1, p0 ); - updateSource(); + + void copy( const Vector3& p0, const Vector3& p1, const Vector3& p2 ){ + if ( !isDoom3Plane() ) { + m_planepts[0] = p0; + m_planepts[1] = p1; + m_planepts[2] = p2; + MakePlane(); + } + else + { + m_planeCached = plane3_for_points( p2, p1, p0 ); + updateSource(); + } } -} }; inline void Winding_testSelect( Winding& winding, SelectionTest& test, SelectionIntersection& best ){ @@ -850,7 +849,7 @@ class Face; class FaceFilter { public: -virtual bool filter( const Face& face ) const = 0; + virtual bool filter( const Face& face ) const = 0; }; bool face_filtered( Face& face ); @@ -867,13 +866,10 @@ extern bool g_brush_texturelock_enabled; class FaceObserver { public: -virtual void planeChanged() = 0; - -virtual void connectivityChanged() = 0; - -virtual void shaderChanged() = 0; - -virtual void evaluateTransform() = 0; + virtual void planeChanged() = 0; + virtual void connectivityChanged() = 0; + virtual void shaderChanged() = 0; + virtual void evaluateTransform() = 0; }; class Face : @@ -1312,21 +1308,21 @@ bool is_bounded() const { class FaceVertexId { -std::size_t m_face; -std::size_t m_vertex; + std::size_t m_face; + std::size_t m_vertex; public: -FaceVertexId( std::size_t face, std::size_t vertex ) - : m_face( face ), m_vertex( vertex ){ -} + FaceVertexId( std::size_t face, std::size_t vertex ) + : m_face( face ), m_vertex( vertex ){ + } -std::size_t getFace() const { - return m_face; -} + std::size_t getFace() const { + return m_face; + } -std::size_t getVertex() const { - return m_vertex; -} + std::size_t getVertex() const { + return m_vertex; + } }; typedef std::size_t faceIndex_t; @@ -1390,7 +1386,7 @@ typedef std::vector brush_vector_t; class BrushFilter { public: -virtual bool filter( const Brush& brush ) const = 0; + virtual bool filter( const Brush& brush ) const = 0; }; bool brush_filtered( Brush& brush ); @@ -1434,91 +1430,81 @@ inline FaceVertexId next_vertex( const Faces& faces, FaceVertexId faceVertex ){ class SelectableEdge { -Vector3 getEdge() const { - const Winding& winding = getFace().getWinding(); - return vector3_mid( winding[m_faceVertex.getVertex()].vertex, winding[Winding_next( winding, m_faceVertex.getVertex() )].vertex ); -} + Vector3 getEdge() const { + const Winding& winding = getFace().getWinding(); + return vector3_mid( winding[m_faceVertex.getVertex()].vertex, winding[Winding_next( winding, m_faceVertex.getVertex() )].vertex ); + } public: -Faces& m_faces; -FaceVertexId m_faceVertex; + Faces& m_faces; + FaceVertexId m_faceVertex; -SelectableEdge( Faces& faces, FaceVertexId faceVertex ) - : m_faces( faces ), m_faceVertex( faceVertex ){ -} + SelectableEdge( Faces& faces, FaceVertexId faceVertex ) + : m_faces( faces ), m_faceVertex( faceVertex ){ + } -SelectableEdge& operator=( const SelectableEdge& other ){ - m_faceVertex = other.m_faceVertex; - return *this; -} + SelectableEdge& operator=( const SelectableEdge& other ){ + m_faceVertex = other.m_faceVertex; + return *this; + } -Face& getFace() const { - return *m_faces[m_faceVertex.getFace()]; -} + Face& getFace() const { + return *m_faces[m_faceVertex.getFace()]; + } -void testSelect( SelectionTest& test, SelectionIntersection& best ){ - test.TestPoint( getEdge(), best ); -} + void testSelect( SelectionTest& test, SelectionIntersection& best ){ + test.TestPoint( getEdge(), best ); + } }; class SelectableVertex { -Vector3 getVertex() const { - return getFace().getWinding()[m_faceVertex.getVertex()].vertex; -} + Vector3 getVertex() const { + return getFace().getWinding()[m_faceVertex.getVertex()].vertex; + } public: -Faces& m_faces; -FaceVertexId m_faceVertex; + Faces& m_faces; + FaceVertexId m_faceVertex; -SelectableVertex( Faces& faces, FaceVertexId faceVertex ) - : m_faces( faces ), m_faceVertex( faceVertex ){ -} + SelectableVertex( Faces& faces, FaceVertexId faceVertex ) + : m_faces( faces ), m_faceVertex( faceVertex ){ + } -SelectableVertex& operator=( const SelectableVertex& other ){ - m_faceVertex = other.m_faceVertex; - return *this; -} + SelectableVertex& operator=( const SelectableVertex& other ){ + m_faceVertex = other.m_faceVertex; + return *this; + } -Face& getFace() const { - return *m_faces[m_faceVertex.getFace()]; -} + Face& getFace() const { + return *m_faces[m_faceVertex.getFace()]; + } -void testSelect( SelectionTest& test, SelectionIntersection& best ){ - test.TestPoint( getVertex(), best ); -} + void testSelect( SelectionTest& test, SelectionIntersection& best ){ + test.TestPoint( getVertex(), best ); + } }; class BrushObserver { public: -virtual void reserve( std::size_t size ) = 0; - -virtual void clear() = 0; - -virtual void push_back( Face& face ) = 0; - -virtual void pop_back() = 0; - -virtual void erase( std::size_t index ) = 0; - -virtual void connectivityChanged() = 0; - -virtual void edge_clear() = 0; - -virtual void edge_push_back( SelectableEdge& edge ) = 0; - -virtual void vertex_clear() = 0; - -virtual void vertex_push_back( SelectableVertex& vertex ) = 0; - -virtual void DEBUG_verify() const = 0; + virtual void reserve( std::size_t size ) = 0; + virtual void clear() = 0; + virtual void push_back( Face& face ) = 0; + virtual void pop_back() = 0; + virtual void erase( std::size_t index ) = 0; + virtual void connectivityChanged() = 0; + virtual void edge_clear() = 0; + virtual void edge_push_back( SelectableEdge& edge ) = 0; + virtual void vertex_clear() = 0; + virtual void vertex_push_back( SelectableVertex& vertex ) = 0; + virtual void DEBUG_verify() const = 0; }; class BrushVisitor { public: -virtual void visit( Face& face ) const = 0; + virtual void visit( Face& face ) const = 0; }; class Brush : @@ -1533,878 +1519,878 @@ class Brush : public BrushDoom3 { private: -scene::Node* m_node; -typedef UniqueSet Observers; -Observers m_observers; -UndoObserver* m_undoable_observer; -MapFile* m_map; + scene::Node* m_node; + typedef UniqueSet Observers; + Observers m_observers; + UndoObserver* m_undoable_observer; + MapFile* m_map; -// state -Faces m_faces; -// ---- + // state + Faces m_faces; + // ---- -// cached data compiled from state -Array m_faceCentroidPoints; -RenderablePointArray m_render_faces; + // cached data compiled from state + Array m_faceCentroidPoints; + RenderablePointArray m_render_faces; -Array m_uniqueVertexPoints; -typedef std::vector SelectableVertices; -SelectableVertices m_select_vertices; -RenderablePointArray m_render_vertices; + Array m_uniqueVertexPoints; + typedef std::vector SelectableVertices; + SelectableVertices m_select_vertices; + RenderablePointArray m_render_vertices; -Array m_uniqueEdgePoints; -typedef std::vector SelectableEdges; -SelectableEdges m_select_edges; -RenderablePointArray m_render_edges; + Array m_uniqueEdgePoints; + typedef std::vector SelectableEdges; + SelectableEdges m_select_edges; + RenderablePointArray m_render_edges; -Array m_edge_indices; -Array m_edge_faces; + Array m_edge_indices; + Array m_edge_faces; -AABB m_aabb_local; -// ---- + AABB m_aabb_local; + // ---- -Callback m_evaluateTransform; -Callback m_boundsChanged; + Callback m_evaluateTransform; + Callback m_boundsChanged; -mutable bool m_planeChanged; // b-rep evaluation required -mutable bool m_transformChanged; // transform evaluation required -// ---- + mutable bool m_planeChanged; // b-rep evaluation required + mutable bool m_transformChanged; // transform evaluation required + // ---- public: -STRING_CONSTANT( Name, "Brush" ); - -Callback m_lightsChanged; - -// static data -static Shader* m_state_point; -// ---- - -static EBrushType m_type; -static double m_maxWorldCoord; + STRING_CONSTANT( Name, "Brush" ); + + Callback m_lightsChanged; + + // static data + static Shader* m_state_point; + // ---- + + static EBrushType m_type; + static double m_maxWorldCoord; + + Brush( scene::Node& node, const Callback& evaluateTransform, const Callback& boundsChanged ) : + m_node( &node ), + m_undoable_observer( 0 ), + m_map( 0 ), + m_render_faces( m_faceCentroidPoints, GL_POINTS ), + m_render_vertices( m_uniqueVertexPoints, GL_POINTS ), + m_render_edges( m_uniqueEdgePoints, GL_POINTS ), + m_evaluateTransform( evaluateTransform ), + m_boundsChanged( boundsChanged ), + m_planeChanged( false ), + m_transformChanged( false ){ + planeChanged(); + } + Brush( const Brush& other, scene::Node& node, const Callback& evaluateTransform, const Callback& boundsChanged ) : + m_node( &node ), + m_undoable_observer( 0 ), + m_map( 0 ), + m_render_faces( m_faceCentroidPoints, GL_POINTS ), + m_render_vertices( m_uniqueVertexPoints, GL_POINTS ), + m_render_edges( m_uniqueEdgePoints, GL_POINTS ), + m_evaluateTransform( evaluateTransform ), + m_boundsChanged( boundsChanged ), + m_planeChanged( false ), + m_transformChanged( false ){ + copy( other ); + } + + Brush( const Brush& other ) : + TransformNode( other ), + Bounded( other ), + Cullable( other ), + Snappable(), + Undoable( other ), + FaceObserver( other ), + Filterable( other ), + Nameable( other ), + BrushDoom3( other ), + m_node( 0 ), + m_undoable_observer( 0 ), + m_map( 0 ), + m_render_faces( m_faceCentroidPoints, GL_POINTS ), + m_render_vertices( m_uniqueVertexPoints, GL_POINTS ), + m_render_edges( m_uniqueEdgePoints, GL_POINTS ), + m_planeChanged( false ), + m_transformChanged( false ){ + copy( other ); + } + + ~Brush(){ + ASSERT_MESSAGE( m_observers.empty(), "Brush::~Brush: observers still attached" ); + } + + // assignment not supported + Brush& operator=( const Brush& other ); + + void setDoom3GroupOrigin( const Vector3& origin ){ + //globalOutputStream() << "func_static origin before: " << m_funcStaticOrigin << " after: " << origin << "\n"; + for ( Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i ) + { + ( *i )->getPlane().m_funcStaticOrigin = origin; + ( *i )->getPlane().updateTranslated(); + ( *i )->planeChanged(); + } + planeChanged(); + } -Brush( scene::Node& node, const Callback& evaluateTransform, const Callback& boundsChanged ) : - m_node( &node ), - m_undoable_observer( 0 ), - m_map( 0 ), - m_render_faces( m_faceCentroidPoints, GL_POINTS ), - m_render_vertices( m_uniqueVertexPoints, GL_POINTS ), - m_render_edges( m_uniqueEdgePoints, GL_POINTS ), - m_evaluateTransform( evaluateTransform ), - m_boundsChanged( boundsChanged ), - m_planeChanged( false ), - m_transformChanged( false ){ - planeChanged(); -} -Brush( const Brush& other, scene::Node& node, const Callback& evaluateTransform, const Callback& boundsChanged ) : - m_node( &node ), - m_undoable_observer( 0 ), - m_map( 0 ), - m_render_faces( m_faceCentroidPoints, GL_POINTS ), - m_render_vertices( m_uniqueVertexPoints, GL_POINTS ), - m_render_edges( m_uniqueEdgePoints, GL_POINTS ), - m_evaluateTransform( evaluateTransform ), - m_boundsChanged( boundsChanged ), - m_planeChanged( false ), - m_transformChanged( false ){ - copy( other ); -} - -Brush( const Brush& other ) : - TransformNode( other ), - Bounded( other ), - Cullable( other ), - Snappable(), - Undoable( other ), - FaceObserver( other ), - Filterable( other ), - Nameable( other ), - BrushDoom3( other ), - m_node( 0 ), - m_undoable_observer( 0 ), - m_map( 0 ), - m_render_faces( m_faceCentroidPoints, GL_POINTS ), - m_render_vertices( m_uniqueVertexPoints, GL_POINTS ), - m_render_edges( m_uniqueEdgePoints, GL_POINTS ), - m_planeChanged( false ), - m_transformChanged( false ){ - copy( other ); -} + void attach( BrushObserver& observer ){ + for ( Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i ) + { + observer.push_back( *( *i ) ); + } -~Brush(){ - ASSERT_MESSAGE( m_observers.empty(), "Brush::~Brush: observers still attached" ); -} + for ( SelectableEdges::iterator i = m_select_edges.begin(); i != m_select_edges.end(); ++i ) + { + observer.edge_push_back( *i ); + } -// assignment not supported -Brush& operator=( const Brush& other ); + for ( SelectableVertices::iterator i = m_select_vertices.begin(); i != m_select_vertices.end(); ++i ) + { + observer.vertex_push_back( *i ); + } -void setDoom3GroupOrigin( const Vector3& origin ){ - //globalOutputStream() << "func_static origin before: " << m_funcStaticOrigin << " after: " << origin << "\n"; - for ( Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i ) - { - ( *i )->getPlane().m_funcStaticOrigin = origin; - ( *i )->getPlane().updateTranslated(); - ( *i )->planeChanged(); + m_observers.insert( &observer ); } - planeChanged(); -} -void attach( BrushObserver& observer ){ - for ( Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i ) - { - observer.push_back( *( *i ) ); + void detach( BrushObserver& observer ){ + m_observers.erase( &observer ); } - for ( SelectableEdges::iterator i = m_select_edges.begin(); i != m_select_edges.end(); ++i ) - { - observer.edge_push_back( *i ); + void forEachFace( const BrushVisitor& visitor ) const { + for ( Faces::const_iterator i = m_faces.begin(); i != m_faces.end(); ++i ) + { + visitor.visit( *( *i ) ); + } } - for ( SelectableVertices::iterator i = m_select_vertices.begin(); i != m_select_vertices.end(); ++i ) - { - observer.vertex_push_back( *i ); + void forEachFace_instanceAttach( MapFile* map ) const { + for ( Faces::const_iterator i = m_faces.begin(); i != m_faces.end(); ++i ) + { + ( *i )->instanceAttach( map ); + } } - m_observers.insert( &observer ); -} + void forEachFace_instanceDetach( MapFile* map ) const { + for ( Faces::const_iterator i = m_faces.begin(); i != m_faces.end(); ++i ) + { + ( *i )->instanceDetach( map ); + } + } -void detach( BrushObserver& observer ){ - m_observers.erase( &observer ); -} + InstanceCounter m_instanceCounter; -void forEachFace( const BrushVisitor& visitor ) const { - for ( Faces::const_iterator i = m_faces.begin(); i != m_faces.end(); ++i ) - { - visitor.visit( *( *i ) ); + void instanceAttach( const scene::Path& path ){ + if ( ++m_instanceCounter.m_count == 1 ) { + m_map = path_find_mapfile( path.begin(), path.end() ); + m_undoable_observer = GlobalUndoSystem().observer( this ); + GlobalFilterSystem().registerFilterable( *this ); + forEachFace_instanceAttach( m_map ); + } + else + { + ASSERT_MESSAGE( path_find_mapfile( path.begin(), path.end() ) == m_map, "node is instanced across more than one file" ); + } } -} -void forEachFace_instanceAttach( MapFile* map ) const { - for ( Faces::const_iterator i = m_faces.begin(); i != m_faces.end(); ++i ) - { - ( *i )->instanceAttach( map ); + void instanceDetach( const scene::Path& path ){ + if ( --m_instanceCounter.m_count == 0 ) { + forEachFace_instanceDetach( m_map ); + GlobalFilterSystem().unregisterFilterable( *this ); + m_map = 0; + m_undoable_observer = 0; + GlobalUndoSystem().release( this ); + } } -} -void forEachFace_instanceDetach( MapFile* map ) const { - for ( Faces::const_iterator i = m_faces.begin(); i != m_faces.end(); ++i ) - { - ( *i )->instanceDetach( map ); + // nameable + const char* name() const { + return "brush"; } -} - -InstanceCounter m_instanceCounter; -void instanceAttach( const scene::Path& path ){ - if ( ++m_instanceCounter.m_count == 1 ) { - m_map = path_find_mapfile( path.begin(), path.end() ); - m_undoable_observer = GlobalUndoSystem().observer( this ); - GlobalFilterSystem().registerFilterable( *this ); - forEachFace_instanceAttach( m_map ); - } - else - { - ASSERT_MESSAGE( path_find_mapfile( path.begin(), path.end() ) == m_map, "node is instanced across more than one file" ); + void attach( const NameCallback& callback ){ } -} -void instanceDetach( const scene::Path& path ){ - if ( --m_instanceCounter.m_count == 0 ) { - forEachFace_instanceDetach( m_map ); - GlobalFilterSystem().unregisterFilterable( *this ); - m_map = 0; - m_undoable_observer = 0; - GlobalUndoSystem().release( this ); + void detach( const NameCallback& callback ){ } -} -// nameable -const char* name() const { - return "brush"; -} + // filterable + void updateFiltered(){ + if ( m_node != 0 ) { + if ( brush_filtered( *this ) ) { + m_node->enable( scene::Node::eFiltered ); + } + else + { + m_node->disable( scene::Node::eFiltered ); + } + } + } -void attach( const NameCallback& callback ){ -} + // observer + void planeChanged(){ + m_planeChanged = true; + aabbChanged(); + m_lightsChanged(); + } -void detach( const NameCallback& callback ){ -} + void shaderChanged(){ + updateFiltered(); + planeChanged(); + } -// filterable -void updateFiltered(){ - if ( m_node != 0 ) { - if ( brush_filtered( *this ) ) { - m_node->enable( scene::Node::eFiltered ); - } - else - { - m_node->disable( scene::Node::eFiltered ); + void evaluateBRep() const { + if ( m_planeChanged ) { + m_planeChanged = false; + const_cast( this )->buildBRep(); } } -} -// observer -void planeChanged(){ - m_planeChanged = true; - aabbChanged(); - m_lightsChanged(); -} + void transformChanged(){ + m_transformChanged = true; + planeChanged(); + } -void shaderChanged(){ - updateFiltered(); - planeChanged(); -} + typedef MemberCaller TransformChangedCaller; -void evaluateBRep() const { - if ( m_planeChanged ) { - m_planeChanged = false; - const_cast( this )->buildBRep(); + void evaluateTransform(){ + if ( m_transformChanged ) { + m_transformChanged = false; + revertTransform(); + m_evaluateTransform(); + } } -} -void transformChanged(){ - m_transformChanged = true; - planeChanged(); -} + const Matrix4& localToParent() const { + return g_matrix4_identity; + } -typedef MemberCaller TransformChangedCaller; + void aabbChanged(){ + m_boundsChanged(); + } -void evaluateTransform(){ - if ( m_transformChanged ) { - m_transformChanged = false; - revertTransform(); - m_evaluateTransform(); + const AABB& localAABB() const { + evaluateBRep(); + return m_aabb_local; } -} -const Matrix4& localToParent() const { - return g_matrix4_identity; -} + VolumeIntersectionValue intersectVolume( const VolumeTest& test, const Matrix4& localToWorld ) const { + return test.TestAABB( m_aabb_local, localToWorld ); + } -void aabbChanged(){ - m_boundsChanged(); -} + void renderComponents( SelectionSystem::EComponentMode mode, Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld ) const { + switch ( mode ) + { + case SelectionSystem::eVertex: + renderer.addRenderable( m_render_vertices, localToWorld ); + break; + case SelectionSystem::eEdge: + renderer.addRenderable( m_render_edges, localToWorld ); + break; + case SelectionSystem::eFace: + renderer.addRenderable( m_render_faces, localToWorld ); + break; + default: + break; + } + } -const AABB& localAABB() const { - evaluateBRep(); - return m_aabb_local; -} + void transform( const Matrix4& matrix ){ + bool mirror = matrix4_handedness( matrix ) == MATRIX4_LEFTHANDED; -VolumeIntersectionValue intersectVolume( const VolumeTest& test, const Matrix4& localToWorld ) const { - return test.TestAABB( m_aabb_local, localToWorld ); -} - -void renderComponents( SelectionSystem::EComponentMode mode, Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld ) const { - switch ( mode ) - { - case SelectionSystem::eVertex: - renderer.addRenderable( m_render_vertices, localToWorld ); - break; - case SelectionSystem::eEdge: - renderer.addRenderable( m_render_edges, localToWorld ); - break; - case SelectionSystem::eFace: - renderer.addRenderable( m_render_faces, localToWorld ); - break; - default: - break; + for ( Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i ) + { + ( *i )->transform( matrix, mirror ); + } } -} -void transform( const Matrix4& matrix ){ - bool mirror = matrix4_handedness( matrix ) == MATRIX4_LEFTHANDED; - - for ( Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i ) - { - ( *i )->transform( matrix, mirror ); + void snapto( float snap ){ + for ( Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i ) + { + ( *i )->snapto( snap ); + } } -} -void snapto( float snap ){ - for ( Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i ) - { - ( *i )->snapto( snap ); + void revertTransform(){ + for ( Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i ) + { + ( *i )->revertTransform(); + } } -} -void revertTransform(){ - for ( Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i ) - { - ( *i )->revertTransform(); + void freezeTransform(){ + for ( Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i ) + { + ( *i )->freezeTransform(); + } } -} -void freezeTransform(){ - for ( Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i ) - { - ( *i )->freezeTransform(); + /// \brief Returns the absolute index of the \p faceVertex. + std::size_t absoluteIndex( FaceVertexId faceVertex ){ + std::size_t index = 0; + for ( std::size_t i = 0; i < faceVertex.getFace(); ++i ) + { + index += m_faces[i]->getWinding().numpoints; + } + return index + faceVertex.getVertex(); } -} -/// \brief Returns the absolute index of the \p faceVertex. -std::size_t absoluteIndex( FaceVertexId faceVertex ){ - std::size_t index = 0; - for ( std::size_t i = 0; i < faceVertex.getFace(); ++i ) - { - index += m_faces[i]->getWinding().numpoints; + void appendFaces( const Faces& other ){ + clear(); + for ( Faces::const_iterator i = other.begin(); i != other.end(); ++i ) + { + push_back( *i ); + } } - return index + faceVertex.getVertex(); -} -void appendFaces( const Faces& other ){ - clear(); - for ( Faces::const_iterator i = other.begin(); i != other.end(); ++i ) + /// \brief The undo memento for a brush stores only the list of face references - the faces are not copied. + class BrushUndoMemento : public UndoMemento { - push_back( *i ); + public: + BrushUndoMemento( const Faces& faces ) : m_faces( faces ){ } -} -/// \brief The undo memento for a brush stores only the list of face references - the faces are not copied. -class BrushUndoMemento : public UndoMemento -{ -public: -BrushUndoMemento( const Faces& faces ) : m_faces( faces ){ -} - -void release(){ - delete this; -} - -Faces m_faces; -}; - -void undoSave(){ - if ( m_map != 0 ) { - m_map->changed(); - } - if ( m_undoable_observer != 0 ) { - m_undoable_observer->save( this ); + void release(){ + delete this; } -} -UndoMemento* exportState() const { - return new BrushUndoMemento( m_faces ); -} + Faces m_faces; + }; -void importState( const UndoMemento* state ){ - undoSave(); - appendFaces( static_cast( state )->m_faces ); - planeChanged(); + void undoSave(){ + if ( m_map != 0 ) { + m_map->changed(); + } + if ( m_undoable_observer != 0 ) { + m_undoable_observer->save( this ); + } + } - for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) - { - ( *i )->DEBUG_verify(); + UndoMemento* exportState() const { + return new BrushUndoMemento( m_faces ); } -} -bool isDetail(){ - return !m_faces.empty() && m_faces.front()->isDetail(); -} + void importState( const UndoMemento* state ){ + undoSave(); + appendFaces( static_cast( state )->m_faces ); + planeChanged(); -/// \brief Appends a copy of \p face to the end of the face list. -Face* addFace( const Face& face ){ - if ( m_faces.size() == c_brush_maxFaces ) { - return 0; + for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) + { + ( *i )->DEBUG_verify(); + } } - undoSave(); - push_back( FaceSmartPointer( new Face( face, this ) ) ); - m_faces.back()->setDetail( isDetail() ); - planeChanged(); - return m_faces.back(); -} -/// \brief Appends a new face constructed from the parameters to the end of the face list. -Face* addPlane( const Vector3& p0, const Vector3& p1, const Vector3& p2, const char* shader, const TextureProjection& projection ){ - if ( m_faces.size() == c_brush_maxFaces ) { - return 0; + bool isDetail(){ + return !m_faces.empty() && m_faces.front()->isDetail(); } - undoSave(); - push_back( FaceSmartPointer( new Face( p0, p1, p2, shader, projection, this ) ) ); - m_faces.back()->setDetail( isDetail() ); - planeChanged(); - return m_faces.back(); -} -static void constructStatic( EBrushType type ){ - m_type = type; - Face::m_type = type; - FacePlane::m_type = type; - - g_bp_globals.m_texdefTypeId = TEXDEFTYPEID_QUAKE; - if ( m_type == eBrushTypeQuake3BP || m_type == eBrushTypeDoom3 || m_type == eBrushTypeQuake4 ) { - g_bp_globals.m_texdefTypeId = TEXDEFTYPEID_BRUSHPRIMITIVES; - // g_brush_texturelock_enabled = true; // bad idea, this overrides user setting - } - else if ( m_type == eBrushTypeHalfLife ) { - g_bp_globals.m_texdefTypeId = TEXDEFTYPEID_HALFLIFE; - // g_brush_texturelock_enabled = true; // bad idea, this overrides user setting + /// \brief Appends a copy of \p face to the end of the face list. + Face* addFace( const Face& face ){ + if ( m_faces.size() == c_brush_maxFaces ) { + return 0; + } + undoSave(); + push_back( FaceSmartPointer( new Face( face, this ) ) ); + m_faces.back()->setDetail( isDetail() ); + planeChanged(); + return m_faces.back(); } - Face::m_quantise = ( m_type == eBrushTypeQuake ) ? quantiseInteger : quantiseFloating; - - m_state_point = GlobalShaderCache().capture( "$POINT" ); -} - -static void destroyStatic(){ - GlobalShaderCache().release( "$POINT" ); -} + /// \brief Appends a new face constructed from the parameters to the end of the face list. + Face* addPlane( const Vector3& p0, const Vector3& p1, const Vector3& p2, const char* shader, const TextureProjection& projection ){ + if ( m_faces.size() == c_brush_maxFaces ) { + return 0; + } + undoSave(); + push_back( FaceSmartPointer( new Face( p0, p1, p2, shader, projection, this ) ) ); + m_faces.back()->setDetail( isDetail() ); + planeChanged(); + return m_faces.back(); + } + + static void constructStatic( EBrushType type ){ + m_type = type; + Face::m_type = type; + FacePlane::m_type = type; + + g_bp_globals.m_texdefTypeId = TEXDEFTYPEID_QUAKE; + if ( m_type == eBrushTypeQuake3BP || m_type == eBrushTypeDoom3 || m_type == eBrushTypeQuake4 ) { + g_bp_globals.m_texdefTypeId = TEXDEFTYPEID_BRUSHPRIMITIVES; + // g_brush_texturelock_enabled = true; // bad idea, this overrides user setting + } + else if ( m_type == eBrushTypeHalfLife ) { + g_bp_globals.m_texdefTypeId = TEXDEFTYPEID_HALFLIFE; + // g_brush_texturelock_enabled = true; // bad idea, this overrides user setting + } -std::size_t DEBUG_size(){ - return m_faces.size(); -} + Face::m_quantise = ( m_type == eBrushTypeQuake ) ? quantiseInteger : quantiseFloating; -typedef Faces::const_iterator const_iterator; + m_state_point = GlobalShaderCache().capture( "$POINT" ); + } -const_iterator begin() const { - return m_faces.begin(); -} + static void destroyStatic(){ + GlobalShaderCache().release( "$POINT" ); + } -const_iterator end() const { - return m_faces.end(); -} + std::size_t DEBUG_size(){ + return m_faces.size(); + } -Face* back(){ - return m_faces.back(); -} + typedef Faces::const_iterator const_iterator; -const Face* back() const { - return m_faces.back(); -} + const_iterator begin() const { + return m_faces.begin(); + } -void reserve( std::size_t count ){ - m_faces.reserve( count ); - for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) - { - ( *i )->reserve( count ); + const_iterator end() const { + return m_faces.end(); } -} -void push_back( Faces::value_type face ){ - m_faces.push_back( face ); - if ( m_instanceCounter.m_count != 0 ) { - m_faces.back()->instanceAttach( m_map ); + Face* back(){ + return m_faces.back(); } - for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) - { - ( *i )->push_back( *face ); - ( *i )->DEBUG_verify(); + + const Face* back() const { + return m_faces.back(); } -} -void pop_back(){ - if ( m_instanceCounter.m_count != 0 ) { - m_faces.back()->instanceDetach( m_map ); + void reserve( std::size_t count ){ + m_faces.reserve( count ); + for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) + { + ( *i )->reserve( count ); + } } - m_faces.pop_back(); - for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) - { - ( *i )->pop_back(); - ( *i )->DEBUG_verify(); + + void push_back( Faces::value_type face ){ + m_faces.push_back( face ); + if ( m_instanceCounter.m_count != 0 ) { + m_faces.back()->instanceAttach( m_map ); + } + for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) + { + ( *i )->push_back( *face ); + ( *i )->DEBUG_verify(); + } } -} -void erase( std::size_t index ){ - if ( m_instanceCounter.m_count != 0 ) { - m_faces[index]->instanceDetach( m_map ); + void pop_back(){ + if ( m_instanceCounter.m_count != 0 ) { + m_faces.back()->instanceDetach( m_map ); + } + m_faces.pop_back(); + for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) + { + ( *i )->pop_back(); + ( *i )->DEBUG_verify(); + } } - m_faces.erase( m_faces.begin() + index ); - for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) - { - ( *i )->erase( index ); - ( *i )->DEBUG_verify(); + + void erase( std::size_t index ){ + if ( m_instanceCounter.m_count != 0 ) { + m_faces[index]->instanceDetach( m_map ); + } + m_faces.erase( m_faces.begin() + index ); + for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) + { + ( *i )->erase( index ); + ( *i )->DEBUG_verify(); + } } -} -void connectivityChanged(){ - for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) - { - ( *i )->connectivityChanged(); + void connectivityChanged(){ + for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) + { + ( *i )->connectivityChanged(); + } } -} -void clear(){ - undoSave(); - if ( m_instanceCounter.m_count != 0 ) { - forEachFace_instanceDetach( m_map ); - } - m_faces.clear(); - for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) - { - ( *i )->clear(); - ( *i )->DEBUG_verify(); + void clear(){ + undoSave(); + if ( m_instanceCounter.m_count != 0 ) { + forEachFace_instanceDetach( m_map ); + } + m_faces.clear(); + for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) + { + ( *i )->clear(); + ( *i )->DEBUG_verify(); + } } -} -std::size_t size() const { - return m_faces.size(); -} + std::size_t size() const { + return m_faces.size(); + } -bool empty() const { - return m_faces.empty(); -} + bool empty() const { + return m_faces.empty(); + } -/// \brief Returns true if any face of the brush contributes to the final B-Rep. -bool hasContributingFaces() const { - for ( const_iterator i = begin(); i != end(); ++i ) - { - if ( ( *i )->contributes() ) { - return true; + /// \brief Returns true if any face of the brush contributes to the final B-Rep. + bool hasContributingFaces() const { + for ( const_iterator i = begin(); i != end(); ++i ) + { + if ( ( *i )->contributes() ) { + return true; + } } + return false; } - return false; -} -/// \brief Removes faces that do not contribute to the brush. This is useful for cleaning up after CSG operations on the brush. -/// Note: removal of empty faces is not performed during direct brush manipulations, because it would make a manipulation irreversible if it created an empty face. -void removeEmptyFaces(){ - evaluateBRep(); + /// \brief Removes faces that do not contribute to the brush. This is useful for cleaning up after CSG operations on the brush. + /// Note: removal of empty faces is not performed during direct brush manipulations, because it would make a manipulation irreversible if it created an empty face. + void removeEmptyFaces(){ + evaluateBRep(); - { - std::size_t i = 0; - while ( i < m_faces.size() ) { - if ( !m_faces[i]->contributes() ) { - erase( i ); - planeChanged(); - } - else + std::size_t i = 0; + while ( i < m_faces.size() ) { - ++i; + if ( !m_faces[i]->contributes() ) { + erase( i ); + planeChanged(); + } + else + { + ++i; + } } } } -} -/// \brief Constructs \p winding from the intersection of \p plane with the other planes of the brush. -void windingForClipPlane( Winding& winding, const Plane3& plane ) const { - FixedWinding buffer[2]; - bool swap = false; + /// \brief Constructs \p winding from the intersection of \p plane with the other planes of the brush. + void windingForClipPlane( Winding& winding, const Plane3& plane ) const { + FixedWinding buffer[2]; + bool swap = false; - // get a poly that covers an effectively infinite area - Winding_createInfinite( buffer[swap], plane, m_maxWorldCoord + 1 ); + // get a poly that covers an effectively infinite area + Winding_createInfinite( buffer[swap], plane, m_maxWorldCoord + 1 ); - // chop the poly by all of the other faces - { - for ( std::size_t i = 0; i < m_faces.size(); ++i ) + // chop the poly by all of the other faces { - const Face& clip = *m_faces[i]; + for ( std::size_t i = 0; i < m_faces.size(); ++i ) + { + const Face& clip = *m_faces[i]; - if ( plane3_equal( clip.plane3(), plane ) - || !plane3_valid( clip.plane3() ) || !plane_unique( i ) - || plane3_opposing( plane, clip.plane3() ) ) { - continue; - } + if ( plane3_equal( clip.plane3(), plane ) + || !plane3_valid( clip.plane3() ) || !plane_unique( i ) + || plane3_opposing( plane, clip.plane3() ) ) { + continue; + } - buffer[!swap].clear(); + buffer[!swap].clear(); #if BRUSH_CONNECTIVITY_DEBUG - globalOutputStream() << "clip vs face: " << i << "\n"; + globalOutputStream() << "clip vs face: " << i << "\n"; #endif - { - // flip the plane, because we want to keep the back side - Plane3 clipPlane( vector3_negated( clip.plane3().normal() ), -clip.plane3().dist() ); - Winding_Clip( buffer[swap], plane, clipPlane, i, buffer[!swap] ); - } + { + // flip the plane, because we want to keep the back side + Plane3 clipPlane( vector3_negated( clip.plane3().normal() ), -clip.plane3().dist() ); + Winding_Clip( buffer[swap], plane, clipPlane, i, buffer[!swap] ); + } #if BRUSH_CONNECTIVITY_DEBUG - for ( FixedWinding::Points::iterator k = buffer[!swap].points.begin(), j = buffer[!swap].points.end() - 1; k != buffer[!swap].points.end(); j = k, ++k ) - { - if ( vector3_length_squared( vector3_subtracted( ( *k ).vertex, ( *j ).vertex ) ) < 1 ) { - globalOutputStream() << "v: " << std::distance( buffer[!swap].points.begin(), j ) << " tiny edge adjacent to face " << ( *j ).adjacent << "\n"; + for ( FixedWinding::Points::iterator k = buffer[!swap].points.begin(), j = buffer[!swap].points.end() - 1; k != buffer[!swap].points.end(); j = k, ++k ) + { + if ( vector3_length_squared( vector3_subtracted( ( *k ).vertex, ( *j ).vertex ) ) < 1 ) { + globalOutputStream() << "v: " << std::distance( buffer[!swap].points.begin(), j ) << " tiny edge adjacent to face " << ( *j ).adjacent << "\n"; + } } - } #endif - //ASSERT_MESSAGE(buffer[!swap].numpoints != 1, "created single-point winding"); + //ASSERT_MESSAGE(buffer[!swap].numpoints != 1, "created single-point winding"); - swap = !swap; + swap = !swap; + } } - } - Winding_forFixedWinding( winding, buffer[swap] ); + Winding_forFixedWinding( winding, buffer[swap] ); #if BRUSH_CONNECTIVITY_DEBUG - Winding_printConnectivity( winding ); + Winding_printConnectivity( winding ); - for ( Winding::iterator i = winding.begin(), j = winding.end() - 1; i != winding.end(); j = i, ++i ) - { - if ( vector3_length_squared( vector3_subtracted( ( *i ).vertex, ( *j ).vertex ) ) < 1 ) { - globalOutputStream() << "v: " << std::distance( winding.begin(), j ) << " tiny edge adjacent to face " << ( *j ).adjacent << "\n"; + for ( Winding::iterator i = winding.begin(), j = winding.end() - 1; i != winding.end(); j = i, ++i ) + { + if ( vector3_length_squared( vector3_subtracted( ( *i ).vertex, ( *j ).vertex ) ) < 1 ) { + globalOutputStream() << "v: " << std::distance( winding.begin(), j ) << " tiny edge adjacent to face " << ( *j ).adjacent << "\n"; + } } - } #endif -} + } -void update_wireframe( RenderableWireframe& wire, const bool* faces_visible ) const { - wire.m_faceVertex.resize( m_edge_indices.size() ); - wire.m_vertices = m_uniqueVertexPoints.data(); - wire.m_size = 0; - for ( std::size_t i = 0; i < m_edge_faces.size(); ++i ) - { - if ( faces_visible[m_edge_faces[i].first] - || faces_visible[m_edge_faces[i].second] ) { - wire.m_faceVertex[wire.m_size++] = m_edge_indices[i]; + void update_wireframe( RenderableWireframe& wire, const bool* faces_visible ) const { + wire.m_faceVertex.resize( m_edge_indices.size() ); + wire.m_vertices = m_uniqueVertexPoints.data(); + wire.m_size = 0; + for ( std::size_t i = 0; i < m_edge_faces.size(); ++i ) + { + if ( faces_visible[m_edge_faces[i].first] + || faces_visible[m_edge_faces[i].second] ) { + wire.m_faceVertex[wire.m_size++] = m_edge_indices[i]; + } } } -} -void update_faces_wireframe( Array& wire, const bool* faces_visible ) const { - std::size_t count = 0; - for ( std::size_t i = 0; i < m_faceCentroidPoints.size(); ++i ) - { - if ( faces_visible[i] ) { - ++count; + void update_faces_wireframe( Array& wire, const bool* faces_visible ) const { + std::size_t count = 0; + for ( std::size_t i = 0; i < m_faceCentroidPoints.size(); ++i ) + { + if ( faces_visible[i] ) { + ++count; + } } - } - wire.resize( count ); - Array::iterator p = wire.begin(); - for ( std::size_t i = 0; i < m_faceCentroidPoints.size(); ++i ) - { - if ( faces_visible[i] ) { - *p++ = m_faceCentroidPoints[i]; + wire.resize( count ); + Array::iterator p = wire.begin(); + for ( std::size_t i = 0; i < m_faceCentroidPoints.size(); ++i ) + { + if ( faces_visible[i] ) { + *p++ = m_faceCentroidPoints[i]; + } } } -} -/// \brief Makes this brush a deep-copy of the \p other. -void copy( const Brush& other ){ - for ( Faces::const_iterator i = other.m_faces.begin(); i != other.m_faces.end(); ++i ) - { - addFace( *( *i ) ); + /// \brief Makes this brush a deep-copy of the \p other. + void copy( const Brush& other ){ + for ( Faces::const_iterator i = other.m_faces.begin(); i != other.m_faces.end(); ++i ) + { + addFace( *( *i ) ); + } + planeChanged(); } - planeChanged(); -} -private: -void edge_push_back( FaceVertexId faceVertex ){ - m_select_edges.push_back( SelectableEdge( m_faces, faceVertex ) ); - for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) - { - ( *i )->edge_push_back( m_select_edges.back() ); + private: + void edge_push_back( FaceVertexId faceVertex ){ + m_select_edges.push_back( SelectableEdge( m_faces, faceVertex ) ); + for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) + { + ( *i )->edge_push_back( m_select_edges.back() ); + } } -} -void edge_clear(){ - m_select_edges.clear(); - for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) - { - ( *i )->edge_clear(); + void edge_clear(){ + m_select_edges.clear(); + for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) + { + ( *i )->edge_clear(); + } } -} -void vertex_push_back( FaceVertexId faceVertex ){ - m_select_vertices.push_back( SelectableVertex( m_faces, faceVertex ) ); - for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) - { - ( *i )->vertex_push_back( m_select_vertices.back() ); + void vertex_push_back( FaceVertexId faceVertex ){ + m_select_vertices.push_back( SelectableVertex( m_faces, faceVertex ) ); + for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) + { + ( *i )->vertex_push_back( m_select_vertices.back() ); + } } -} -void vertex_clear(){ - m_select_vertices.clear(); - for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) - { - ( *i )->vertex_clear(); + void vertex_clear(){ + m_select_vertices.clear(); + for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i ) + { + ( *i )->vertex_clear(); + } } -} -/// \brief Returns true if the face identified by \p index is preceded by another plane that takes priority over it. -bool plane_unique( std::size_t index ) const { - // duplicate plane - for ( std::size_t i = 0; i < m_faces.size(); ++i ) - { - if ( index != i && !plane3_inside( m_faces[index]->plane3(), m_faces[i]->plane3(), index < i ) ) { - return false; + /// \brief Returns true if the face identified by \p index is preceded by another plane that takes priority over it. + bool plane_unique( std::size_t index ) const { + // duplicate plane + for ( std::size_t i = 0; i < m_faces.size(); ++i ) + { + if ( index != i && !plane3_inside( m_faces[index]->plane3(), m_faces[i]->plane3(), index < i ) ) { + return false; + } } + return true; } - return true; -} -/// \brief Removes edges that are smaller than the tolerance used when generating brush windings. -void removeDegenerateEdges(){ - for ( std::size_t i = 0; i < m_faces.size(); ++i ) - { - Winding& winding = m_faces[i]->getWinding(); - for ( Winding::iterator j = winding.begin(); j != winding.end(); ) + /// \brief Removes edges that are smaller than the tolerance used when generating brush windings. + void removeDegenerateEdges(){ + for ( std::size_t i = 0; i < m_faces.size(); ++i ) { - std::size_t index = std::distance( winding.begin(), j ); - std::size_t next = Winding_next( winding, index ); - if ( Edge_isDegenerate( winding[index].vertex, winding[next].vertex ) ) { + Winding& winding = m_faces[i]->getWinding(); + for ( Winding::iterator j = winding.begin(); j != winding.end(); ) + { + std::size_t index = std::distance( winding.begin(), j ); + std::size_t next = Winding_next( winding, index ); + if ( Edge_isDegenerate( winding[index].vertex, winding[next].vertex ) ) { #if BRUSH_DEGENERATE_DEBUG - globalOutputStream() << "Brush::buildWindings: face " << i << ": degenerate edge adjacent to " << winding[index].adjacent << "\n"; + globalOutputStream() << "Brush::buildWindings: face " << i << ": degenerate edge adjacent to " << winding[index].adjacent << "\n"; #endif - Winding& other = m_faces[winding[index].adjacent]->getWinding(); - std::size_t adjacent = Winding_FindAdjacent( other, i ); - if ( adjacent != c_brush_maxFaces ) { - other.erase( other.begin() + adjacent ); + Winding& other = m_faces[winding[index].adjacent]->getWinding(); + std::size_t adjacent = Winding_FindAdjacent( other, i ); + if ( adjacent != c_brush_maxFaces ) { + other.erase( other.begin() + adjacent ); + } + winding.erase( j ); + } + else + { + ++j; } - winding.erase( j ); - } - else - { - ++j; } } } -} -/// \brief Invalidates faces that have only two vertices in their winding, while preserving edge-connectivity information. -void removeDegenerateFaces(){ - // save adjacency info for degenerate faces - for ( std::size_t i = 0; i < m_faces.size(); ++i ) - { - Winding& degen = m_faces[i]->getWinding(); + /// \brief Invalidates faces that have only two vertices in their winding, while preserving edge-connectivity information. + void removeDegenerateFaces(){ + // save adjacency info for degenerate faces + for ( std::size_t i = 0; i < m_faces.size(); ++i ) + { + Winding& degen = m_faces[i]->getWinding(); - if ( degen.numpoints == 2 ) { + if ( degen.numpoints == 2 ) { #if BRUSH_DEGENERATE_DEBUG - globalOutputStream() << "Brush::buildWindings: face " << i << ": degenerate winding adjacent to " << degen[0].adjacent << ", " << degen[1].adjacent << "\n"; + globalOutputStream() << "Brush::buildWindings: face " << i << ": degenerate winding adjacent to " << degen[0].adjacent << ", " << degen[1].adjacent << "\n"; #endif - // this is an "edge" face, where the plane touches the edge of the brush - { - Winding& winding = m_faces[degen[0].adjacent]->getWinding(); - std::size_t index = Winding_FindAdjacent( winding, i ); - if ( index != c_brush_maxFaces ) { + // this is an "edge" face, where the plane touches the edge of the brush + { + Winding& winding = m_faces[degen[0].adjacent]->getWinding(); + std::size_t index = Winding_FindAdjacent( winding, i ); + if ( index != c_brush_maxFaces ) { #if BRUSH_DEGENERATE_DEBUG - globalOutputStream() << "Brush::buildWindings: face " << degen[0].adjacent << ": remapping adjacent " << winding[index].adjacent << " to " << degen[1].adjacent << "\n"; + globalOutputStream() << "Brush::buildWindings: face " << degen[0].adjacent << ": remapping adjacent " << winding[index].adjacent << " to " << degen[1].adjacent << "\n"; #endif - winding[index].adjacent = degen[1].adjacent; + winding[index].adjacent = degen[1].adjacent; + } } - } - { - Winding& winding = m_faces[degen[1].adjacent]->getWinding(); - std::size_t index = Winding_FindAdjacent( winding, i ); - if ( index != c_brush_maxFaces ) { + { + Winding& winding = m_faces[degen[1].adjacent]->getWinding(); + std::size_t index = Winding_FindAdjacent( winding, i ); + if ( index != c_brush_maxFaces ) { #if BRUSH_DEGENERATE_DEBUG - globalOutputStream() << "Brush::buildWindings: face " << degen[1].adjacent << ": remapping adjacent " << winding[index].adjacent << " to " << degen[0].adjacent << "\n"; + globalOutputStream() << "Brush::buildWindings: face " << degen[1].adjacent << ": remapping adjacent " << winding[index].adjacent << " to " << degen[0].adjacent << "\n"; #endif - winding[index].adjacent = degen[0].adjacent; + winding[index].adjacent = degen[0].adjacent; + } } - } - degen.resize( 0 ); + degen.resize( 0 ); + } } } -} -/// \brief Removes edges that have the same adjacent-face as their immediate neighbour. -void removeDuplicateEdges(){ - // verify face connectivity graph - for ( std::size_t i = 0; i < m_faces.size(); ++i ) - { - //if(m_faces[i]->contributes()) + /// \brief Removes edges that have the same adjacent-face as their immediate neighbour. + void removeDuplicateEdges(){ + // verify face connectivity graph + for ( std::size_t i = 0; i < m_faces.size(); ++i ) { - Winding& winding = m_faces[i]->getWinding(); - for ( std::size_t j = 0; j != winding.numpoints; ) + //if(m_faces[i]->contributes()) { - std::size_t next = Winding_next( winding, j ); - if ( winding[j].adjacent == winding[next].adjacent ) { + Winding& winding = m_faces[i]->getWinding(); + for ( std::size_t j = 0; j != winding.numpoints; ) + { + std::size_t next = Winding_next( winding, j ); + if ( winding[j].adjacent == winding[next].adjacent ) { #if BRUSH_DEGENERATE_DEBUG - globalOutputStream() << "Brush::buildWindings: face " << i << ": removed duplicate edge adjacent to face " << winding[j].adjacent << "\n"; + globalOutputStream() << "Brush::buildWindings: face " << i << ": removed duplicate edge adjacent to face " << winding[j].adjacent << "\n"; #endif - winding.erase( winding.begin() + next ); - } - else - { - ++j; + winding.erase( winding.begin() + next ); + } + else + { + ++j; + } } } } } -} -/// \brief Removes edges that do not have a matching pair in their adjacent-face. -void verifyConnectivityGraph(){ - // verify face connectivity graph - for ( std::size_t i = 0; i < m_faces.size(); ++i ) - { - //if(m_faces[i]->contributes()) + /// \brief Removes edges that do not have a matching pair in their adjacent-face. + void verifyConnectivityGraph(){ + // verify face connectivity graph + for ( std::size_t i = 0; i < m_faces.size(); ++i ) { - Winding& winding = m_faces[i]->getWinding(); - for ( Winding::iterator j = winding.begin(); j != winding.end(); ) + //if(m_faces[i]->contributes()) { + Winding& winding = m_faces[i]->getWinding(); + for ( Winding::iterator j = winding.begin(); j != winding.end(); ) + { #if BRUSH_CONNECTIVITY_DEBUG - globalOutputStream() << "Brush::buildWindings: face " << i << ": adjacent to face " << ( *j ).adjacent << "\n"; + globalOutputStream() << "Brush::buildWindings: face " << i << ": adjacent to face " << ( *j ).adjacent << "\n"; #endif - // remove unidirectional graph edges - if ( ( *j ).adjacent == c_brush_maxFaces - || Winding_FindAdjacent( m_faces[( *j ).adjacent]->getWinding(), i ) == c_brush_maxFaces ) { + // remove unidirectional graph edges + if ( ( *j ).adjacent == c_brush_maxFaces + || Winding_FindAdjacent( m_faces[( *j ).adjacent]->getWinding(), i ) == c_brush_maxFaces ) { #if BRUSH_CONNECTIVITY_DEBUG - globalOutputStream() << "Brush::buildWindings: face " << i << ": removing unidirectional connectivity graph edge adjacent to face " << ( *j ).adjacent << "\n"; + globalOutputStream() << "Brush::buildWindings: face " << i << ": removing unidirectional connectivity graph edge adjacent to face " << ( *j ).adjacent << "\n"; #endif - winding.erase( j ); - } - else - { - ++j; + winding.erase( j ); + } + else + { + ++j; + } } } } } -} -/// \brief Returns true if the brush is a finite volume. A brush without a finite volume extends past the maximum world bounds and is not valid. -bool isBounded(){ - for ( const_iterator i = begin(); i != end(); ++i ) - { - if ( !( *i )->is_bounded() ) { - return false; + /// \brief Returns true if the brush is a finite volume. A brush without a finite volume extends past the maximum world bounds and is not valid. + bool isBounded(){ + for ( const_iterator i = begin(); i != end(); ++i ) + { + if ( !( *i )->is_bounded() ) { + return false; + } } + return true; } - return true; -} - -/// \brief Constructs the polygon windings for each face of the brush. Also updates the brush bounding-box and face texture-coordinates. -bool buildWindings(){ - { - m_aabb_local = AABB(); + /// \brief Constructs the polygon windings for each face of the brush. Also updates the brush bounding-box and face texture-coordinates. + bool buildWindings(){ - for ( std::size_t i = 0; i < m_faces.size(); ++i ) { - Face& f = *m_faces[i]; + m_aabb_local = AABB(); - if ( !plane3_valid( f.plane3() ) || !plane_unique( i ) ) { - f.getWinding().resize( 0 ); - } - else + for ( std::size_t i = 0; i < m_faces.size(); ++i ) { + Face& f = *m_faces[i]; + + if ( !plane3_valid( f.plane3() ) || !plane_unique( i ) ) { + f.getWinding().resize( 0 ); + } + else + { #if BRUSH_CONNECTIVITY_DEBUG - globalOutputStream() << "face: " << i << "\n"; + globalOutputStream() << "face: " << i << "\n"; #endif - windingForClipPlane( f.getWinding(), f.plane3() ); + windingForClipPlane( f.getWinding(), f.plane3() ); - // update brush bounds - const Winding& winding = f.getWinding(); - for ( Winding::const_iterator i = winding.begin(); i != winding.end(); ++i ) - { - aabb_extend_by_point_safe( m_aabb_local, ( *i ).vertex ); - } + // update brush bounds + const Winding& winding = f.getWinding(); + for ( Winding::const_iterator i = winding.begin(); i != winding.end(); ++i ) + { + aabb_extend_by_point_safe( m_aabb_local, ( *i ).vertex ); + } - // update texture coordinates - f.EmitTextureCoordinates(); + // update texture coordinates + f.EmitTextureCoordinates(); + } } } - } - bool degenerate = !isBounded(); + bool degenerate = !isBounded(); - if ( !degenerate ) { - // clean up connectivity information. - // these cleanups must be applied in a specific order. - removeDegenerateEdges(); - removeDegenerateFaces(); - removeDuplicateEdges(); - verifyConnectivityGraph(); - } + if ( !degenerate ) { + // clean up connectivity information. + // these cleanups must be applied in a specific order. + removeDegenerateEdges(); + removeDegenerateFaces(); + removeDuplicateEdges(); + verifyConnectivityGraph(); + } - return degenerate; -} + return degenerate; + } -/// \brief Constructs the face windings and updates anything that depends on them. -void buildBRep(); + /// \brief Constructs the face windings and updates anything that depends on them. + void buildBRep(); }; @@ -2412,32 +2398,32 @@ class FaceInstance; class FaceInstanceSet { -typedef SelectionList FaceInstances; -FaceInstances m_faceInstances; + typedef SelectionList FaceInstances; + FaceInstances m_faceInstances; public: -void insert( FaceInstance& faceInstance ){ - m_faceInstances.append( faceInstance ); -} + void insert( FaceInstance& faceInstance ){ + m_faceInstances.append( faceInstance ); + } -void erase( FaceInstance& faceInstance ){ - m_faceInstances.erase( faceInstance ); -} + void erase( FaceInstance& faceInstance ){ + m_faceInstances.erase( faceInstance ); + } -template -void foreach( Functor functor ){ - for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - functor( *( *i ) ); + template + void foreach( Functor functor ){ + for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + functor( *( *i ) ); + } } -} -bool empty() const { - return m_faceInstances.empty(); -} + bool empty() const { + return m_faceInstances.empty(); + } -FaceInstance& last() const { - return m_faceInstances.back(); -} + FaceInstance& last() const { + return m_faceInstances.back(); + } }; extern FaceInstanceSet g_SelectedFaceInstances; @@ -2488,498 +2474,498 @@ typedef PlanePointer* PlanesIterator; class VectorLightList : public LightList { -typedef std::vector Lights; -Lights m_lights; + typedef std::vector Lights; + Lights m_lights; public: -void addLight( const RendererLight& light ){ - m_lights.push_back( &light ); -} + void addLight( const RendererLight& light ){ + m_lights.push_back( &light ); + } -void clear(){ - m_lights.clear(); -} + void clear(){ + m_lights.clear(); + } -void evaluateLights() const { -} + void evaluateLights() const { + } -void lightsChanged() const { -} + void lightsChanged() const { + } -void forEachLight( const RendererLightCallback& callback ) const { - for ( Lights::const_iterator i = m_lights.begin(); i != m_lights.end(); ++i ) - { - callback( *( *i ) ); + void forEachLight( const RendererLightCallback& callback ) const { + for ( Lights::const_iterator i = m_lights.begin(); i != m_lights.end(); ++i ) + { + callback( *( *i ) ); + } } -} }; class FaceInstance { -Face* m_face; -ObservedSelectable m_selectable; -ObservedSelectable m_selectableVertices; -ObservedSelectable m_selectableEdges; -SelectionChangeCallback m_selectionChanged; + Face* m_face; + ObservedSelectable m_selectable; + ObservedSelectable m_selectableVertices; + ObservedSelectable m_selectableEdges; + SelectionChangeCallback m_selectionChanged; -VertexSelection m_vertexSelection; -VertexSelection m_edgeSelection; + VertexSelection m_vertexSelection; + VertexSelection m_edgeSelection; public: -mutable VectorLightList m_lights; - -FaceInstance( Face& face, const SelectionChangeCallback& observer ) : - m_face( &face ), - m_selectable( SelectedChangedCaller( *this ) ), - m_selectableVertices( observer ), - m_selectableEdges( observer ), - m_selectionChanged( observer ){ -} - -FaceInstance( const FaceInstance& other ) : - m_face( other.m_face ), - m_selectable( SelectedChangedCaller( *this ) ), - m_selectableVertices( other.m_selectableVertices ), - m_selectableEdges( other.m_selectableEdges ), - m_selectionChanged( other.m_selectionChanged ){ -} - -FaceInstance& operator=( const FaceInstance& other ){ - m_face = other.m_face; - return *this; -} - -Face& getFace(){ - return *m_face; -} + mutable VectorLightList m_lights; -const Face& getFace() const { - return *m_face; -} + FaceInstance( Face& face, const SelectionChangeCallback& observer ) : + m_face( &face ), + m_selectable( SelectedChangedCaller( *this ) ), + m_selectableVertices( observer ), + m_selectableEdges( observer ), + m_selectionChanged( observer ){ + } -void selectedChanged( const Selectable& selectable ){ - if ( selectable.isSelected() ) { - g_SelectedFaceInstances.insert( *this ); + FaceInstance( const FaceInstance& other ) : + m_face( other.m_face ), + m_selectable( SelectedChangedCaller( *this ) ), + m_selectableVertices( other.m_selectableVertices ), + m_selectableEdges( other.m_selectableEdges ), + m_selectionChanged( other.m_selectionChanged ){ } - else - { - g_SelectedFaceInstances.erase( *this ); + + FaceInstance& operator=( const FaceInstance& other ){ + m_face = other.m_face; + return *this; } - m_selectionChanged( selectable ); -} -typedef MemberCaller SelectedChangedCaller; + Face& getFace(){ + return *m_face; + } -bool selectedVertices() const { - return !m_vertexSelection.empty(); -} + const Face& getFace() const { + return *m_face; + } -bool selectedEdges() const { - return !m_edgeSelection.empty(); -} + void selectedChanged( const Selectable& selectable ){ + if ( selectable.isSelected() ) { + g_SelectedFaceInstances.insert( *this ); + } + else + { + g_SelectedFaceInstances.erase( *this ); + } + m_selectionChanged( selectable ); + } -bool isSelected() const { - return m_selectable.isSelected(); -} + typedef MemberCaller SelectedChangedCaller; -bool selectedComponents() const { - return selectedVertices() || selectedEdges() || isSelected(); -} + bool selectedVertices() const { + return !m_vertexSelection.empty(); + } -bool selectedComponents( SelectionSystem::EComponentMode mode ) const { - switch ( mode ) - { - case SelectionSystem::eVertex: - return selectedVertices(); - case SelectionSystem::eEdge: - return selectedEdges(); - case SelectionSystem::eFace: - return isSelected(); - default: - return false; + bool selectedEdges() const { + return !m_edgeSelection.empty(); } -} -void setSelected( SelectionSystem::EComponentMode mode, bool select ){ - switch ( mode ) - { - case SelectionSystem::eFace: - m_selectable.setSelected( select ); - break; - case SelectionSystem::eVertex: - ASSERT_MESSAGE( !select, "select-all not supported" ); + bool isSelected() const { + return m_selectable.isSelected(); + } - m_vertexSelection.clear(); - m_selectableVertices.setSelected( false ); - break; - case SelectionSystem::eEdge: - ASSERT_MESSAGE( !select, "select-all not supported" ); + bool selectedComponents() const { + return selectedVertices() || selectedEdges() || isSelected(); + } - m_edgeSelection.clear(); - m_selectableEdges.setSelected( false ); - break; - default: - break; + bool selectedComponents( SelectionSystem::EComponentMode mode ) const { + switch ( mode ) + { + case SelectionSystem::eVertex: + return selectedVertices(); + case SelectionSystem::eEdge: + return selectedEdges(); + case SelectionSystem::eFace: + return isSelected(); + default: + return false; + } } -} -template -void SelectedVertices_foreach( Functor functor ) const { - for ( VertexSelection::const_iterator i = m_vertexSelection.begin(); i != m_vertexSelection.end(); ++i ) - { - std::size_t index = Winding_FindAdjacent( getFace().getWinding(), *i ); - if ( index != c_brush_maxFaces ) { - functor( getFace().getWinding()[index].vertex ); + void setSelected( SelectionSystem::EComponentMode mode, bool select ){ + switch ( mode ) + { + case SelectionSystem::eFace: + m_selectable.setSelected( select ); + break; + case SelectionSystem::eVertex: + ASSERT_MESSAGE( !select, "select-all not supported" ); + + m_vertexSelection.clear(); + m_selectableVertices.setSelected( false ); + break; + case SelectionSystem::eEdge: + ASSERT_MESSAGE( !select, "select-all not supported" ); + + m_edgeSelection.clear(); + m_selectableEdges.setSelected( false ); + break; + default: + break; } } -} -template -void SelectedEdges_foreach( Functor functor ) const { - for ( VertexSelection::const_iterator i = m_edgeSelection.begin(); i != m_edgeSelection.end(); ++i ) - { - std::size_t index = Winding_FindAdjacent( getFace().getWinding(), *i ); - if ( index != c_brush_maxFaces ) { - const Winding& winding = getFace().getWinding(); - std::size_t adjacent = Winding_next( winding, index ); - functor( vector3_mid( winding[index].vertex, winding[adjacent].vertex ) ); + template + void SelectedVertices_foreach( Functor functor ) const { + for ( VertexSelection::const_iterator i = m_vertexSelection.begin(); i != m_vertexSelection.end(); ++i ) + { + std::size_t index = Winding_FindAdjacent( getFace().getWinding(), *i ); + if ( index != c_brush_maxFaces ) { + functor( getFace().getWinding()[index].vertex ); + } } } -} -template -void SelectedFaces_foreach( Functor functor ) const { - if ( isSelected() ) { - functor( centroid() ); + template + void SelectedEdges_foreach( Functor functor ) const { + for ( VertexSelection::const_iterator i = m_edgeSelection.begin(); i != m_edgeSelection.end(); ++i ) + { + std::size_t index = Winding_FindAdjacent( getFace().getWinding(), *i ); + if ( index != c_brush_maxFaces ) { + const Winding& winding = getFace().getWinding(); + std::size_t adjacent = Winding_next( winding, index ); + functor( vector3_mid( winding[index].vertex, winding[adjacent].vertex ) ); + } + } } -} -template -void SelectedComponents_foreach( Functor functor ) const { - SelectedVertices_foreach( functor ); - SelectedEdges_foreach( functor ); - SelectedFaces_foreach( functor ); -} + template + void SelectedFaces_foreach( Functor functor ) const { + if ( isSelected() ) { + functor( centroid() ); + } + } -void iterate_selected( AABB& aabb ) const { - SelectedComponents_foreach([&](const Vector3 &point) { - aabb_extend_by_point_safe(aabb, point); - }); -} + template + void SelectedComponents_foreach( Functor functor ) const { + SelectedVertices_foreach( functor ); + SelectedEdges_foreach( functor ); + SelectedFaces_foreach( functor ); + } -void iterate_selected( RenderablePointVector& points ) const { - SelectedComponents_foreach([&](const Vector3 &point) { - const Colour4b colour_selected(0, 0, 255, 255); - points.push_back(pointvertex_for_windingpoint(point, colour_selected)); - }); -} + void iterate_selected( AABB& aabb ) const { + SelectedComponents_foreach([&](const Vector3 &point) { + aabb_extend_by_point_safe(aabb, point); + }); + } -bool intersectVolume( const VolumeTest& volume, const Matrix4& localToWorld ) const { - return m_face->intersectVolume( volume, localToWorld ); -} + void iterate_selected( RenderablePointVector& points ) const { + SelectedComponents_foreach([&](const Vector3 &point) { + const Colour4b colour_selected(0, 0, 255, 255); + points.push_back(pointvertex_for_windingpoint(point, colour_selected)); + }); + } -void render( Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld ) const { - if ( !m_face->isFiltered() && m_face->contributes() && intersectVolume( volume, localToWorld ) ) { - renderer.PushState(); - if ( selectedComponents() ) { - renderer.Highlight( Renderer::eFace ); - } - m_face->render( renderer, localToWorld ); - renderer.PopState(); + bool intersectVolume( const VolumeTest& volume, const Matrix4& localToWorld ) const { + return m_face->intersectVolume( volume, localToWorld ); } -} -void testSelect( SelectionTest& test, SelectionIntersection& best ){ - if ( !m_face->isFiltered() ) { - m_face->testSelect( test, best ); + void render( Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld ) const { + if ( !m_face->isFiltered() && m_face->contributes() && intersectVolume( volume, localToWorld ) ) { + renderer.PushState(); + if ( selectedComponents() ) { + renderer.Highlight( Renderer::eFace ); + } + m_face->render( renderer, localToWorld ); + renderer.PopState(); + } } -} -void testSelect( Selector& selector, SelectionTest& test ){ - SelectionIntersection best; - testSelect( test, best ); - if ( best.valid() ) { - Selector_add( selector, m_selectable, best ); + void testSelect( SelectionTest& test, SelectionIntersection& best ){ + if ( !m_face->isFiltered() ) { + m_face->testSelect( test, best ); + } } -} -void testSelect_centroid( Selector& selector, SelectionTest& test ){ - if ( m_face->contributes() && !m_face->isFiltered() ) { + void testSelect( Selector& selector, SelectionTest& test ){ SelectionIntersection best; - m_face->testSelect_centroid( test, best ); + testSelect( test, best ); if ( best.valid() ) { Selector_add( selector, m_selectable, best ); } } -} -void selectPlane( Selector& selector, const Line& line, PlanesIterator first, PlanesIterator last, const PlaneCallback& selectedPlaneCallback ){ - for ( Winding::const_iterator i = getFace().getWinding().begin(); i != getFace().getWinding().end(); ++i ) - { - Vector3 v( vector3_subtracted( line_closest_point( line, ( *i ).vertex ), ( *i ).vertex ) ); - double dot = vector3_dot( getFace().plane3().normal(), v ); - if ( dot <= 0 ) { - return; + void testSelect_centroid( Selector& selector, SelectionTest& test ){ + if ( m_face->contributes() && !m_face->isFiltered() ) { + SelectionIntersection best; + m_face->testSelect_centroid( test, best ); + if ( best.valid() ) { + Selector_add( selector, m_selectable, best ); + } } } - Selector_add( selector, m_selectable ); - - selectedPlaneCallback( getFace().plane3() ); -} + void selectPlane( Selector& selector, const Line& line, PlanesIterator first, PlanesIterator last, const PlaneCallback& selectedPlaneCallback ){ + for ( Winding::const_iterator i = getFace().getWinding().begin(); i != getFace().getWinding().end(); ++i ) + { + Vector3 v( vector3_subtracted( line_closest_point( line, ( *i ).vertex ), ( *i ).vertex ) ); + double dot = vector3_dot( getFace().plane3().normal(), v ); + if ( dot <= 0 ) { + return; + } + } -void selectReversedPlane( Selector& selector, const SelectedPlanes& selectedPlanes ){ - if ( selectedPlanes.contains( plane3_flipped( getFace().plane3() ) ) ) { Selector_add( selector, m_selectable ); + + selectedPlaneCallback( getFace().plane3() ); } -} -void transformComponents( const Matrix4& matrix ){ - if ( isSelected() ) { - m_face->transform( matrix, false ); + void selectReversedPlane( Selector& selector, const SelectedPlanes& selectedPlanes ){ + if ( selectedPlanes.contains( plane3_flipped( getFace().plane3() ) ) ) { + Selector_add( selector, m_selectable ); + } } - if ( selectedVertices() ) { - if ( m_vertexSelection.size() == 1 ) { - matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[1] ); - m_face->assign_planepts( m_face->m_move_planeptsTransformed ); + + void transformComponents( const Matrix4& matrix ){ + if ( isSelected() ) { + m_face->transform( matrix, false ); } - else if ( m_vertexSelection.size() == 2 ) { - matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[1] ); - matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[2] ); - m_face->assign_planepts( m_face->m_move_planeptsTransformed ); + if ( selectedVertices() ) { + if ( m_vertexSelection.size() == 1 ) { + matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[1] ); + m_face->assign_planepts( m_face->m_move_planeptsTransformed ); + } + else if ( m_vertexSelection.size() == 2 ) { + matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[1] ); + matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[2] ); + m_face->assign_planepts( m_face->m_move_planeptsTransformed ); + } + else if ( m_vertexSelection.size() >= 3 ) { + matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[0] ); + matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[1] ); + matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[2] ); + m_face->assign_planepts( m_face->m_move_planeptsTransformed ); + } } - else if ( m_vertexSelection.size() >= 3 ) { - matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[0] ); - matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[1] ); - matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[2] ); - m_face->assign_planepts( m_face->m_move_planeptsTransformed ); + if ( selectedEdges() ) { + if ( m_edgeSelection.size() == 1 ) { + matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[0] ); + matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[1] ); + m_face->assign_planepts( m_face->m_move_planeptsTransformed ); + } + else if ( m_edgeSelection.size() >= 2 ) { + matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[0] ); + matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[1] ); + matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[2] ); + m_face->assign_planepts( m_face->m_move_planeptsTransformed ); + } } } - if ( selectedEdges() ) { - if ( m_edgeSelection.size() == 1 ) { - matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[0] ); - matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[1] ); - m_face->assign_planepts( m_face->m_move_planeptsTransformed ); + + void snapto( float snap ){ + m_face->snapto( snap ); + } + + void snapComponents( float snap ){ + if ( isSelected() ) { + snapto( snap ); + } + if ( selectedVertices() ) { + vector3_snap( m_face->m_move_planepts[0], snap ); + vector3_snap( m_face->m_move_planepts[1], snap ); + vector3_snap( m_face->m_move_planepts[2], snap ); + m_face->assign_planepts( m_face->m_move_planepts ); + planepts_assign( m_face->m_move_planeptsTransformed, m_face->m_move_planepts ); + m_face->freezeTransform(); } - else if ( m_edgeSelection.size() >= 2 ) { - matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[0] ); - matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[1] ); - matrix4_transform_point( matrix, m_face->m_move_planeptsTransformed[2] ); - m_face->assign_planepts( m_face->m_move_planeptsTransformed ); + if ( selectedEdges() ) { + vector3_snap( m_face->m_move_planepts[0], snap ); + vector3_snap( m_face->m_move_planepts[1], snap ); + vector3_snap( m_face->m_move_planepts[2], snap ); + m_face->assign_planepts( m_face->m_move_planepts ); + planepts_assign( m_face->m_move_planeptsTransformed, m_face->m_move_planepts ); + m_face->freezeTransform(); } } -} - -void snapto( float snap ){ - m_face->snapto( snap ); -} -void snapComponents( float snap ){ - if ( isSelected() ) { - snapto( snap ); - } - if ( selectedVertices() ) { - vector3_snap( m_face->m_move_planepts[0], snap ); - vector3_snap( m_face->m_move_planepts[1], snap ); - vector3_snap( m_face->m_move_planepts[2], snap ); - m_face->assign_planepts( m_face->m_move_planepts ); - planepts_assign( m_face->m_move_planeptsTransformed, m_face->m_move_planepts ); - m_face->freezeTransform(); - } - if ( selectedEdges() ) { - vector3_snap( m_face->m_move_planepts[0], snap ); - vector3_snap( m_face->m_move_planepts[1], snap ); - vector3_snap( m_face->m_move_planepts[2], snap ); - m_face->assign_planepts( m_face->m_move_planepts ); - planepts_assign( m_face->m_move_planeptsTransformed, m_face->m_move_planepts ); - m_face->freezeTransform(); + void update_move_planepts_vertex( std::size_t index ){ + m_face->update_move_planepts_vertex( index, m_face->m_move_planepts ); } -} - -void update_move_planepts_vertex( std::size_t index ){ - m_face->update_move_planepts_vertex( index, m_face->m_move_planepts ); -} - -void update_move_planepts_vertex2( std::size_t index, std::size_t other ){ - const std::size_t numpoints = m_face->getWinding().numpoints; - ASSERT_MESSAGE( index < numpoints, "select_vertex: invalid index" ); - const std::size_t opposite = Winding_Opposite( m_face->getWinding(), index, other ); + void update_move_planepts_vertex2( std::size_t index, std::size_t other ){ + const std::size_t numpoints = m_face->getWinding().numpoints; + ASSERT_MESSAGE( index < numpoints, "select_vertex: invalid index" ); - if ( triangle_reversed( index, other, opposite ) ) { - std::swap( index, other ); - } - - ASSERT_MESSAGE( - triangles_same_winding( - m_face->getWinding()[opposite].vertex, - m_face->getWinding()[index].vertex, - m_face->getWinding()[other].vertex, - m_face->getWinding()[0].vertex, - m_face->getWinding()[1].vertex, - m_face->getWinding()[2].vertex - ), - "update_move_planepts_vertex2: error" - ); + const std::size_t opposite = Winding_Opposite( m_face->getWinding(), index, other ); - m_face->m_move_planepts[0] = m_face->getWinding()[opposite].vertex; - m_face->m_move_planepts[1] = m_face->getWinding()[index].vertex; - m_face->m_move_planepts[2] = m_face->getWinding()[other].vertex; - planepts_quantise( m_face->m_move_planepts, GRID_MIN ); // winding points are very inaccurate -} + if ( triangle_reversed( index, other, opposite ) ) { + std::swap( index, other ); + } -void update_selection_vertex(){ - if ( m_vertexSelection.size() == 0 ) { - m_selectableVertices.setSelected( false ); - } - else - { - m_selectableVertices.setSelected( true ); + ASSERT_MESSAGE( + triangles_same_winding( + m_face->getWinding()[opposite].vertex, + m_face->getWinding()[index].vertex, + m_face->getWinding()[other].vertex, + m_face->getWinding()[0].vertex, + m_face->getWinding()[1].vertex, + m_face->getWinding()[2].vertex + ), + "update_move_planepts_vertex2: error" + ); + + m_face->m_move_planepts[0] = m_face->getWinding()[opposite].vertex; + m_face->m_move_planepts[1] = m_face->getWinding()[index].vertex; + m_face->m_move_planepts[2] = m_face->getWinding()[other].vertex; + planepts_quantise( m_face->m_move_planepts, GRID_MIN ); // winding points are very inaccurate + } + + void update_selection_vertex(){ + if ( m_vertexSelection.size() == 0 ) { + m_selectableVertices.setSelected( false ); + } + else + { + m_selectableVertices.setSelected( true ); - if ( m_vertexSelection.size() == 1 ) { - std::size_t index = Winding_FindAdjacent( getFace().getWinding(), *m_vertexSelection.begin() ); + if ( m_vertexSelection.size() == 1 ) { + std::size_t index = Winding_FindAdjacent( getFace().getWinding(), *m_vertexSelection.begin() ); - if ( index != c_brush_maxFaces ) { - update_move_planepts_vertex( index ); + if ( index != c_brush_maxFaces ) { + update_move_planepts_vertex( index ); + } } - } - else if ( m_vertexSelection.size() == 2 ) { - std::size_t index = Winding_FindAdjacent( getFace().getWinding(), *m_vertexSelection.begin() ); - std::size_t other = Winding_FindAdjacent( getFace().getWinding(), *( ++m_vertexSelection.begin() ) ); + else if ( m_vertexSelection.size() == 2 ) { + std::size_t index = Winding_FindAdjacent( getFace().getWinding(), *m_vertexSelection.begin() ); + std::size_t other = Winding_FindAdjacent( getFace().getWinding(), *( ++m_vertexSelection.begin() ) ); - if ( index != c_brush_maxFaces - && other != c_brush_maxFaces ) { - update_move_planepts_vertex2( index, other ); + if ( index != c_brush_maxFaces + && other != c_brush_maxFaces ) { + update_move_planepts_vertex2( index, other ); + } } } } -} - -void select_vertex( std::size_t index, bool select ){ - if ( select ) { - VertexSelection_insert( m_vertexSelection, getFace().getWinding()[index].adjacent ); - } - else - { - VertexSelection_erase( m_vertexSelection, getFace().getWinding()[index].adjacent ); - } - SceneChangeNotify(); - update_selection_vertex(); -} + void select_vertex( std::size_t index, bool select ){ + if ( select ) { + VertexSelection_insert( m_vertexSelection, getFace().getWinding()[index].adjacent ); + } + else + { + VertexSelection_erase( m_vertexSelection, getFace().getWinding()[index].adjacent ); + } -bool selected_vertex( std::size_t index ) const { - return VertexSelection_find( m_vertexSelection, getFace().getWinding()[index].adjacent ) != m_vertexSelection.end(); -} + SceneChangeNotify(); + update_selection_vertex(); + } -void update_move_planepts_edge( std::size_t index ){ - std::size_t numpoints = m_face->getWinding().numpoints; - ASSERT_MESSAGE( index < numpoints, "select_edge: invalid index" ); + bool selected_vertex( std::size_t index ) const { + return VertexSelection_find( m_vertexSelection, getFace().getWinding()[index].adjacent ) != m_vertexSelection.end(); + } - std::size_t adjacent = Winding_next( m_face->getWinding(), index ); - std::size_t opposite = Winding_Opposite( m_face->getWinding(), index ); - m_face->m_move_planepts[0] = m_face->getWinding()[index].vertex; - m_face->m_move_planepts[1] = m_face->getWinding()[adjacent].vertex; - m_face->m_move_planepts[2] = m_face->getWinding()[opposite].vertex; - planepts_quantise( m_face->m_move_planepts, GRID_MIN ); // winding points are very inaccurate -} + void update_move_planepts_edge( std::size_t index ){ + std::size_t numpoints = m_face->getWinding().numpoints; + ASSERT_MESSAGE( index < numpoints, "select_edge: invalid index" ); -void update_selection_edge(){ - if ( m_edgeSelection.size() == 0 ) { - m_selectableEdges.setSelected( false ); + std::size_t adjacent = Winding_next( m_face->getWinding(), index ); + std::size_t opposite = Winding_Opposite( m_face->getWinding(), index ); + m_face->m_move_planepts[0] = m_face->getWinding()[index].vertex; + m_face->m_move_planepts[1] = m_face->getWinding()[adjacent].vertex; + m_face->m_move_planepts[2] = m_face->getWinding()[opposite].vertex; + planepts_quantise( m_face->m_move_planepts, GRID_MIN ); // winding points are very inaccurate } - else - { - m_selectableEdges.setSelected( true ); - if ( m_edgeSelection.size() == 1 ) { - std::size_t index = Winding_FindAdjacent( getFace().getWinding(), *m_edgeSelection.begin() ); + void update_selection_edge(){ + if ( m_edgeSelection.size() == 0 ) { + m_selectableEdges.setSelected( false ); + } + else + { + m_selectableEdges.setSelected( true ); - if ( index != c_brush_maxFaces ) { - update_move_planepts_edge( index ); + if ( m_edgeSelection.size() == 1 ) { + std::size_t index = Winding_FindAdjacent( getFace().getWinding(), *m_edgeSelection.begin() ); + + if ( index != c_brush_maxFaces ) { + update_move_planepts_edge( index ); + } } } } -} -void select_edge( std::size_t index, bool select ){ - if ( select ) { - VertexSelection_insert( m_edgeSelection, getFace().getWinding()[index].adjacent ); - } - else - { - VertexSelection_erase( m_edgeSelection, getFace().getWinding()[index].adjacent ); - } + void select_edge( std::size_t index, bool select ){ + if ( select ) { + VertexSelection_insert( m_edgeSelection, getFace().getWinding()[index].adjacent ); + } + else + { + VertexSelection_erase( m_edgeSelection, getFace().getWinding()[index].adjacent ); + } - SceneChangeNotify(); - update_selection_edge(); -} + SceneChangeNotify(); + update_selection_edge(); + } -bool selected_edge( std::size_t index ) const { - return VertexSelection_find( m_edgeSelection, getFace().getWinding()[index].adjacent ) != m_edgeSelection.end(); -} + bool selected_edge( std::size_t index ) const { + return VertexSelection_find( m_edgeSelection, getFace().getWinding()[index].adjacent ) != m_edgeSelection.end(); + } -const Vector3& centroid() const { - return m_face->centroid(); -} + const Vector3& centroid() const { + return m_face->centroid(); + } -void connectivityChanged(){ - // This occurs when a face is added or removed. - // The current vertex and edge selections no longer valid and must be cleared. - m_vertexSelection.clear(); - m_selectableVertices.setSelected( false ); - m_edgeSelection.clear(); - m_selectableEdges.setSelected( false ); -} + void connectivityChanged(){ + // This occurs when a face is added or removed. + // The current vertex and edge selections no longer valid and must be cleared. + m_vertexSelection.clear(); + m_selectableVertices.setSelected( false ); + m_edgeSelection.clear(); + m_selectableEdges.setSelected( false ); + } }; class BrushClipPlane : public OpenGLRenderable { -Plane3 m_plane; -Winding m_winding; -static Shader* m_state; + Plane3 m_plane; + Winding m_winding; + static Shader* m_state; public: -static void constructStatic(){ - m_state = GlobalShaderCache().capture( "$CLIPPER_OVERLAY" ); -} - -static void destroyStatic(){ - GlobalShaderCache().release( "$CLIPPER_OVERLAY" ); -} - -void setPlane( const Brush& brush, const Plane3& plane ){ - m_plane = plane; - if ( plane3_valid( m_plane ) ) { - brush.windingForClipPlane( m_winding, m_plane ); + static void constructStatic(){ + m_state = GlobalShaderCache().capture( "$CLIPPER_OVERLAY" ); } - else - { - m_winding.resize( 0 ); + + static void destroyStatic(){ + GlobalShaderCache().release( "$CLIPPER_OVERLAY" ); } -} -void render( RenderStateFlags state ) const { - if ( ( state & RENDER_FILL ) != 0 ) { - Winding_Draw( m_winding, m_plane.normal(), state ); + void setPlane( const Brush& brush, const Plane3& plane ){ + m_plane = plane; + if ( plane3_valid( m_plane ) ) { + brush.windingForClipPlane( m_winding, m_plane ); + } + else + { + m_winding.resize( 0 ); + } } - else - { - Winding_DrawWireframe( m_winding ); - // also draw a line indicating the direction of the cut - Vector3 lineverts[2]; - Winding_Centroid( m_winding, m_plane, lineverts[0] ); - lineverts[1] = vector3_added( lineverts[0], vector3_scaled( m_plane.normal(), Brush::m_maxWorldCoord * 4 ) ); + void render( RenderStateFlags state ) const { + if ( ( state & RENDER_FILL ) != 0 ) { + Winding_Draw( m_winding, m_plane.normal(), state ); + } + else + { + Winding_DrawWireframe( m_winding ); + + // also draw a line indicating the direction of the cut + Vector3 lineverts[2]; + Winding_Centroid( m_winding, m_plane, lineverts[0] ); + lineverts[1] = vector3_added( lineverts[0], vector3_scaled( m_plane.normal(), Brush::m_maxWorldCoord * 4 ) ); - glVertexPointer( 3, GL_FLOAT, sizeof( Vector3 ), &lineverts[0] ); - glDrawArrays( GL_LINES, 0, GLsizei( 2 ) ); + glVertexPointer( 3, GL_FLOAT, sizeof( Vector3 ), &lineverts[0] ); + glDrawArrays( GL_LINES, 0, GLsizei( 2 ) ); + } } -} -void render( Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld ) const { - renderer.SetState( m_state, Renderer::eWireframeOnly ); - renderer.SetState( m_state, Renderer::eFullMaterials ); - renderer.addRenderable( *this, localToWorld ); -} + void render( Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld ) const { + renderer.SetState( m_state, Renderer::eWireframeOnly ); + renderer.SetState( m_state, Renderer::eFullMaterials ); + renderer.addRenderable( *this, localToWorld ); + } }; inline void Face_addLight( const FaceInstance& face, const Matrix4& localToWorld, const RendererLight& light ){ @@ -2997,114 +2983,114 @@ typedef std::vector FaceInstances; class EdgeInstance : public Selectable { -FaceInstances& m_faceInstances; -SelectableEdge* m_edge; + FaceInstances& m_faceInstances; + SelectableEdge* m_edge; -void select_edge( bool select ){ - FaceVertexId faceVertex = m_edge->m_faceVertex; - m_faceInstances[faceVertex.getFace()].select_edge( faceVertex.getVertex(), select ); - faceVertex = next_edge( m_edge->m_faces, faceVertex ); - m_faceInstances[faceVertex.getFace()].select_edge( faceVertex.getVertex(), select ); -} - -bool selected_edge() const { - FaceVertexId faceVertex = m_edge->m_faceVertex; - if ( !m_faceInstances[faceVertex.getFace()].selected_edge( faceVertex.getVertex() ) ) { - return false; - } - faceVertex = next_edge( m_edge->m_faces, faceVertex ); - if ( !m_faceInstances[faceVertex.getFace()].selected_edge( faceVertex.getVertex() ) ) { - return false; + void select_edge( bool select ){ + FaceVertexId faceVertex = m_edge->m_faceVertex; + m_faceInstances[faceVertex.getFace()].select_edge( faceVertex.getVertex(), select ); + faceVertex = next_edge( m_edge->m_faces, faceVertex ); + m_faceInstances[faceVertex.getFace()].select_edge( faceVertex.getVertex(), select ); } - return true; -} + bool selected_edge() const { + FaceVertexId faceVertex = m_edge->m_faceVertex; + if ( !m_faceInstances[faceVertex.getFace()].selected_edge( faceVertex.getVertex() ) ) { + return false; + } + faceVertex = next_edge( m_edge->m_faces, faceVertex ); + if ( !m_faceInstances[faceVertex.getFace()].selected_edge( faceVertex.getVertex() ) ) { + return false; + } + + return true; + } public: -EdgeInstance( FaceInstances& faceInstances, SelectableEdge& edge ) - : m_faceInstances( faceInstances ), m_edge( &edge ){ -} -EdgeInstance& operator=( const EdgeInstance& other ){ - m_edge = other.m_edge; - return *this; -} + EdgeInstance( FaceInstances& faceInstances, SelectableEdge& edge ) + : m_faceInstances( faceInstances ), m_edge( &edge ){ + } + EdgeInstance& operator=( const EdgeInstance& other ){ + m_edge = other.m_edge; + return *this; + } -void setSelected( bool select ){ - select_edge( select ); -} + void setSelected( bool select ){ + select_edge( select ); + } -bool isSelected() const { - return selected_edge(); -} + bool isSelected() const { + return selected_edge(); + } -void testSelect( Selector& selector, SelectionTest& test ){ - SelectionIntersection best; - m_edge->testSelect( test, best ); - if ( best.valid() ) { - Selector_add( selector, *this, best ); + void testSelect( Selector& selector, SelectionTest& test ){ + SelectionIntersection best; + m_edge->testSelect( test, best ); + if ( best.valid() ) { + Selector_add( selector, *this, best ); + } } -} }; class VertexInstance : public Selectable { -FaceInstances& m_faceInstances; -SelectableVertex* m_vertex; + FaceInstances& m_faceInstances; + SelectableVertex* m_vertex; -void select_vertex( bool select ){ - FaceVertexId faceVertex = m_vertex->m_faceVertex; - do - { - m_faceInstances[faceVertex.getFace()].select_vertex( faceVertex.getVertex(), select ); - faceVertex = next_vertex( m_vertex->m_faces, faceVertex ); + void select_vertex( bool select ){ + FaceVertexId faceVertex = m_vertex->m_faceVertex; + do + { + m_faceInstances[faceVertex.getFace()].select_vertex( faceVertex.getVertex(), select ); + faceVertex = next_vertex( m_vertex->m_faces, faceVertex ); + } + while ( faceVertex.getFace() != m_vertex->m_faceVertex.getFace() ); } - while ( faceVertex.getFace() != m_vertex->m_faceVertex.getFace() ); -} -bool selected_vertex() const { - FaceVertexId faceVertex = m_vertex->m_faceVertex; - do - { - if ( !m_faceInstances[faceVertex.getFace()].selected_vertex( faceVertex.getVertex() ) ) { - return false; + bool selected_vertex() const { + FaceVertexId faceVertex = m_vertex->m_faceVertex; + do + { + if ( !m_faceInstances[faceVertex.getFace()].selected_vertex( faceVertex.getVertex() ) ) { + return false; + } + faceVertex = next_vertex( m_vertex->m_faces, faceVertex ); } - faceVertex = next_vertex( m_vertex->m_faces, faceVertex ); + while ( faceVertex.getFace() != m_vertex->m_faceVertex.getFace() ); + return true; } - while ( faceVertex.getFace() != m_vertex->m_faceVertex.getFace() ); - return true; -} -public: -VertexInstance( FaceInstances& faceInstances, SelectableVertex& vertex ) - : m_faceInstances( faceInstances ), m_vertex( &vertex ){ -} -VertexInstance& operator=( const VertexInstance& other ){ - m_vertex = other.m_vertex; - return *this; -} + public: + VertexInstance( FaceInstances& faceInstances, SelectableVertex& vertex ) + : m_faceInstances( faceInstances ), m_vertex( &vertex ){ + } + VertexInstance& operator=( const VertexInstance& other ){ + m_vertex = other.m_vertex; + return *this; + } -void setSelected( bool select ){ - select_vertex( select ); -} + void setSelected( bool select ){ + select_vertex( select ); + } -bool isSelected() const { - return selected_vertex(); -} + bool isSelected() const { + return selected_vertex(); + } -void testSelect( Selector& selector, SelectionTest& test ){ - SelectionIntersection best; - m_vertex->testSelect( test, best ); - if ( best.valid() ) { - Selector_add( selector, *this, best ); + void testSelect( Selector& selector, SelectionTest& test ){ + SelectionIntersection best; + m_vertex->testSelect( test, best ); + if ( best.valid() ) { + Selector_add( selector, *this, best ); + } } -} }; class BrushInstanceVisitor { public: -virtual void visit( FaceInstance& face ) const = 0; + virtual void visit( FaceInstance& face ) const = 0; }; class BrushInstance : @@ -3119,497 +3105,498 @@ class BrushInstance : public PlaneSelectable, public LightCullable { -class TypeCasts -{ -InstanceTypeCastTable m_casts; -public: -TypeCasts(){ - InstanceStaticCast::install( m_casts ); - InstanceContainedCast::install( m_casts ); - InstanceContainedCast::install( m_casts ); - InstanceStaticCast::install( m_casts ); - InstanceStaticCast::install( m_casts ); - InstanceStaticCast::install( m_casts ); - InstanceStaticCast::install( m_casts ); - InstanceStaticCast::install( m_casts ); - InstanceStaticCast::install( m_casts ); - InstanceIdentityCast::install( m_casts ); - InstanceContainedCast::install( m_casts ); -} - -InstanceTypeCastTable& get(){ - return m_casts; -} -}; + class TypeCasts + { + InstanceTypeCastTable m_casts; + public: + TypeCasts(){ + InstanceStaticCast::install( m_casts ); + InstanceContainedCast::install( m_casts ); + InstanceContainedCast::install( m_casts ); + InstanceStaticCast::install( m_casts ); + InstanceStaticCast::install( m_casts ); + InstanceStaticCast::install( m_casts ); + InstanceStaticCast::install( m_casts ); + InstanceStaticCast::install( m_casts ); + InstanceStaticCast::install( m_casts ); + InstanceIdentityCast::install( m_casts ); + InstanceContainedCast::install( m_casts ); + } + + InstanceTypeCastTable& get(){ + return m_casts; + } + }; + + Brush& m_brush; -Brush& m_brush; + FaceInstances m_faceInstances; -FaceInstances m_faceInstances; + typedef std::vector EdgeInstances; + EdgeInstances m_edgeInstances; + typedef std::vector VertexInstances; + VertexInstances m_vertexInstances; -typedef std::vector EdgeInstances; -EdgeInstances m_edgeInstances; -typedef std::vector VertexInstances; -VertexInstances m_vertexInstances; + ObservedSelectable m_selectable; -ObservedSelectable m_selectable; + mutable RenderableWireframe m_render_wireframe; + mutable RenderablePointVector m_render_selected; + mutable AABB m_aabb_component; + mutable Array m_faceCentroidPointsCulled; + RenderablePointArray m_render_faces_wireframe; + mutable bool m_viewChanged; // requires re-evaluation of view-dependent cached data -mutable RenderableWireframe m_render_wireframe; -mutable RenderablePointVector m_render_selected; -mutable AABB m_aabb_component; -mutable Array m_faceCentroidPointsCulled; -RenderablePointArray m_render_faces_wireframe; -mutable bool m_viewChanged; // requires re-evaluation of view-dependent cached data + BrushClipPlane m_clipPlane; -BrushClipPlane m_clipPlane; + static Shader* m_state_selpoint; -static Shader* m_state_selpoint; + const LightList* m_lightList; -const LightList* m_lightList; + TransformModifier m_transform; -TransformModifier m_transform; + BrushInstance( const BrushInstance& other ); // NOT COPYABLE + BrushInstance& operator=( const BrushInstance& other ); // NOT ASSIGNABLE -BrushInstance( const BrushInstance& other ); // NOT COPYABLE -BrushInstance& operator=( const BrushInstance& other ); // NOT ASSIGNABLE public: -static Counter* m_counter; + static Counter* m_counter; -typedef LazyStatic StaticTypeCasts; + typedef LazyStatic StaticTypeCasts; -void lightsChanged(){ - m_lightList->lightsChanged(); -} + void lightsChanged(){ + m_lightList->lightsChanged(); + } -typedef MemberCaller LightsChangedCaller; + typedef MemberCaller LightsChangedCaller; -STRING_CONSTANT( Name, "BrushInstance" ); + STRING_CONSTANT( Name, "BrushInstance" ); -BrushInstance( const scene::Path& path, scene::Instance* parent, Brush& brush ) : - Instance( path, parent, this, StaticTypeCasts::instance().get() ), - m_brush( brush ), - m_selectable( SelectedChangedCaller( *this ) ), - m_render_selected( GL_POINTS ), - m_render_faces_wireframe( m_faceCentroidPointsCulled, GL_POINTS ), - m_viewChanged( false ), - m_transform( Brush::TransformChangedCaller( m_brush ), ApplyTransformCaller( *this ) ){ - m_brush.instanceAttach( Instance::path() ); - m_brush.attach( *this ); - m_counter->increment(); + BrushInstance( const scene::Path& path, scene::Instance* parent, Brush& brush ) : + Instance( path, parent, this, StaticTypeCasts::instance().get() ), + m_brush( brush ), + m_selectable( SelectedChangedCaller( *this ) ), + m_render_selected( GL_POINTS ), + m_render_faces_wireframe( m_faceCentroidPointsCulled, GL_POINTS ), + m_viewChanged( false ), + m_transform( Brush::TransformChangedCaller( m_brush ), ApplyTransformCaller( *this ) ){ + m_brush.instanceAttach( Instance::path() ); + m_brush.attach( *this ); + m_counter->increment(); - m_lightList = &GlobalShaderCache().attach( *this ); - m_brush.m_lightsChanged = LightsChangedCaller( *this ); ///\todo Make this work with instancing. + m_lightList = &GlobalShaderCache().attach( *this ); + m_brush.m_lightsChanged = LightsChangedCaller( *this ); ///\todo Make this work with instancing. - Instance::setTransformChangedCallback( LightsChangedCaller( *this ) ); -} + Instance::setTransformChangedCallback( LightsChangedCaller( *this ) ); + } -~BrushInstance(){ - Instance::setTransformChangedCallback( Callback() ); + ~BrushInstance(){ + Instance::setTransformChangedCallback( Callback() ); - m_brush.m_lightsChanged = Callback(); - GlobalShaderCache().detach( *this ); + m_brush.m_lightsChanged = Callback(); + GlobalShaderCache().detach( *this ); - m_counter->decrement(); - m_brush.detach( *this ); - m_brush.instanceDetach( Instance::path() ); -} + m_counter->decrement(); + m_brush.detach( *this ); + m_brush.instanceDetach( Instance::path() ); + } -Brush& getBrush(){ - return m_brush; -} -const Brush& getBrush() const { - return m_brush; -} + Brush& getBrush(){ + return m_brush; + } + const Brush& getBrush() const { + return m_brush; + } -Bounded& get( NullType){ - return m_brush; -} + Bounded& get( NullType){ + return m_brush; + } -Cullable& get( NullType){ - return m_brush; -} + Cullable& get( NullType){ + return m_brush; + } -Transformable& get( NullType){ - return m_transform; -} + Transformable& get( NullType){ + return m_transform; + } -void selectedChanged( const Selectable& selectable ){ - GlobalSelectionSystem().getObserver ( SelectionSystem::ePrimitive )( selectable ); - GlobalSelectionSystem().onSelectedChanged( *this, selectable ); + void selectedChanged( const Selectable& selectable ){ + GlobalSelectionSystem().getObserver ( SelectionSystem::ePrimitive )( selectable ); + GlobalSelectionSystem().onSelectedChanged( *this, selectable ); - Instance::selectedChanged(); -} -typedef MemberCaller SelectedChangedCaller; + Instance::selectedChanged(); + } + typedef MemberCaller SelectedChangedCaller; -void selectedChangedComponent( const Selectable& selectable ){ - GlobalSelectionSystem().getObserver ( SelectionSystem::eComponent )( selectable ); - GlobalSelectionSystem().onComponentSelection( *this, selectable ); -} -typedef MemberCaller SelectedChangedComponentCaller; + void selectedChangedComponent( const Selectable& selectable ){ + GlobalSelectionSystem().getObserver ( SelectionSystem::eComponent )( selectable ); + GlobalSelectionSystem().onComponentSelection( *this, selectable ); + } + typedef MemberCaller SelectedChangedComponentCaller; -const BrushInstanceVisitor& forEachFaceInstance( const BrushInstanceVisitor& visitor ){ - for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - visitor.visit( *i ); + const BrushInstanceVisitor& forEachFaceInstance( const BrushInstanceVisitor& visitor ){ + for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + visitor.visit( *i ); + } + return visitor; } - return visitor; -} -static void constructStatic(){ - m_state_selpoint = GlobalShaderCache().capture( "$SELPOINT" ); -} + static void constructStatic(){ + m_state_selpoint = GlobalShaderCache().capture( "$SELPOINT" ); + } -static void destroyStatic(){ - GlobalShaderCache().release( "$SELPOINT" ); -} + static void destroyStatic(){ + GlobalShaderCache().release( "$SELPOINT" ); + } -void clear(){ - m_faceInstances.clear(); -} + void clear(){ + m_faceInstances.clear(); + } -void reserve( std::size_t size ){ - m_faceInstances.reserve( size ); -} + void reserve( std::size_t size ){ + m_faceInstances.reserve( size ); + } -void push_back( Face& face ){ - m_faceInstances.push_back( FaceInstance( face, SelectedChangedComponentCaller( *this ) ) ); -} + void push_back( Face& face ){ + m_faceInstances.push_back( FaceInstance( face, SelectedChangedComponentCaller( *this ) ) ); + } -void pop_back(){ - ASSERT_MESSAGE( !m_faceInstances.empty(), "erasing invalid element" ); - m_faceInstances.pop_back(); -} + void pop_back(){ + ASSERT_MESSAGE( !m_faceInstances.empty(), "erasing invalid element" ); + m_faceInstances.pop_back(); + } -void erase( std::size_t index ){ - ASSERT_MESSAGE( index < m_faceInstances.size(), "erasing invalid element" ); - m_faceInstances.erase( m_faceInstances.begin() + index ); -} + void erase( std::size_t index ){ + ASSERT_MESSAGE( index < m_faceInstances.size(), "erasing invalid element" ); + m_faceInstances.erase( m_faceInstances.begin() + index ); + } -void connectivityChanged(){ - for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - ( *i ).connectivityChanged(); + void connectivityChanged(){ + for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + ( *i ).connectivityChanged(); + } } -} -void edge_clear(){ - m_edgeInstances.clear(); -} + void edge_clear(){ + m_edgeInstances.clear(); + } -void edge_push_back( SelectableEdge& edge ){ - m_edgeInstances.push_back( EdgeInstance( m_faceInstances, edge ) ); -} + void edge_push_back( SelectableEdge& edge ){ + m_edgeInstances.push_back( EdgeInstance( m_faceInstances, edge ) ); + } -void vertex_clear(){ - m_vertexInstances.clear(); -} + void vertex_clear(){ + m_vertexInstances.clear(); + } -void vertex_push_back( SelectableVertex& vertex ){ - m_vertexInstances.push_back( VertexInstance( m_faceInstances, vertex ) ); -} + void vertex_push_back( SelectableVertex& vertex ){ + m_vertexInstances.push_back( VertexInstance( m_faceInstances, vertex ) ); + } -void DEBUG_verify() const { - ASSERT_MESSAGE( m_faceInstances.size() == m_brush.DEBUG_size(), "FATAL: mismatch" ); -} + void DEBUG_verify() const { + ASSERT_MESSAGE( m_faceInstances.size() == m_brush.DEBUG_size(), "FATAL: mismatch" ); + } -bool isSelected() const { - return m_selectable.isSelected(); -} + bool isSelected() const { + return m_selectable.isSelected(); + } -void setSelected( bool select ){ - m_selectable.setSelected( select ); -} + void setSelected( bool select ){ + m_selectable.setSelected( select ); + } -void update_selected() const { - m_render_selected.clear(); - for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - if ( ( *i ).getFace().contributes() ) { - ( *i ).iterate_selected( m_render_selected ); + void update_selected() const { + m_render_selected.clear(); + for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + if ( ( *i ).getFace().contributes() ) { + ( *i ).iterate_selected( m_render_selected ); + } } } -} -void evaluateViewDependent( const VolumeTest& volume, const Matrix4& localToWorld ) const { - if ( m_viewChanged ) { - m_viewChanged = false; + void evaluateViewDependent( const VolumeTest& volume, const Matrix4& localToWorld ) const { + if ( m_viewChanged ) { + m_viewChanged = false; - bool faces_visible[c_brush_maxFaces]; - { - bool* j = faces_visible; - for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i, ++j ) + bool faces_visible[c_brush_maxFaces]; { - *j = ( *i ).intersectVolume( volume, localToWorld ); + bool* j = faces_visible; + for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i, ++j ) + { + *j = ( *i ).intersectVolume( volume, localToWorld ); + } } - } - m_brush.update_wireframe( m_render_wireframe, faces_visible ); - m_brush.update_faces_wireframe( m_faceCentroidPointsCulled, faces_visible ); + m_brush.update_wireframe( m_render_wireframe, faces_visible ); + m_brush.update_faces_wireframe( m_faceCentroidPointsCulled, faces_visible ); + } } -} -void renderComponentsSelected( Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld ) const { - m_brush.evaluateBRep(); + void renderComponentsSelected( Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld ) const { + m_brush.evaluateBRep(); - update_selected(); - if ( !m_render_selected.empty() ) { - renderer.Highlight( Renderer::ePrimitive, false ); - renderer.SetState( m_state_selpoint, Renderer::eWireframeOnly ); - renderer.SetState( m_state_selpoint, Renderer::eFullMaterials ); - renderer.addRenderable( m_render_selected, localToWorld ); + update_selected(); + if ( !m_render_selected.empty() ) { + renderer.Highlight( Renderer::ePrimitive, false ); + renderer.SetState( m_state_selpoint, Renderer::eWireframeOnly ); + renderer.SetState( m_state_selpoint, Renderer::eFullMaterials ); + renderer.addRenderable( m_render_selected, localToWorld ); + } } -} -void renderComponents( Renderer& renderer, const VolumeTest& volume ) const { - m_brush.evaluateBRep(); + void renderComponents( Renderer& renderer, const VolumeTest& volume ) const { + m_brush.evaluateBRep(); - const Matrix4& localToWorld = Instance::localToWorld(); + const Matrix4& localToWorld = Instance::localToWorld(); - renderer.SetState( m_brush.m_state_point, Renderer::eWireframeOnly ); - renderer.SetState( m_brush.m_state_point, Renderer::eFullMaterials ); + renderer.SetState( m_brush.m_state_point, Renderer::eWireframeOnly ); + renderer.SetState( m_brush.m_state_point, Renderer::eFullMaterials ); - if ( volume.fill() && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace ) { - evaluateViewDependent( volume, localToWorld ); - renderer.addRenderable( m_render_faces_wireframe, localToWorld ); - } - else - { - m_brush.renderComponents( GlobalSelectionSystem().ComponentMode(), renderer, volume, localToWorld ); + if ( volume.fill() && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace ) { + evaluateViewDependent( volume, localToWorld ); + renderer.addRenderable( m_render_faces_wireframe, localToWorld ); + } + else + { + m_brush.renderComponents( GlobalSelectionSystem().ComponentMode(), renderer, volume, localToWorld ); + } } -} -void renderClipPlane( Renderer& renderer, const VolumeTest& volume ) const { - if ( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip && isSelected() ) { - m_clipPlane.render( renderer, volume, localToWorld() ); + void renderClipPlane( Renderer& renderer, const VolumeTest& volume ) const { + if ( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip && isSelected() ) { + m_clipPlane.render( renderer, volume, localToWorld() ); + } } -} -void renderCommon( Renderer& renderer, const VolumeTest& volume ) const { - bool componentMode = GlobalSelectionSystem().Mode() == SelectionSystem::eComponent; + void renderCommon( Renderer& renderer, const VolumeTest& volume ) const { + bool componentMode = GlobalSelectionSystem().Mode() == SelectionSystem::eComponent; - if ( componentMode && isSelected() ) { - renderComponents( renderer, volume ); - } + if ( componentMode && isSelected() ) { + renderComponents( renderer, volume ); + } - if ( parentSelected() ) { - if ( !componentMode ) { - renderer.Highlight( Renderer::eFace ); + if ( parentSelected() ) { + if ( !componentMode ) { + renderer.Highlight( Renderer::eFace ); + } + renderer.Highlight( Renderer::ePrimitive ); } - renderer.Highlight( Renderer::ePrimitive ); } -} -void renderSolid( Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld ) const { - //renderCommon(renderer, volume); + void renderSolid( Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld ) const { + //renderCommon(renderer, volume); - m_lightList->evaluateLights(); + m_lightList->evaluateLights(); - for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - renderer.setLights( ( *i ).m_lights ); - ( *i ).render( renderer, volume, localToWorld ); + for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + renderer.setLights( ( *i ).m_lights ); + ( *i ).render( renderer, volume, localToWorld ); + } + + renderComponentsSelected( renderer, volume, localToWorld ); } - renderComponentsSelected( renderer, volume, localToWorld ); -} + void renderWireframe( Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld ) const { + //renderCommon(renderer, volume); -void renderWireframe( Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld ) const { - //renderCommon(renderer, volume); + evaluateViewDependent( volume, localToWorld ); - evaluateViewDependent( volume, localToWorld ); + if ( m_render_wireframe.m_size != 0 ) { + renderer.addRenderable( m_render_wireframe, localToWorld ); + } - if ( m_render_wireframe.m_size != 0 ) { - renderer.addRenderable( m_render_wireframe, localToWorld ); + renderComponentsSelected( renderer, volume, localToWorld ); } - renderComponentsSelected( renderer, volume, localToWorld ); -} - -void renderSolid( Renderer& renderer, const VolumeTest& volume ) const { - m_brush.evaluateBRep(); + void renderSolid( Renderer& renderer, const VolumeTest& volume ) const { + m_brush.evaluateBRep(); - renderClipPlane( renderer, volume ); + renderClipPlane( renderer, volume ); - renderSolid( renderer, volume, localToWorld() ); -} + renderSolid( renderer, volume, localToWorld() ); + } -void renderWireframe( Renderer& renderer, const VolumeTest& volume ) const { - m_brush.evaluateBRep(); + void renderWireframe( Renderer& renderer, const VolumeTest& volume ) const { + m_brush.evaluateBRep(); - renderClipPlane( renderer, volume ); + renderClipPlane( renderer, volume ); - renderWireframe( renderer, volume, localToWorld() ); -} + renderWireframe( renderer, volume, localToWorld() ); + } -void viewChanged() const { - m_viewChanged = true; -} + void viewChanged() const { + m_viewChanged = true; + } -void testSelect( Selector& selector, SelectionTest& test ){ - test.BeginMesh( localToWorld() ); + void testSelect( Selector& selector, SelectionTest& test ){ + test.BeginMesh( localToWorld() ); - SelectionIntersection best; - for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - ( *i ).testSelect( test, best ); - } - if ( best.valid() ) { - selector.addIntersection( best ); + SelectionIntersection best; + for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + ( *i ).testSelect( test, best ); + } + if ( best.valid() ) { + selector.addIntersection( best ); + } } -} -bool isSelectedComponents() const { - for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - if ( ( *i ).selectedComponents() ) { - return true; + bool isSelectedComponents() const { + for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + if ( ( *i ).selectedComponents() ) { + return true; + } } + return false; } - return false; -} -void setSelectedComponents( bool select, SelectionSystem::EComponentMode mode ){ - for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - ( *i ).setSelected( mode, select ); + void setSelectedComponents( bool select, SelectionSystem::EComponentMode mode ){ + for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + ( *i ).setSelected( mode, select ); + } } -} -void testSelectComponents( Selector& selector, SelectionTest& test, SelectionSystem::EComponentMode mode ){ - test.BeginMesh( localToWorld() ); + void testSelectComponents( Selector& selector, SelectionTest& test, SelectionSystem::EComponentMode mode ){ + test.BeginMesh( localToWorld() ); - switch ( mode ) - { - case SelectionSystem::eVertex: - { - for ( VertexInstances::iterator i = m_vertexInstances.begin(); i != m_vertexInstances.end(); ++i ) + switch ( mode ) { - ( *i ).testSelect( selector, test ); - } - } - break; - case SelectionSystem::eEdge: - { - for ( EdgeInstances::iterator i = m_edgeInstances.begin(); i != m_edgeInstances.end(); ++i ) + case SelectionSystem::eVertex: { - ( *i ).testSelect( selector, test ); + for ( VertexInstances::iterator i = m_vertexInstances.begin(); i != m_vertexInstances.end(); ++i ) + { + ( *i ).testSelect( selector, test ); + } } - } - break; - case SelectionSystem::eFace: - { - if ( test.getVolume().fill() ) { - for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + break; + case SelectionSystem::eEdge: + { + for ( EdgeInstances::iterator i = m_edgeInstances.begin(); i != m_edgeInstances.end(); ++i ) { ( *i ).testSelect( selector, test ); } } - else + break; + case SelectionSystem::eFace: { - for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + if ( test.getVolume().fill() ) { + for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + ( *i ).testSelect( selector, test ); + } + } + else { - ( *i ).testSelect_centroid( selector, test ); + for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + ( *i ).testSelect_centroid( selector, test ); + } } } - } - break; - default: break; + default: + break; + } } -} -void selectPlanes( Selector& selector, SelectionTest& test, const PlaneCallback& selectedPlaneCallback ){ - test.BeginMesh( localToWorld() ); + void selectPlanes( Selector& selector, SelectionTest& test, const PlaneCallback& selectedPlaneCallback ){ + test.BeginMesh( localToWorld() ); - PlanePointer brushPlanes[c_brush_maxFaces]; - PlanesIterator j = brushPlanes; + PlanePointer brushPlanes[c_brush_maxFaces]; + PlanesIterator j = brushPlanes; - for ( Brush::const_iterator i = m_brush.begin(); i != m_brush.end(); ++i ) - { - *j++ = &( *i )->plane3(); - } + for ( Brush::const_iterator i = m_brush.begin(); i != m_brush.end(); ++i ) + { + *j++ = &( *i )->plane3(); + } - for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - ( *i ).selectPlane( selector, Line( test.getNear(), test.getFar() ), brushPlanes, j, selectedPlaneCallback ); + for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + ( *i ).selectPlane( selector, Line( test.getNear(), test.getFar() ), brushPlanes, j, selectedPlaneCallback ); + } } -} -void selectReversedPlanes( Selector& selector, const SelectedPlanes& selectedPlanes ){ - for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - ( *i ).selectReversedPlane( selector, selectedPlanes ); + void selectReversedPlanes( Selector& selector, const SelectedPlanes& selectedPlanes ){ + for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + ( *i ).selectReversedPlane( selector, selectedPlanes ); + } } -} -void transformComponents( const Matrix4& matrix ){ - for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - ( *i ).transformComponents( matrix ); + void transformComponents( const Matrix4& matrix ){ + for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + ( *i ).transformComponents( matrix ); + } } -} -const AABB& getSelectedComponentsBounds() const { - m_aabb_component = AABB(); + const AABB& getSelectedComponentsBounds() const { + m_aabb_component = AABB(); - for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - ( *i ).iterate_selected( m_aabb_component ); - } + for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + ( *i ).iterate_selected( m_aabb_component ); + } - return m_aabb_component; -} + return m_aabb_component; + } -void snapComponents( float snap ){ - for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - ( *i ).snapComponents( snap ); + void snapComponents( float snap ){ + for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + ( *i ).snapComponents( snap ); + } } -} -void evaluateTransform(){ - Matrix4 matrix( m_transform.calculateTransform() ); - //globalOutputStream() << "matrix: " << matrix << "\n"; + void evaluateTransform(){ + Matrix4 matrix( m_transform.calculateTransform() ); + //globalOutputStream() << "matrix: " << matrix << "\n"; - if ( m_transform.getType() == TRANSFORM_PRIMITIVE ) { - m_brush.transform( matrix ); - } - else - { - transformComponents( matrix ); + if ( m_transform.getType() == TRANSFORM_PRIMITIVE ) { + m_brush.transform( matrix ); + } + else + { + transformComponents( matrix ); + } } -} -void applyTransform(){ - m_brush.revertTransform(); - evaluateTransform(); - m_brush.freezeTransform(); -} + void applyTransform(){ + m_brush.revertTransform(); + evaluateTransform(); + m_brush.freezeTransform(); + } -typedef MemberCaller ApplyTransformCaller; + typedef MemberCaller ApplyTransformCaller; -void setClipPlane( const Plane3& plane ){ - m_clipPlane.setPlane( m_brush, plane ); -} + void setClipPlane( const Plane3& plane ){ + m_clipPlane.setPlane( m_brush, plane ); + } -bool testLight( const RendererLight& light ) const { - return light.testAABB( worldAABB() ); -} + bool testLight( const RendererLight& light ) const { + return light.testAABB( worldAABB() ); + } -void insertLight( const RendererLight& light ){ - const Matrix4& localToWorld = Instance::localToWorld(); - for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - Face_addLight( *i, localToWorld, light ); + void insertLight( const RendererLight& light ){ + const Matrix4& localToWorld = Instance::localToWorld(); + for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + Face_addLight( *i, localToWorld, light ); + } } -} -void clearLights(){ - for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) - { - ( *i ).m_lights.clear(); + void clearLights(){ + for ( FaceInstances::const_iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i ) + { + ( *i ).m_lights.clear(); + } } -} }; inline BrushInstance* Instance_getBrush( scene::Instance& instance ){ @@ -3620,17 +3607,17 @@ inline BrushInstance* Instance_getBrush( scene::Instance& instance ){ template class BrushSelectedVisitor : public SelectionSystem::Visitor { -const Functor& m_functor; + const Functor& m_functor; public: -BrushSelectedVisitor( const Functor& functor ) : m_functor( functor ){ -} + BrushSelectedVisitor( const Functor& functor ) : m_functor( functor ){ + } -void visit( scene::Instance& instance ) const { - BrushInstance* brush = Instance_getBrush( instance ); - if ( brush != 0 ) { - m_functor( *brush ); + void visit( scene::Instance& instance ) const { + BrushInstance* brush = Instance_getBrush( instance ); + if ( brush != 0 ) { + m_functor( *brush ); + } } -} }; template @@ -3642,18 +3629,18 @@ inline const Functor& Scene_forEachSelectedBrush( const Functor& functor ){ template class BrushVisibleSelectedVisitor : public SelectionSystem::Visitor { -const Functor& m_functor; + const Functor& m_functor; public: -BrushVisibleSelectedVisitor( const Functor& functor ) : m_functor( functor ){ -} + BrushVisibleSelectedVisitor( const Functor& functor ) : m_functor( functor ){ + } -void visit( scene::Instance& instance ) const { - BrushInstance* brush = Instance_getBrush( instance ); - if ( brush != 0 - && instance.path().top().get().visible() ) { - m_functor( *brush ); + void visit( scene::Instance& instance ) const { + BrushInstance* brush = Instance_getBrush( instance ); + if ( brush != 0 + && instance.path().top().get().visible() ) { + m_functor( *brush ); + } } -} }; template @@ -3664,28 +3651,28 @@ inline const Functor& Scene_forEachVisibleSelectedBrush( const Functor& functor class BrushForEachFace { -const BrushInstanceVisitor& m_visitor; + const BrushInstanceVisitor& m_visitor; public: -BrushForEachFace( const BrushInstanceVisitor& visitor ) : m_visitor( visitor ){ -} + BrushForEachFace( const BrushInstanceVisitor& visitor ) : m_visitor( visitor ){ + } -void operator()( BrushInstance& brush ) const { - brush.forEachFaceInstance( m_visitor ); -} + void operator()( BrushInstance& brush ) const { + brush.forEachFaceInstance( m_visitor ); + } }; template class FaceInstanceVisitFace : public BrushInstanceVisitor { -const Functor& functor; + const Functor& functor; public: -FaceInstanceVisitFace( const Functor& functor ) - : functor( functor ){ -} + FaceInstanceVisitFace( const Functor& functor ) + : functor( functor ){ + } -void visit( FaceInstance& face ) const { - functor( face.getFace() ); -} + void visit( FaceInstance& face ) const { + functor( face.getFace() ); + } }; template @@ -3697,15 +3684,15 @@ inline const Functor& Brush_forEachFace( BrushInstance& brush, const Functor& fu template class FaceVisitAll : public BrushVisitor { -const Functor& functor; + const Functor& functor; public: -FaceVisitAll( const Functor& functor ) - : functor( functor ){ -} + FaceVisitAll( const Functor& functor ) + : functor( functor ){ + } -void visit( Face& face ) const { - functor( face ); -} + void visit( Face& face ) const { + functor( face ); + } }; template @@ -3723,15 +3710,15 @@ inline const Functor& Brush_forEachFace( Brush& brush, const Functor& functor ){ template class FaceInstanceVisitAll : public BrushInstanceVisitor { -const Functor& functor; + const Functor& functor; public: -FaceInstanceVisitAll( const Functor& functor ) - : functor( functor ){ -} + FaceInstanceVisitAll( const Functor& functor ) + : functor( functor ){ + } -void visit( FaceInstance& face ) const { - functor( face ); -} + void visit( FaceInstance& face ) const { + functor( face ); + } }; template @@ -3750,33 +3737,33 @@ template class InstanceIfVisible : public Functor { public: -InstanceIfVisible( const Functor& functor ) : Functor( functor ){ -} + InstanceIfVisible( const Functor& functor ) : Functor( functor ){ + } -void operator()( scene::Instance& instance ){ - if ( instance.path().top().get().visible() ) { - Functor::operator()( instance ); + void operator()( scene::Instance& instance ){ + if ( instance.path().top().get().visible() ) { + Functor::operator()( instance ); + } } -} }; template class BrushVisibleWalker : public scene::Graph::Walker { -const Functor& m_functor; + const Functor& m_functor; public: -BrushVisibleWalker( const Functor& functor ) : m_functor( functor ){ -} + BrushVisibleWalker( const Functor& functor ) : m_functor( functor ){ + } -bool pre( const scene::Path& path, scene::Instance& instance ) const { - if ( path.top().get().visible() ) { - BrushInstance* brush = Instance_getBrush( instance ); - if ( brush != 0 ) { - m_functor( *brush ); + bool pre( const scene::Path& path, scene::Instance& instance ) const { + if ( path.top().get().visible() ) { + BrushInstance* brush = Instance_getBrush( instance ); + if ( brush != 0 ) { + m_functor( *brush ); + } } + return true; } - return true; -} }; template @@ -3813,14 +3800,14 @@ inline const Functor& Scene_ForEachSelectedBrush_ForEachFaceInstance( scene::Gra template class FaceVisitorWrapper { -const Functor& functor; + const Functor& functor; public: -FaceVisitorWrapper( const Functor& functor ) : functor( functor ){ -} + FaceVisitorWrapper( const Functor& functor ) : functor( functor ){ + } -void operator()( FaceInstance& faceInstance ) const { - functor( faceInstance.getFace() ); -} + void operator()( FaceInstance& faceInstance ) const { + functor( faceInstance.getFace() ); + } }; template diff --git a/radiant/mru.cpp b/radiant/mru.cpp index 37fd9a17..798e7f5e 100644 --- a/radiant/mru.cpp +++ b/radiant/mru.cpp @@ -36,12 +36,12 @@ const int MRU_MAX = 4; namespace { -GtkMenuItem *MRU_items[MRU_MAX]; -std::size_t MRU_used; -typedef CopiedString MRU_filename_t; -MRU_filename_t MRU_filenames[MRU_MAX]; -typedef const char* MRU_key_t; -MRU_key_t MRU_keys[MRU_MAX] = { "File0", "File1", "File2", "File3" }; + GtkMenuItem *MRU_items[MRU_MAX]; + std::size_t MRU_used; + typedef CopiedString MRU_filename_t; + MRU_filename_t MRU_filenames[MRU_MAX]; + typedef const char* MRU_key_t; + MRU_key_t MRU_keys[MRU_MAX] = { "File0", "File1", "File2", "File3" }; } inline const char* MRU_GetText( std::size_t index ){ @@ -50,28 +50,30 @@ inline const char* MRU_GetText( std::size_t index ){ class EscapedMnemonic { -StringBuffer m_buffer; +private: + StringBuffer m_buffer; + public: -EscapedMnemonic( std::size_t capacity ) : m_buffer( capacity ){ - m_buffer.push_back( '_' ); -} -const char* c_str() const { - return m_buffer.c_str(); -} -void push_back( char c ){ // not escaped - m_buffer.push_back( c ); -} -std::size_t write( const char* buffer, std::size_t length ){ - for ( const char* end = buffer + length; buffer != end; ++buffer ) - { - if ( *buffer == '_' ) { - m_buffer.push_back( '_' ); - } + EscapedMnemonic( std::size_t capacity ) : m_buffer( capacity ){ + m_buffer.push_back( '_' ); + } + const char* c_str() const { + return m_buffer.c_str(); + } + void push_back( char c ){ // not escaped + m_buffer.push_back( c ); + } + std::size_t write( const char* buffer, std::size_t length ){ + for ( const char* end = buffer + length; buffer != end; ++buffer ) + { + if ( *buffer == '_' ) { + m_buffer.push_back( '_' ); + } - m_buffer.push_back( *buffer ); + m_buffer.push_back( *buffer ); + } + return length; } - return length; -} }; template @@ -173,16 +175,18 @@ void MRU_Activate( std::size_t index ){ class LoadMRU { -std::size_t m_number; +private: + std::size_t m_number; + public: -LoadMRU( std::size_t number ) - : m_number( number ){ -} -void load(){ - if ( ConfirmModified( "Open Map" ) ) { - MRU_Activate( m_number - 1 ); + LoadMRU( std::size_t number ) + : m_number( number ){ + } + void load(){ + if ( ConfirmModified( "Open Map" ) ) { + MRU_Activate( m_number - 1 ); + } } -} }; typedef MemberCaller LoadMRUCaller; -- 2.39.2