comparison engine/core/model/model.h @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 112fc4af772d
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
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 modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, 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
28 // 3rd party library includes
29
30 // FIFE includes
31 // These includes are split up in two parts, separated by one empty line
32 // First block: files included from the FIFE root src directory
33 // Second block: files included from the same folder
34 #include "util/base/fifeclass.h"
35
36 #include "model/structures/map.h"
37 #include "model/metamodel/timeprovider.h"
38
39 namespace FIFE {
40
41 class MetaModel;
42 class AbstractPather;
43 class Object;
44
45 /**
46 * A model is a facade for everything in the model.
47 */
48 class Model: public FifeClass {
49 public:
50
51 /** Constructor
52 *
53 */
54 Model();
55
56 /** Destructor
57 *
58 */
59 ~Model();
60
61 /** Add a map this model, and get a pointer to it.
62 * The returned pointer is owned by the Model, so don't delete it!
63 */
64 Map* createMap(const std::string& identifier);
65
66 /** Remove a map from this model
67 */
68 void deleteMap(Map*);
69
70 /** Get all the maps in the model.
71 */
72 const std::list<Map*>& getMaps() const { return m_maps; }
73
74 /** Get a map.
75 *
76 * @param identifier the id of the map to be found.
77 */
78 Map* getMap(const std::string& identifier) const;
79
80 /** Return the number of maps in this model
81 */
82 size_t getNumMaps() const;
83
84 /** Remove all elevations from a map
85 */
86 void deleteMaps();
87
88 /** Get a list of namespaces currently referenced by objects in the metamodel.
89 */
90 std::list<std::string> getNamespaces() const;
91
92 /** Add an object to the metamodel.
93 *
94 * @param identifier A string for identifying this object; must be unique for its namespace.
95 * @param parent Objects may optionally inherit values from a parent object.
96 * @note This object belongs to the model, so don't delete the returned pointer
97 */
98 Object* createObject(const std::string& identifier, const std::string& name_space, Object* parent=0);
99
100 /** Get an object by its id. If no namespace is specified, the namespaces are searched in order
101 * and the first matching object is returned. Returns 0 if object is not found.
102 */
103 Object* getObject(const std::string& id, const std::string& name_space);
104
105 /** Get all the objects in the given namespace.
106 */
107 const std::list<Object*>& getObjects(const std::string& name_space) const;
108
109 /** Adds pather to model. Moves ownership to model
110 */
111 void adoptPather(AbstractPather* pather);
112
113 /** Returns pather corresponding given name. If none found, returns NULL
114 */
115 AbstractPather* getPather(const std::string& pathername);
116
117 /** Called periodically to update events on model
118 */
119 void update();
120
121 /** Sets speed for the model. With speed 1.0, everything runs with normal speed.
122 * With speed 2.0, clock is ticking twice as fast. With 0, everything gets paused.
123 * Negavtive values are not supported (throws NotSupported exception).
124 */
125 void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); }
126
127 /** Gets model speed. @see setTimeMultiplier.
128 */
129 double getTimeMultiplier() const { return m_timeprovider.getMultiplier(); }
130
131 private:
132
133 std::list<Map*> m_maps;
134
135 typedef std::pair<std::string, std::list<Object*> > namespace_t;
136 std::list<namespace_t> m_namespaces;
137
138 std::vector<AbstractPather*> m_pathers;
139 TimeProvider m_timeprovider;
140 };
141
142 }; //FIFE
143 #endif