X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=plugins%2Fmapq3%2Fwrite.cpp;h=7a95458644ce22909f52518521b484ce60f064ef;hp=f64bbe548d907b94657c68e39101803e2cabee9f;hb=826fce3cdc0bce78d15c04a2eb0a373dc1b251a3;hpb=bfc8a12a6b315ae261101a34db8ba1b682c67bb7 diff --git a/plugins/mapq3/write.cpp b/plugins/mapq3/write.cpp index f64bbe54..7a954586 100644 --- a/plugins/mapq3/write.cpp +++ b/plugins/mapq3/write.cpp @@ -1,23 +1,23 @@ /* -Copyright (C) 2001-2006, William Joseph. -All Rights Reserved. + Copyright (C) 2001-2006, William Joseph. + All Rights Reserved. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ #include "write.h" @@ -25,9 +25,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "iscriplib.h" #include "scenelib.h" -inline MapExporter* Node_getMapExporter(scene::Node& node) -{ - return NodeTypeCast::cast(node); +inline MapExporter* Node_getMapExporter( scene::Node& node ){ + return NodeTypeCast::cast( node ); } @@ -35,90 +34,79 @@ static std::size_t g_count_entities; static std::size_t g_count_brushes; -void Entity_ExportTokens(const Entity& entity, TokenWriter& writer) -{ - g_count_brushes = 0; - - class WriteKeyValue : public Entity::Visitor - { - TokenWriter& m_writer; - public: - WriteKeyValue(TokenWriter& writer) - : m_writer(writer) - { - } - - void visit(const char* key, const char* value) - { - m_writer.writeString(key); - m_writer.writeString(value); - m_writer.nextLine(); - } - - } visitor(writer); - - entity.forEachKeyValue(visitor); +void Entity_ExportTokens( const Entity& entity, TokenWriter& writer ){ + g_count_brushes = 0; + + class WriteKeyValue : public Entity::Visitor + { + TokenWriter& m_writer; +public: + WriteKeyValue( TokenWriter& writer ) + : m_writer( writer ){ + } + + void visit( const char* key, const char* value ){ + m_writer.writeString( key ); + m_writer.writeString( value ); + m_writer.nextLine(); + } + + } visitor( writer ); + + entity.forEachKeyValue( visitor ); } class WriteTokensWalker : public scene::Traversable::Walker { - mutable Stack m_stack; - TokenWriter& m_writer; - bool m_ignorePatches; +mutable Stack m_stack; +TokenWriter& m_writer; +bool m_ignorePatches; public: - WriteTokensWalker(TokenWriter& writer, bool ignorePatches) - : m_writer(writer), m_ignorePatches(ignorePatches) - { - } - bool pre(scene::Node& node) const - { - m_stack.push(false); - - Entity* entity = Node_getEntity(node); - if(entity != 0) - { - m_writer.writeToken("//"); - m_writer.writeToken("entity"); - m_writer.writeUnsigned(g_count_entities++); - m_writer.nextLine(); - - m_writer.writeToken("{"); - m_writer.nextLine(); - m_stack.top() = true; - - Entity_ExportTokens(*entity, m_writer); - } - else - { - MapExporter* exporter = Node_getMapExporter(node); - if(exporter != 0 - && !(m_ignorePatches && Node_isPatch(node))) - { - m_writer.writeToken("//"); - m_writer.writeToken("brush"); - m_writer.writeUnsigned(g_count_brushes++); - m_writer.nextLine(); - - exporter->exportTokens(m_writer); - } - } - - return true; - } - void post(scene::Node& node) const - { - if(m_stack.top()) - { - m_writer.writeToken("}"); - m_writer.nextLine(); - } - m_stack.pop(); - } +WriteTokensWalker( TokenWriter& writer, bool ignorePatches ) + : m_writer( writer ), m_ignorePatches( ignorePatches ){ +} +bool pre( scene::Node& node ) const { + m_stack.push( false ); + + Entity* entity = Node_getEntity( node ); + if ( entity != 0 ) { + m_writer.writeToken( "//" ); + m_writer.writeToken( "entity" ); + m_writer.writeUnsigned( g_count_entities++ ); + m_writer.nextLine(); + + m_writer.writeToken( "{" ); + m_writer.nextLine(); + m_stack.top() = true; + + Entity_ExportTokens( *entity, m_writer ); + } + else + { + MapExporter* exporter = Node_getMapExporter( node ); + if ( exporter != 0 + && !( m_ignorePatches && Node_isPatch( node ) ) ) { + m_writer.writeToken( "//" ); + m_writer.writeToken( "brush" ); + m_writer.writeUnsigned( g_count_brushes++ ); + m_writer.nextLine(); + + exporter->exportTokens( m_writer ); + } + } + + return true; +} +void post( scene::Node& node ) const { + if ( m_stack.top() ) { + m_writer.writeToken( "}" ); + m_writer.nextLine(); + } + m_stack.pop(); +} }; -void Map_Write(scene::Node& root, GraphTraversalFunc traverse, TokenWriter& writer, bool ignorePatches) -{ - g_count_entities = 0; - traverse(root, WriteTokensWalker(writer, ignorePatches)); +void Map_Write( scene::Node& root, GraphTraversalFunc traverse, TokenWriter& writer, bool ignorePatches ){ + g_count_entities = 0; + traverse( root, WriteTokensWalker( writer, ignorePatches ) ); } -