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 
95  std::list<std::string> getNamespaces() const;
96 
104  Object* createObject(const std::string& identifier, const std::string& name_space, Object* parent=0);
105 
109  bool deleteObject(Object*);
110 
114  bool deleteObjects();
115 
118  Object* getObject(const std::string& id, const std::string& name_space);
119 
122  std::list<Object*> getObjects(const std::string& name_space) const;
123 
126  void adoptPather(IPather* pather);
127 
130  IPather* getPather(const std::string& pathername);
131 
134  void adoptCellGrid(CellGrid* grid);
135 
138  CellGrid* getCellGrid(const std::string& gridtype);
139 
142  void update();
143 
148  void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); }
149 
152  double getTimeMultiplier() const { return m_timeprovider.getMultiplier(); }
153 
154  private:
155 
156  std::list<Map*> m_maps;
157 
158  typedef std::map<std::string,Object*> objectmap_t;
159  typedef std::pair<std::string,objectmap_t> namespace_t;
160  std::list<namespace_t> m_namespaces;
161 
164 
166  namespace_t* selectNamespace(const std::string& name_space);
167 
169  const namespace_t* selectNamespace(const std::string& name_space) const;
170 
171  std::vector<IPather*> m_pathers;
172  std::vector<CellGrid*> m_created_grids;
173  std::vector<CellGrid*> m_adopted_grids;
174  //std::vector<CellGrid*> m_created_grids;
176 
178 
179  std::vector<RendererBase*> m_renderers;
180  };
181 
182 }; //FIFE
183 #endif
std::list< std::string > getNamespaces() const
Get a list of namespaces currently referenced by objects in the metamodel.
Definition: model.cpp:140
Abstract interface for all the renderbackends.
Definition: renderbackend.h:92
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:152
void adoptCellGrid(CellGrid *grid)
Adds cellgrid to model.
Definition: model.cpp:92
std::vector< CellGrid * > m_adopted_grids
Definition: model.h:173
void setMultiplier(float multiplier)
With multiplier, you can adjust the time speed.
RenderBackend * m_renderbackend
Definition: model.h:177
bool deleteObjects()
Attempt to remove all objects from the model Fails and returns false if any maps with instances are p...
Definition: model.cpp:201
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 &#39;selected&#39; namespace.
Definition: model.h:163
Object class.
Definition: object.h:51
std::vector< IPather * > m_pathers
Definition: model.h:171
Object * createObject(const std::string &identifier, const std::string &name_space, Object *parent=0)
Add an object to the metamodel.
Definition: model.cpp:149
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:271
std::vector< RendererBase * > m_renderers
Definition: model.h:179
void setTimeMultiplier(float multip)
Sets speed for the model.
Definition: model.h:148
std::list< namespace_t > m_namespaces
Definition: model.h:160
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:156
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&#39;t exist.
Definition: model.cpp:257
TimeProvider m_timeprovider
Definition: model.h:175
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:159
Object * getObject(const std::string &id, const std::string &name_space)
Get an object by its id.
Definition: model.cpp:224
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:169
A container of Layer(s).
Definition: map.h:87
std::vector< CellGrid * > m_created_grids
Definition: model.h:172
unsigned int uint32_t
Definition: core.h:40
std::map< std::string, Object * > objectmap_t
Definition: model.h:158
std::list< Object * > getObjects(const std::string &name_space) const
Get all the objects in the given namespace.
Definition: model.cpp:234
Map * createMap(const std::string &identifier)
Add a map this model, and get a pointer to it.
Definition: model.cpp:64