Spinning Topp Logo BlackTopp Studios
inc
terrainmanager.cpp
1 // © Copyright 2010 - 2016 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 {
51  const String TerrainManager::ImplementationName = "DefaultTerrainManager";
52  const ManagerBase::ManagerType TerrainManager::InterfaceType = ManagerBase::MT_TerrainManager;
53 
55  WorldManager(Creator)
56  { }
57 
58  TerrainManager::TerrainManager(World* Creator, const XML::Node& XMLNode) :
59  WorldManager(Creator)
60  {
61  /// @todo This class currently doesn't initialize anything from XML, if that changes this constructor needs to be expanded.
62  }
63 
65  {
66  this->Deinitialize();
67  this->DestroyAllTerrains();
68  }
69 
71  {
72  return Terrains.at(Index);
73  }
74 
76  {
77  for( std::vector<TerrainBase*>::iterator it = Terrains.begin(); it != Terrains.end(); ++it )
78  {
79  if( Name == (*it)->GetName() )
80  return (*it);
81  }
82  return NULL;
83  }
84 
86  {
87  return Terrains.size();
88  }
89 
91  {
92  Terrains.push_back(Terrain);
93  Terrain->AddToWorld();
94  }
95 
97  {
98  std::vector<TerrainBase*>::iterator it = Terrains.begin() + Index;
99  (*it)->RemoveFromWorld();
100  Terrains.erase(it);
101  }
102 
104  {
105  for( std::vector<TerrainBase*>::iterator it = Terrains.begin() ; it != Terrains.end() ; ++it )
106  {
107  if(ToBeRemoved == (*it))
108  {
109  (*it)->RemoveFromWorld();
110  Terrains.erase(it);
111  return;
112  }
113  }
114  }
115 
117  {
118  /// @todo When adding more types of terrains, it should be remembered that code should be added to clear the extra vectors.
119  if( Terrains.empty() )
120  return;
121  for( std::vector<TerrainBase*>::iterator it = Terrains.begin() ; it != Terrains.end() ; ++it )
122  (*it)->RemoveFromWorld();
123  Terrains.clear();
124  }
125 
127  {
128  std::vector<TerrainBase*>::iterator it = Terrains.begin() + Index;
129  (*it)->RemoveFromWorld();
130  delete (*it);
131  Terrains.erase(it);
132  }
133 
135  {
136  for( std::vector<TerrainBase*>::iterator it = Terrains.begin() ; it != Terrains.end() ; ++it )
137  {
138  if(ToBeDestroyed == (*it))
139  {
140  (*it)->RemoveFromWorld();
141  delete (*it);
142  Terrains.erase(it);
143  return;
144  }
145  }
146  }
147 
149  {
150  if( Terrains.empty() )
151  return;
152  for( std::vector<TerrainBase*>::iterator it = Terrains.begin() ; it != Terrains.end() ; ++it )
153  {
154  (*it)->RemoveFromWorld();
155  delete (*it);
156  }
157  Terrains.clear();
158  }
159 
160  MeshTerrain* TerrainManager::CreateMeshTerrain(const Vector3& InitPosition, const String& name, const String& file, const String& group)
161  {
162  /*MeshTerrain* Terrain = new MeshTerrain(InitPosition, name, file, group);
163  Terrains.push_back(Terrain);
164  Terrain->AddTerrainToWorld();
165  return Terrain;// */
166  return NULL;
167  }
168 
169  ///////////////////////////////////////////////////////////////////////////////
170  // HeightfieldTerrain Management
171 
172  ///////////////////////////////////////////////////////////////////////////////
173  // VectorfieldTerrain Management
174 
175  ///////////////////////////////////////////////////////////////////////////////
176  // Utility
177 
179  {
180  // Do nothing currently
181  }
182 
184  {
185  if( !this->Initialized ) {
186  this->WorldManager::Initialize();
187  this->Initialized = true;
188  }
189  }
190 
192  {
193  if( this->Initialized ) {
194  this->Initialized = false;
195  }
196  }
197 
198  ///////////////////////////////////////////////////////////////////////////////
199  // Type Identifier Methods
200 
203 
206 
207  ///////////////////////////////////////////////////////////////////////////////
208  // DefaultTerrainManagerFactory Methods
209 
211  { }
212 
214  { }
215 
218 
221 
223  { return new TerrainManager(Creator); }
224 
226  { return new TerrainManager(Creator,XMLNode); }
227 
229  { delete ToBeDestroyed; }
230 }//Mezzanine
231 
232 #endif
TerrainContainer Terrains
A container of all terrain instances.
virtual Whole GetNumTerrains() const
Gets the number of terrains being stored in this manager.
virtual ~TerrainManager()
Class destructor.
virtual void RemoveTerrain(const Whole &Index)
Removes a terrain from the world and this manager by index.
virtual void AddToWorld()=0
Adds the object to the World.
void DestroyManager(WorldManager *ToBeDestroyed)
Destroys a Manager created by this factory.
ManagerType
A listing of Manager Types.
Definition: managerbase.h:65
WorldManager * CreateManager(World *Creator, const NameValuePairList &Params)
Creates a manager of the type represented by this factory.
static const String ImplementationName
A String containing the name of this manager implementation.
virtual void AddTerrain(TerrainBase *Terrain)
Adds a pre-made terrain to the world and the manager.
String GetManagerImplName() const
Gets the name of the manager that is created by this factory.
virtual void DestroyTerrain(const Whole &Index)
Destroys a terrain and removes it from world.
static const ManagerBase::ManagerType InterfaceType
A ManagerType enum value used to describe the type of interface/functionality this manager provides...
virtual void Initialize()
Configures this manager for use prior to entering the main loop.
virtual ManagerType GetInterfaceType() const
This returns the type of this manager.
virtual void RemoveAllTerrains()
Removes all terrains currently in this manager from the world and the manager.
virtual void Pause(const UInt32 PL)
Sets the pause state of this manager, or has no effect depending on the value passed in...
virtual void DestroyAllTerrains()
Removes and deletes all terrains currently in this manager from the world and the manager...
ManagerBase::ManagerType GetManagerType() const
Gets the type of manager that is created by this factory.
virtual MeshTerrain * CreateMeshTerrain(const Vector3 &InitPosition, const String &name, const String &file, const String &group)
Creates a terrain based on a given mesh.
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
This is manager for terrains and their functions.
This is the base class from which all the terrains inherit.
Definition: terrainbase.h:57
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
virtual TerrainBase * GetTerrainByIndex(const Whole &Index)
Retrieves a MeshTerrain from the list of terrains.
TerrainManager(World *Creator)
Class constructor.
virtual String GetImplementationTypeName() const
This Allows any manager name to be sent to a stream. Primarily used for logging.
std::list< NameValuePair > NameValuePairList
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
Definition: datatypes.h:206
This is the base class for all managers that belong to a single world instance.
Definition: worldmanager.h:55
virtual void Initialize()
Configures this manager for use prior to entering the main loop.
DefaultTerrainManagerFactory()
Class constructor.
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
virtual void Deinitialize()
Removes this manager from any necessary configuration so it can be safely disposed of...
This class represents a world for objects to interact within.
Definition: world.h:74
virtual TerrainBase * GetTerrainByName(const String &Name)
Retrieves a Meshterrain from the list of terrains.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
virtual ~DefaultTerrainManagerFactory()
Class destructor.
Boole Initialized
Simple Boole indicating whether or not this manager has been initialized.
Definition: managerbase.h:111