~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/manipulation/EntityRecipe.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Interface: EntityRecipe
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Alexey Torkhov <atorkhov@gmail.com>, (C) 2008
 
8
//
 
9
// This program is free software; you can redistribute it and/or modify
 
10
// it under the terms of the GNU General Public License as published by
 
11
// the Free Software Foundation; either version 2 of the License, or
 
12
// (at your option) any later version.
 
13
// 
 
14
// This program is distributed in the hope that it will be useful,
 
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
// GNU General Public License for more details.
 
18
// 
 
19
// You should have received a copy of the GNU General Public License
 
20
// along with this program; if not, write to the Free Software
 
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
 
22
//
 
23
#ifndef EMBEROGREENTITYRECIPE_H
 
24
#define EMBEROGREENTITYRECIPE_H
 
25
 
 
26
#include "components/ogre/EmberOgrePrerequisites.h"
 
27
#include "GUIAdapter.h"
 
28
#include "GUIAdapterBindings.h"
 
29
 
 
30
#include "framework/tinyxml/tinyxml.h"
 
31
#include <Atlas/Message/Element.h>
 
32
#include <sigc++/signal.h>
 
33
 
 
34
namespace Eris
 
35
{
 
36
class TypeService;
 
37
}
 
38
 
 
39
namespace EmberOgre {
 
40
 
 
41
typedef std::map<std::string, GUIAdapter*> GUIAdaptersStore;
 
42
typedef std::map<std::string, GUIAdapterBindings*> BindingsStore;
 
43
 
 
44
/**
 
45
 * @brief Resource that stores entity recipes.
 
46
 *
 
47
 * This class is for storing and manipulating with entity recipe.
 
48
 *
 
49
 * @author Alexey Torkhov <atorkhov@gmail.com>
 
50
 */
 
51
class EntityRecipe : public Ogre::Resource {
 
52
 
 
53
friend class XMLEntityRecipeSerializer;
 
54
 
 
55
public:
 
56
        /**
 
57
         * Constructor.
 
58
         */
 
59
        EntityRecipe(Ogre::ResourceManager* creator, const Ogre::String& name, Ogre::ResourceHandle handle,
 
60
                const Ogre::String& group, bool isManual = false, Ogre::ManualResourceLoader* loader = 0);
 
61
 
 
62
        /**
 
63
         * Destructor.
 
64
         */
 
65
        virtual ~EntityRecipe();
 
66
 
 
67
        /**
 
68
         * Implemented from Ogre::Resource.
 
69
         */
 
70
        void loadImpl(void);
 
71
 
 
72
        /**
 
73
         * Implemented from Ogre::Resource.
 
74
         */
 
75
        void unloadImpl(void);
 
76
 
 
77
        /**
 
78
         * Implemented from Ogre::Resource.
 
79
         */
 
80
        size_t calculateSize(void) const;
 
81
 
 
82
        /**
 
83
         * Returns entity type.
 
84
         */
 
85
        const std::string& getEntityType() const;
 
86
 
 
87
        /**
 
88
         * Creates and returns GUI adapter. This used currently by entity recipes parser (XMLEntityRecipeSerializer) for populating entity recipes.
 
89
         */
 
90
        GUIAdapter* createGUIAdapter(const std::string& name, const std::string& type, const std::string& tooltip);
 
91
 
 
92
        /**
 
93
         * Returns named GUI adapter.
 
94
         */
 
95
        GUIAdapter* getGUIAdapter(const std::string& name);
 
96
 
 
97
        /**
 
98
         * Returns list of GUI adapters.
 
99
         */
 
100
        const GUIAdaptersStore& getGUIAdapters();
 
101
 
 
102
        /**
 
103
         * Creates and returns GUI adapter bindings. This used currently by entity recipes parser (XMLEntityRecipeSerializer) for populating entity recipes.
 
104
         */
 
105
        GUIAdapterBindings* createGUIAdapterBindings(const std::string& name);
 
106
 
 
107
        /**
 
108
         * Associate each binding with correspondent placeholders (entity spec nodes).
 
109
         */
 
110
        void associateBindings();
 
111
 
 
112
        /**
 
113
         * @brief Composes an entity.
 
114
         *
 
115
         * Grabs current values from adapters, runs it through Lua function and composes resulting Atlas message.
 
116
         * @param typeService The main eris type service, from which type info will be queried.
 
117
         */
 
118
        Atlas::Message::MapType createEntity(Eris::TypeService& typeService);
 
119
 
 
120
        /**
 
121
         * Sets author.
 
122
         */
 
123
        void setAuthor(const std::string& author);
 
124
 
 
125
        /**
 
126
         * Gets author.
 
127
         */
 
128
        const std::string& getAuthor() const;
 
129
 
 
130
        /**
 
131
         * Sets description.
 
132
         */
 
133
        void setDescription(const std::string& description);
 
134
 
 
135
        /**
 
136
         * Gets description.
 
137
         */
 
138
        const std::string& getDescription() const;
 
139
 
 
140
        /**
 
141
         * Does some test checking.
 
142
         */
 
143
        //void doTest();
 
144
 
 
145
        /**
 
146
         * Emits when value of any of adapters is changed.
 
147
         */
 
148
        sigc::signal<void> EventValueChanged;
 
149
 
 
150
protected:
 
151
        void valueChanged();
 
152
 
 
153
        /**
 
154
         * Author of recipe.
 
155
         */
 
156
        std::string mAuthor;
 
157
 
 
158
        /**
 
159
         * Recipe description.
 
160
         */
 
161
        std::string mDescription;
 
162
 
 
163
        /**
 
164
         * Stores semi-atlas entity spec.
 
165
         */
 
166
        TiXmlElement* mEntitySpec;
 
167
 
 
168
        /**
 
169
         * Entity type.
 
170
         */
 
171
        std::string mEntityType;
 
172
 
 
173
        /**
 
174
         * GUI adapters.
 
175
         */
 
176
        GUIAdaptersStore mGUIAdapters;
 
177
 
 
178
        /**
 
179
         * Script bindings.
 
180
         */
 
181
        BindingsStore mBindings;
 
182
 
 
183
        /**
 
184
         * String that contains Lua script.
 
185
         */
 
186
        std::string mScript;
 
187
 
 
188
        /**
 
189
         * Helper iterator over TinyXml nodes for associateBindings()
 
190
         */
 
191
        class SpecIterator : public TiXmlVisitor
 
192
        {
 
193
        public:
 
194
                SpecIterator(EntityRecipe* recipe);
 
195
                virtual bool Visit(const TiXmlText& elem);
 
196
        private:
 
197
                EntityRecipe* mRecipe;
 
198
        };
 
199
};
 
200
 
 
201
/** Specialisation of SharedPtr to allow SharedPtr to be assigned to EntityRecipePtr 
 
202
@note Has to be a subclass since we need operator=.
 
203
We could templatise this instead of repeating per Resource subclass, 
 
204
except to do so requires a form VC6 does not support i.e.
 
205
ResourceSubclassPtr<T> : public SharedPtr<T>
 
206
*/
 
207
class EntityRecipePtr : public Ogre::SharedPtr<EntityRecipe> 
 
208
{
 
209
public:
 
210
    EntityRecipePtr() : Ogre::SharedPtr<EntityRecipe>() {}
 
211
    explicit EntityRecipePtr(EntityRecipe* rep) : Ogre::SharedPtr<EntityRecipe>(rep) {}
 
212
    EntityRecipePtr(const EntityRecipePtr& r) : Ogre::SharedPtr<EntityRecipe>(r) {} 
 
213
    EntityRecipePtr(const Ogre::ResourcePtr& r) : Ogre::SharedPtr<EntityRecipe>()
 
214
    {
 
215
                // lock & copy other mutex pointer
 
216
                OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
 
217
                {
 
218
                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
 
219
                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
 
220
                        pRep = static_cast<EntityRecipe*>(r.getPointer());
 
221
                        pUseCount = r.useCountPointer();
 
222
                        if (pUseCount)
 
223
                        {
 
224
                                ++(*pUseCount);
 
225
                        }
 
226
                }
 
227
    }
 
228
 
 
229
    /// Operator used to convert a ResourcePtr to a EntityRecipePtr
 
230
    EntityRecipePtr& operator=(const Ogre::ResourcePtr& r)
 
231
    {
 
232
                if (pRep == static_cast<EntityRecipe*>(r.getPointer()))
 
233
                        return *this;
 
234
                release();
 
235
                // lock & copy other mutex pointer
 
236
                OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
 
237
                {
 
238
                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
 
239
                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
 
240
                        pRep = static_cast<EntityRecipe*>(r.getPointer());
 
241
                        pUseCount = r.useCountPointer();
 
242
                        if (pUseCount)
 
243
                        {
 
244
                                ++(*pUseCount);
 
245
                        }
 
246
                }
 
247
                else
 
248
                {
 
249
                        // RHS must be a null pointer
 
250
                        assert(r.isNull() && "RHS must be null if it has no mutex!");
 
251
                        setNull();
 
252
                }
 
253
                return *this;
 
254
    }
 
255
};
 
256
 
 
257
}
 
258
 
 
259
#endif