2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // DMap.cpp: implementation of the DMap class.
22 //////////////////////////////////////////////////////////////////////
38 #include "generic/referencecounted.h"
48 //////////////////////////////////////////////////////////////////////
49 // Construction/Destruction
50 //////////////////////////////////////////////////////////////////////
54 AddEntity( "worldspawn", 0 );
61 DEntity* DMap::AddEntity( char *classname, int ID ){
64 newEntity = new DEntity( classname, m_nNextEntity++ );
67 newEntity = new DEntity( classname, ID );
70 entityList.push_back( newEntity );
75 void DMap::ClearEntities(){
78 for ( std::list<DEntity *>::const_iterator deadEntity = entityList.begin(); deadEntity != entityList.end(); deadEntity++ )
84 DEntity* DMap::GetEntityForID( int ID ){
85 DEntity* findEntity = NULL;
87 for ( std::list<DEntity *>::const_iterator chkEntity = entityList.begin(); chkEntity != entityList.end(); chkEntity++ )
89 if ( ( *chkEntity )->m_nID == ID ) {
90 findEntity = ( *chkEntity );
96 findEntity = AddEntity( "worldspawn", ID );
103 DEntity* DMap::GetWorldSpawn(){
104 return GetEntityForID( 0 );
107 void DMap::BuildInRadiant( bool bAllowDestruction ){
108 for ( std::list<DEntity *>::const_iterator buildEntity = entityList.begin(); buildEntity != entityList.end(); buildEntity++ )
109 ( *buildEntity )->BuildInRadiant( bAllowDestruction );
112 void DMap::LoadAll( bool bLoadPatches ){
115 GlobalSelectionSystem().setSelectedAll( false );
117 class load_entities_t : public scene::Traversable::Walker
122 load_entities_t( DMap* map, bool bLoadPatches )
123 : m_map( map ), m_bLoadPatches( bLoadPatches ){
125 bool pre( scene::Node& node ) const {
126 if ( Node_isEntity( node ) ) {
127 DEntity* loadEntity = m_map->AddEntity( "", 0 );
128 loadEntity->LoadFromEntity( node, m_bLoadPatches );
132 } load_entities( this, bLoadPatches );
134 Node_getTraversable( GlobalSceneGraph().root() )->traverse( load_entities );
137 int DMap::FixBrushes(){
139 for ( std::list<DEntity *>::const_iterator fixEntity = entityList.begin(); fixEntity != entityList.end(); fixEntity++ )
141 count += ( *fixEntity )->FixBrushes();
147 void DMap::ResetTextures( const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName,
148 int bResetTextureName, int bResetScale[2], int bResetShift[2], int bResetRotation ){
149 for ( std::list<DEntity *>::const_iterator texEntity = entityList.begin(); texEntity != entityList.end(); texEntity++ )
151 if ( string_equal_nocase( "worldspawn", ( *texEntity )->m_Classname ) ) {
152 ( *texEntity )->ResetTextures( textureName, fScale, fShift, rotation, newTextureName,
153 bResetTextureName, bResetScale, bResetShift, bResetRotation, true );
157 if ( ( *texEntity )->ResetTextures( textureName, fScale, fShift, rotation, newTextureName,
158 bResetTextureName, bResetScale, bResetShift, bResetRotation, false ) ) {
159 RebuildEntity( *texEntity );
165 void DMap::RebuildEntity( DEntity *ent ){
166 ent->RemoveFromRadiant();
167 ent->BuildInRadiant( false );