FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 IPather;
48  class Object;
49 
53  class Model: public FifeClass {
54  public:
55 
59  Model(RenderBackend* renderbackend, const std::vector<RendererBase*>& renderers);
60 
64  ~Model();
65 
69  Map* createMap(const std::string& identifier);
70 
73  void deleteMap(Map*);
74 
77  const std::list<Map*>& getMaps() const { return m_maps; }
78 
83  Map* getMap(const std::string& identifier) const;
84 
87  uint32_t getMapCount() const;
88 
91  void deleteMaps();
92 
96 
99  std::list<std::string> getNamespaces() const;
100 
108  Object* createObject(const std::string& identifier, const std::string& name_space, Object* parent=0);
109 
113  bool deleteObject(Object*);
114 
118  bool deleteObjects();
119 
122  Object* getObject(const std::string& id, const std::string& name_space);
123 
126  std::list<Object*> getObjects(const std::string& name_space) const;
127 
130  void adoptPather(IPather* pather);
131 
134  IPather* getPather(const std::string& pathername);
135 
138  void adoptCellGrid(CellGrid* grid);
139 
142  CellGrid* getCellGrid(const std::string& gridtype);
143 
146  void update();
147 
152  void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); }
153 
156  double getTimeMultiplier() const { return m_timeprovider.getMultiplier(); }
157 
158  private:
159 
160  std::list<Map*> m_maps;
161 
162  typedef std::map<std::string,Object*> objectmap_t;
163  typedef std::pair<std::string,objectmap_t> namespace_t;
164  std::list<namespace_t> m_namespaces;
165 
168 
170  namespace_t* selectNamespace(const std::string& name_space);
171 
173  const namespace_t* selectNamespace(const std::string& name_space) const;
174 
175  std::vector<IPather*> m_pathers;
176  std::vector<CellGrid*> m_created_grids;
177  std::vector<CellGrid*> m_adopted_grids;
178  //std::vector<CellGrid*> m_created_grids;
180 
182 
183  std::vector<RendererBase*> m_renderers;
184  };
185 
186 }; //FIFE
187 #endif
std::list< std::string > getNamespaces() const
Get a list of namespaces currently referenced by objects in the metamodel.
Definition: model.cpp:149
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:110
double getTimeMultiplier() const
Gets model speed.
Definition: model.h:156
void adoptCellGrid(CellGrid *grid)
Adds cellgrid to model.
Definition: model.cpp:92
std::vector< CellGrid * > m_adopted_grids
Definition: model.h:177
void setMultiplier(float multiplier)
With multiplier, you can adjust the time speed.
RenderBackend * m_renderbackend
Definition: model.h:181
bool deleteObjects()
Attempt to remove all objects from the model Fails and returns false if any maps with instances are p...
Definition: model.cpp:210
const std::list< Map * > & getMaps() const
Get all the maps in the model.
Definition: model.h:77
namespace_t * m_last_namespace
Used to remember last 'selected' namespace.
Definition: model.h:167
Object class.
Definition: object.h:51
std::vector< IPather * > m_pathers
Definition: model.h:175
Object * createObject(const std::string &identifier, const std::string &name_space, Object *parent=0)
Add an object to the metamodel.
Definition: model.cpp:158
uint32_t getActiveCameraCount() const
Return the number of enabled cameras in this model.
Definition: model.cpp:140
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:280
std::vector< RendererBase * > m_renderers
Definition: model.h:183
void setTimeMultiplier(float multip)
Sets speed for the model.
Definition: model.h:152
std::list< namespace_t > m_namespaces
Definition: model.h:164
float getMultiplier() const
void deleteMaps()
Removes all maps from this model.
Definition: model.cpp:135
uint32_t getMapCount() const
Return the number of maps in this model.
Definition: model.cpp:131
A model is a facade for everything in the model.
Definition: model.h:53
std::list< Map * > m_maps
Definition: model.h:160
CellGrid * getCellGrid(const std::string &gridtype)
Returns new copy of cellgrid corresponding given name.
Definition: model.cpp:96
~Model()
Destructor.
Definition: model.cpp:55
Model(RenderBackend *renderbackend, const std::vector< RendererBase * > &renderers)
Constructor.
Definition: model.cpp:47
namespace_t * selectNamespace(const std::string &name_space)
Convenience function to retrieve a pointer to a namespace or NULL if it doesn't exist.
Definition: model.cpp:266
TimeProvider m_timeprovider
Definition: model.h:179
void deleteMap(Map *)
Remove a map from this model.
Definition: model.cpp:120
IPather * getPather(const std::string &pathername)
Returns pather corresponding given name.
Definition: model.cpp:81
void adoptPather(IPather *pather)
Adds pather to model.
Definition: model.cpp:77
std::pair< std::string, objectmap_t > namespace_t
Definition: model.h:163
Object * getObject(const std::string &id, const std::string &name_space)
Get an object by its id.
Definition: model.cpp:233
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:178
A container of Layer(s).
Definition: map.h:88
std::vector< CellGrid * > m_created_grids
Definition: model.h:176
unsigned int uint32_t
Definition: core.h:40
std::map< std::string, Object * > objectmap_t
Definition: model.h:162
std::list< Object * > getObjects(const std::string &name_space) const
Get all the objects in the given namespace.
Definition: model.cpp:243
Map * createMap(const std::string &identifier)
Add a map this model, and get a pointer to it.
Definition: model.cpp:64