Debian Codegraph @

engine/core/model/model.h

raw
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"
40 #include "model/metamodel/timeprovider.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
51 /**
52 * A model is a facade for everything in the model.
53 */
54 class Model: public FifeClass {
55 public:
56
57 /** Constructor
58 *
59 */
60 Model(RenderBackend* renderbackend, const std::vector<RendererBase*>& renderers);
61
62 /** Destructor
63 *
64 */
65 ~Model();
66
67 /** Add a map this model, and get a pointer to it.
68 * The returned pointer is owned by the Model, so don't delete it!
69 */
70 Map* createMap(const std::string& identifier);
71
72 /** Remove a map from this model
73 */
74 void deleteMap(Map*);
75
76 /** Get all the maps in the model.
77 */
78 const std::list<Map*>& getMaps() const { return m_maps; }
79
80 /** Get a map.
81 *
82 * @param identifier the id of the map to be found.
83 */
84 Map* getMap(const std::string& identifier) const;
85
86 /** Return the number of maps in this model
87 */
88 uint32_t getMapCount() const;
89
90 /** Removes all maps from this model
91 */
92 void deleteMaps();
93
94 /** Return the number of enabled cameras in this model.
95 */
96 uint32_t getActiveCameraCount() const;
97
98 /** Get a list of namespaces currently referenced by objects in the metamodel.
99 */
100 std::list<std::string> getNamespaces() const;
101
102 /** Add an object to the metamodel.
103 *
104 * @param identifier A string for identifying this object; must be unique for its namespace.
105 * @param name_space A string identifying the namespace this object resides in.
106 * @param parent Objects may optionally inherit values from a parent object.
107 * @note This object belongs to the model, so don't delete the returned pointer
108 */
109 Object* createObject(const std::string& identifier, const std::string& name_space, Object* parent=0);
110
111 /** Attempt to remove an object from the model
112 * Fails and returns false if the object is referenced by an instance.
113 */
114 bool deleteObject(Object*);
115
116 /** Attempt to remove all objects from the model
117 * Fails and returns false if any maps with instances are present.
118 */
119 bool deleteObjects();
120
121 /** Get an object by its id. Returns 0 if object is not found.
122 */
123 Object* getObject(const std::string& id, const std::string& name_space);
124
125 /** Get all the objects in the given namespace.
126 */
127 std::list<Object*> getObjects(const std::string& name_space) const;
128
129 /** Adds pather to model. Moves ownership to model
130 */
131 void adoptPather(IPather* pather);
132
133 /** Returns pather corresponding given name. If none found, returns NULL
134 */
135 IPather* getPather(const std::string& pathername);
136
137 /** Adds cellgrid to model. Moves ownership to model
138 */
139 void adoptCellGrid(CellGrid* grid);
140
141 /** Returns new copy of cellgrid corresponding given name. If none found, returns NULL
142 */
143 CellGrid* getCellGrid(const std::string& gridtype);
144
145 /** Removes cellgrid from model.
146 */
147 void removeCellGrid(CellGrid* grid);
148
149 /** Called periodically to update events on model
150 */
151 void update();
152
153 /** Sets speed for the model. With speed 1.0, everything runs with normal speed.
154 * With speed 2.0, clock is ticking twice as fast. With 0, everything gets paused.
155 * Negavtive values are not supported (throws NotSupported exception).
156 */
157 void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); }
158
159 /** Gets model speed. @see setTimeMultiplier.
160 */
161 double getTimeMultiplier() const { return m_timeprovider.getMultiplier(); }
162
163 private:
164 // Map observer, currently only used to delete CellGrids from deleted layers
165 ModelMapObserver* m_mapObserver;
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
173 /// Used to remember last 'selected' namespace.
174 namespace_t* m_lastNamespace;
175
176 /// Convenience function to retrieve a pointer to a namespace or NULL if it doesn't exist
177 namespace_t* selectNamespace(const std::string& name_space);
178
179 /// Convenience function to retrieve a pointer to a namespace or NULL if it doesn't exist
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
186 TimeProvider m_timeprovider;
187
188 RenderBackend* m_renderbackend;
189
190 std::vector<RendererBase*> m_renderers;
191 };
192
193 }; //FIFE
194 #endif