FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
model.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
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"
40 #include "model/metamodel/timeprovider.h"
41 
42 namespace FIFE {
43 
44  class RenderBackend;
45  class RendererBase;
46  class ImagePool;
47  class AnimationPool;
48  class MetaModel;
49  class AbstractPather;
50  class Object;
51 
55  class Model: public FifeClass {
56  public:
57 
61  Model(RenderBackend* renderbackend, const std::vector<RendererBase*>& renderers,
62  ImagePool* imagepool, AnimationPool* animpool);
63 
67  ~Model();
68 
72  Map* createMap(const std::string& identifier);
73 
76  void deleteMap(Map*);
77 
80  const std::list<Map*>& getMaps() const { return m_maps; }
81 
86  Map* getMap(const std::string& identifier) const;
87 
90  uint32_t getNumMaps() const;
91 
94  void deleteMaps();
95 
98  std::list<std::string> getNamespaces() const;
99 
106  Object* createObject(const std::string& identifier, const std::string& name_space, Object* parent=0);
107 
111  bool deleteObject(Object*);
112 
116  bool deleteObjects();
117 
120  Object* getObject(const std::string& id, const std::string& name_space);
121 
124  std::list<Object*> getObjects(const std::string& name_space) const;
125 
128  void adoptPather(AbstractPather* pather);
129 
132  AbstractPather* getPather(const std::string& pathername);
133 
136  void adoptCellGrid(CellGrid* grid);
137 
140  CellGrid* getCellGrid(const std::string& gridtype);
141 
144  void update();
145 
150  void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); }
151 
154  double getTimeMultiplier() const { return m_timeprovider.getMultiplier(); }
155 
156  private:
157 
158  std::list<Map*> m_maps;
159 
160  typedef std::map<std::string,Object*> objectmap_t;
161  typedef std::pair<std::string,objectmap_t> namespace_t;
162  std::list<namespace_t> m_namespaces;
163 
165  namespace_t* m_last_namespace;
166 
168  namespace_t* selectNamespace(const std::string& name_space);
169 
171  const namespace_t* selectNamespace(const std::string& name_space) const;
172 
173  std::vector<AbstractPather*> m_pathers;
174  std::vector<CellGrid*> m_adopted_grids;
175  std::vector<CellGrid*> m_created_grids;
176  TimeProvider m_timeprovider;
177 
178  RenderBackend* m_renderbackend;
179  ImagePool* m_imagepool;
180  AnimationPool* m_animpool;
181 
182  std::vector<RendererBase*> m_renderers;
183  };
184 
185 }; //FIFE
186 #endif