FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
model.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2006-2011 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_MODEL_H
23 #define FIFE_MODEL_H
24 
25 // Standard C++ library includes
26 #include <list>
27 #include <map>
28 #include <vector>
29 #include <utility>
30 
31 // 3rd party library includes
32 
33 // FIFE includes
34 // These includes are split up in two parts, separated by one empty line
35 // First block: files included from the FIFE root src directory
36 // Second block: files included from the same folder
37 #include "util/base/fifeclass.h"
38 
39 #include "model/structures/map.h"
41 
42 namespace FIFE {
43 
44  class RenderBackend;
45  class RendererBase;
46  class MetaModel;
47  class ModelMapObserver;
48  class IPather;
49  class Object;
50 
54  class Model: public FifeClass {
55  public:
56 
60  Model(RenderBackend* renderbackend, const std::vector<RendererBase*>& renderers);
61 
65  ~Model();
66 
70  Map* createMap(const std::string& identifier);
71 
74  void deleteMap(Map*);
75 
78  const std::list<Map*>& getMaps() const { return m_maps; }
79 
84  Map* getMap(const std::string& identifier) const;
85 
88  uint32_t getMapCount() const;
89 
92  void deleteMaps();
93 
97 
100  std::list<std::string> getNamespaces() const;
101 
109  Object* createObject(const std::string& identifier, const std::string& name_space, Object* parent=0);
110 
114  bool deleteObject(Object*);
115 
119  bool deleteObjects();
120 
123  Object* getObject(const std::string& id, const std::string& name_space);
124 
127  std::list<Object*> getObjects(const std::string& name_space) const;
128 
131  void adoptPather(IPather* pather);
132 
135  IPather* getPather(const std::string& pathername);
136 
139  void adoptCellGrid(CellGrid* grid);
140 
143  CellGrid* getCellGrid(const std::string& gridtype);
144 
147  void removeCellGrid(CellGrid* grid);
148 
151  void update();
152 
157  void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); }
158 
161  double getTimeMultiplier() const { return m_timeprovider.getMultiplier(); }
162 
163  private:
164  // Map observer, currently only used to delete CellGrids from deleted layers
166 
167  std::list<Map*> m_maps;
168 
169  typedef std::map<std::string,Object*> objectmap_t;
170  typedef std::pair<std::string,objectmap_t> namespace_t;
171  std::list<namespace_t> m_namespaces;
172 
174  namespace_t* m_lastNamespace;
175 
177  namespace_t* selectNamespace(const std::string& name_space);
178 
180  const namespace_t* selectNamespace(const std::string& name_space) const;
181 
182  std::vector<IPather*> m_pathers;
183  std::vector<CellGrid*> m_createdGrids;
184  std::vector<CellGrid*> m_adoptedGrids;
185 
187 
189 
190  std::vector<RendererBase*> m_renderers;
191  };
192 
193 }; //FIFE
194 #endif
std::list< std::string > getNamespaces() const
Get a list of namespaces currently referenced by objects in the metamodel.
Definition: model.cpp:196
Abstract interface for all the renderbackends.
Timeprovider is an utility providing time management functionality You can have hierarchy of time pro...
Definition: timeprovider.h:42
Map * getMap(const std::string &identifier) const
Get a map.
Definition: model.cpp:151
double getTimeMultiplier() const
Gets model speed.
Definition: model.h:161
void adoptCellGrid(CellGrid *grid)
Adds cellgrid to model.
Definition: model.cpp:122
void setMultiplier(float multiplier)
With multiplier, you can adjust the time speed.
RenderBackend * m_renderbackend
Definition: model.h:188
bool deleteObjects()
Attempt to remove all objects from the model Fails and returns false if any maps with instances are p...
Definition: model.cpp:257
const std::list< Map * > & getMaps() const
Get all the maps in the model.
Definition: model.h:78
Object class.
Definition: object.h:51
namespace_t * m_lastNamespace
Used to remember last &#39;selected&#39; namespace.
Definition: model.h:174
std::vector< IPather * > m_pathers
Definition: model.h:182
Object * createObject(const std::string &identifier, const std::string &name_space, Object *parent=0)
Add an object to the metamodel.
Definition: model.cpp:205
uint32_t getActiveCameraCount() const
Return the number of enabled cameras in this model.
Definition: model.cpp:187
Base class for all fife classes Used e.g.
Definition: fifeclass.h:42
void update()
Called periodically to update events on model.
Definition: model.cpp:327
std::vector< RendererBase * > m_renderers
Definition: model.h:190
void setTimeMultiplier(float multip)
Sets speed for the model.
Definition: model.h:157
std::vector< CellGrid * > m_createdGrids
Definition: model.h:183
std::vector< CellGrid * > m_adoptedGrids
Definition: model.h:184
std::list< namespace_t > m_namespaces
Definition: model.h:171
float getMultiplier() const
void deleteMaps()
Removes all maps from this model.
Definition: model.cpp:176
uint32_t getMapCount() const
Return the number of maps in this model.
Definition: model.cpp:172
void removeCellGrid(CellGrid *grid)
Removes cellgrid from model.
Definition: model.cpp:139
A model is a facade for everything in the model.
Definition: model.h:54
ModelMapObserver * m_mapObserver
Definition: model.h:165
std::list< Map * > m_maps
Definition: model.h:167
CellGrid * getCellGrid(const std::string &gridtype)
Returns new copy of cellgrid corresponding given name.
Definition: model.cpp:126
~Model()
Destructor.
Definition: model.cpp:78
Model(RenderBackend *renderbackend, const std::vector< RendererBase * > &renderers)
Constructor.
Definition: model.cpp:68
namespace_t * selectNamespace(const std::string &name_space)
Convenience function to retrieve a pointer to a namespace or NULL if it doesn&#39;t exist.
Definition: model.cpp:313
TimeProvider m_timeprovider
Definition: model.h:186
void deleteMap(Map *)
Remove a map from this model.
Definition: model.cpp:161
IPather * getPather(const std::string &pathername)
Returns pather corresponding given name.
Definition: model.cpp:111
void adoptPather(IPather *pather)
Adds pather to model.
Definition: model.cpp:107
std::pair< std::string, objectmap_t > namespace_t
Definition: model.h:170
Object * getObject(const std::string &id, const std::string &name_space)
Get an object by its id.
Definition: model.cpp:280
bool deleteObject(Object *)
Attempt to remove an object from the model Fails and returns false if the object is referenced by an ...
Definition: model.cpp:225
A container of Layer(s).
Definition: map.h:88
unsigned int uint32_t
Definition: core.h:40
std::map< std::string, Object * > objectmap_t
Definition: model.h:169
std::list< Object * > getObjects(const std::string &name_space) const
Get all the objects in the given namespace.
Definition: model.cpp:290
Map * createMap(const std::string &identifier)
Add a map this model, and get a pointer to it.
Definition: model.cpp:93