comparison engine/core/model/metamodel/object.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 90005975cdbb
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_PROTOTYPE_H
23 #define FIFE_PROTOTYPE_H
24
25 // Standard C++ library includes
26 #include <string>
27 #include <map>
28
29 // 3rd party library includes
30
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 #include "util/base/resourceclass.h"
36 #include "util/math/angles.h"
37
38 namespace FIFE {
39
40 class Action;
41 class AbstractPather;
42 class AbstractVisual;
43
44 /** Object class
45 *
46 * Objects describe the properties of objects.
47 * Objects may inherit default values from another object.
48 *
49 */
50 class Object : public ResourceClass {
51 public:
52 /** Constructor
53 * An object may optionally inherit default attributes
54 * from another object. This object may override these
55 * defaults, but it may not CHANGE the inherited values.
56 *
57 * Objects are created by calling addObject from dataset, thus
58 * this method should really be called only by dataset or test code
59 * @see Dataset in model/metamodel/dataset.h for creation
60 * of objects.
61 */
62 Object(const std::string& identifier, const std::string& name_space, Object* inherited=NULL);
63
64 /** Destructor
65 */
66 ~Object();
67
68 const std::string& getId() { return m_id; }
69 const std::string& getNamespace() { return m_namespace; }
70
71 /** Adds new action with given id. In case there is action already
72 * with given id, returns it instead of new object
73 * Action instances are managed by object
74 * @param is_default if true, becomes default action for this object
75 * default objects are used e.g. when showing them on editor.
76 * if multiple default actions are created, last one remains.
77 * In case there's no explicit default action created, first
78 * action created becomes the default
79 */
80 Action* createAction(const std::string& identifier, bool is_default=false);
81
82 /** Gets action with given id. If not found, returns NULL
83 */
84 Action* getAction(const std::string& identifier);
85
86 /** Gets default action assigned to this object. If none available, returns NULL
87 */
88 Action* getDefaultAction() { return m_defaultaction; }
89
90 /** Sets pather used by instances created out of this object
91 */
92 void setPather(AbstractPather* pather);
93
94 /** Gets associated pather
95 */
96 AbstractPather* getPather() { return m_pather; }
97
98 /** Gets an object where this object was inherited from
99 * @see inherited object
100 */
101 Object* getInherited() { return m_inherited; }
102
103 /** Sets visualization to be used. Transfers ownership.
104 */
105 void adoptVisual(AbstractVisual* visual) { m_visual = visual; }
106
107 /** Gets used visualization
108 */
109 template<typename T> T* getVisual() const { return reinterpret_cast<T*>(m_visual); }
110
111 /** Sets if object blocks movement
112 */
113 void setBlocking(bool blocking) { m_blocking = blocking; }
114
115 /** Gets if object blocks movement
116 */
117 bool isBlocking();
118
119 /** Set to true, if object is such that it doesn't move
120 */
121 void setStatic(bool stat) { m_static = stat; }
122
123 /** Gets if object moves
124 */
125 bool isStatic();
126
127
128 private:
129 std::string m_id;
130 std::string m_namespace;
131 Object* m_inherited;
132 std::map<std::string, Action*>* m_actions;
133 bool m_blocking;
134 bool m_static;
135 AbstractPather* m_pather;
136 AbstractVisual* m_visual;
137 Action* m_defaultaction;
138 };
139
140 class ObjectLoader : public ResourceLoader {
141 public:
142 Object* load(const ResourceLocation& location) { return dynamic_cast<Object*>(load(location)); }
143 Object* load(const std::string& filename) { return load(ResourceLocation(filename)); }
144 };
145
146 } //FIFE
147 #endif
148