minor refactoring

This commit is contained in:
Garux
2025-02-12 21:13:34 +05:00
parent 372bf08e79
commit 2abab5904c
4 changed files with 68 additions and 104 deletions
+39 -67
View File
@@ -380,13 +380,9 @@ public:
: m_brushlist( brushlist ){
}
bool pre( const scene::Path& path, scene::Instance& instance ) const {
if ( path.top().get().visible() ) {
Brush* brush = Node_getBrush( path.top() );
if ( brush != 0
&& Instance_isSelected( instance ) ) {
if ( path.top().get().visible() && Instance_isSelected( instance ) )
if ( Brush* brush = Node_getBrush( path.top() ) )
m_brushlist.push_back( brush );
}
}
return true;
}
};
@@ -414,41 +410,28 @@ void post( const scene::Path& path, scene::Instance& instance ) const {
class BrushDeleteSelected : public scene::Graph::Walker
{
scene::Node* m_keepNode;
mutable bool m_eraseParent;
scene::Node* m_world = Map_FindWorldspawn( g_map );
mutable bool m_eraseParent = false;
public:
BrushDeleteSelected( scene::Node* keepNode ): m_keepNode( keepNode ), m_eraseParent( false ){
}
BrushDeleteSelected(): m_keepNode( NULL ), m_eraseParent( false ){
BrushDeleteSelected( scene::Node* keepNode = nullptr ): m_keepNode( keepNode ){
}
bool pre( const scene::Path& path, scene::Instance& instance ) const {
return true;
}
void post( const scene::Path& path, scene::Instance& instance ) const {
//globalOutputStream() << path.size() << '\n';
if ( path.top().get().visible() ) {
Brush* brush = Node_getBrush( path.top() );
if ( brush != 0
if ( Brush* brush = Node_getBrush( path.top() ) ) {
if ( path.top().get().visible()
&& Instance_isSelected( instance )
&& path.size() > 1
&& path.top().get_pointer() != m_keepNode ) {
scene::Node& parent = path.parent();
Path_deleteTop( path );
if( Node_getTraversable( parent )->empty() ){
m_eraseParent = true;
//globalOutputStream() << "Empty node?!.\n";
}
return;
m_eraseParent = Node_getTraversable( parent )->empty();
}
}
if( m_eraseParent && !Node_isPrimitive( path.top() ) && path.size() > 1 ){
//globalOutputStream() << "about to Delete empty node!.\n";
else if( m_eraseParent ){
m_eraseParent = false;
Entity* entity = Node_getEntity( path.top() );
if ( entity != 0 && path.top().get_pointer() != Map_FindWorldspawn( g_map )
&& Node_getTraversable( path.top() )->empty() && path.top().get_pointer() != m_keepNode ) {
//globalOutputStream() << "now Deleting empty node!.\n";
if ( path.top().get_pointer() != m_world && path.top().get_pointer() != m_keepNode )
Path_deleteTop( path );
}
}
}
};
@@ -605,46 +588,40 @@ class SubtractBrushesFromUnselected : public scene::Graph::Walker
const brush_vector_t& m_brushlist;
std::size_t& m_before;
std::size_t& m_after;
mutable bool m_eraseParent;
mutable bool m_eraseParent = false;
scene::Node* m_world = Map_FindWorldspawn( g_map );
public:
SubtractBrushesFromUnselected( const brush_vector_t& brushlist, std::size_t& before, std::size_t& after )
: m_brushlist( brushlist ), m_before( before ), m_after( after ), m_eraseParent( false ){
: m_brushlist( brushlist ), m_before( before ), m_after( after ){
}
bool pre( const scene::Path& path, scene::Instance& instance ) const {
if ( path.top().get().visible() ) {
return true;
}
return false;
return path.top().get().visible();
}
void post( const scene::Path& path, scene::Instance& instance ) const {
if ( path.top().get().visible() ) {
Brush* brush = Node_getBrush( path.top() );
if ( brush != 0
&& !Instance_isSelected( instance ) ) {
if ( Brush* thebrush = Node_getBrush( path.top() ) ) {
if ( path.top().get().visible() && !Instance_isSelected( instance ) ) {
brush_vector_t buffer[2];
bool swap = false;
Brush* original = new Brush( *brush );
buffer[static_cast<std::size_t>( swap )].push_back( original );
Brush* original = new Brush( *thebrush );
buffer[swap].push_back( original );
for ( const Brush *subbrush : m_brushlist )
{
for ( brush_vector_t::const_iterator i( m_brushlist.begin() ); i != m_brushlist.end(); ++i )
for ( Brush *brush : buffer[swap] )
{
for ( brush_vector_t::iterator j( buffer[static_cast<std::size_t>( swap )].begin() ); j != buffer[static_cast<std::size_t>( swap )].end(); ++j )
if ( Brush_subtract( *brush, *subbrush, buffer[!swap] ) ) {
delete brush;
}
else
{
if ( Brush_subtract( *( *j ), *( *i ), buffer[static_cast<std::size_t>( !swap )] ) ) {
delete ( *j );
}
else
{
buffer[static_cast<std::size_t>( !swap )].push_back( ( *j ) );
}
buffer[!swap].push_back( brush );
}
buffer[static_cast<std::size_t>( swap )].clear();
swap = !swap;
}
buffer[swap].clear();
swap = !swap;
}
brush_vector_t& out = buffer[static_cast<std::size_t>( swap )];
brush_vector_t& out = buffer[swap];
if ( out.size() == 1 && out.back() == original ) {
delete original;
@@ -652,35 +629,30 @@ public:
else
{
++m_before;
for ( brush_vector_t::const_iterator i = out.begin(); i != out.end(); ++i )
for ( Brush *brush : out )
{
++m_after;
( *i )->removeEmptyFaces();
if ( !( *i )->empty() ) {
brush->removeEmptyFaces();
if ( !brush->empty() ) {
NodeSmartReference node( ( new BrushNode() )->node() );
Node_getBrush( node )->copy( *( *i ) );
delete ( *i );
Node_getBrush( node )->copy( *brush );
delete brush;
Node_getTraversable( path.parent() )->insert( node );
}
else{
delete ( *i );
delete brush;
}
}
scene::Node& parent = path.parent();
Path_deleteTop( path );
if( Node_getTraversable( parent )->empty() ){
m_eraseParent = true;
}
m_eraseParent = Node_getTraversable( parent )->empty();
}
}
}
if( m_eraseParent && !Node_isPrimitive( path.top() ) && path.size() > 1 ){
else if( m_eraseParent ){
m_eraseParent = false;
Entity* entity = Node_getEntity( path.top() );
if ( entity != 0 && path.top().get_pointer() != Map_FindWorldspawn( g_map )
&& Node_getTraversable( path.top() )->empty() ) {
if ( path.top().get_pointer() != m_world )
Path_deleteTop( path );
}
}
}
};
@@ -703,8 +675,8 @@ void CSG_Subtract(){
std::size_t after = 0;
GlobalSceneGraph().traverse( SubtractBrushesFromUnselected( selected_brushes, before, after ) );
globalOutputStream() << "CSG Subtract: Result: "
<< after << " fragment" << ( after == 1 ? "" : "s" )
<< " from " << before << " brush" << ( before == 1 ? "" : "es" ) << ".\n";
<< after << ( after == 1 ? " fragment" : " fragments" )
<< " from " << before << ( before == 1 ? " brush.\n" : " brushes.\n" );
SceneChangeNotify();
}
+8 -7
View File
@@ -383,13 +383,14 @@ void Entity_createFromSelection( const char* name, const Vector3& origin ){
return;
}
#else
const scene::Node* world_node = Map_FindWorldspawn( g_map );
if ( world_node && string_equal( name, "worldspawn" ) ) {
// GlobalRadiant().m_pfnMessageBox( MainFrame_getWindow(), "There's already a worldspawn in your map!", "Info", EMessageBoxType::Info, 0 );
UndoableCommand undo( "ungroupSelectedPrimitives" );
Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), Map_FindOrInsertWorldspawn( g_map ) ); //=no action, if no worldspawn (but one inserted) (since insertion deselects everything)
//Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), *Map_FindWorldspawn( g_map ) ); = crash, if no worldspawn
return;
if ( string_equal( name, "worldspawn" ) ) {
// only process if worldspawn is present
// Map_FindOrInsertWorldspawn( g_map ) ) would be no action (since worldspawn insertion deselects everything)
if( scene::Node* world_node = Map_FindWorldspawn( g_map ) ){
UndoableCommand undo( "ungroupSelectedPrimitives" );
Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), *world_node );
return;
}
}
#endif
+4 -4
View File
@@ -1611,10 +1611,10 @@ bool Map_SaveSelected( const char* filename ){
class ParentSelectedBrushesToEntityWalker : public scene::Graph::Walker
{
scene::Node& m_parent;
scene::Node* m_world;
mutable bool m_emptyOldParent;
scene::Node* m_world = Map_FindWorldspawn( g_map );
mutable bool m_emptyOldParent = false;
public:
ParentSelectedBrushesToEntityWalker( scene::Node& parent ) : m_parent( parent ), m_world( Map_FindWorldspawn( g_map ) ), m_emptyOldParent( false ){
ParentSelectedBrushesToEntityWalker( scene::Node& parent ) : m_parent( parent ){
}
bool pre( const scene::Path& path, scene::Instance& instance ) const {
return path.top().get_pointer() != &m_parent; /* skip traverse of target node */
@@ -1631,7 +1631,7 @@ public:
}
else if ( m_emptyOldParent ){
m_emptyOldParent = false;
if ( Node_isEntity( path.top() ) && path.top().get_pointer() != m_world && Node_getTraversable( path.top() )->empty() ) /* delete empty entity left */
if ( path.top().get_pointer() != m_world ) /* delete empty entity left */
Path_deleteTop( path );
}
}
+17 -26
View File
@@ -241,9 +241,8 @@ public:
m_removedChild = false;
// delete empty entities
Entity* entity = Node_getEntity( path.top() );
if ( entity != 0
&& path.top().get_pointer() != Map_FindWorldspawn( g_map )
if ( Node_isEntity( path.top() )
&& path.top().get_pointer() != Map_FindWorldspawn( g_map ) // direct worldspawn deletion is permitted, so do find it each time
&& Node_getTraversable( path.top() )->empty() ) {
Path_deleteTop( path );
}
@@ -334,11 +333,9 @@ void Select_Invert(){
//interesting printings
class ExpandSelectionToEntitiesWalker_dbg : public scene::Graph::Walker
{
mutable std::size_t m_depth;
const scene::Node* m_world;
mutable std::size_t m_depth = 0;
const scene::Node* m_world = Map_FindWorldspawn( g_map );
public:
ExpandSelectionToEntitiesWalker_dbg() : m_depth( 0 ), m_world( Map_FindWorldspawn( g_map ) ){
}
bool pre( const scene::Path& path, scene::Instance& instance ) const {
++m_depth;
globalOutputStream() << "pre depth_" << m_depth;
@@ -385,11 +382,9 @@ public:
class ExpandSelectionToPrimitivesWalker : public scene::Graph::Walker
{
mutable std::size_t m_depth;
const scene::Node* m_world;
mutable std::size_t m_depth = 0;
const scene::Node* m_world = Map_FindWorldspawn( g_map );
public:
ExpandSelectionToPrimitivesWalker() : m_depth( 0 ), m_world( Map_FindWorldspawn( g_map ) ){
}
bool pre( const scene::Path& path, scene::Instance& instance ) const {
++m_depth;
@@ -426,11 +421,9 @@ void Scene_ExpandSelectionToPrimitives(){
class ExpandSelectionToEntitiesWalker : public scene::Graph::Walker
{
mutable std::size_t m_depth;
const scene::Node* m_world;
mutable std::size_t m_depth = 0;
const scene::Node* m_world = Map_FindWorldspawn( g_map );
public:
ExpandSelectionToEntitiesWalker() : m_depth( 0 ), m_world( Map_FindWorldspawn( g_map ) ){
}
bool pre( const scene::Path& path, scene::Instance& instance ) const {
++m_depth;
@@ -731,10 +724,9 @@ template<typename EntityMatcher>
class EntityFindByPropertyValueWalker : public scene::Graph::Walker
{
const EntityMatcher& m_entityMatcher;
const scene::Node* m_world;
const scene::Node* m_world = Map_FindWorldspawn( g_map );
public:
EntityFindByPropertyValueWalker( const EntityMatcher& entityMatcher )
: m_entityMatcher( entityMatcher ), m_world( Map_FindWorldspawn( g_map ) ){
EntityFindByPropertyValueWalker( const EntityMatcher& entityMatcher ) : m_entityMatcher( entityMatcher ){
}
bool pre( const scene::Path& path, scene::Instance& instance ) const {
if( !path.top().get().visible() ){
@@ -777,14 +769,13 @@ class EntityGetSelectedPropertyValuesWalker : public scene::Graph::Walker
{
PropertyValues& m_propertyvalues;
const char *m_prop;
const scene::Node* m_world;
const scene::Node* m_world = Map_FindWorldspawn( g_map );
public:
EntityGetSelectedPropertyValuesWalker( const char *prop, PropertyValues& propertyvalues )
: m_propertyvalues( propertyvalues ), m_prop( prop ), m_world( Map_FindWorldspawn( g_map ) ){
: m_propertyvalues( propertyvalues ), m_prop( prop ){
}
bool pre( const scene::Path& path, scene::Instance& instance ) const {
Entity* entity = Node_getEntity( path.top() );
if ( entity != 0 ){
if ( Entity* entity = Node_getEntity( path.top() ) ){
if( path.top().get_pointer() != m_world ){
if ( Instance_isSelected( instance ) || instance.childSelected() ) {
if ( !propertyvalues_contain( m_propertyvalues, entity->getKeyValue( m_prop ) ) ) {
@@ -1235,10 +1226,10 @@ void MoveToCamera(){
class CloneSelected : public scene::Graph::Walker
{
const bool m_makeUnique;
const scene::Node* m_world;
const scene::Node* m_world = Map_FindWorldspawn( g_map );
public:
mutable std::vector<scene::Node*> m_cloned;
CloneSelected( bool makeUnique ) : m_makeUnique( makeUnique ), m_world( Map_FindWorldspawn( g_map ) ){
CloneSelected( bool makeUnique ) : m_makeUnique( makeUnique ){
}
bool pre( const scene::Path& path, scene::Instance& instance ) const {
if ( path.size() == 1 ) {
@@ -1771,10 +1762,10 @@ class EntityGetSelectedPropertyValuesWalker_nonEmpty : public scene::Graph::Walk
{
PropertyValues& m_propertyvalues;
const char *m_prop;
const scene::Node* m_world;
const scene::Node* m_world = Map_FindWorldspawn( g_map );
public:
EntityGetSelectedPropertyValuesWalker_nonEmpty( const char *prop, PropertyValues& propertyvalues )
: m_propertyvalues( propertyvalues ), m_prop( prop ), m_world( Map_FindWorldspawn( g_map ) ){
: m_propertyvalues( propertyvalues ), m_prop( prop ){
}
bool pre( const scene::Path& path, scene::Instance& instance ) const {
Entity* entity = Node_getEntity( path.top() );