MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
terrainmanager.cpp
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 
41 #ifndef terrainmanager_cpp
42 #define terrainmanager_cpp
43 
44 #include <vector>
45 
46 #include "terrainmanager.h"
47 #include "meshterrain.h"
48 
49 namespace Mezzanine
50 {
52  {
53  }
54 
56  {
57  /// @todo This class currently doesn't initialize anything from XML, if that changes this constructor needs to be expanded.
58  }
59 
61  {
62  this->Deinitialize();
63  this->DestroyAllTerrains();
64  }
65 
67  {
68  return Terrains.at(Index);
69  }
70 
72  {
73  for( std::vector<TerrainBase*>::iterator it = Terrains.begin(); it != Terrains.end(); ++it )
74  {
75  if( Name == (*it)->GetName() )
76  return (*it);
77  }
78  return NULL;
79  }
80 
82  {
83  return Terrains.size();
84  }
85 
87  {
88  Terrains.push_back(Terrain);
89  Terrain->AddToWorld();
90  }
91 
93  {
94  std::vector<TerrainBase*>::iterator it = Terrains.begin() + Index;
95  (*it)->RemoveFromWorld();
96  Terrains.erase(it);
97  }
98 
100  {
101  for( std::vector<TerrainBase*>::iterator it = Terrains.begin() ; it != Terrains.end() ; ++it )
102  {
103  if(ToBeRemoved == (*it))
104  {
105  (*it)->RemoveFromWorld();
106  Terrains.erase(it);
107  return;
108  }
109  }
110  }
111 
113  {
114  /// @todo When adding more types of terrains, it should be remembered that code should be added to clear the extra vectors.
115  if( Terrains.empty() )
116  return;
117  for( std::vector<TerrainBase*>::iterator it = Terrains.begin() ; it != Terrains.end() ; ++it )
118  (*it)->RemoveFromWorld();
119  Terrains.clear();
120  }
121 
123  {
124  std::vector<TerrainBase*>::iterator it = Terrains.begin() + Index;
125  (*it)->RemoveFromWorld();
126  delete (*it);
127  Terrains.erase(it);
128  }
129 
131  {
132  for( std::vector<TerrainBase*>::iterator it = Terrains.begin() ; it != Terrains.end() ; ++it )
133  {
134  if(ToBeDestroyed == (*it))
135  {
136  (*it)->RemoveFromWorld();
137  delete (*it);
138  Terrains.erase(it);
139  return;
140  }
141  }
142  }
143 
145  {
146  if( Terrains.empty() )
147  return;
148  for( std::vector<TerrainBase*>::iterator it = Terrains.begin() ; it != Terrains.end() ; ++it )
149  {
150  (*it)->RemoveFromWorld();
151  delete (*it);
152  }
153  Terrains.clear();
154  }
155 
156  MeshTerrain* TerrainManager::CreateMeshTerrain(const Vector3& InitPosition, const String& name, const String& file, const String& group)
157  {
158  /*MeshTerrain* Terrain = new MeshTerrain(InitPosition, name, file, group);
159  Terrains.push_back(Terrain);
160  Terrain->AddTerrainToWorld();
161  return Terrain;//*/
162  return NULL;
163  }
164 
165  ///////////////////////////////////////////////////////////////////////////////
166  // HeightfieldTerrain Management
167 
168  ///////////////////////////////////////////////////////////////////////////////
169  // VectorfieldTerrain Management
170 
171  ///////////////////////////////////////////////////////////////////////////////
172  // Utility
173 
175  {
176  // Do nothing currently
177  }
178 
180  {
181  if( !this->Initialized )
182  {
183  //WorldManager::Initialize();
184 
185  this->Initialized = true;
186  }
187  }
188 
190  {
191  if( this->Initialized )
192  {
193  this->Initialized = false;
194  }
195  }
196 
197  ///////////////////////////////////////////////////////////////////////////////
198  // Type Identifier Methods
199 
201  { return ManagerBase::MT_TerrainManager; }
202 
204  { return "DefaultTerrainManager"; }
205 
206  ///////////////////////////////////////////////////////////////////////////////
207  // DefaultTerrainManagerFactory Methods
208 
210  {
211  }
212 
214  {
215  }
216 
218  {
219  return "DefaultTerrainManager";
220  }
221 
223  {
224  return new TerrainManager();
225  }
226 
228  {
229  return new TerrainManager(XMLNode);
230  }
231 
233  {
234  delete ToBeDestroyed;
235  }
236 }//Mezzanine
237 
238 #endif